Skip to content

Commit

Permalink
fix: generate examples for multipart-form (#3253)
Browse files Browse the repository at this point in the history
  • Loading branch information
abvthecity authored Mar 29, 2024
1 parent d68ebb2 commit e91093e
Show file tree
Hide file tree
Showing 34 changed files with 4,767 additions and 711 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ import {
SupportedSdkLanguage
} from "@fern-api/ir-sdk";
import { FernWorkspace } from "@fern-api/workspace-loader";
import { isInlineRequestBody, RawSchemas, visitExampleCodeSampleSchema } from "@fern-api/yaml-schema";
import {
isInlineRequestBody,
parseBytesRequest,
parseRawFileType,
RawSchemas,
visitExampleCodeSampleSchema
} from "@fern-api/yaml-schema";
import { FernFileContext } from "../../FernFileContext";
import { ErrorResolver } from "../../resolvers/ErrorResolver";
import { ExampleResolver } from "../../resolvers/ExampleResolver";
Expand Down Expand Up @@ -342,6 +348,11 @@ function convertExampleRequestBody({
if (requestType == null) {
return undefined;
}
// (HACK: Skip bytes request example creation)
if (typeof requestType === "string" && parseBytesRequest(requestType) != null) {
return undefined;
}

if (!isInlineRequestBody(requestType)) {
return ExampleRequestBody.reference(
convertTypeReferenceExample({
Expand All @@ -367,6 +378,14 @@ function convertExampleRequestBody({
const exampleProperties: ExampleInlinedRequestBodyProperty[] = [];
for (const [wireKey, propertyExample] of Object.entries(example.request)) {
const inlinedRequestPropertyDeclaration = requestType.properties?.[wireKey];
const inilnedRequestPropertyType =
typeof inlinedRequestPropertyDeclaration === "string"
? inlinedRequestPropertyDeclaration
: inlinedRequestPropertyDeclaration?.type;
if (inilnedRequestPropertyType != null && parseRawFileType(inilnedRequestPropertyType) != null) {
// HACK skip file properties
continue;
}
if (inlinedRequestPropertyDeclaration != null) {
exampleProperties.push({
name: file.casingsGenerator.generateNameAndWireValue({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class TypeResolverImpl implements TypeResolver {
public resolveTypeOrThrow({ type, file }: { type: string; file: FernFileContext }): ResolvedType {
const resolvedType = this.resolveType({ type, file });
if (resolvedType == null) {
throw new Error("Cannot resolve type: " + type);
throw new Error("Cannot resolve type: " + type + " in file " + file.relativeFilepath);
}
return resolvedType;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14286,6 +14286,13 @@ exports[`open api parser aries simple 1`] = `
"auth": true,
"display-name": "Download tails file",
"docs": undefined,
"examples": [
{
"path-parameters": {
"rev_reg_id": "rev_reg_id",
},
},
],
"method": "GET",
"path": "/revocation/registry/{rev_reg_id}/tails-file",
"path-parameters": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ exports[`open api parser assembly simple 1`] = `
"root.InternalServerError",
"root.ServiceUnavailableError",
],
"examples": [
{
"response": {
"body": {
"upload_url": "upload_url",
},
},
},
],
"method": "POST",
"path": "/v2/upload",
"request": {
Expand Down Expand Up @@ -1221,6 +1230,14 @@ The parameter should map to a JSON encoded list of strings.
"auth": true,
"display-name": "Export transcript as SRT or VTT captions.",
"docs": "Export your transcript in SRT or VTT format, to be plugged into a video player for subtitles and closed captions.",
"examples": [
{
"path-parameters": {
"subtitle_format": "srt",
"transcript_id": "transcript_id",
},
},
],
"method": "GET",
"path": "/v2/transcript/{transcript_id}/{subtitle_format}",
"path-parameters": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1695,6 +1695,22 @@ exports[`open api parser deel simple 1`] = `
"root.TooManyRequestsError",
"root.InternalServerError",
],
"examples": [
{
"path-parameters": {
"contract_id": "contract_id",
},
"request": {},
"response": {
"body": {
"data": {
"filename": "filename",
"key": "key",
},
},
},
},
],
"method": "POST",
"path": "/contracts/{contract_id}/documents",
"path-parameters": {
Expand All @@ -1709,6 +1725,7 @@ exports[`open api parser deel simple 1`] = `
"file": "optional<file>",
},
},
"content-type": "multipart/form-data",
"headers": undefined,
"name": "AddContractDocumentRequest",
"query-parameters": undefined,
Expand Down Expand Up @@ -1899,6 +1916,22 @@ exports[`open api parser deel simple 1`] = `
"root.TooManyRequestsError",
"root.InternalServerError",
],
"examples": [
{
"path-parameters": {
"contract_id": "contract_id",
},
"request": {},
"response": {
"body": {
"data": {
"filename": "filename",
"key": "key",
},
},
},
},
],
"method": "PUT",
"path": "/contracts/{contract_id}/documents",
"path-parameters": {
Expand All @@ -1913,6 +1946,7 @@ exports[`open api parser deel simple 1`] = `
"file": "optional<file>",
},
},
"content-type": "multipart/form-data",
"headers": undefined,
"name": "EditContractDocumentRequest",
"query-parameters": undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ exports[`open api parser file-upload simple 1`] = `
"auth": false,
"display-name": "Upload a file",
"docs": undefined,
"examples": [
{
"request": {
"file": "file",
},
},
],
"method": "POST",
"path": "/upload",
"request": {
Expand All @@ -21,6 +28,7 @@ exports[`open api parser file-upload simple 1`] = `
"maybe_file": "optional<file>",
},
},
"content-type": "multipart/form-data",
"headers": undefined,
"name": "UploadFileRequest",
"query-parameters": undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4613,6 +4613,13 @@ exports[`open api parser flexport simple 1`] = `
"auth": false,
"display-name": "Download a document",
"docs": "Retrieves the contents of a specified file. Returns the file as a stream of bytes.",
"examples": [
{
"path-parameters": {
"id": "id",
},
},
],
"method": "GET",
"path": "/documents/{id}/download",
"path-parameters": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,17 @@ exports[`open api parser hathora simple 1`] = `
"root.NotFoundError",
"root.InternalServerError",
],
"examples": [
{
"path-parameters": {
"appId": "appId",
"buildId": 1.1,
},
"request": {
"file": "file",
},
},
],
"method": "POST",
"path": "/builds/v1/{appId}/run/{buildId}",
"path-parameters": {
Expand All @@ -540,6 +551,7 @@ exports[`open api parser hathora simple 1`] = `
"file": "file",
},
},
"content-type": "multipart/form-data",
"headers": undefined,
"name": "RunBuildRequest",
"query-parameters": undefined,
Expand Down Expand Up @@ -1427,6 +1439,14 @@ exports[`open api parser hathora simple 1`] = `
"GetLogsForDeployment": {
"auth": true,
"docs": undefined,
"examples": [
{
"path-parameters": {
"appId": "appId",
"deploymentId": 1.1,
},
},
],
"method": "GET",
"path": "/logs/v1/{appId}/deployment/{deploymentId}",
"path-parameters": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ exports[`open api parser hume simple 1`] = `
"auth": true,
"display-name": "Get Job Artifacts",
"docs": "Get the artifacts ZIP of a completed job.",
"examples": [
{
"path-parameters": {
"id": "id",
},
},
],
"method": "GET",
"path": "/v0/batch/jobs/{id}/artifacts",
"path-parameters": {
Expand Down
Loading

0 comments on commit e91093e

Please sign in to comment.