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
"Constant" does not seem to validate the same way as equivalent single-value enum #682
Comments
@jthomerson It should be “const”: https://github.com/epoberezkin/ajv/blob/master/KEYWORDS.md#const |
It was originally proposed as “constant” and previously implemented this way though, so I understand where the confusion can be coming from... |
Yeah, the Google results are hurting us here ... json schema constant results all pull up those previous proposals (for good reasons ... constant vs const). I should've looked at the actual spec, but that (ironically) is harder to find when you're searching by keywords. Sorry for the wasted time. Thanks for your work on the library! |
Gahhh... I spent like an hour trying to figure out why my |
Please see the details in my StackOverflow question: https://stackoverflow.com/questions/48389997/json-schema-why-does-constant-not-validate-the-same-way-as-a-single-valued-e/
It's unclear why changing
{ "constant": "client" }
to{ "enum": [ "client" ] }
affects the validation. Is that an error in my usage, or a bug in AJV? Thanks!What version of Ajv are you using? Does the issue happen if you use the latest version?
6.0.1
Ajv options object
Not sure. I'm using this via ajv-cli@3.0.0. I also tried with my own script, using AJV@6.0.1 directly, with no options, and received the same error.
JSON Schema
See https://stackoverflow.com/questions/48389997/json-schema-why-does-constant-not-validate-the-same-way-as-a-single-valued-e/
Sample data
See https://stackoverflow.com/questions/48389997/json-schema-why-does-constant-not-validate-the-same-way-as-a-single-valued-e/
Your code
N/A
Validation result, data AFTER validation, error messages
https://stackoverflow.com/questions/48389997/json-schema-why-does-constant-not-validate-the-same-way-as-a-single-valued-e/
What results did you expect?
I expected the sample data (two shown in the SO question) to be valid. However, both were invalid because the validator said that they matched both sub-schemas in the
oneOf
clause. I don't see how the sample documents would ever match both of the sub-schemas - they should only match one. When changing{ "constant": "client" }
to{ "enum": [ "client" ] }
, the validation worked as expected.Are you going to resolve the issue?
The text was updated successfully, but these errors were encountered: