Skip to content

Commit

Permalink
fix(cli): openapi example generator handles circular oneOf schemas (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
dsinghvi authored Aug 25, 2024
1 parent 8b65213 commit 10db746
Show file tree
Hide file tree
Showing 29 changed files with 76,692 additions and 25,532 deletions.
10 changes: 10 additions & 0 deletions packages/cli/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.39.19] - 2024-08-25

- Fix: The OpenAPI importer now handles generating examples for referenced `oneOf` schemas. Previously,
examples generation would fail.
- Fix: The OpenAPI importer now handles generating examples for circular `oneOf` schemas. Previously, the
the converter would only default to generating examples for the first `oneOf` schema. If the first variant,
circularly referenced itself, this would make terminating the example impossible.
Now, the example generator tries every schema in order, guaranteeing that a termination condition will be
reached.

## [0.39.18] - 2024-08-23

- Internal: Produce IR v57.8.0 with raw datetime examples. The raw datetime examples help
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/cli/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.39.18
0.39.19
54 changes: 33 additions & 21 deletions packages/cli/docs-preview/src/previewDocs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export async function getPreviewDocsDefinition({
)
);

const apiCollector = new ReferencedAPICollector();
const apiCollector = new ReferencedAPICollector(context);

const filesV2: Record<string, DocsV1Read.File_> = {};

Expand Down Expand Up @@ -91,33 +91,45 @@ type APIDefinitionID = string;
class ReferencedAPICollector {
private readonly apis: Record<APIDefinitionID, APIV1Read.ApiDefinition> = {};

constructor(private readonly context: TaskContext) {}

public addReferencedAPI({
ir,
snippetsConfig
}: {
ir: IntermediateRepresentation;
snippetsConfig: APIV1Write.SnippetsConfig;
}): APIDefinitionID {
const id = uuidv4();

const apiDefinition = convertIrToFdrApi({ ir, snippetsConfig });

const dbApiDefinition = convertAPIDefinitionToDb(
apiDefinition,
id,
new SDKSnippetHolder({
snippetsConfigWithSdkId: {},
snippetsBySdkId: {},
snippetTemplatesByEndpoint: {},
snippetTemplatesByEndpointId: {},
snippetsBySdkIdAndEndpointId: {}
})
);

const readApiDefinition = convertDbAPIDefinitionToRead(dbApiDefinition);

this.apis[id] = readApiDefinition;
return id;
try {
const id = uuidv4();

const apiDefinition = convertIrToFdrApi({ ir, snippetsConfig });

const dbApiDefinition = convertAPIDefinitionToDb(
apiDefinition,
id,
new SDKSnippetHolder({
snippetsConfigWithSdkId: {},
snippetsBySdkId: {},
snippetTemplatesByEndpoint: {},
snippetTemplatesByEndpointId: {},
snippetsBySdkIdAndEndpointId: {}
})
);

const readApiDefinition = convertDbAPIDefinitionToRead(dbApiDefinition);

this.apis[id] = readApiDefinition;
return id;
} catch (e) {
// Print Error
const err = e as Error;
this.context.logger.error(`Failed to read referenced API: ${err?.message}`);
if (err.stack != null) {
this.context.logger.error(err?.stack);
}
throw e;
}
}

public getAPIsForDefinition(): Record<FdrAPI.ApiDefinitionId, APIV1Read.ApiDefinition> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -871,4 +871,4 @@ exports[`dependencies > correctly incorporates dependencies 1`] = `
}"
`;

exports[`dependencies > file dependencies 1`] = `3049151`;
exports[`dependencies > file dependencies 1`] = `3085349`;
Loading

0 comments on commit 10db746

Please sign in to comment.