-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Labels
featureNew functionality or improvementNew functionality or improvement
Milestone
Description
Describe the problem you are trying to fix (provide as much context as possible)
OpenAPI spec provides several keywords which you can use to combine schemas. You can use these keywords to create a complex schema, or validate a value against multiple criteria.
oneOf– validates the value against exactly one of the subschemasallOf– validates the value against all the subschemasanyOf– validates the value against any (one or more) of the subschemas
When I implement an REST API from the OpenAPI v3 definition in node.js, Joi doesn't provide corresponding API to validate the combined schema. Our team is trying to make server code generated from API definition, which uses Joi to perform input parameters validation.
Which API (or modification of the current API) do you suggest to solve that problem ?
We suggest the API to be used like this:
Joi.object().keys({
name: Joi.string(),
kind: Joi.oneOf([
Joi.object().keys({
x: Joi.number(),
y: Joi.boolean()
}),
Joi.object().keys({
a: Joi.string(),
b: Joi.number()
}),
])
});Are you ready to work on a pull request if your suggestion is accepted ?
Our team mate @ufonion has make Joi extensions to support allOf and oneOf. Would like to see if it's possible to implement into Joi API.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
featureNew functionality or improvementNew functionality or improvement