【问题标题】:Node json-schema prevent null for interger节点 json-schema 防止整数为空
【发布时间】:2015-02-02 17:44:57
【问题描述】:

我有架构,

'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'} 它认为它是有效的。

除了null 之外的我只有在我在类型中明确说["integer", "null"] 时才能被接受。

如何防止null 被接受为整数?

【问题讨论】:

  • 仅供参考,您在架构中也拼错了“minimum”。

标签: javascript json node.js jsonschema


【解决方案1】:

该架构适用于我,因为它应该(我得到“无效类型:null(预期整数)”)。

我的最佳猜测是问题可能出在较大的文档结构中,这意味着实际上并未针对您期望的架构测试数据。

【讨论】:

  • Tnx 回答,我很确定它是正确的.. 但会再次检查。
  • 不,仍然不适合我。 @cloudfeet,你能告诉我你正在尝试的 json-schema 版本吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-08-06
  • 2014-11-04
  • 1970-01-01
  • 2013-03-08
  • 2010-11-05
  • 1970-01-01
相关资源
最近更新 更多