小编Sau*_*dhu的帖子

JSON Schema 是否可以使用 if/then/else 引用外部属性

我想根据其他一些财产的价值添加有条件的要求。仅当“isInexperienced”值为 false 时才需要“companyName”和“companyAddress”。

模式

{
  "type": "object",
  "properties": {
    "previous_employment_section": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "companyAddress": {
            "type": "string"
          },
          "companyName": {
            "type": "string"
          }
        },
        "if": {
          "#/properties/isInexperienced": {
            "const": false
          }
        },
        "then": {
          "required": [
            "companyName",
            "companyAddress"
          ]
        }
      }
    },
    "isInexperienced": {
      "type": "boolean"
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

数据

{
  "previous_employment_section": [],
  "isInexperienced": true
}
Run Code Online (Sandbox Code Playgroud)

javascript json object ajv

5
推荐指数
1
解决办法
529
查看次数

标签 统计

ajv ×1

javascript ×1

json ×1

object ×1