Skip to content

Commit

Permalink
add nullable lable for OAS 3.1 JSON schema
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton_Kozachuk committed May 18, 2021
1 parent 2f85d42 commit e03c4e8
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/services/models/Schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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(
Expand All @@ -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;
}
Expand Down

0 comments on commit e03c4e8

Please sign in to comment.