Skip to content

Commit

Permalink
feat: no content parsing openapi v2 parser (#2091)
Browse files Browse the repository at this point in the history
Co-authored-by: fern-bot <[email protected]>
  • Loading branch information
RohinBhargava and fern-support authored Jan 30, 2025
1 parent fea1b24 commit c425af4
Show file tree
Hide file tree
Showing 16 changed files with 210 additions and 43 deletions.
1 change: 1 addition & 0 deletions fern/apis/fdr/definition/api/latest/endpoint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ types:

HttpResponseBodyShape:
union:
empty: {}
object: type.ObjectType
alias: type.TypeReference
fileDownload: FileDownloadResponseBodyShape
Expand Down
2 changes: 1 addition & 1 deletion packages/fdr-sdk/src/api-definition/sort-keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export function sortKeysByShape(
fileDownload: () => obj,
streamingText: () => obj,
stream: () => obj,
empty: () => obj,
_other: () => obj,
});
}
Expand All @@ -153,7 +154,6 @@ export function safeSortKeysByShape(
try {
return stripUndefines(sortKeysByShape(value, shape, types));
} catch (e) {
// eslint-disable-next-line no-console
console.error("Failed to sort JSON keys by type shape", e);

return value;
Expand Down
1 change: 1 addition & 0 deletions packages/fdr-sdk/src/api-definition/transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ export class Transformer {
...value,
shape: this.visitor.TypeShape(value.shape, `${parentKey}/stream/shape`),
}),
empty: identity,
});
return { ...response, body };
};
Expand Down
1 change: 1 addition & 0 deletions packages/fdr-sdk/src/api-definition/typeid-visitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export class ApiTypeIdVisitor {
fileDownload: noop,
streamingText: noop,
stream: (value) => ApiTypeIdVisitor.visitTypeShape(value.shape, visit),
empty: noop,
});
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ function EndpointResponseSectionContent({
types,
}: EndpointResponseSectionContentProps) {
switch (body.type) {
case "empty":
case "fileDownload":
case "streamingText":
return null;
Expand Down Expand Up @@ -118,6 +119,8 @@ function getResponseSummary({
isAudioFileDownloadSpanSummary: boolean;
}) {
switch (response.body.type) {
case "empty":
return "This endpoint returns nothing.";
case "fileDownload": {
if (isAudioFileDownloadSpanSummary) {
return (
Expand Down
2 changes: 1 addition & 1 deletion packages/parsers/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fern-api/docs-parsers",
"version": "0.0.41",
"version": "0.0.42",
"repository": {
"type": "git",
"url": "https://github.com/fern-api/fern-platform.git",
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,15 @@ describe("PathItemObjectConverterNode", () => {
},
},
],
responses: [],
responses: [
{
body: {
type: "empty",
},
description: "A pet to be returned",
statusCode: 200,
},
],
errors: [],
examples: [],
});
Expand All @@ -120,7 +128,15 @@ describe("PathItemObjectConverterNode", () => {
},
],
environments: [],
responses: [],
responses: [
{
body: {
type: "empty",
},
description: "A pet to be returned",
statusCode: 200,
},
],
errors: [],
examples: [],
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export class ResponseObjectConverterNode extends BaseOpenApiV3_1ConverterNode<
headers: Record<string, ParameterBaseObjectConverterNode> | undefined;
responses: ResponseMediaTypeObjectConverterNode[] | undefined;
description: string | undefined;
emptyResponse: boolean | undefined;

constructor(
args: BaseOpenApiV3_1ConverterNodeConstructorArgs<
Expand Down Expand Up @@ -60,33 +61,39 @@ export class ResponseObjectConverterNode extends BaseOpenApiV3_1ConverterNode<
});
});

Object.entries(input.content ?? {}).forEach(
([contentType, contentTypeObject]) => {
this.responses ??= [];
this.responses.push(
new ResponseMediaTypeObjectConverterNode(
{
input: contentTypeObject,
context: this.context,
accessPath: this.accessPath,
pathId: ["content", contentType],
},
contentType,
streamingFormat,
this.path,
this.statusCode,
this.requests,
// TODO: add response headers, but this needs to be added to FDR shape
this.shapes
)
);
}
);
if (input.content == null) {
this.emptyResponse = true;
} else {
Object.entries(input.content ?? {}).forEach(
([contentType, contentTypeObject]) => {
this.responses ??= [];
this.responses.push(
new ResponseMediaTypeObjectConverterNode(
{
input: contentTypeObject,
context: this.context,
accessPath: this.accessPath,
pathId: ["content", contentType],
},
contentType,
streamingFormat,
this.path,
this.statusCode,
this.requests,
// TODO: add response headers, but this needs to be added to FDR shape
this.shapes
)
);
}
);
}
}

convert(): FernRegistry.api.latest.HttpResponseBodyShape[] | undefined {
return this.responses
?.flatMap((response) => response.convert())
.filter(isNonNullish);
return this.emptyResponse
? [{ type: "empty" }]
: this.responses
?.flatMap((response) => response.convert())
.filter(isNonNullish);
}
}
31 changes: 30 additions & 1 deletion packages/parsers/src/openapi/__test__/__snapshots__/cohere.json
Original file line number Diff line number Diff line change
Expand Up @@ -12220,7 +12220,36 @@
"description": "The name of the project that is making the request.\n"
}
],
"responses": [],
"responseHeaders": [
{
"key": "X-API-Warning",
"valueShape": {
"type": "alias",
"value": {
"type": "optional",
"shape": {
"type": "alias",
"value": {
"type": "primitive",
"value": {
"type": "string"
}
}
}
}
},
"description": "Warning description for incorrect usage of the API"
}
],
"responses": [
{
"statusCode": 200,
"body": {
"type": "empty"
},
"description": "OK"
}
],
"errors": [
{
"statusCode": 400,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,15 @@
"description": "The ID of the voice to delete"
}
],
"responses": [],
"responses": [
{
"statusCode": 204,
"body": {
"type": "empty"
},
"description": "Successful deletion"
}
],
"errors": [],
"examples": []
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27699,7 +27699,15 @@
}
}
],
"responses": [],
"responses": [
{
"statusCode": 202,
"body": {
"type": "empty"
},
"description": "successful"
}
],
"errors": [
{
"statusCode": 401,
Expand Down Expand Up @@ -27823,7 +27831,15 @@
}
}
],
"responses": [],
"responses": [
{
"statusCode": 200,
"body": {
"type": "empty"
},
"description": "successful"
}
],
"errors": [
{
"statusCode": 401,
Expand Down Expand Up @@ -28394,7 +28410,15 @@
}
}
],
"responses": [],
"responses": [
{
"statusCode": 200,
"body": {
"type": "empty"
},
"description": "successful"
}
],
"errors": [],
"examples": []
},
Expand Down Expand Up @@ -32559,7 +32583,15 @@
}
}
],
"responses": [],
"responses": [
{
"statusCode": 200,
"body": {
"type": "empty"
},
"description": "Successful"
}
],
"errors": [
{
"statusCode": 400,
Expand Down
Loading

0 comments on commit c425af4

Please sign in to comment.