Skip to content

Commit

Permalink
fix: add extra null-check + warning
Browse files Browse the repository at this point in the history
  • Loading branch information
RomanHotsiy committed Mar 7, 2018
1 parent a78f9ab commit 8757fa5
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/services/models/Schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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,
Expand Down

0 comments on commit 8757fa5

Please sign in to comment.