kibach / joi-machine

Generate a Joi schema from some JSON or a JS object

Home Page:https://www.npmjs.org/package/joi-machine

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Joi Machine Build Status Dependency Status

Generate a Joi schema from some JSON or a JS object.

Useful for creating a base to build your schema from when you have a big payload to validate.

Example

npm install -g joi-machine
echo '{"foo": {}, "bar": 45, "baz": ["foob"]}' | joi-machine
Joi.object().keys({foo: Joi.object(), bar: Joi.number().integer(), baz: Joi.array().items(Joi.string())})

or

var fs = require('fs')
var concat = require('concat-stream')
var joiMachine = require('joi-machine')

// data.json: {"foo": {}, "bar": 45, "baz": ["foob"]}
fs.createReadStream(__dirname + '/data.json')
  .pipe(joiMachine())
  .pipe(concat({encoding: 'string'}, console.log))

// Output: Joi.object().keys({foo: Joi.object(), bar: Joi.number().integer(), baz: Joi.array().items(Joi.string())})

or

var fs = require('fs')
var concat = require('concat-stream')
var joiMachine = require('joi-machine')

var generator = joiMachine.obj()

generator.pipe(concat({encoding: 'string'}, console.log))

// data.json: {"foo": {}, "bar": 45, "baz": ["foob"]}
generator.write(require('./data.json'))
generator.end()

// Output: Joi.object().keys({foo: Joi.object(), bar: Joi.number().integer(), baz: Joi.array().items(Joi.string())})

About

Generate a Joi schema from some JSON or a JS object

https://www.npmjs.org/package/joi-machine

License:ISC License


Languages

Language:JavaScript 100.0%