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

Azure Logic Apps嵌套JSON Schema验证未返回预期错误提示

Azure Logic Apps JSON Schema验证错误信息不精准的解决办法

你当前的问题是因为then部分的Schema只定义了properties,但没有对address数组的items做完整的对象约束,导致验证器只检测到整体不符合then规则,无法递归抛出子属性的具体错误。

要让错误信息精准提示缺失firstName,调整Schema结构如下:

{
    "if": {
        "properties": {
            "address": {
                "type": "array",
                "items": {
                    "properties": {
                        "type": {
                            "const": "bill"
                        }
                    },
                    "required": ["type"]
                }
            }
        },
        "required": ["address"]
    },
    "then": {
        "properties": {
            "address": {
                "type": "array",
                "items": {
                    "type": "object",
                    "properties": {
                        "type": {
                            "const": "bill"
                        },
                        "contact": {
                            "type": "object",
                            "properties": {
                                "firstName": {
                                    "type": "string"
                                },
                                "lastName": {
                                    "type": "string"
                                }
                            },
                            "required": ["firstName"],
                            "additionalProperties": false
                        }
                    },
                    "required": ["type", "contact"],
                    "additionalProperties": false
                }
            }
        },
        "required": ["address"],
        "additionalProperties": false
    }
}

关键调整说明:

  • 在then的address.items中明确指定"type": "object",并添加required: ["type", "contact"],确保contact字段必须存在
  • 给contact对象补充具体的属性类型定义(如firstName为string),保留required: ["firstName"]的约束
  • 添加additionalProperties: false(可选,用于严格校验未定义属性),帮助验证器精准定位错误
  • 在if和then的顶层添加required: ["address"],确保address字段必传

调整后,当输入JSON缺失firstName时,验证错误会明确提示Missing required property: firstName,并附带具体路径(如/address/0/contact),直接定位问题所在。

Azure Logic Apps的JSON Schema验证对if/then结构的错误反馈依赖Schema的完整性,只有子属性的约束被明确定义时,才会返回具体的子错误,否则只会提示整体不符合then规则。


内容的提问来源于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.26 04:37:39