feat: add basic support openApi 3.1

This commit is contained in:
Alex Varchuk 2021-05-19 12:07:53 +03:00
parent f7f28bfbd0
commit db610b4a05
3 changed files with 12 additions and 13 deletions

View File

@ -6,7 +6,7 @@ describe('Menu', () => {
it('should have valid items count', () => { it('should have valid items count', () => {
cy.get('.menu-content') cy.get('.menu-content')
.find('li') .find('li')
.should('have.length', 34); .should('have.length', 33);
}); });
it('should sync active menu items while scroll', () => { it('should sync active menu items while scroll', () => {

View File

@ -78,11 +78,6 @@ export class SchemaModel {
this.pointer = schemaOrRef.$ref || pointer || ''; this.pointer = schemaOrRef.$ref || pointer || '';
this.rawSchema = parser.deref(schemaOrRef); 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.schema = parser.mergeAllOf(this.rawSchema, this.pointer, isChild);
this.init(parser, isChild); this.init(parser, isChild);
@ -111,7 +106,7 @@ export class SchemaModel {
this.title = this.title =
schema.title || (isNamedDefinition(this.pointer) && JsonPointer.baseName(this.pointer)) || ''; schema.title || (isNamedDefinition(this.pointer) && JsonPointer.baseName(this.pointer)) || '';
this.description = schema.description || ''; this.description = schema.description || '';
this.type = schema.type || detectType(schema); this.type = (Array.isArray(schema.type) && schema.type) || (schema.type || detectType(schema));
this.format = schema.format; this.format = schema.format;
this.enum = schema.enum || []; this.enum = schema.enum || [];
this.example = schema.example; this.example = schema.example;
@ -120,7 +115,6 @@ export class SchemaModel {
this.externalDocs = schema.externalDocs; this.externalDocs = schema.externalDocs;
this.constraints = humanizeConstraints(schema); this.constraints = humanizeConstraints(schema);
this.displayType = Array.isArray(this.type) ? this.type.join(' or ') : this.type;
this.displayFormat = this.format; this.displayFormat = this.format;
this.isPrimitive = isPrimitiveType(schema, this.type); this.isPrimitive = isPrimitiveType(schema, this.type);
this.default = schema.default; this.default = schema.default;
@ -138,6 +132,13 @@ export class SchemaModel {
? this.type.map(item => item === null ? 'null' : item).join(' or ') ? this.type.map(item => item === null ? 'null' : item).join(' or ')
: this.type; : this.type;
if (!!schema.nullable) {
if (Array.isArray(this.type)) this.type.push('null');
else this.type = [this.type, 'null'];
}
this.displayType = Array.isArray(this.type) ? this.type.join(' or ') : this.type;
if (this.isCircular) { if (this.isCircular) {
return; return;
} }
@ -155,8 +156,7 @@ export class SchemaModel {
} }
if (schema.oneOf !== undefined) { if (schema.oneOf !== undefined) {
this.nullable = this.nullable || schema.oneOf.some(s => s.type === 'null'); this.initOneOf(schema.oneOf, parser);
this.initOneOf(schema.oneOf.filter(s => s.type !== 'null'), parser);
this.oneOfType = 'One of'; this.oneOfType = 'One of';
if (schema.anyOf !== undefined) { if (schema.anyOf !== undefined) {
console.warn( console.warn(
@ -167,8 +167,7 @@ export class SchemaModel {
} }
if (schema.anyOf !== undefined) { if (schema.anyOf !== undefined) {
this.nullable = this.nullable || schema.anyOf.some(s => s.type === 'null'); this.initOneOf(schema.anyOf, parser);
this.initOneOf(schema.anyOf.filter(s => s.type !== 'null'), parser);
this.oneOfType = 'Any of'; this.oneOfType = 'Any of';
return; return;
} }

View File

@ -240,7 +240,7 @@ describe('Utils', () => {
expect(isPrimitiveType(schema)).toEqual(true); expect(isPrimitiveType(schema)).toEqual(true);
}); });
it('Should return false for array of string which include the null value', () => { it('Should return true for array of string which include the null value', () => {
const schema = { const schema = {
type: ['object', 'string', 'null'], type: ['object', 'string', 'null'],
}; };