From 5cf7a075e26726c66136e176fe076390797416f5 Mon Sep 17 00:00:00 2001 From: Greg Tyler Date: Mon, 14 Oct 2024 11:06:02 +0100 Subject: [PATCH] Default date fields to null json-schema-library is defaulting al text fields to empty strings. This is fine for general text fields, but causes problems for dates as the the API then tries to unmarshal the string and finds it isn't a valid ISO-8601 date. Empty date strings should instead be treated as `null` so that unmarshaling is skipped. Fixes VEGA-2708 #patch --- fixtures/static/js/json-schema-editor.mjs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/fixtures/static/js/json-schema-editor.mjs b/fixtures/static/js/json-schema-editor.mjs index 341d3dbc..edb2485f 100644 --- a/fixtures/static/js/json-schema-editor.mjs +++ b/fixtures/static/js/json-schema-editor.mjs @@ -100,6 +100,7 @@ export class JsonSchemaEditor { const value = JSON.parse(this.$module.value); const data = jsonSchema.getTemplate(value); + this.nullEmptyDates(data); this.$module.value = JSON.stringify(data); this.$formContainer.innerHTML = ""; @@ -112,6 +113,19 @@ export class JsonSchemaEditor { }); } + nullEmptyDates(data) { + [ + "/signedAt", + "/witnessedByCertificateProviderAt", + "/witnessedByIndependentWitnessAt", + "/certificateProviderNotRelatedConfirmedAt", + ].forEach((datePointer) => { + if (jsonGet(data, datePointer) === "") { + jsonSet(data, datePointer, null); + } + }); + } + addToArray(pointer) { const value = JSON.parse(this.$module.value); const arr = jsonGet(value, pointer) ?? [];