fix: types over-pluralization (#1057)

fixes #1053
This commit is contained in:
Michael Huynh 2019-10-12 17:33:03 +08:00 committed by Roman Hotsiy
parent 4adb927463
commit 4494f80dbc
2 changed files with 9 additions and 1 deletions

View File

@ -381,6 +381,14 @@ describe('Utils', () => {
'objects (Pet) or numbers <int64>',
);
});
it('should not pluralize display types that are already pluralized', () => {
expect(pluralizeType('strings')).toEqual('strings');
expect(pluralizeType('objects (Pet)')).toEqual('objects (Pet)');
expect(pluralizeType('strings <email>')).toEqual('strings <email>');
expect(pluralizeType('objects or strings')).toEqual('objects or strings');
expect(pluralizeType('objects (Pet) or numbers <int64>')).toEqual('objects (Pet) or numbers <int64>');
});
});
describe('openapi serializeParameter', () => {

View File

@ -579,6 +579,6 @@ export function extractExtensions(obj: object, showExtensions: string[] | true):
export function pluralizeType(displayType: string): string {
return displayType
.split(' or ')
.map(type => type.replace(/^(string|object|number|integer|array|boolean)( ?.*)/, '$1s$2'))
.map(type => type.replace(/^(string|object|number|integer|array|boolean)s?( ?.*)/, '$1s$2'))
.join(' or ');
}