Skip to content

Commit

Permalink
(fix): openapi ir to fern carries through error examples (#3551)
Browse files Browse the repository at this point in the history
(fix): openapi ir to fern carries through error eexamples
  • Loading branch information
dsinghvi authored May 7, 2024
1 parent fc65b62 commit 0029393
Show file tree
Hide file tree
Showing 4 changed files with 1,151 additions and 793 deletions.
23 changes: 23 additions & 0 deletions packages/cli/openapi-ir-to-fern/src/FernDefnitionBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ export interface FernDefinitionBuilder {
{ name, schema }: { name: string; schema: RawSchemas.ErrorDeclarationSchema }
): void;

addErrorExample(
file: RelativeFilePath,
{ name, example }: { name: string; example: RawSchemas.ExampleTypeSchema }
): void;

addEndpoint(
file: RelativeFilePath,
{ name, schema }: { name: string; schema: RawSchemas.HttpEndpointSchema }
Expand Down Expand Up @@ -264,6 +269,24 @@ export class FernDefinitionBuilderImpl implements FernDefinitionBuilder {
}
}

public addErrorExample(
file: RelativeFilePath,
{ name, example }: { name: string; example: RawSchemas.ExampleTypeSchema }
): void {
const fernFile = this.getOrCreateFile(file);
if (fernFile.errors == null) {
return;
}
const errorDeclaration = fernFile.errors[name];
if (errorDeclaration == null) {
return;
}
if (errorDeclaration.examples == null) {
errorDeclaration.examples = [];
}
errorDeclaration.examples?.push(example);
}

public addEndpoint(
file: RelativeFilePath,
{ name, schema }: { name: string; schema: RawSchemas.HttpEndpointSchema }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1874,6 +1874,21 @@ This error response may have one of the following \`type\` values:
The named \`accountId\` does not exist or the user is not entitled to access the account.
Remediation: Pass the \`id\` of an existing account the caller has access to.
",
"examples": [
{
"docs": undefined,
"name": undefined,
"value": {
"detail": "No such account exists for the given account ID.",
"id": "3fbad566-be86-4b22-9ba6-3ca99fdc0799",
"instance": "https://production.api.apiture.com/banking/accountBalances?accounts=bb709151-575041fcd617",
"occurredAt": "2022-04-25T12:42:21.375Z",
"status": 422,
"title": "Unprocessable Entity",
"type": "https://production.api.apiture.com/errors/invalidAccountId/v1.0.0",
},
},
],
"status-code": 422,
"type": "ProblemResponse",
},
Expand Down Expand Up @@ -7027,6 +7042,21 @@ This error response may have one of the following \`type\` values:
The syntax of the request entity is correct but was unable to process the contained instructions.
Remediation: Provide a semantically correct request.
",
"examples": [
{
"docs": undefined,
"name": undefined,
"value": {
"detail": "No such account exists for the given account ID.",
"id": "3fbad566-be86-4b22-9ba6-3ca99fdc0799",
"instance": "https://production.api.apiture.com/banking/accountBalances?accounts=bb709151-575041fcd617",
"occurredAt": "2022-04-25T12:42:21.375Z",
"status": 422,
"title": "Unprocessable Entity",
"type": "https://production.api.apiture.com/errors/invalidAccountId/v1.0.0",
},
},
],
"status-code": 422,
"type": "ProblemResponse",
},
Expand Down
Loading

0 comments on commit 0029393

Please sign in to comment.