-
-
Notifications
You must be signed in to change notification settings - Fork 211
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
anyOf/oneOf coerces to property first fitting type (in body response) #391
Comments
@kevinval good catch. PR #387 improves the way request validation is handled. Essentially, it no longer performs type coercion on request bodies. Everything else remains the same (though coerceTypes becomes ambiguous and hence will be removed in the next major version). As you example illustrates, a similar change is needed for response bodies. I'll start work on that. |
* (fix) #391 - do not coerce response body value * update README
@kevinval this should be fixed in |
confirmed fixed in |
Describe the bug
A property defined as
anyOf
with a mixture ofinteger
/boolean
results in being coerced (cast) to the first type it matches. Additionally usingoneOf
isn't possible either as both boolean and an integer value will with both types and the match is no longeroneOf
.To Reproduce
Having a schema like this:
And having
validateResponses: true
enabled, when an object like this is passed to the validator:Actual behavior
It comes out of the validator as this:
Expected behavior
The type should be kept as boolean:
Examples and context
It also works the other way, if the schema will have
boolean
first in the list stuff will get coerced toboolean
instead - whatever matches first it seems based on coercion rules of AJV.coerceTypes: false
seems to fix this behavior. It also fixes it foroneOf
(obviously, I guess). But that's not the best workaround as we do rely on it for eg. URL GET parameters.I noticed the recent work in #387 and that
coerceTypes
got deprecated. Is it possible it somehow does not apply to validation of responses? At least from the quick look it seemed to be request-related.The text was updated successfully, but these errors were encountered: