diff --git a/packages/cli/src/metadataGeneration/metadataGenerator.ts b/packages/cli/src/metadataGeneration/metadataGenerator.ts index acf29efd7..0a36d2ce3 100644 --- a/packages/cli/src/metadataGeneration/metadataGenerator.ts +++ b/packages/cli/src/metadataGeneration/metadataGenerator.ts @@ -44,7 +44,7 @@ export class MetadataGenerator { } private setProgramToDynamicControllersFiles(controllers: string[], esm: boolean) { - const allGlobFiles = importClassesFromDirectories(controllers, esm ? ['.mts', '.ts', '.cts']: ['.ts']); + const allGlobFiles = importClassesFromDirectories(controllers, esm ? ['.mts', '.ts', '.cts'] : ['.ts']); if (allGlobFiles.length === 0) { throw new GenerateMetadataError(`[${controllers.join(', ')}] globs found 0 controllers.`); } @@ -216,7 +216,7 @@ export class MetadataGenerator { if (!referenceType.refName) { return; } - this.referenceTypeMap[referenceType.refName] = referenceType; + this.referenceTypeMap[decodeURIComponent(referenceType.refName)] = referenceType; } public GetReferenceType(refName: string) { diff --git a/packages/cli/src/metadataGeneration/typeResolver.ts b/packages/cli/src/metadataGeneration/typeResolver.ts index 93f07266f..785aeac13 100644 --- a/packages/cli/src/metadataGeneration/typeResolver.ts +++ b/packages/cli/src/metadataGeneration/typeResolver.ts @@ -763,21 +763,19 @@ export class TypeResolver { } private getRefTypeName(name: string): string { - return encodeURIComponent( - name - .replace(/<|>/g, '_') - .replace(/\s+/g, '') - .replace(/,/g, '.') - .replace(/'([^']*)'/g, '$1') - .replace(/"([^"]*)"/g, '$1') - .replace(/&/g, '-and-') - .replace(/\|/g, '-or-') - .replace(/\[\]/g, '-Array') - .replace(/{|}/g, '_') // SuccessResponse_{indexesCreated-number}_ -> SuccessResponse__indexesCreated-number__ - .replace(/([a-z]+):([a-z]+)/gi, '$1-$2') // SuccessResponse_indexesCreated:number_ -> SuccessResponse_indexesCreated-number_ - .replace(/;/g, '--') - .replace(/([a-z]+)\[([a-z]+)\]/gi, '$1-at-$2'), // Partial_SerializedDatasourceWithVersion[format]_ -> Partial_SerializedDatasourceWithVersion~format~_, - ); + return name + .replace(/<|>/g, '_') + .replace(/\s+/g, '') + .replace(/,/g, '.') + .replace(/'([^']*)'/g, '$1') + .replace(/"([^"]*)"/g, '$1') + .replace(/&/g, '-and-') + .replace(/\|/g, '-or-') + .replace(/\[\]/g, '-Array') + .replace(/{|}/g, '_') // SuccessResponse_{indexesCreated-number}_ -> SuccessResponse__indexesCreated-number__ + .replace(/([a-z]+):([a-z]+)/gi, '$1-$2') // SuccessResponse_indexesCreated:number_ -> SuccessResponse_indexesCreated-number_ + .replace(/;/g, '--') + .replace(/([a-z]+)\[([a-z]+)\]/gi, '$1-at-$2'); // Partial_SerializedDatasourceWithVersion[format]_ -> Partial_SerializedDatasourceWithVersion~format~_, } private attemptToResolveKindToPrimitive = (syntaxKind: ts.SyntaxKind): ResolvesToPrimitive | DoesNotResolveToPrimitive => { diff --git a/packages/cli/src/swagger/specGenerator2.ts b/packages/cli/src/swagger/specGenerator2.ts index 57c8f6ff0..ee5c3b50f 100644 --- a/packages/cli/src/swagger/specGenerator2.ts +++ b/packages/cli/src/swagger/specGenerator2.ts @@ -478,7 +478,7 @@ export class SpecGenerator2 extends SpecGenerator { } protected getSwaggerTypeForReferenceType(referenceType: Tsoa.ReferenceType): Swagger.BaseSchema { - return { $ref: `#/definitions/${referenceType.refName}` }; + return { $ref: `#/definitions/${encodeURIComponent(referenceType.refName)}` }; } private decideEnumType(anEnum: Array, nameOfEnum: string): 'string' | 'number' { diff --git a/packages/cli/src/swagger/specGenerator3.ts b/packages/cli/src/swagger/specGenerator3.ts index f1da8ca63..55399be3c 100644 --- a/packages/cli/src/swagger/specGenerator3.ts +++ b/packages/cli/src/swagger/specGenerator3.ts @@ -572,7 +572,7 @@ export class SpecGenerator3 extends SpecGenerator { } protected getSwaggerTypeForReferenceType(referenceType: Tsoa.ReferenceType): Swagger.BaseSchema { - return { $ref: `#/components/schemas/${referenceType.refName}` }; + return { $ref: `#/components/schemas/${encodeURIComponent(referenceType.refName)}` }; } protected getSwaggerTypeForPrimitiveType(dataType: Tsoa.PrimitiveTypeLiteral): Swagger.Schema {