@@ -65,6 +65,10 @@ export const getZodiosEndpointDefinitionList = (doc: OpenAPIObject, options?: Te
65
65
. otherwise ( ( fn ) => fn ) ;
66
66
67
67
const ctx : ConversionTypeContext = { resolver, zodSchemaByName : { } , schemaByName : { } } ;
68
+ if ( options ?. exportAllNamedSchemas ) {
69
+ ctx . schemasByName = { } ;
70
+ }
71
+
68
72
const complexityThreshold = options ?. complexityThreshold ?? 4 ;
69
73
const getZodVarName = ( input : CodeMeta , fallbackName ?: string ) => {
70
74
const result = input . toString ( ) ;
@@ -84,7 +88,7 @@ export const getZodiosEndpointDefinitionList = (doc: OpenAPIObject, options?: Te
84
88
85
89
// if schema is already assigned to a variable, re-use that variable name
86
90
if ( ! options ?. exportAllNamedSchemas && ctx . schemaByName [ result ] ) {
87
- return ctx . schemaByName [ result ] ! [ 0 ] ! ;
91
+ return ctx . schemaByName [ result ] ! ;
88
92
}
89
93
90
94
// result is complex and would benefit from being re-used
@@ -95,7 +99,7 @@ export const getZodiosEndpointDefinitionList = (doc: OpenAPIObject, options?: Te
95
99
let isVarNameAlreadyUsed = false ;
96
100
while ( ( isVarNameAlreadyUsed = Boolean ( ctx . zodSchemaByName [ formatedName ] ) ) ) {
97
101
if ( isVarNameAlreadyUsed ) {
98
- if ( options ?. exportAllNamedSchemas && ctx . schemaByName [ result ] ?. includes ( formatedName ) ) {
102
+ if ( options ?. exportAllNamedSchemas && ctx . schemasByName ?. [ result ] ?. includes ( formatedName ) ) {
99
103
return formatedName ;
100
104
} else if ( ctx . zodSchemaByName [ formatedName ] === safeName ) {
101
105
return formatedName ;
@@ -107,11 +111,10 @@ export const getZodiosEndpointDefinitionList = (doc: OpenAPIObject, options?: Te
107
111
}
108
112
109
113
ctx . zodSchemaByName [ formatedName ] = result ;
114
+ ctx . schemaByName [ result ] = formatedName ;
110
115
111
- if ( options ?. exportAllNamedSchemas ) {
112
- ctx . schemaByName [ result ] = ( ctx . schemaByName [ result ] ?? [ ] ) . concat ( formatedName ) ;
113
- } else {
114
- ctx . schemaByName [ result ] = [ formatedName ] ;
116
+ if ( options ?. exportAllNamedSchemas && ctx . schemasByName ) {
117
+ ctx . schemasByName [ result ] = ( ctx . schemasByName [ result ] ?? [ ] ) . concat ( formatedName ) ;
115
118
}
116
119
117
120
return formatedName ;
@@ -315,7 +318,11 @@ export const getZodiosEndpointDefinitionList = (doc: OpenAPIObject, options?: Te
315
318
}
316
319
317
320
if ( endpointDefinition . responses !== undefined ) {
318
- endpointDefinition . responses . push ( { statusCode, schema : schemaString ?? voidSchema , description : responseItem . description } ) ;
321
+ endpointDefinition . responses . push ( {
322
+ statusCode,
323
+ schema : schemaString ?? voidSchema ,
324
+ description : responseItem . description ,
325
+ } ) ;
319
326
}
320
327
321
328
if ( schemaString ) {
0 commit comments