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

Additional cleanup is not longer needed; fix #470

parent 7b878e47
Branches
Tags
No related merge requests found
......@@ -69,13 +69,7 @@ function traverse(schema, path, resolve, rootSchema) {
}
} else {
try {
const result = types[type](schema, path, resolve, traverse);
const required = schema.items
? schema.items.required
: schema.required;
return utils.clean(result, null, required);
return types[type](schema, path, resolve, traverse);
} catch (e) {
if (typeof e.path === 'undefined') {
throw new ParseError(e.message, path);
......
......@@ -170,36 +170,6 @@ function merge(a, b) {
return a;
}
function clean(obj, isArray, requiredProps) {
if (!obj || typeof obj !== 'object') {
return obj;
}
if (Array.isArray(obj)) {
obj = obj
.map(value => clean(value, true, requiredProps))
.filter(value => typeof value !== 'undefined');
return obj;
}
Object.keys(obj).forEach(k => {
if (!requiredProps || requiredProps.indexOf(k) === -1) {
if (Array.isArray(obj[k]) && !obj[k].length) {
delete obj[k];
}
} else {
obj[k] = clean(obj[k]);
}
});
if (!Object.keys(obj).length && isArray) {
return undefined;
}
return obj;
}
function short(schema) {
const s = JSON.stringify(schema);
const l = JSON.stringify(schema, null, 2);
......@@ -334,7 +304,6 @@ export default {
omitProps,
typecast,
merge,
clean,
short,
notValue,
anyValue,
......
{
"description": "Missing property 'array of object' in object",
"tests": [
{
"description": "xxx",
"schema": {
"additionalProperties": false,
"properties": {
"offer": {
"type": "object",
"properties": {
"multiplier_for_durations": {
"items": {
"type": "object"
},
"type": "array"
}
},
"required": [
"multiplier_for_durations"
]
}
},
"required": [
"offer"
],
"type": "object"
},
"valid": true
}
]
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment