From a79962a70e4ea8ac6f89a33adb3467285f0307bf Mon Sep 17 00:00:00 2001 From: Thijn Date: Fri, 9 Aug 2024 16:34:11 +0200 Subject: [PATCH] first concept of changing null => default value --- src/entities/metadata/metadata.ts | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/entities/metadata/metadata.ts b/src/entities/metadata/metadata.ts index d668ce4b..c6a2a6f9 100644 --- a/src/entities/metadata/metadata.ts +++ b/src/entities/metadata/metadata.ts @@ -52,6 +52,33 @@ export class Metadata implements TMetadata { valuation: 'n', class: 1, } + + // changed null to default values within these properties + const ensureDefaults = (obj: TMetadata['properties']) => { + const defaultValues: Partial = { + minimum: 0, + maximum: 0, + multipleOf: 0, + minItems: 0, + maxItems: 0, + minLength: 0, + maxLength: 0, + } + + for (const key in obj) { + // eslint-disable-next-line no-prototype-builtins + if (obj.hasOwnProperty(key)) { + if (obj[key].minimum === null) obj[key].minimum = defaultValues.minimum! + if (obj[key].maximum === null) obj[key].maximum = defaultValues.maximum! + if (obj[key].multipleOf === null) obj[key].multipleOf = defaultValues.multipleOf! + if (obj[key].minItems === null) obj[key].minItems = defaultValues.minItems! + if (obj[key].maxItems === null) obj[key].maxItems = defaultValues.maxItems! + if (obj[key].minLength === null) obj[key].minLength = defaultValues.minLength! + if (obj[key].maxLength === null) obj[key].maxLength = defaultValues.maxLength! + } + } + } + ensureDefaults(this.properties) } /* istanbul ignore next */