【发布时间】:2021-09-03 07:55:04
【问题描述】:
我的 json 模式结构如下所示。
{
"$schema": "https://json-schema.org/draft/2019-09/schema",
"description": "My sample Json",
"type": "object",
"properties": {
"eventId": {
"description": "The event Indetifier",
"type": [ "number", "string" ]
},
"serviceType": {
"description": "The service type. It can be either ABC or EFG",
"enum": [ "ABC", "EFG" ]
},
"parameters": { "$ref": "/schemas/parameters" }
},
"required": [ "eventId", "serviceType" ],
"$defs": {
"parameters": {
"$id": "/schemas/parameters",
"$schema": "http://json-schema.org/draft-07/schema#",
"description": "Other Parameters",
"type": "object",
"properties": {
"activityType": {
"description": "The activity type",
"type": [ "null", "string" ]
},
"activitySubType": {
"description": "The activity sub type",
"type": [ "null", "string" ]
}
}
}
}
}
现在我需要执行一些验证逻辑。
- 如果 eventId == "100" 和 serviceType == "ABC",则 parameters.activityType 不应为 null,且最小长度必须为 10。
- 如果 eventId == "200" 和 serviceType == "EFG",则 parameters.activitySubType 不应为 null,且最小长度必须为 20。
我正在尝试使用“if then else”条件执行验证。我不确定如何在 Json Schema 验证器中添加它。
谁能帮我语法?有可能吗?
【问题讨论】:
标签: json jsonschema