Skip to content
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

Catch Enum Errors value #2475

Open
Meriyemelhajoui opened this issue Jul 18, 2024 · 4 comments
Open

Catch Enum Errors value #2475

Meriyemelhajoui opened this issue Jul 18, 2024 · 4 comments

Comments

@Meriyemelhajoui
Copy link

Hello , I m using AJV Compiler to validate JSON Data against a defined Schemas , and I m using Literal or Enum to allow only a specific Values :

comparator:
       "strictly-greater" | "strictly-lower"  | "greater-or-equal" |"lower-or-equal" ;

However , during validation the compiler doesn't show all allowed values , it only shows :

message: "must be equal to constant"
​​
params: Object { allowedValue: "strictly-greater" }

Can anyone assist on that , is it related to my validation logic or the AJV Compiler does catch errros for enum or literal values only for the first value ?!

@Meriyemelhajoui
Copy link
Author

@epoberezkin

@jasoniangreen
Copy link
Collaborator

Hi @Meriyemelhajoui can you please provide as simple an example as possible using Runkit (it is limited to v8.12.0 but should be good for most issues). The simpler you can make the example the better the chance I have of understanding and investigating.

@Meriyemelhajoui
Copy link
Author

Given this example of schema that requires that the user should enter a specific value for a field :
address : "address1" | "address2" | "address3",
Which is basically an enum values where the allowed values are address1 or address2 or address3.
While trying to validate User input against my defined schema , the AJV Compiler , catch the error if the user enter a value for address like : "address100" , but the provided error catched doesn't provide enough information such as : the value for address should be one of these allowed values : address1 , address2 or address3 . Until I have defined the property address as an enum value , then it can catch the error as it should be , which means that define enums as literals doesn't really give a clear error information while catching the error

@jasoniangreen
Copy link
Collaborator

This syntax address : "address1" | "address2" | "address3" is typescript, isn't it, not JSON Schema? You'll really need to provide an example in runkit so I can properly investigate.

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

No branches or pull requests

2 participants