openjoi
Converts OpenApi 3.0 specs (JSON) to Joi schemas.
Installation
npm install openjoi
Usage
// Import // Get file (local file, or from remote, whatever)const specPath = pathconst doc = JSON // Convertconst schemas =
Given the following openapi.json
as the doc
:
convert
would give you
const schemas = // schemas would be the same as:schemas = foo: Joi bar: Joi
So you can use them for validation, etc...
schemas'foo' // -> `true`schemas'foo' // -> `false
Constructor
convert( { doc } ):
doc
: valid OpenApi 3.0 document in JSON format
Misc
Gotchas / Heads up
- Passing
$refs
that refer to ancestors of itself will result in a generic Joi validation model (Joi.any()
), or else we end up maxing out the call stack. allOf
currently only supports objects (either $ref or inline)
Roadmap
allOf
& descriminator support- string formatting
- integer formatting
Kudos
Highly influenced and inspired by enjoi. Much thanks.