Javascript 节点json模式阻止INTEGER为null
我有图式Javascript 节点json模式阻止INTEGER为null,javascript,json,node.js,jsonschema,Javascript,Json,Node.js,Jsonschema,我有图式 'demand': { description: 'demand model', type: 'object', additionalProperties: false, properties: { '_id': { type: 'string' }, 'driversNeeded': { required: true, type: '
'demand': {
description: 'demand model',
type: 'object',
additionalProperties: false,
properties: {
'_id': {
type: 'string'
},
'driversNeeded': {
required: true,
type: 'integer',
minumum: 0
},
'date': {
required: true,
type: 'string',
pattern: /^\d{4}-\d{2}-\d{2}$/
}
}
}
driversNeeded
假设为整数,最小值=0
但是,然后我验证有效负载{driversNeeded:null,date:'2015-11-11'}
它将其视为有效
只有当我在type中显式地说[“integer”,“null”]
时,才能接受除null以外的I
我如何防止
null
被接受为整数?该模式对我来说应该是有效的(我得到了“无效类型:null(预期整数)”)
我最好的猜测是,问题可能出在更大的文档结构中,这意味着数据实际上没有按照您期望的模式进行测试。FYI,您在模式中也拼写错了“minimum”。Tnx作为答案,我非常肯定它是正确的。。但是我会再检查一次的。不,我还是不行@CloudFoots,你能告诉我你正在试用json模式的版本吗?