From 4494f80dbc41b7bfe2eb64bbd727271658860898 Mon Sep 17 00:00:00 2001 From: Michael Huynh <43751307+miqh@users.noreply.github.com> Date: Sat, 12 Oct 2019 17:33:03 +0800 Subject: [PATCH] fix: types over-pluralization (#1057) fixes #1053 --- src/utils/__tests__/openapi.test.ts | 8 ++++++++ src/utils/openapi.ts | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/utils/__tests__/openapi.test.ts b/src/utils/__tests__/openapi.test.ts index 92057583..244ab63c 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 7eefb30d..2836cfed 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 '); }