我正在使用https://github.com/everit-org/json-schema库对 JSONSchema 进行服务器端验证,当我在最大验证中使用 dataref 时失败
我的架构属性就像
"fromYear": {
"array": false,
"type": "number",
"title": "From Year",
"minimum": {
"$data": "1/toYear"
},
"key": "fromYear",
"required": false
}
但是当我们调用 Schema 的验证方法时,它会抛出类似的错误
"#/properties/qualificationsection/items/properties/fromYear/minimum: expected type: Number, found: JsonObject"
JSON Schema 支持最小数量以及 jsonobject(即它支持联合类型),我们可以在其中指定数据引用。
图书馆无法处理这个问题,因为期望 minumum 总是类型为 number
$data
不是当前的 JSON 模式关键字(draft-7)。
一些图书馆试图实现它,因为它是对未来草案的建议,但它目前不是官方规范的一部分。
对此别无选择。目前根本不可能。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句