-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bug: discriminator compilation fails for discriminators nested in oneOf #176
Comments
The error seems to originate at this line: fix(functions.deepEqual(stat.type, ['object']), 'has to be checked for type:', 'object') I logged the value of stat: {
type: null,
items: 0,
properties: [ 'method', 'type' ],
patterns: [],
required: [ 'method' ],
fullstring: false,
dyn: { item: false, items: 0, properties: [Array], patterns: [] },
unknown: false
} Seems like |
@ChALkeR Can you take a look? |
I see the error and a there is a work-around, working on a fix. |
There are three typecheck levels here:
@olistic @kklash #177 should stop failing now if Without #177 (i.e. on current releases), removing lvl1 check and leaving only 2/3 or a combo of them will also work. A Explanation: Each discriminator expects either itself or each of it sub-branches to be typechecked to Nested useless typechecks are ignored, but branches didn't report them as typechecked in the So, when lvl 1 typecheck was present, the safeguard in the second discriminator didn't see that all the branches are already checked. This happened regardless of if the second discriminator or it subbranches had #177 just adds the corresponding type info to the stat object in that "short-circuit" codepath, but only if it tries to typecheck again (for now). #179 solves this completely. |
Side note: you probably want |
Thanks for the tip @ChALkeR! Moving |
Context
Consider an object which can have three different shapes:
To validate such an object, i first set a
discriminator
on thetype
property, and branched based on that. Then, within thetype: 'request'
branch ofoneOf
, i specified anotherdiscriminator
on themethod
property. However, Schemasafe fails to compile in this scenario, throwing the following error:Note that we clearly did check the node for
type: 'object'
before applying thediscriminator
keyword.Demo
This test case demonstrates the problem:
Compilation fails even if
type: 'object'
is added to both of the relevantoneOf
branches.The text was updated successfully, but these errors were encountered: