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) { ...@@ -117,9 +117,10 @@ function resolve(obj, data, values, property) {
// TODO provide types // TODO provide types
function run(refs, schema, container) { function run(refs, schema, container) {
let depth = 0; let depth = 0;
let lastRef;
try { 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') { if (typeof sub.generate === 'function') {
return sub; return sub;
} }
...@@ -134,15 +135,14 @@ function run(refs, schema, container) { ...@@ -134,15 +135,14 @@ function run(refs, schema, container) {
} }
if (typeof sub.$ref === 'string') { if (typeof sub.$ref === 'string') {
if (index !== null && parentSchema && parentSchema.required) { // increasing depth only for repeated refs seems to be fixing #258
if (parentSchema.required.includes(index)) return sub; if (sub.$ref === '#' || (lastRef === sub.$ref && ++depth > random.number(0, 3))) {
}
if (sub.$ref === '#' || (++depth > random.number(1, 2))) {
delete sub.$ref; delete sub.$ref;
return sub; return sub;
} }
lastRef = sub.$ref;
let ref; let ref;
if (sub.$ref.indexOf('#/') === -1) { if (sub.$ref.indexOf('#/') === -1) {
...@@ -221,7 +221,7 @@ function run(refs, schema, container) { ...@@ -221,7 +221,7 @@ function run(refs, schema, container) {
Object.keys(sub).forEach(prop => { Object.keys(sub).forEach(prop => {
if ((Array.isArray(sub[prop]) || typeof sub[prop] === 'object') && !utils.isKey(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) { ...@@ -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'); const optionalsProbability = optionAPI('alwaysFakeOptionals') === true ? 1.0 : optionAPI('optionalsProbability');
...@@ -100,7 +100,7 @@ function objectType(value, path, resolve, traverseCallback) { ...@@ -100,7 +100,7 @@ function objectType(value, path, resolve, traverseCallback) {
return traverseCallback({ return traverseCallback({
allOf: _defns.concat(value), allOf: _defns.concat(value),
}, path.concat(['properties']), resolve); }, path.concat(['properties']), resolve, value);
} }
} }
......
...@@ -94,7 +94,6 @@ ...@@ -94,7 +94,6 @@
"set": { "set": {
"optionalsProbability": 0.6 "optionalsProbability": 0.6
}, },
"skip": true,
"valid": true "valid": true
} }
] ]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment