Skip to content

Commit

Permalink
Update v3 generator to handle URI encoding correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
LucianBuzzo committed Aug 29, 2023
1 parent 38c14f1 commit 4305e20
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
5 changes: 2 additions & 3 deletions packages/cli/src/swagger/specGenerator2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,17 @@ export class SpecGenerator2 extends SpecGenerator {
const definitions: { [definitionsName: string]: Swagger.Schema2 } = {};
Object.keys(this.metadata.referenceTypeMap).map(typeName => {
const referenceType = this.metadata.referenceTypeMap[typeName];
const decodedName = decodeURIComponent(referenceType.refName);
if (referenceType.dataType === 'refObject') {
const required = referenceType.properties.filter(p => this.isRequiredWithoutDefault(p) && !this.hasUndefined(p)).map(p => p.name);
definitions[decodedName] = {
definitions[referenceType.refName] = {
description: referenceType.description,
properties: this.buildProperties(referenceType.properties),
required: required && required.length > 0 ? Array.from(new Set(required)) : undefined,
type: 'object',
};

if (referenceType.additionalProperties) {
definitions[decodedName].additionalProperties = this.buildAdditionalProperties(referenceType.additionalProperties);
definitions[referenceType.refName].additionalProperties = this.buildAdditionalProperties(referenceType.additionalProperties);
} else {
// Since additionalProperties was not explicitly set in the TypeScript interface for this model
// ...we need to make a decision
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/swagger/specGenerator3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 4305e20

Please sign in to comment.