JSON 斯克马呼叫蒙哥斯克马 
一个翻译库 杰森·斯克马 财务报告和审定财务报表 绵竹司马。在 TypeScript 中写入.
这个项目基于克里斯蒂安·曼德鲁克的工作: gi, (中文(简体) ), 无。 。 。 .
所有依赖关系都得到了更新,一揽子方案是无害环境管理.
替代品
一些选择...
- 2017 (英语) 生成-schema-必需
- 2016 (英语) 货币化
- 2016 (英语) 蒙哥斯 -杰森谢马
- 2015 (英语) 好蛋-json-schema-转换器
- 2014 (中文(简体) ) json-schema- 转换器
- 2014 (中文(简体) ) json-schema-to-mongoose-schema (日语)
安装
npm i @audc/convert-json-schema-to-mongoose -S
使用量
import { createMongooseSchema } from 'convert-json-schema-to-mongoose';
// Or use plain javascript
// const createMongooseSchema = require('json-schema-to-mongoose').default;
// example json-schema references
const refs =
{
yep:
{
type: 'string',
pattern: '^\\d{3}$'
},
idSpec: {
type: 'object',
properties:
{
id:
{
$ref: 'yep'
}
}
}
};
// example schema to convert to mongoose schema
const 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'}
}
}
}
};
//Convert the schema
const mongooseSchema = createMongooseSchema(refs, 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.dir(mongooseSchema, {depth: null});
const Schema = new mongoose.Schema(mongooseSchema);