From 9fdcdfb049e2af9145810a85ae5df90fc92b496d Mon Sep 17 00:00:00 2001 From: Alex Varchuk Date: Mon, 31 May 2021 13:53:15 +0300 Subject: [PATCH] fix: improve code --- src/services/models/Schema.ts | 2 +- src/utils/__tests__/openapi.test.ts | 13 +++++++++++++ src/utils/openapi.ts | 2 +- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/services/models/Schema.ts b/src/services/models/Schema.ts index 4d8a9665e4..2de8740ae0 100644 --- a/src/services/models/Schema.ts +++ b/src/services/models/Schema.ts @@ -196,7 +196,7 @@ export class SchemaModel { const title = isNamedDefinition(variant.$ref) && !merged.title ? JsonPointer.baseName(variant.$ref) - : (merged.const && JSON.stringify(merged.const)) || merged.title; + : `${(merged.title || '')}${(merged.const && JSON.stringify(merged.const)) || ''}`; const schema = new SchemaModel( parser, diff --git a/src/utils/__tests__/openapi.test.ts b/src/utils/__tests__/openapi.test.ts index 670ac42c99..d4f23e0219 100644 --- a/src/utils/__tests__/openapi.test.ts +++ b/src/utils/__tests__/openapi.test.ts @@ -227,6 +227,19 @@ describe('Utils', () => { expect(isPrimitiveType(schema)).toEqual(false); }); + it('should return true for array contains array of strings', () => { + const schema = { + type: 'array', + items: { + type: 'array', + items: { + type: 'string' + }, + }, + }; + expect(isPrimitiveType(schema)).toEqual(true); + }); + it('Should return false for array of string which include the null value', () => { const schema = { type: ['object', 'string', 'null'], diff --git a/src/utils/openapi.ts b/src/utils/openapi.ts index f6d80f3148..c31e3cd21c 100644 --- a/src/utils/openapi.ts +++ b/src/utils/openapi.ts @@ -126,7 +126,7 @@ export function isPrimitiveType(schema: OpenAPISchema, type: string | string[] | } if (schema.items !== undefined && (type === 'array' || (isArray && type?.includes('array')))) { - isPrimitive = false; + isPrimitive = isPrimitiveType(schema.items, schema.items.type); } return isPrimitive;