You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
This is not strictly required per RFC. Normative references:
The text was updated successfully, but these errors were encountered: