@ycnt/mm2ssd
v1.0.2
Published
Transforming Mongoose model into Swagger schema definitions
Downloads
8
Readme
Overview
Transforming Mongoose model into Swagger schema definitions
Installation
npm i @ycnt/mm2ssd
or
yarn add @ycnt/mm2ssd
Usage
mm2ssd(model: mongoose.Model, xmlTagName: string);
// model: the mongoose model to be converted
// xmlTagName: xml root tag name
Example
import * as mongoose from 'mongoose';
import { mm2ssd } from '@ycnt/mm2ssd';
test('Should generate simple schema', () => {
const model = mongoose.model('simple', new mongoose.Schema({
name: {
type: String,
required: true,
enum: ['Tom', 'Jerry']
},
age: Number,
date: Date,
balance: mongoose.SchemaTypes.Decimal128
}));
const schema = mm2ssd(model, 'xml');
expect(schema).toEqual({
type: 'object',
properties: {
_id: {
type: 'string',
required: false
},
__v: {
type: 'integer',
format: 'int64',
required: false
},
name: {
type: 'string',
required: true,
enum: ['Tom', 'Jerry']
},
age: {
type: 'integer',
format: 'int64',
required: false
},
date: {
type: 'string',
format: 'date-time',
required: false
},
balance: {
type: 'number',
format: 'double',
required: false
}
},
xml: {
name: 'xml'
},
required: ['name']
});
});
Contributing
Looking forward to seeing your contributions!