-
-
Notifications
You must be signed in to change notification settings - Fork 297
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
format for non-string data types (complex validation rules) #759
Comments
This is absolutely not true. JSON Schema does not restrict the sort of values that |
Or plainly lazy implementation. I discussed this on slack and suggested filing an issue. I agree it's an implementation issue, but I agreed it could be made clearer in the spec that this is possible, without having to say it explicitly. |
@handrews Wait, that's a misunderstanding. My intention was to say that all pre-defined formats in the spec (e.g. uri) are for string types. There's no pre-defined format for any other data type in the spec. That could lead to confusion as people may thing it's meant to be only for strings. Having that said, I assumed "Understanding JSON Schema" is somewhat part of the official spec as it's hosted at https://json-schema.org - I can fill an issue for it, but I don't know where to do that (edit: found it, opened an issue: json-schema-org/website#187). I also filled an issue already for ajv (see referenced issues above), but I didn't had clear docs that helped me prove my point that implementations should/could allow format for non-string types. @Relequestual Fully agreed. That's the only thing I'm personally aiming for, a clarification.
If devs don't understand the spec it is eventually a spec problem. I'm assuming devs are somewhat intelligent... ;-) |
This will get taken care of by my fix for #646. |
Transferred from the JSON Schema Slack Channel...
Background: I'm working on a project, which passes workflows in JSON from clients to servers. These workflows we mostly validate with JSON Schema and (aim to) do the complex validation with
format
(see also https://github.com/Open-EO/openeo-processes/issues/67). Therefore, we have quite an extensive list of formats. Some examples:collection-id
checks in the database whether the specified dataset exists and can be used in the workflow. It's a string and the validation with ajv works well.epsg-code
check against the EPSG code database. It's an integer and doesn't work with ajv as ajv only supports format on numbers and strings.Specifying format on non-string data types doesn't seem very uncommon. OpenAPI also has formats for non-string types, for example int32/int64 for integer and float/double for number.
Problem: The JSON spec itself only defines formats on string values. Also, custom formats is described in the "Understanding JSON Schema" documentation as part of the string data type. This seems to lead to the problem that several libraries only implement custom formats for strings (or a subset of JSON data types). For example, ajv currently only supports format to be defined for strings and numbers, see also ajv-validator/ajv#1039. kin-openapi also only supports string formats (yes, it's OpenAPI, but seems to be the same problem).
In contrast, https://json-schema.org/latest/json-schema-validation.html#format doesn't mention this restriction and explicitly mentions for individual types that they apply for strings ('These attributes apply to string instances.'), which would not be required if format is only defined for strings anyway. Therefore, I couldn't really figure out from the spec whether
format
meant to be only for strings or for all data types.Proposal: Therefore, I have asked on the Slack channel for a clarification in the spec (see the discussion).
@handrews wrote:
So it seems there should be a clarification in the spec that format is allowed for all data types. This would clarify and help to convince implementers to support format for more data types.
Alternative: In the Slack discussion, an alternative was discussed. I was proposed to use custom keywords, which seems to be supported by ajv (JS) and Manatee.Json (.Net), but I'd still want to figure out how well supported these are by the libraries out there (e.g. in Python land). I'd be happy to switch over to custom keywords if they offer the same functionality and are well supported.
It was also suggested to deprecate
format
in favor of custom keywords. @handrews wrote:(Although the alternative seems to be a good way forward, clarification regarding
format
still would be worth the effort, I think.)For the full discussion, please see the Slack channel. My quotes are only short excerpts.
The text was updated successfully, but these errors were encountered: