Skip to content

Commit

Permalink
fix: nullable object's fields were missing (#1721)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexVarchuk authored Aug 11, 2021
1 parent 919a5f0 commit ddf297b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
17 changes: 6 additions & 11 deletions src/components/Schema/Schema.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,15 @@ export class Schema extends React.Component<Partial<SchemaProps>> {
return <OneOfSchema schema={schema} {...this.props} />;
}

if (type && Array.isArray(type)) {
const types = Array.isArray(type) ? type : [type];
if (types.includes('object')) {
if (schema.fields?.length) {
return <ObjectSchema {...(this.props as any)} />;
}
} else if (types.includes('array')) {
return <ArraySchema {...(this.props as any)} />;
}

switch (type) {
case 'object':
if (schema.fields?.length) {
return <ObjectSchema {...(this.props as any)} />;
}
break;
case 'array':
return <ArraySchema {...(this.props as any)} />;
}

// TODO: maybe adjust FieldDetails to accept schema
const field = ({
schema,
Expand Down
8 changes: 6 additions & 2 deletions src/services/models/Schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit ddf297b

Please sign in to comment.