Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add "allowedValue" to error params of "const" keyword #713

Closed
marshall007 opened this issue Feb 21, 2018 · 2 comments
Closed

Add "allowedValue" to error params of "const" keyword #713

marshall007 opened this issue Feb 21, 2018 · 2 comments

Comments

@marshall007
Copy link
Contributor

What version of Ajv are you using? Does the issue happen if you use the latest version?
6.1.1, yes.

Ajv options object

{
  allErrors: true,
  useDefaults: true,
  removeAdditional: 'all',
  coerceTypes: 'array',
}

JSON Schema

{
  "type": "string",
  "const": "EVENT",
  "default": "EVENT"
}

Sample data

"FOO"

Your code

ajv.validate({
  "type": "string",
  "const": "EVENT"
}, 'FOO');

Validation result, data AFTER validation, error messages

[
  {
    "keyword": "const",
    "dataPath": "",
    "schemaPath": "#/const",
    "params": {},
    "message": "should be equal to constant"
  }
]

What results did you expect?

This issue is virtually identical to #282, i.e. that it would be nice if the error payload contained a reference to the required constant value.

Are you going to resolve the issue?

I would need to investigate the templating stuff before submitting a fix, but the issue should be resolved by adding allowedValue (or similar) here.

@epoberezkin
Copy link
Member

Yes, that’s ok, makes error reporting more consistent. Implementation should be quite straightforward, see the PR that closed the other issue.

@marshall007
Copy link
Contributor Author

@epoberezkin great, I'll have a PR up in the next day or two.

# for free to join this conversation on GitHub. Already have an account? # to comment
Development

No branches or pull requests

2 participants