2014년 12월 12일 금요일

[mongoose] Return a mongoose schema as JSON

Try out https://github.com/stemey/mongoose-schema:

var schemaGenerator = new require('mongoose-schema').JsonSchemaGenerator();
var jsonSchema = schemaGenerator.generate(mongooseSchema);

Hi

how to return a mongoose  schema as JSON? for example convert:
var InfoSchema = new Schema({
  name: {
    type: String,
    required: true
  },
  title: {
    type: String,
    required: true,
    trim: true
  }
});
to somthing like:
schema = {
    type: "object",
    properties: {
      name: { type: "string"},
      title: {
        type: "string"
      }
    };



YourSchema.paths
YourModel.schema.paths

You can overwrite the toJSON method on those objects if you want.  


댓글 없음:

댓글 쓰기