fix: nullable object's fields were missing (#1721)

This commit is contained in:
AlexVarchuk 2021-08-11 12:59:31 +03:00 committed by GitHub
parent 919a5f02fb
commit ddf297b112
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 13 deletions

View File

@ -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,

View File

@ -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;