相关疑难解决方法(0)

我如何需要一个或另一个领域或(另外两个)中的一个但不是全部?

我在设置JSON模式时遇到问题,该模式将验证JSON是否包含:

  • 只有一个领域
  • 另一个领域
  • (仅限于其他两个领域之一)

但是当它们的倍数存在时不匹配.

在我的具体情况下,我想要一个

  • copyAll
  • fileNames
  • matchesFiles 和/或 doesntMatchFiles

验证,但我不想接受超过那个.

这是我到目前为止所得到的:

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "type": "object",
    "required": [ "unrelatedA" ],
    "properties": {
    "unrelatedA": {
        "type": "string"
    },
    "fileNames": {
        "type": "array"
    },
    "copyAll": {
        "type": "boolean"
    },
    "matchesFiles": {
        "type": "array"
    },
    "doesntMatchFiles": {
        "type": "array"
        }
    },
    "oneOf": [
         {"required": ["copyAll"], "not":{"required":["matchesFiles"]}, "not":{"required":["doesntMatchFiles"]}, "not":{"required":["fileNames"]}},
         {"required": ["fileNames"], "not":{"required":["matchesFiles"]}, "not":{"required":["doesntMatchFiles"]}, "not":{"required":["copyAll"]}},
         {"anyOf": [
               {"required": ["matchesFiles"], "not":{"required":["copyAll"]}, "not":{"required":["fileNames"]}},
               {"required": ["doesntMatchFiles"], "not":{"required":["copyAll"]}, "not":{"required":["fileNames"]}}]}
    ]
} ;
Run Code Online (Sandbox Code Playgroud)

这比我想要的更多.我希望这匹配以下所有内容:

{"copyAll": true, "unrelatedA":"xxx"}
{"fileNames": …
Run Code Online (Sandbox Code Playgroud)

validation json jsonschema

44
推荐指数
1
解决办法
3万
查看次数

JSON模式 - 如果对象*不包含特定属性,则有效

是否有可能建立一个JSON模式,它仍然允许additionalProperties若一个非常特别的属性名存在匹配吗?换句话说,我需要知道是否可能与required声明完全相反.

架构:

{
    "type": "object",
    "properties": {
        "x": { "type": "integer" }
    },
    "required": [ "x" ],
    "ban": [ "z" ] // possible?
}
Run Code Online (Sandbox Code Playgroud)

比赛:

{ "x": 123 }
Run Code Online (Sandbox Code Playgroud)

比赛:

{ "x": 123, "y": 456 }
Run Code Online (Sandbox Code Playgroud)

难道匹配:

{ "x": 123, "y": 456, "z": 789 }
Run Code Online (Sandbox Code Playgroud)

json jsonschema

13
推荐指数
4
解决办法
6729
查看次数

标签 统计

json ×2

jsonschema ×2

validation ×1