JSON 即使缺少必填字段,验证也会成功
JSON validation giving success even when required field is missing
请解释为什么这个 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 没有被拒绝?
脸掌
我将 properties 拼错为 properites!!妈的!
请解释为什么这个 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 没有被拒绝?
脸掌
我将 properties 拼错为 properites!!妈的!