Skip to content

Commit

Permalink
fix: generate types schemas not in reticular structure
Browse files Browse the repository at this point in the history
  • Loading branch information
C-ra-ZY committed Sep 2, 2024
1 parent 76d86f6 commit 54951d8
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions lib/src/template-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,13 @@ export const getZodClientTemplateContext = (

for (const name in result.zodSchemaByName) {
data.schemas[normalizeString(name)] = wrapWithLazyIfNeeded(name);
}

for (const ref in depsGraphs.deepDependencyGraph) {
const schema = result.resolver.resolveSchemaName(name);
const ref = schema.ref;
const isCircular = ref && depsGraphs.deepDependencyGraph[ref]?.has(ref);
const ctx: TsConversionContext = { nodeByRef: {}, resolver: result.resolver, visitedsRefs: {} };

// Specifically check isCircular if shouldExportAllTypes is false. Either should cause shouldGenerateType to be true.
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
const shouldGenerateType = options?.shouldExportAllTypes || isCircular;
const schemaName = shouldGenerateType ? result.resolver.resolveRef(ref).normalized : undefined;
const shouldGenerateType = options?.shouldExportAllTypes ?? isCircular;
const schemaName = shouldGenerateType ? schema.normalized : undefined;
const ctx: TsConversionContext = { nodeByRef: {}, resolver: result.resolver, visitedsRefs: {} };
if (shouldGenerateType && schemaName && !data.types[schemaName]) {
const node = getTypescriptFromOpenApi({
schema: result.resolver.getSchemaByRef(ref),
Expand Down

0 comments on commit 54951d8

Please sign in to comment.