nijikokun / Validator

JSON Schema validation library for Javascript / Node / Express.
159 stars 21 forks source link

Add Mongoose Schema #5

Open alanjames1987 opened 10 years ago

alanjames1987 commented 10 years ago

Mongoose has a schema with additional syntax. It can define schemas without using a type attribute. It can use a type attribute also, but the point is that its not required.

Theses are the same in Mongoose.

var schema = new Schema({
    someString : String,
    someNumber : Number,
    someArray : [someDataType],
    someObject : {
        someKey : someDataType
    }
});
var schema = new Schema({
    someString : {
        type : String
    },
    someNumber : {
        type : Number
    },
    someArray : [{
        type : someDataType
    }],
    someObject : {
        someKey : {
            type : someDataType
        }
    }
});

I want to use schema-validator for validating objects received by socket.io before it sends them to another user. This is an area Mongoose can't validate as far as I know.

It would be great if schema-validator could accept a Mongoose schema syntax so developers don't have to write two schemas. They can just copy paste.

bitplanets commented 9 years ago

+1 would be amazing.

Todo:

It would be great if schema-validator could accept a Mongoose schema syntax so developers don't have to write two schemas. They can just copy paste.

If you use webpack/requirejs/mongoose you can share the exact same schema file! No need to copy paste

nijikokun commented 9 years ago

I am actually faced with this right now. I will see what I can do, the only issue is that custom types will not be supported.