-
-
Notifications
You must be signed in to change notification settings - Fork 313
Proposal: Standardize validation error and introduce new keyword messages
#1241
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
Comments
The tag for this is localization, and another related issue might be #743. Although "localization" normally implies "translating for one language & culture from another", in the case of JSON Schema, there might not be any localization (the only output format is for machines), and we're trying to create one from scratch. In addition to multiple locales, you have to accommodate multiple interfaces. For example, a response from an API isn't going to be the same as an error in a form. |
Yes, when multiple APIs share a same schema, to accommodate these APIs, it's better not to put |
The current output formats already specify the keyword. Moreso, they specify the location of the keyword. We've gone back and forth on inclusion of specific wording. I do appreciate the thought you've put into the For my implementation, json-everything, I have added support for defining custom error messages, including support for language packs (though I only have Spanish defined for now). This is currently an implementation-defined thing, though, so your mileage may vary with other libraries. |
Yes, I see. I'd appreciate if there's also a seperate
Great feature, that's what I really want, buy sadly I'm using some other lib in golang (https://github.com/santhosh-tekuri/jsonschema). So, this proposal is to make this feature a specification, so that all the implementations behave the same, including the
In my usage, I won't share a schema between multiple APIs, so embedding
I propose to standardize and structuring the validation error (the first part of the proposal), and output them, like: {
"valid": false,
"keyword": "minLength",
"keywordLocaation": "#/description",
"xxx": {
"received": 1,
"limit": 3
},
"schemaLocation": "https://example.com/mySchema#/description",
"instanceLocation": "",
"annotation": "description"
} so users can format their own messages. Here |
Please start a new thread in my output format proposed changes discussion linked above. I think that's the appropriate place to catalog features like this. |
OK, I've started a new thread in the discussion, and the issue can be closed if needed. |
Standardize validation error
When using jsonschema in validating user's input (e.g. in a html form), usually we want to give users friendly/multilingual/custom error messages. Futhermore, the error message may include some validation params.
Take the
minLength
keyword as example, two validation params are available for sure:With those two params, we can form various error messages like:
Considering the usage described above, I proposal to standarlize params that a validation error must give, including the type and the meaning. e.g.,
As for
minLength
,number
)number
)As for
minimum
,number
)number
)and so on.
In a word, the proposal can be regarded as "Standardize and structuring the validation error".
A new keyword
messages
Based on the structuralized error, I propose to add a new keyword, let me call it
messages
. This keyword is used to define templates for formating errors. It looks like:There are two keys in the
messages
keyword,default
andminLength
. When a validation error occurs, the validator should use corresponding error message template defined in themessages
keyword to format the error.e.g., if the error is caused by
minLength
keyword, then,minLength
in themessages
should be used.default
template should be used.default
template isn't present, then validators can format the error as they want.Without the proposed
messages
keyword, it will be very hard for developers to format error messages as they want, especially in the circumstance that developers won't be able to get the validation params as mentioned above. By the way, error message are ususually tied closely to a specific schema, that's why I propose to embedmessages
in the schema itself.Finally, if there's a duplicate issue, please let me know, thanks.
The text was updated successfully, but these errors were encountered: