diff --git a/src/utils/__tests__/openapi.test.ts b/src/utils/__tests__/openapi.test.ts index 92057583b1..244ab63c22 100644 --- a/src/utils/__tests__/openapi.test.ts +++ b/src/utils/__tests__/openapi.test.ts @@ -381,6 +381,14 @@ describe('Utils', () => { 'objects (Pet) or numbers ', ); }); + + 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 ')).toEqual('strings '); + expect(pluralizeType('objects or strings')).toEqual('objects or strings'); + expect(pluralizeType('objects (Pet) or numbers ')).toEqual('objects (Pet) or numbers '); + }); }); describe('openapi serializeParameter', () => { diff --git a/src/utils/openapi.ts b/src/utils/openapi.ts index 7eefb30dfe..2836cfedc2 100644 --- a/src/utils/openapi.ts +++ b/src/utils/openapi.ts @@ -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 '); }