diff --git a/src/components/Schema/Schema.tsx b/src/components/Schema/Schema.tsx index 8948e2b4..392a0f23 100644 --- a/src/components/Schema/Schema.tsx +++ b/src/components/Schema/Schema.tsx @@ -63,20 +63,15 @@ export class Schema extends React.Component> { return ; } - if (type && Array.isArray(type)) { + const types = Array.isArray(type) ? type : [type]; + if (types.includes('object')) { + if (schema.fields?.length) { + return ; + } + } else if (types.includes('array')) { return ; } - switch (type) { - case 'object': - if (schema.fields?.length) { - return ; - } - break; - case 'array': - return ; - } - // TODO: maybe adjust FieldDetails to accept schema const field = ({ schema, diff --git a/src/services/models/Schema.ts b/src/services/models/Schema.ts index e5b36ae1..d79d738b 100644 --- a/src/services/models/Schema.ts +++ b/src/services/models/Schema.ts @@ -100,6 +100,10 @@ export class SchemaModel { this.activeOneOf = idx; } + hasType(type: string) { + return this.type === type || (Array.isArray(this.type) && this.type.includes(type)); + } + init(parser: OpenAPIParser, isChild: boolean) { const schema = this.schema; this.isCircular = schema['x-circular-ref']; @@ -170,9 +174,9 @@ export class SchemaModel { return; } - if (this.type === 'object') { + if (this.hasType('object')) { this.fields = buildFields(parser, schema, this.pointer, this.options); - } else if ((this.type === 'array' || Array.isArray(this.type)) && schema.items) { + } else if (this.hasType('array') && schema.items) { this.items = new SchemaModel(parser, schema.items, this.pointer + '/items', this.options); this.displayType = pluralizeType(this.items.displayType); this.displayFormat = this.items.format;