Skip to content

Commit

Permalink
fix: schemes without type: object are not expandable
Browse files Browse the repository at this point in the history
fixes #599
  • Loading branch information
RomanHotsiy committed Aug 8, 2018
1 parent 597688e commit 97e1620
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/services/models/Schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export class SchemaModel {
this.constraints = humanizeConstraints(schema);
this.displayType = this.type;
this.displayFormat = this.format;
this.isPrimitive = isPrimitiveType(schema);
this.isPrimitive = isPrimitiveType(schema, this.type);
this.default = schema.default;
this.readOnly = !!schema.readOnly;
this.writeOnly = !!schema.writeOnly;
Expand Down
11 changes: 11 additions & 0 deletions src/utils/__tests__/openapi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,17 @@ describe('Utils', () => {
};
expect(isPrimitiveType(schema)).toEqual(false);
});

it('should work with externally provided type', () => {
const schema = {
properties: {
a: {
type: 'string',
},
},
};
expect(isPrimitiveType(schema, 'object')).toEqual(false);
});
});

describe('openapi mergeParams', () => {
Expand Down
6 changes: 3 additions & 3 deletions src/utils/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,18 +105,18 @@ export function detectType(schema: OpenAPISchema): string {
return 'any';
}

export function isPrimitiveType(schema: OpenAPISchema) {
export function isPrimitiveType(schema: OpenAPISchema, type: string | undefined = schema.type) {
if (schema.oneOf !== undefined || schema.anyOf !== undefined) {
return false;
}

if (schema.type === 'object') {
if (type === 'object') {
return schema.properties !== undefined
? Object.keys(schema.properties).length === 0
: schema.additionalProperties === undefined;
}

if (schema.type === 'array') {
if (type === 'array') {
if (schema.items === undefined) {
return true;
}
Expand Down

0 comments on commit 97e1620

Please sign in to comment.