Skip to content

Commit

Permalink
fix: types over-pluralization (#1057)
Browse files Browse the repository at this point in the history
fixes #1053
  • Loading branch information
miqh authored and RomanHotsiy committed Oct 12, 2019
1 parent 4adb927 commit 4494f80
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/utils/__tests__/openapi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ');
}

0 comments on commit 4494f80

Please sign in to comment.