-
Notifications
You must be signed in to change notification settings - Fork 57
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
Feature/extend joi validation #67
Feature/extend joi validation #67
Conversation
@@ -28,6 +28,8 @@ Please file issues for other unsupported features. | |||
- `refineType(type, format)` - an (optional) function to call to apply to type based on the type and format of the JSON schema. | |||
- `extensions` - an array of extensions to pass [joi.extend](https://github.com/hapijs/joi/blob/master/API.md#extendextension). | |||
- `strictMode` - make schemas `strict(value)` with a default value of `false`. | |||
- `warnOnEmpty` - outputs a warning message on console if a schema is empty or considered empty - https://json-schema.org/latest/json-schema-core.html#rfc.section.4.3.1 | |||
- `extendValidation` - gives the ability to extend the default joi validation schema produced by `enjoi`. Works for the root schema and for references. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concerned this sounds a lot like joi extensions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It sound similar, but the key is in the details. Maybe it can be called extendJoiSchemas
with a bit addition to the description:
extendJoiSchemas
- gives the ability to extend the defaultJoi
validation schema produced byEnjoi
. Works for the root schema and for referenced ones. In contrast to extensions which extends on a per type level, this options extends on a per schema level. Useful when you want the extend theJoi
schema produced byEnjoi
, without defining a new custom type.
}, | ||
extendValidation: { | ||
'#': Joi.object().keys({title: Joi.string().max(3)}), | ||
'#/definitions/Name': Joi.string().max(8), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hard to use this as an example to illustrate why this is useful. Could use currently supported json-schema to specify.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right. What do you think about this example:
const schema = Enjoi.schema({
type: 'object',
required: ['min', 'max'],
properties: {
lower: {type: 'number', minimum: 5},
higher: {type: 'number', maximum: 20},
},
}, {
extendValidation: {
'#': Joi.object().keys({
higher: Joi.number().greater(Joi.ref('lower')),
}),
},
});
I wonder if the best way to support this is to use the concept of "vendor" extensions. For example:
|
Maybe, just enable something that lets people have a general catch-all for an |
Well the original idea (which was inspired by the needs of our project) was to stay as close to native |
I think at this point this needs to be closed. I believe this feature would now be supported by recent merged |
Resolves #65 + some small additions
enjoi
options
- an empty schema or one that is considered empty is valid, so the warning should be removable. Refer to https://json-schema.org/latest/json-schema-core.html#rfc.section.4.3.1. The default value of the option is left totrue
to avoid breaking changes.