Skip to content
This repository has been archived by the owner on Nov 16, 2023. It is now read-only.

Commit

Permalink
fix: types over-pluralization (Redocly#1057)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Cerman committed Jun 5, 2020
1 parent d575e37 commit 93af51d
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 @@ -570,6 +570,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 93af51d

Please sign in to comment.