Skip to content

Commit

Permalink
fix(cli): namespacing no longer breaks when objects conflict across n…
Browse files Browse the repository at this point in the history
…amespaces (#4673)
  • Loading branch information
armandobelardo authored Sep 17, 2024
1 parent 9ddf483 commit a97860e
Show file tree
Hide file tree
Showing 119 changed files with 417,834 additions and 394,163 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { dirname, join, RelativeFilePath } from "@fern-api/fs-utils";
import { Schema } from "@fern-api/openapi-ir-sdk";
import { getEndpointLocation } from "@fern-api/openapi-ir-to-fern";
import { parse } from "@fern-api/openapi-parser";
import { Project } from "@fern-api/project-loader";
Expand Down Expand Up @@ -100,15 +101,9 @@ async function writeDefinitionForOpenAPIWorkspace({
? (existingOverrides.path as Record<string, Record<string, unknown>>)
: {};
if (includeModels) {
for (const [schemaId, schema] of Object.entries(ir.schemas)) {
if (schemaId in schemas) {
continue;
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const typeNameOverride: Record<string, any> = {};
typeNameOverride["x-fern-type-name"] =
"nameOverride" in schema ? schema.nameOverride ?? schemaId : schemaId;
schemas[schemaId] = typeNameOverride;
writeModels(schemas, ir.groupedSchemas.rootSchemas);
for (const [_, namespacedSchemas] of Object.entries(ir.groupedSchemas.namespacedSchemas)) {
writeModels(schemas, namespacedSchemas);
}
}
const components: Record<string, Record<string, unknown>> = { schemas };
Expand All @@ -119,3 +114,15 @@ async function writeDefinitionForOpenAPIWorkspace({
);
}
}

function writeModels(existingSchemas: Record<string, Record<string, unknown>>, schemas: Record<string, Schema>) {
for (const [schemaId, schema] of Object.entries(schemas)) {
if (schemaId in existingSchemas) {
continue;
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const typeNameOverride: Record<string, any> = {};
typeNameOverride["x-fern-type-name"] = "nameOverride" in schema ? schema.nameOverride ?? schemaId : schemaId;
existingSchemas[schemaId] = typeNameOverride;
}
}
Loading

0 comments on commit a97860e

Please sign in to comment.