You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

求助:Azure Logic Apps中跨域依赖属性的JSON Schema验证方案

符合要求的JSON Schema实现

以下是满足验证规则的JSON Schema,适配Azure Logic Apps的验证场景:

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "customFields": {
      "type": "object",
      "properties": {
        "paymentMethods": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "tokenizedCard": { "type": "string" },
              "cardNumber": { "type": "string" }
            },
            "required": ["tokenizedCard"]
          }
        }
      },
      "required": ["paymentMethods"]
    },
    "paymentDetails": {
      "type": "object",
      "properties": {
        "method": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "paymentType": { "type": "string", "enum": ["CREDIT_CARD", "UPI"] },
              "tokenizedCard": { "type": "string" }
            },
            "required": ["paymentType", "tokenizedCard"]
          }
        }
      },
      "required": ["method"]
    }
  },
  "required": ["customFields", "paymentDetails"],
  "allOf": [
    {
      "if": {
        "properties": {
          "paymentDetails": {
            "properties": {
              "method": {
                "contains": {
                  "properties": {
                    "paymentType": { "const": "CREDIT_CARD" }
                  }
                }
              }
            }
          }
        }
      },
      "then": {
        "properties": {
          "customFields": {
            "properties": {
              "paymentMethods": {
                "allOf": [
                  {
                    "items": {
                      "if": {
                        "properties": {
                          "tokenizedCard": {
                            "enum": {
                              "$data": "/paymentDetails/method[?(@.paymentType == 'CREDIT_CARD')].tokenizedCard"
                            }
                          }
                        }
                      },
                      "then": {
                        "required": ["cardNumber"]
                      }
                    }
                  },
                  {
                    "contains": {
                      "properties": {
                        "tokenizedCard": {
                          "enum": {
                            "$data": "/paymentDetails/method[?(@.paymentType == 'CREDIT_CARD')].tokenizedCard"
                          }
                        }
                      }
                    }
                  }
                ]
              }
            }
          }
        }
      }
    }
  ]
}

关键规则说明

  • 基础结构验证:定义JSON的核心结构,确保customFields.paymentMethods和paymentDetails.method为必填数组,且数组项的基础字段(如tokenizedCard)必填。
  • 条件触发逻辑:通过if判断paymentDetails.method中是否存在paymentType为CREDIT_CARD的项,触发后续验证规则。
  • 匹配与必填验证:
    1. 使用$data引用提取paymentDetails.method中所有paymentType为CREDIT_CARD的tokenizedCard值。
    2. 对customFields.paymentMethods中的每一项,若其tokenizedCard属于上述提取的集合,则强制要求cardNumber为必填项。
    3. 额外验证customFields.paymentMethods中必须包含匹配的tokenizedCard项,避免CREDIT_CARD的token在paymentMethods中不存在的情况。

注意事项

若Azure Logic Apps当前环境不支持$data关键字,可改用以下替代方案(仅当token值可提前枚举时适用):

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "customFields": {
      "type": "object",
      "properties": {
        "paymentMethods": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "tokenizedCard": { "type": "string" },
              "cardNumber": { "type": "string" }
            },
            "required": ["tokenizedCard"]
          }
        }
      },
      "required": ["paymentMethods"]
    },
    "paymentDetails": {
      "type": "object",
      "properties": {
        "method": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "paymentType": { "type": "string", "enum": ["CREDIT_CARD", "UPI"] },
              "tokenizedCard": { "type": "string" }
            },
            "required": ["paymentType", "tokenizedCard"]
          }
        }
      },
      "required": ["method"]
    }
  },
  "required": ["customFields", "paymentDetails"],
  "allOf": [
    {
      "if": {
        "properties": {
          "paymentDetails": {
            "properties": {
              "method": {
                "contains": {
                  "properties": {
                    "paymentType": { "const": "CREDIT_CARD" },
                    "tokenizedCard": { "const": "11223" }
                  }
                }
              }
            }
          }
        }
      },
      "then": {
        "properties": {
          "customFields": {
            "properties": {
              "paymentMethods": {
                "contains": {
                  "properties": {
                    "tokenizedCard": { "const": "11223" },
                    "cardNumber": { "type": "string" }
                  },
                  "required": ["cardNumber"]
                }
              }
            }
          }
        }
      }
    }
  ]
}

内容的提问来源于stack exchange,提问作者Prakash H

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.24 20:52:43