簡體   English   中英

節點json模式防止null為整數

[英]Node json-schema prevent null for interger

我有圖式

'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被接受為整數?

該模式對我來說是可行的(我得到了“無效類型:null(期望的整數)”)。

我最好的猜測是,問題可能出在更大的文檔結構中,這意味着實際上並未針對所需的架構對數據進行測試。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM