Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): Prefer application/json Content-Type #5743

Merged
merged 4 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions fern/pages/changelogs/cli/2025-01-24.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## 0.51.3
**`(fix):`** The OpenAPI parser now prefers the JSON Content-Type variant over
others (e.g. application/x-www-form-urlencoded).


4 changes: 4 additions & 0 deletions fern/pages/changelogs/openapi/2025-01-24.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## 0.1.7
**`(fix):`** The generator now correctly handles different success response codes.


Original file line number Diff line number Diff line change
Expand Up @@ -104,26 +104,6 @@ export function convertRequest({

const jsonMediaObject = getApplicationJsonSchemaMediaObject(resolvedRequestBody.content, context);

// convert as application/x-www-form-urlencoded
if (urlEncodedRequest != null && urlEncodedRequest.schema != null) {
const convertedUrlEncodedSchema = convertSchema(
urlEncodedRequest.schema,
false,
context,
requestBreadcrumbs,
source,
namespace
);
return RequestWithExample.json({
schema: convertedUrlEncodedSchema,
description: resolvedRequestBody.description,
contentType: urlEncodedRequest.contentType,
source,
fullExamples: urlEncodedRequest.examples,
additionalProperties: false
});
}

// convert as application/octet-stream
if (isOctetStreamRequest(resolvedRequestBody)) {
return RequestWithExample.octetStream({
Expand Down Expand Up @@ -238,29 +218,49 @@ export function convertRequest({
});
}

// otherwise, convert as json request.
if (jsonMediaObject == null) {
return undefined;
// convert as application/json
if (jsonMediaObject != null) {
const requestSchema = convertSchema(
jsonMediaObject.schema,
false,
context,
requestBreadcrumbs,
source,
namespace,
true
);
return RequestWithExample.json({
description: undefined,
schema: requestSchema,
contentType: jsonMediaObject.contentType,
fullExamples: jsonMediaObject.examples,
additionalProperties:
!isReferenceObject(jsonMediaObject.schema) &&
isAdditionalPropertiesAny(jsonMediaObject.schema.additionalProperties),
source
});
}

// convert as application/x-www-form-urlencoded
if (urlEncodedRequest != null && urlEncodedRequest.schema != null) {
const convertedUrlEncodedSchema = convertSchema(
urlEncodedRequest.schema,
false,
context,
requestBreadcrumbs,
source,
namespace
);
return RequestWithExample.json({
schema: convertedUrlEncodedSchema,
description: resolvedRequestBody.description,
contentType: urlEncodedRequest.contentType,
source,
fullExamples: urlEncodedRequest.examples,
additionalProperties: false
});
}
const requestSchema = convertSchema(
jsonMediaObject.schema,
false,
context,
requestBreadcrumbs,
source,
namespace,
true
);
return RequestWithExample.json({
description: undefined,
schema: requestSchema,
contentType: jsonMediaObject.contentType,
fullExamples: jsonMediaObject.examples,
additionalProperties:
!isReferenceObject(jsonMediaObject.schema) &&
isAdditionalPropertiesAny(jsonMediaObject.schema.additionalProperties),
source
});
return undefined;
}

interface ResolvedSchema {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,54 @@
"openapi": "../openapi.yml",
},
},
"testWithDualContentTypeRequestTypes": {
"auth": false,
"display-name": "Test with dual Content-Type request types",
"docs": "Test request with dual content types.
",
"examples": [
{
"path-parameters": {
"corpus_key": "corpus_key",
},
"request": {},
"response": {
"body": "string",
},
},
],
"method": "POST",
"pagination": undefined,
"path": "/example",
"path-parameters": {
"corpus_key": {
"docs": "The unique key",
"type": "string",
},
},
"request": {
"body": {
"properties": {
"metadata": {
"docs": "Arbitrary object that will be attached as document metadata to the extracted document.",
"type": "optional<map<string, unknown>>",
},
},
},
"content-type": "application/json",
"headers": undefined,
"name": "PostExampleRequest",
"path-parameters": undefined,
"query-parameters": undefined,
},
"response": {
"docs": "The sample response",
"type": "string",
},
"source": {
"openapi": "../openapi.yml",
},
},
},
"source": {
"openapi": "../openapi.yml",
Expand Down Expand Up @@ -119,6 +167,38 @@
request: {}
response:
body: string
testWithDualContentTypeRequestTypes:
path: /example
method: POST
auth: false
docs: |
Test request with dual content types.
source:
openapi: ../openapi.yml
path-parameters:
corpus_key:
type: string
docs: The unique key
display-name: Test with dual Content-Type request types
request:
name: PostExampleRequest
body:
properties:
metadata:
type: optional<map<string, unknown>>
docs: >-
Arbitrary object that will be attached as document metadata to
the extracted document.
content-type: application/json
response:
docs: The sample response
type: string
examples:
- path-parameters:
corpus_key: corpus_key
request: {}
response:
body: string
source:
openapi: ../openapi.yml
",
Expand Down
Loading
Loading