Skip to content

Commit

Permalink
fix: improve code
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexVarchuk committed May 31, 2021
1 parent 532c30e commit 9fdcdfb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/services/models/Schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 13 additions & 0 deletions src/utils/__tests__/openapi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down
2 changes: 1 addition & 1 deletion src/utils/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 9fdcdfb

Please sign in to comment.