mirror of
https://github.com/Redocly/redoc.git
synced 2025-02-26 23:10:33 +03:00
Resolve allOf in JsonSchema component
This commit is contained in:
parent
743f270feb
commit
f538d15ece
|
@ -17,6 +17,7 @@ export default class JsonSchema extends BaseComponent {
|
||||||
|
|
||||||
prepareModel() {
|
prepareModel() {
|
||||||
this.dereference();
|
this.dereference();
|
||||||
|
this.joinAllOf();
|
||||||
this.requiredMap = {};
|
this.requiredMap = {};
|
||||||
if (this.schema.required) {
|
if (this.schema.required) {
|
||||||
this.schema.required.forEach(prop => this.requiredMap[prop] = true);
|
this.schema.required.forEach(prop => this.requiredMap[prop] = true);
|
||||||
|
@ -26,7 +27,7 @@ export default class JsonSchema extends BaseComponent {
|
||||||
this.data.properties = [];
|
this.data.properties = [];
|
||||||
if (schema.type !== 'object') {
|
if (schema.type !== 'object') {
|
||||||
// TODO
|
// TODO
|
||||||
this.errorMessage = 'Non-object (array-based or all-of) schemas are not implemented yet';
|
this.errorMessage = 'Non-object (array-based) schemas are not implemented yet';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!schema.properties) return;
|
if (!schema.properties) return;
|
||||||
|
|
|
@ -98,6 +98,36 @@ export class BaseComponent {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
joinAllOf(schema = this.componentSchema) {
|
||||||
|
var self = this;
|
||||||
|
function merge(into, schemas) {
|
||||||
|
if (into.required || into.properties) {
|
||||||
|
console.warn('WARN: properties or required field set on the same level as allOf');
|
||||||
|
}
|
||||||
|
into.required = [];
|
||||||
|
into.properties = {};
|
||||||
|
for (let subSchema of schemas) {
|
||||||
|
if (typeof subSchema !== 'object' || subSchema.type !== 'object') {
|
||||||
|
console.warn('WARN: incorrect allOf element skipped\nObject: ', subSchema);
|
||||||
|
}
|
||||||
|
|
||||||
|
self.joinAllOf(subSchema);
|
||||||
|
|
||||||
|
if (subSchema.properties) {
|
||||||
|
Object.assign(into.properties, subSchema.properties);
|
||||||
|
}
|
||||||
|
if (subSchema.required) {
|
||||||
|
into.required.push(...subSchema.required);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
into.type = 'object';
|
||||||
|
into.allOf = null;
|
||||||
|
}
|
||||||
|
if (schema.allOf) {
|
||||||
|
merge(schema, schema.allOf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used to prepare model based on component schema
|
* Used to prepare model based on component schema
|
||||||
* @abstract
|
* @abstract
|
||||||
|
|
Loading…
Reference in New Issue
Block a user