From 8757fa510a1f6e27c14aa896e82090afc2feaad9 Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Wed, 7 Mar 2018 16:43:56 +0200 Subject: [PATCH] fix: add extra null-check + warning --- src/services/models/Schema.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/services/models/Schema.ts b/src/services/models/Schema.ts index bddd68d111..074770ec8c 100644 --- a/src/services/models/Schema.ts +++ b/src/services/models/Schema.ts @@ -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,