diff --git a/src/core/run.js b/src/core/run.js index 7780d5ad9e3dd129be723dfc841e8397fd50d920..2194479b21b725b97edc3b819596dd8f648a77b0 100644 --- a/src/core/run.js +++ b/src/core/run.js @@ -117,9 +117,10 @@ function resolve(obj, data, values, property) { // TODO provide types function run(refs, schema, container) { let depth = 0; + let lastRef; try { - const result = traverse(utils.clone(schema), [], function reduce(sub, index, rootPath, parentSchema) { + const result = traverse(utils.clone(schema), [], function reduce(sub, index, rootPath) { if (typeof sub.generate === 'function') { return sub; } @@ -134,15 +135,14 @@ function run(refs, schema, container) { } if (typeof sub.$ref === 'string') { - if (index !== null && parentSchema && parentSchema.required) { - if (parentSchema.required.includes(index)) return sub; - } - - if (sub.$ref === '#' || (++depth > random.number(1, 2))) { + // increasing depth only for repeated refs seems to be fixing #258 + if (sub.$ref === '#' || (lastRef === sub.$ref && ++depth > random.number(0, 3))) { delete sub.$ref; return sub; } + lastRef = sub.$ref; + let ref; if (sub.$ref.indexOf('#/') === -1) { @@ -221,7 +221,7 @@ function run(refs, schema, container) { Object.keys(sub).forEach(prop => { if ((Array.isArray(sub[prop]) || typeof sub[prop] === 'object') && !utils.isKey(prop)) { - sub[prop] = reduce(sub[prop], prop, rootPath.concat(prop), parentSchema); + sub[prop] = reduce(sub[prop], prop, rootPath.concat(prop)); } }); diff --git a/src/types/object.js b/src/types/object.js index 6de8ba157598089705b7d3d7731b5cd1f893c524..697334731cc42db58517959d77790d0711f6f9d5 100644 --- a/src/types/object.js +++ b/src/types/object.js @@ -43,7 +43,7 @@ function objectType(value, path, resolve, traverseCallback) { } }); - return traverseCallback(props, path.concat(['properties']), resolve); + return traverseCallback(props, path.concat(['properties']), resolve, value); } const optionalsProbability = optionAPI('alwaysFakeOptionals') === true ? 1.0 : optionAPI('optionalsProbability'); @@ -100,7 +100,7 @@ function objectType(value, path, resolve, traverseCallback) { return traverseCallback({ allOf: _defns.concat(value), - }, path.concat(['properties']), resolve); + }, path.concat(['properties']), resolve, value); } } diff --git a/tests/schema/core/issues/issue-427.json b/tests/schema/core/issues/issue-427.json index 4db305ac809e4dffa652ad9f38c7884428695e9b..d75b79078e561ed882769ce583d1a3ec1dcc1558 100644 --- a/tests/schema/core/issues/issue-427.json +++ b/tests/schema/core/issues/issue-427.json @@ -94,7 +94,6 @@ "set": { "optionalsProbability": 0.6 }, - "skip": true, "valid": true } ]