Skip to content

Commit 3fa324f

Browse files
committed
fix(code-gen/experimental): use anyOf#discriminant in JS validators
1 parent f8168fb commit 3fa324f

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

packages/code-gen/src/experimental/generated/experimental/validators.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/code-gen/src/experimental/validators/javascript.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,10 @@ export function validatorJavascriptAnyOf(file, type, validatorState) {
374374

375375
matchableValues.push(oneOf);
376376

377-
fileBlockStart(file, `if (${valuePath}.type === "${oneOf}")`);
377+
fileBlockStart(
378+
file,
379+
`if (${valuePath}.${type.validator.discriminant} === "${oneOf}")`,
380+
);
378381

379382
validatorState.skipFirstNilCheck = true;
380383
validatorGeneratorGenerateBody(
@@ -398,6 +401,7 @@ export function validatorJavascriptAnyOf(file, type, validatorState) {
398401
`${errorKey} = {
399402
key: "validator.anyOf",
400403
discriminant: "${type.validator.discriminant}",
404+
foundValue: ${valuePath}.${type.validator.discriminant},
401405
allowedValues: ${JSON.stringify(matchableValues)},
402406
};`,
403407
);

0 commit comments

Comments
 (0)