JSON Schema to Mongoose (Schema)
A translation library between JSON Schema and
Mongoose Schema. Written in TypeScript.
This project was created from the ashes of json-schema-converter
. I took away
some features and made it more single purpose and added features to the
conversion.
Installation
npm install json-schema-to-mongoose --save
Usage
import createMongooseSchema = require('./lib/json-schema')
import util = require('util')
var refs =
{
yep:
{
type: 'string',
pattern: '^\\d{3}$'
},
idSpec: {
type: 'object',
properties:
{
id:
{
$ref: 'yep'
}
}
}
}
var schema =
{
type: 'object',
properties:
{
id:
{
$ref: 'yep'
},
address:
{
type: 'object',
properties:
{
street: {type: 'string', default: '44', pattern: '^\\d{2}$'},
houseColor: {type: 'string', default: '[Function=Date.now]', format: 'date-time'}
}
}
}
}
var mongooseSchema = createMongooseSchema(refs, schema)
console.log(util.inspect(mongooseSchema, false, null))