README
joi-to-json-schema
The goal is to provide best effort conversion from Joi objects to JSON Schema (draft-04) with the understanding that only some of Joi's schematics can be converted directly. Primarily this module exists to convert Joi schema objects for existing tools which happen to currently consume JSON Schema.
Installation
npm install joi-to-json-schema
Usage
var joi = require('joi'),
convert = require('joi-to-json-schema'),
joiSchema = joi.object({
'name': joi.string().required().regex(/^\w+$/),
'description': joi.string().optional().default('no description provided'),
'a': joi.boolean().required().default(false),
'b': joi.alternatives().when('a', {
is: true,
then: joi.string().default('a is true'),
otherwise: joi.number().default(0)
})
});
convert(joiSchema);
which will produce:
{ type: 'object',
properties:
{ name: { type: 'string', pattern: '^\\w+