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
/// // Or use plain javascript// var createMongooseSchema = require('./lib/json-schema')// var util = require('util') // example json-schema references // example schema to convert to mongoose schema //Convert the schema //Alternative syntax, which makes it so you can convert many at one time. // var jsonSchemas = {commonRef: ..., good: ..., schema: ..., naming: ...}// var convert = createMongooseSchema(jsonSchemas)// var schemaNames = ['good', 'schema', 'naming']// var schemas = _.map(schemaNames, (name) => { return jsonSchemas[name] })// var mongooseSchemas = _.zipObject(schemaNames, schemas.reduce((mongooseSchemas, schema) => {// return mongooseSchemas.concat(convert(schema))// }, [])) console.logutil.inspectmongooseSchema, false, null