【发布时间】:2021-01-20 15:57:16
【问题描述】:
我正在尝试验证以 JSON 表示的防火墙规则。
我的 JSONSchema 的最小示例如下:
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Example",
"type": "object",
"properties": {
"from": {
"$ref": "#/definitions/addressGroup"
},
"action": {
"type": "string",
"enum": ["binat", "pass"]
}
},
"allOf": [
{
"if": {
"properties": {
"action": {
"const": "binat"
}
}
},
"then": {
"properties": {
"from": {
"format": "ip-address"
}
}
}
}
],
"additionalProperties": false,
"required": [
"from",
"action"
],
"definitions": {
"addressGroup": {
"type": "string",
"pattern": "^[ !<a-zA-Z].+$"
}
}
}
以下 JSON 通过验证:
{
"action": "pass",
"from": "test"
}
但是对于这个 JSON,“from”字段是根据 addressGroup 而不是 "format": "ip-address" 评估的。
{
"action": "binat",
"from": "10.1.1.1"
}
我希望触发“then”子句并根据“ip-address”定义强制格式化“from”字段。
可以在这里找到一个最小的演示:https://www.jsonschemavalidator.net/s/EsQVoaXw
我忽略了什么?
【问题讨论】:
标签: json jsonschema