feat: add nullable lable for OAS 3.1 JSON schema

This commit is contained in:
Anton Kozachuk 2021-02-13 21:57:24 +02:00
parent 0dce880dce
commit 22e52f2b3f

View File

@ -104,9 +104,17 @@ export class SchemaModel {
this.title =
schema.title || (isNamedDefinition(this.pointer) && JsonPointer.baseName(this.pointer)) || '';
this.description = schema.description || '';
this.type = schema.type || detectType(schema);
if (Array.isArray(schema.type) && schema.type.includes('null')) {
this.nullable = true;
const schemaType = schema.type.filter((t) => t !== 'null');
this.type = schemaType.length === 1 ? schemaType[0] : schemaType;
} else {
this.nullable = !!schema.nullable;
this.type = schema.type || detectType(schema);
}
this.format = schema.format;
this.nullable = !!schema.nullable;
this.enum = schema.enum || [];
this.example = schema.example;
this.deprecated = !!schema.deprecated;
@ -221,9 +229,12 @@ export class SchemaModel {
if (name.indexOf(' or ') > -1) {
name = `(${name})`;
}
if (name.indexOf('null') !== -1) {
this.nullable = true;
}
return name;
})
.join(' or ');
.filter((t) => t !== 'null').join(' or ');
}
}