首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Node json-schema防止整数为null

Node json-schema防止整数为null
EN

Stack Overflow用户
提问于 2015-02-03 01:44:57
回答 1查看 282关注 0票数 1

我有图式,

代码语言:javascript
复制
'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被接受为整数?

EN

回答 1

Stack Overflow用户

发布于 2015-02-03 03:42:21

该模式适用于我,因为它应该是有效的(我得到了“无效类型: null (期望的整数)”)。

我最好的猜测是,问题可能出在较大的文档结构中,这意味着数据实际上并没有针对您期望的模式进行测试。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28283590

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档