Throw errors for incorrect or not-supported allOfs

This commit is contained in:
Roman Hotsiy 2015-12-14 10:18:15 +02:00
parent e633c02657
commit 54461e3582

View File

@ -106,17 +106,24 @@ export class BaseComponent {
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');
let errMessage = `Can\'t merge allOf: properties or required fields are specified on the same level as allOf
${into}`;
throw new Error(errMessage);
}
into.required = [];
into.properties = {};
for (let subSchema of schemas) {
// TODO: add support for merge array schemas
if (typeof subSchema !== 'object' || subSchema.type !== 'object') {
console.warn('WARN: incorrect allOf element skipped\nObject: ', subSchema);
let errMessage = `Can\'t merge allOf: only subschemas with type: object can be merged
${subSchema}`;
throw new Error(errMessage);
}
self.joinAllOf(subSchema);
// TODO: add check if can be merged correctly (no different properties with the same name)
if (subSchema.properties) {
Object.assign(into.properties, subSchema.properties);
}