Skip to content
Snippets Groups Projects
Commit 426ef2a5 authored by Alvaro Cabrera Durán's avatar Alvaro Cabrera Durán
Browse files

Handle circular-refs and such; fixes #258 #427

parent 47764bad
No related branches found
No related tags found
No related merge requests found
......@@ -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));
}
});
......
......@@ -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);
}
}
......
......@@ -94,7 +94,6 @@
"set": {
"optionalsProbability": 0.6
},
"skip": true,
"valid": true
}
]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment