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

Handle unwanted properties from oneOf mixins; fix

parent b427355b
Branches
Tags
No related merge requests found
...@@ -185,7 +185,7 @@ function run(refs, schema, container) { ...@@ -185,7 +185,7 @@ function run(refs, schema, container) {
// call given thunks if present // call given thunks if present
utils.merge(sub, typeof _sub.thunk === 'function' utils.merge(sub, typeof _sub.thunk === 'function'
? _sub.thunk() ? _sub.thunk(sub)
: _sub); : _sub);
}); });
} }
...@@ -200,24 +200,26 @@ function run(refs, schema, container) { ...@@ -200,24 +200,26 @@ function run(refs, schema, container) {
} }
return { return {
thunk() { thunk(rootSchema) {
const copy = utils.omitProps(sub, ['anyOf', 'oneOf']); const copy = utils.omitProps(sub, ['anyOf', 'oneOf']);
const fixed = random.pick(mix); const fixed = random.pick(mix);
utils.merge(copy, fixed); utils.merge(copy, fixed);
if (sub.oneOf && copy.properties) { // remove additional properties from merged schemas
mix.forEach(omit => { mix.forEach(omit => {
if (omit !== fixed && omit.required) { if (omit.required && omit !== fixed) {
omit.required.forEach(key => { omit.required.forEach(key => {
// remove additional properties from merged schemas if (copy.properties && !copy.required.includes(key)) {
if (!copy.required.includes(key)) {
delete copy.properties[key]; delete copy.properties[key];
} }
});
if (rootSchema && rootSchema.properties) {
delete rootSchema.properties[key];
} }
}); });
} }
});
return copy; return copy;
}, },
... ...
......
...@@ -54,7 +54,7 @@ function traverse(schema, path, resolve, rootSchema) { ...@@ -54,7 +54,7 @@ function traverse(schema, path, resolve, rootSchema) {
// thunks can return sub-schemas // thunks can return sub-schemas
if (typeof schema.thunk === 'function') { if (typeof schema.thunk === 'function') {
return traverse(schema.thunk(), path, resolve); return traverse(schema.thunk(rootSchema), path, resolve);
} }
if (typeof schema.generate === 'function') { if (typeof schema.generate === 'function') {
... ...
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment