From 263fcc5af2eb28b516615a91a989883efcdab677 Mon Sep 17 00:00:00 2001 From: Rinse Vlaswinkel <43185712+RinseV@users.noreply.github.com> Date: Tue, 1 Oct 2024 15:20:12 +0200 Subject: [PATCH 1/2] chore: Expand const specification with false and 0 constants --- tests/specifications/const.yaml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/specifications/const.yaml b/tests/specifications/const.yaml index eef4de41c..ab7a3b105 100644 --- a/tests/specifications/const.yaml +++ b/tests/specifications/const.yaml @@ -26,11 +26,15 @@ components: type: object required: - value + - valueFalse - valueNullable properties: value: type: boolean const: true + valueFalse: + type: boolean + const: false valueNullable: type: - boolean @@ -40,11 +44,15 @@ components: type: object required: - value + - valueZero - valueNullable properties: value: type: number const: 1 + valueZero: + type: number + const: 0 valueNullable: type: - number From 12c335cac9fc470f05098e0f87702ac26f7a623e Mon Sep 17 00:00:00 2001 From: Rinse Vlaswinkel <43185712+RinseV@users.noreply.github.com> Date: Tue, 1 Oct 2024 15:22:16 +0200 Subject: [PATCH 2/2] fix: Correctly set type for false or 0 constants --- packages/core/src/getters/scalar.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/core/src/getters/scalar.ts b/packages/core/src/getters/scalar.ts index c6a2ffdb1..2325b7dbe 100644 --- a/packages/core/src/getters/scalar.ts +++ b/packages/core/src/getters/scalar.ts @@ -52,7 +52,7 @@ export const getScalar = ({ } const itemWithConst = item as SchemaWithConst; - if (itemWithConst.const) { + if (itemWithConst.const !== undefined) { value = itemWithConst.const; } @@ -73,7 +73,7 @@ export const getScalar = ({ let value = 'boolean'; const itemWithConst = item as SchemaWithConst; - if (itemWithConst.const) { + if (itemWithConst.const !== undefined) { value = itemWithConst.const; }