[英]Node json-schema prevent null for interger
I have schema, 我有图式
'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
is supposed to be integer, with minimum value = 0; driversNeeded
应该是整数,最小值= 0;
But, then I validate payload {driversNeeded: null, date: '2015-11-11'}
it treat it as valid. 但是,然后我验证了有效载荷
{driversNeeded: null, date: '2015-11-11'}
,将其视为有效载荷。
I except null
could be only accepted if I explicitly say ["integer", "null"]
in type. 除
null
外,我只有在类型中明确说出["integer", "null"]
时才能接受。
How can I prevent null
to be accepted as integer? 如何防止
null
被接受为整数?
That schema works for me, as it should (I get "Invalid type: null (expected integer)"). 该模式对我来说是可行的(我得到了“无效类型:null(期望的整数)”)。
My best guess is that the issue might be in the larger document structure, meaning that the data isn't actually being tested against the schema you expect. 我最好的猜测是,问题可能出在更大的文档结构中,这意味着实际上并未针对所需的架构对数据进行测试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.