【发布时间】:2021-08-05 13:10:08
【问题描述】:
我正在尝试编写一个架构,如果存在属性 A,那么属性 B 或 C 也应该使用 dependencyschema 构造来存在,并且在我的架构中,我已关闭任何附加属性。
{
"$schema": "https://json-schema.org/draft/2019-09/schema",
"$id": "PropertiesSchema.json",
"type": "object",
"properties": {
"A": { "type": "boolean" }
},
"additionalProperties": false,
"dependentSchemas": {
"A": {
"anyOf": [
{ "required": [ "B" ] },
{ "required": [ "C" ] }
],
"properties": {
"B": { "type": "boolean" },
"C": { "type": "boolean" }
}
}
}
}
但由于附加属性构造,它目前在以下输入中失败
{“A”:真,“B”:假}或{“A”:真,“C”:假}
那么是否有可能在 AdditionalProperties 关闭时允许dependentSchemas 属性?
因此有效的输入应该是
{“A”:真,“B”:假}或{“A”:真,“C”:假}
但是对于任何其他属性说 D,它应该失败-
{“A”:真,“D”:假}
【问题讨论】:
标签: jsonschema json-schema-validator