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

json-schema: support registering custom formats #33

Open
matthias-t opened this issue May 21, 2020 · 2 comments
Open

json-schema: support registering custom formats #33

matthias-t opened this issue May 21, 2020 · 2 comments
Labels
enhancement New feature or request

Comments

@matthias-t
Copy link

This is not strictly required per RFC. Normative references:

@jdanyow jdanyow added the enhancement New feature or request label May 23, 2020
@matthias-t
Copy link
Author

Note that ajv initially supported custom formats for strings only. Later, this was revised and format handlers could be registered to handle either strings or numbers. Support for other types has been requested multiple times (ajv-validator/ajv#291, ajv-validator/ajv#418, ajv-validator/ajv#1039). According to the draft 2019-09 RFC:

A format attribute can generally only validate a given set of instance types. If the type of the instance to validate is not in this set, validation for this format attribute and instance SHOULD succeed. All format attributes defined in this section apply to strings, but a format attribute can be specified to apply to any instance types defined in the data model defined in the core JSON Schema.

What remains unclear to me, from the specification, is whether implementations must require that exactly one type be specified when registering a format handler. In my opinion, a natural way to implement format is:

  • the element to be validated is passed as is to the format handler, regardless of type; but
  • always validate type assertions before format assertions.

@handrews
Copy link

What remains unclear to me, from the specification, is whether implementations must require that exactly one type be specified when registering a format handler.

No, a format can theoretically apply to multiple types, or to any type, although don't ask me to come up with an example! From 2019-09 onward, the hope is that new keyword vocabularies will replace format, which has so many quirks and difficult-to-support aspects that it's not really salvageable as a keyword with reliable, consistent behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants