Skip to content

Commit

Permalink
feat(code-gen/experimental): auto convert string 0/1 to boolean in th…
Browse files Browse the repository at this point in the history
…e validators
  • Loading branch information
dirkdev98 committed Apr 19, 2023
1 parent 32b7120 commit 129debc
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/code-gen/src/experimental/validators/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,9 @@ export function validatorJavascriptBoolean(file, type, validatorState) {
file,
`if (${valuePath} === ${type.oneOf} || ${valuePath} === "${
type.oneOf
}" || ${valuePath} === ${type.oneOf ? 1 : 0})`,
}" || ${valuePath} === ${type.oneOf ? 1 : 0} || ${valuePath} === "${
type.oneOf ? 1 : 0
}")`,
);

fileWrite(file, `${resultPath} = ${type.oneOf};`);
Expand All @@ -699,14 +701,14 @@ export function validatorJavascriptBoolean(file, type, validatorState) {
} else {
fileBlockStart(
file,
`if (${valuePath} === true || ${valuePath} === "true" || ${valuePath} === 1)`,
`if (${valuePath} === true || ${valuePath} === "true" || ${valuePath} === 1 || ${valuePath} === "1")`,
);
fileWrite(file, `${resultPath} = true;`);

fileBlockEnd(file);
fileBlockStart(
file,
`else if (${valuePath} === false || ${valuePath} === "false" || ${valuePath} === 0)`,
`else if (${valuePath} === false || ${valuePath} === "false" || ${valuePath} === 0 || ${valuePath} === "0")`,
);
fileWrite(file, `${resultPath} = false;`);

Expand Down

0 comments on commit 129debc

Please sign in to comment.