Skip to content

Commit

Permalink
Add test for backtick escaping
Browse files Browse the repository at this point in the history
  • Loading branch information
MacFJA committed Aug 27, 2023
1 parent da4d5d6 commit a7a7331
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tests/fixtures/controllers/typeInferenceController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,11 @@ export class TypeInferenceController {
demo21: '',
};
}

@Get('escape-string-literal-type')
public escapeStringLiteralType(): Omit<TruncationTestModel, `demo${number}`> {
return {
d: '',
};
}
}
16 changes: 16 additions & 0 deletions tests/unit/swagger/definitionsGeneration/metadata.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1006,6 +1006,22 @@ describe('Metadata generation', () => {
'demo21',
]);
});

it('should generate escapeStringLiteralType method', () => {
const method = controller.methods.find(method => method.name === 'escapeStringLiteralType');
if (!method) {
throw new Error('Method escapeStringLiteralType not defined!');
}

expect(method.method).to.equal('get');
expect(method.path).to.equal('escape-string-literal-type');
const [response] = method.responses;
expect(response.schema?.dataType).to.eq('refAlias');
expect((response.schema as Tsoa.RefAliasType)?.refName).to.equal('Omit_TruncationTestModel.demo_number_');
const properties = (((response.schema as Tsoa.RefAliasType).type as Tsoa.RefAliasType).type as Tsoa.NestedObjectLiteralType).properties;
expect(properties.length).to.equal(1);
expect(properties.map(prop => prop.name)).to.have.members(['d']);
});
});

describe('controllerWithJsDocResponseDescriptionGeneration', () => {
Expand Down

0 comments on commit a7a7331

Please sign in to comment.