【发布时间】:2020-10-20 11:29:46
【问题描述】:
请解释为什么这个 json 没有针对架构给出验证错误:
架构
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properites": {
"address": {
"type": "array",
"items":{
"type": "object",
"properties": {
"ip": {
"type": "string"
},
"port": {
"type": "integer"
},
"interface": {
"type": "string"
},
"maskLength": {
"type": "integer"
}
},
"required": [
"ip",
"port",
"interface",
"maskLength"
]
}
}
},
"required": [
"address"
]
}
JSON
{
"address": [
{
"ip": 1,
"port": 8305
},
{
"ip": "2405:200:1413:100::5:cc",
"port": "8205",
"interface": "eno1",
"maskLength": 112
},
{
"ip": 2,
"port": 8105,
}
]
}
我正在https://www.jsonschemavalidator.net/ 上对此进行测试,它使验证成功,我不明白。 interface 和 maskLength 根据架构是必需的字段,并且在某些数组元素中缺少这些字段。此外,“ip”的类型在模式中是字符串,但在 json 中,整数类型也被接受。为什么这个json没有被拒绝?
【问题讨论】:
标签: json jsonschema json-schema-validator