loop through composite schemas in _findSchema method

This commit is contained in:
hachichaud 2017-09-07 17:04:46 +02:00
parent a418fbab01
commit fc1a81a6f5
1 changed files with 27 additions and 10 deletions

View File

@ -2040,18 +2040,35 @@ Node._findEnum = function (schema) {
*/ */
Node._findSchema = function (schema, path) { Node._findSchema = function (schema, path) {
var childSchema = schema; var childSchema = schema;
var foundSchema = childSchema;
var allSchemas = schema.oneOf || schema.anyOf || schema.allOf;
if (!allSchemas) {
allSchemas = [schema];
}
for (var j = 0; j < allSchemas.length; j++) {
childSchema = allSchemas[j];
for (var i = 0; i < path.length && childSchema; i++) { for (var i = 0; i < path.length && childSchema; i++) {
var key = path[i]; var key = path[i];
if (typeof key === 'string' && childSchema.properties) { if (typeof key === 'string' && childSchema.properties) {
childSchema = childSchema.properties[key] || null childSchema = childSchema.properties[key] || null;
if (childSchema) {
foundSchema = childSchema;
}
} }
else if (typeof key === 'number' && childSchema.items) { else if (typeof key === 'number' && childSchema.items) {
childSchema = childSchema.items childSchema = childSchema.items;
if (childSchema) {
foundSchema = childSchema;
}
} }
} }
return childSchema }
return foundSchema
}; };
/** /**