Skip to content

Commit

Permalink
fix recursive thrash
Browse files Browse the repository at this point in the history
  • Loading branch information
RohinBhargava committed Dec 20, 2024
1 parent 3abdb34 commit c156011
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 21 deletions.
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.14",
"version": "0.0.15",
"repository": {
"type": "git",
"url": "https://github.com/fern-api/fern-platform.git",
Expand Down
102 changes: 100 additions & 2 deletions packages/parsers/src/__test__/__snapshots__/openapi/cohere.json
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,30 @@
}
}
],
"responses": [],
"responses": [
{
"statusCode": 200,
"body": {
"type": "alias",
"value": {
"type": "id",
"id": "NonStreamedChatResponse"
}
},
"description": "OK"
},
{
"statusCode": 200,
"body": {
"type": "alias",
"value": {
"type": "id",
"id": "StreamedChatResponse"
}
},
"description": "OK"
}
],
"errors": [
{
"statusCode": 400,
Expand Down Expand Up @@ -1621,6 +1644,28 @@
}
]
}
},
{
"path": "/v1/chat",
"responseStatusCode": 200,
"responseBody": {
"type": "json",
"value": {
"text": "string"
}
},
"snippets": {}
},
{
"path": "/v1/chat",
"responseStatusCode": 200,
"responseBody": {
"type": "json",
"value": {
"text": "string"
}
},
"snippets": {}
}
]
},
Expand Down Expand Up @@ -2041,7 +2086,30 @@
}
}
],
"responses": [],
"responses": [
{
"statusCode": 200,
"body": {
"type": "alias",
"value": {
"type": "id",
"id": "ChatResponse"
}
},
"description": "OK"
},
{
"statusCode": 200,
"body": {
"type": "alias",
"value": {
"type": "id",
"id": "StreamedChatResponseV2"
}
},
"description": "OK"
}
],
"errors": [
{
"statusCode": 400,
Expand Down Expand Up @@ -2959,6 +3027,36 @@
}
]
}
},
{
"path": "/v2/chat",
"responseStatusCode": 200,
"responseBody": {
"type": "json",
"value": {
"id": "string",
"finish_reason": "string",
"message": {
"role": "string"
}
}
},
"snippets": {}
},
{
"path": "/v2/chat",
"responseStatusCode": 200,
"responseBody": {
"type": "json",
"value": {
"id": "string",
"finish_reason": "string",
"message": {
"role": "string"
}
}
},
"snippets": {}
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ export class RequestMediaTypeObjectConverterNode extends BaseOpenApiV3_1Converte
return undefined;
}

const newSeenVariants = new Set(seenVariants);
if (shape.type === "alias" && shape.value.type === "id") {
newSeenVariants.add(shape.value.id);
}

const type = shape.type;
switch (type) {
case "alias":
Expand All @@ -154,17 +159,10 @@ export class RequestMediaTypeObjectConverterNode extends BaseOpenApiV3_1Converte
},
},
}));
case "undiscriminatedUnion": {
const newSeenVariants = new Set(seenVariants);
shape.variants.forEach((variant) =>
variant.shape.type === "alias" && variant.shape.value.type === "id"
? newSeenVariants.add(variant.shape.value.id)
: undefined,
);
case "undiscriminatedUnion":
return shape.variants
.flatMap((variant) => this.convertTypeShapeToHttpRequestBodyShape(variant.shape, newSeenVariants))
.filter(isNonNullish);
}
case "discriminatedUnion":
return shape.variants.map((variant) => ({
type: "object",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,25 +223,22 @@ export class ResponseMediaTypeObjectConverterNode extends BaseOpenApiV3_1Convert
return undefined;
}

const newSeenVariants = new Set(seenVariants);
if (shape.type === "alias" && shape.value.type === "id") {
newSeenVariants.add(shape.value.id);
}

const type = shape.type;
switch (type) {
case "object":
case "alias":
return [shape];
case "undiscriminatedUnion": {
const newSeenVariants = new Set(seenVariants);
shape.variants.forEach(
(variant) =>
variant.shape.type === "alias" &&
variant.shape.value.type === "id" &&
newSeenVariants.add(variant.shape.value.id),
);
case "undiscriminatedUnion":
return shape.variants
.flatMap((variant) =>
this.convertTypeShapeIntoHttpResponseBodyShape(variant.shape, newSeenVariants),
)
.filter(isNonNullish);
}
case "discriminatedUnion":
return shape.variants.map((variant) => ({
type: "object",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ export class ResponsesObjectConverterNode extends BaseOpenApiV3_1ConverterNode<
convertResponseObjectToErrors(): FernRegistry.api.latest.ErrorResponse[] {
return Object.entries(this.errorsByStatusCode ?? {})
.flatMap(([statusCode, response]) => {
// TODO: resolve reference here, if not done already
return response.responses?.map((response) => {
const schema = response.schema;
const shape = schema?.convert();
Expand Down

0 comments on commit c156011

Please sign in to comment.