fix: add extra null-check + warning

This commit is contained in:
Roman Hotsiy 2018-03-07 16:43:56 +02:00
parent a78f9ab688
commit 8757fa510a
No known key found for this signature in database
GPG Key ID: 5CB7B3ACABA57CB0

View File

@ -208,6 +208,15 @@ function buildFields(
const additionalProps = schema.additionalProperties;
const defaults = schema.default || {};
const fields = Object.keys(props || []).map(fieldName => {
let field = props[fieldName];
if (!field) {
console.warn(
`Field "${fieldName}" is invalid, skipping.\n Field must be an object but got ${typeof field} at "${$ref}"`,
);
field = {};
}
const required =
schema.required === undefined ? false : schema.required.indexOf(fieldName) > -1;
@ -217,8 +226,8 @@ function buildFields(
name: fieldName,
required,
schema: {
...props[fieldName],
default: props[fieldName].default || defaults[fieldName],
...field,
default: field.default || defaults[fieldName],
},
},
$ref + '/properties/' + fieldName,