@kenyip/joi
v0.0.5
Published
Object schema validation
Downloads
6
Readme
@kenyip/joi
Forked from joi (version 14.3.1). Adding some convenient functions like removeKey
, toSwagger
... etc
Installation
// Using NPM
$ npm i @kenyip/joi --save
// Using Yarn
$ yarn add @kenyip/joi
Plugins
A list of plugins added into Joi framework
toSwagger
Convert the Joi schema objects into Swagger OAS 3.0 schema definitions. The library is cloned from joi-to-swagger with a little bit modification. Click here for the usage and the support conventions.
const object = Joi.object({
hello: Joi.string(),
world: Joi.string()
});
console.log(JSON.stringify(objectA.toSwagger(), null, 4));
{
"type": "object",
"properties": {
"hello": {
"type": "string"
},
"world": {
"type": "string"
}
}
}
remove
Remove keys from the existing schema
const objectA = Joi.object({
hello: Joi.string(),
world: Joi.string(),
});
const objectB = objectA
.keys({ foo: Joi.string() })
.remove(["hello"]);
console.log(JSON.stringify(objectB.toSwagger(), null, 4));
// {
// "type": "object",
// "properties": {
// "world": {
// "type": "string"
// },
// "foo": {
// "type": "string"
// }
// }
// }