From e03c4e86d096851175f6975f7e7646a99d873d07 Mon Sep 17 00:00:00 2001 From: Anton_Kozachuk Date: Tue, 18 May 2021 14:06:30 +0300 Subject: [PATCH] add nullable lable for OAS 3.1 JSON schema --- src/services/models/Schema.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/services/models/Schema.ts b/src/services/models/Schema.ts index 674afcbe61..e6fbe4345d 100644 --- a/src/services/models/Schema.ts +++ b/src/services/models/Schema.ts @@ -76,6 +76,12 @@ export class SchemaModel { this.pointer = schemaOrRef.$ref || pointer || ''; this.rawSchema = parser.deref(schemaOrRef); + + if (Array.isArray(this.rawSchema.type)) { + this.rawSchema.oneOf = this.rawSchema.type.map( type => ({type})); + delete this.rawSchema.type; + } + this.schema = parser.mergeAllOf(this.rawSchema, this.pointer, isChild); this.init(parser, isChild); @@ -138,7 +144,8 @@ export class SchemaModel { } if (schema.oneOf !== undefined) { - this.initOneOf(schema.oneOf, parser); + this.nullable = this.nullable || schema.oneOf.some(s => s.type === 'null'); + this.initOneOf(schema.oneOf.filter(s => s.type !== 'null'), parser); this.oneOfType = 'One of'; if (schema.anyOf !== undefined) { console.warn( @@ -149,7 +156,8 @@ export class SchemaModel { } if (schema.anyOf !== undefined) { - this.initOneOf(schema.anyOf, parser); + this.nullable = this.nullable || schema.anyOf.some(s => s.type === 'null'); + this.initOneOf(schema.anyOf.filter(s => s.type !== 'null'), parser); this.oneOfType = 'Any of'; return; }