与邮差的jsonschema

我用node.js和express.js做了一个简单的web api,我想validation将json数据input到我的应用程序的模式。

我有这个非常确切的模式:

var schema = { "$schema": "http://json-schema.org/draft-04/schema#", "title": "Student", "description": "Schema for student", "type": "object", "properties": { "first_name": { "description": "Firts name of the student", "type": "string" }, "last_name": { "description": "Last name of the student", "type": "string" } }, "additionalProperties": false, "required": ["first_name", "last_name"] }; 

我只想validation(现在)的名字和姓氏。 所以我添加了“additionalProperties”,所以只有名字和姓氏的json才是有效的。

当我用POSTMANtesting我的应用程序与以下数据时,我得到了很多错误。 (这应该是有效的)

 {"first_name":"Test", "last_name":"Test"} 

这应该是无效的:

 {"first_name":"Test", "last_name":"Test", "jibber":"ish"} 

控制台显示约700行jsonshemavalidation错误:

 { instance: { first_name: 'Test', last_name: 'Test', _id: 5451419404e5006c094057c1, }, schema: { '$schema': 'http://json-schema.org/draft-04/schema#', title: 'Student', description: 'Schema for student', type: 'object', properties: { first_name: [Object], last_name: [Object] }, additionalProperties: false, required: [ 'first_name', 'first_name' ] }, propertyPath: 'instance', errors: [ { property: 'instance', message: 'Property $__ does not exist in the schema', schema: [Object], instance: { first_name: 'Test', last_name: 'Test', _id: 5451419404e5006c094057c1, }, stack: 'instance Property $__ does not exist in the schema' }, { property: 'instance', message: 'Property isNew does not exist in the schema', schema: [Object], instance: { first_name: 'Test', last_name: 'Test', _id: 5451419404e5006c094057c1, }, stack: 'instance Property isNew does not exist in the schema' }, 

那些邮递员使用的一些隐藏的属性?

我做了一些testing,我的身体很好。 额外的属性是由mongoose铸造我的身体产生一个mongoose的对象。

validation必须仅validation页面主体,否则将失败。

古人的智慧