@@ -37,9 +37,17 @@ type ParameterSchemaGroup = {
3737 * collisions from overwriting earlier validators in the generated module.
3838 */
3939export function createUniqueName ( candidate : string , seen : Map < string , number > ) : string {
40- const count = seen . get ( candidate ) ?? 0
40+ let count = seen . get ( candidate ) ?? 0
41+ let uniqueName = count === 0 ? candidate : `${ candidate } ${ count + 1 } `
42+
43+ while ( seen . has ( uniqueName ) ) {
44+ count += 1
45+ uniqueName = `${ candidate } ${ count + 1 } `
46+ }
47+
4148 seen . set ( candidate , count + 1 )
42- return count === 0 ? candidate : `${ candidate } ${ count + 1 } `
49+ seen . set ( uniqueName , 1 )
50+ return uniqueName
4351}
4452
4553/**
@@ -344,6 +352,9 @@ function registerRequestSchemasAndCollectValidators(spec: OpenAPIV3.Document): V
344352 const componentSchemas = ensureComponentsSchemas ( spec )
345353 const validators : ValidatorExports = { }
346354 const seenOperationNames = new Map < string , number > ( )
355+ const seenSchemaNames = new Map < string , number > (
356+ Object . keys ( componentSchemas ) . map ( ( schemaName ) => [ schemaName , 1 ] ) ,
357+ )
347358
348359 for ( const [ pathKey , rawPathItem ] of Object . entries ( spec . paths ?? { } ) ) {
349360 const pathItem = resolvePathItem (
@@ -367,7 +378,7 @@ function registerRequestSchemasAndCollectValidators(spec: OpenAPIV3.Document): V
367378 continue
368379 }
369380
370- const schemaName = `${ baseName } Request`
381+ const schemaName = createUniqueName ( `${ baseName } Request` , seenSchemaNames )
371382 componentSchemas [ schemaName ] = requestSchema
372383 validators [ `validate${ baseName } Request` ] = `Spec#/components/schemas/${ schemaName } `
373384 }
0 commit comments