JSONSchemas without the type keyword are still valid, eg:
{ format: 'date-time' }
is a valid JSONSchema that matches against any non-string value, or any string value that is date-time formatted.
Additionally, type can be an array of types. In this way a single JSONSchema can do complex validations of multiple types of value without using combination keywords (allOf, etc.). As an example:
The above would successfully match a string with length 5 or greater, or a integer less than 10.
Since these are valid JSONSchema cases they should ideally be supported by Enjoi, but it would require notable changes to how JSONSchemas are translated to Joi. Application of validation keywords is currently tied to the presence of an expected type value.
For cases where there is no explicit type Joi conditional validations would need to be used, something like:
Joi.any().when({ is: Joi.string(), then: Joi.date(), otherwise: Joi.any() })
JSONSchemas without the
type
keyword are still valid, eg:is a valid JSONSchema that matches against any non-string value, or any string value that is date-time formatted.
Additionally,
type
can be an array of types. In this way a single JSONSchema can do complex validations of multiple types of value without using combination keywords (allOf, etc.). As an example:The above would successfully match a string with length 5 or greater, or a integer less than 10.
Since these are valid JSONSchema cases they should ideally be supported by Enjoi, but it would require notable changes to how JSONSchemas are translated to Joi. Application of validation keywords is currently tied to the presence of an expected
type
value.For cases where there is no explicit type Joi conditional validations would need to be used, something like: