From 97f48f124543db228602b93ddaee141a8cc52ef3 Mon Sep 17 00:00:00 2001 From: Hermann <blumh@student.ethz.ch> Date: Fri, 25 May 2018 18:19:53 +0200 Subject: [PATCH] handle nullable fields in validation --- src/views/editView.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/views/editView.js b/src/views/editView.js index 7402c1a..4ca4557 100644 --- a/src/views/editView.js +++ b/src/views/editView.js @@ -63,6 +63,14 @@ export default class EditView extends ItemView { if (objectSchema.properties[property].format === 'objectid') { delete objectSchema.properties[property]; } + // translate nullable field from OpenAPI specification to + // possible type null in jsonschema + if (objectSchema.properties[property].nullable) { + objectSchema.properties[property].type = [ + 'null', + objectSchema.properties[property].type, + ]; + } }); // delete objectSchema.properties['_id']; console.log(this.ajv.addSchema(objectSchema, 'schema')); @@ -152,8 +160,8 @@ export default class EditView extends ItemView { return m(numInput, this.bind(field)); } else if (field.type === 'checkbox') { field.checked = this.data[key] || false; - field.onChange = (state) => { - this.data[key] = state.checked; + field.onChange = ({ checked }) => { + this.data[key] = checked; }; delete field.type; return m(Checkbox, field); -- GitLab