没有从嵌套的 json 模式验证中得到预期的错误消息

问题描述 投票:0回答:1

尝试使用 json 模式验证在 azure 逻辑应用程序中验证 json。

这是我的示例 json:

{
    "address": [
        {
            "contact": {
                "firstName": "myFirstName",
                "lastName": "myLastName"
            },
            "type": "bill"
        }
    ]
}

这是我的模式:

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

如果我没有在输入 json 中传递 firstName 属性,验证将失败,这是预期的,但我收到的错误消息是不正确的。它不显示缺少哪个属性。就像在这个例子中一样,我期待消息应该告诉 firstName 属性丢失。

这是上述验证的输出:

"outputs": {
            "errors": [
                {
                    "message": "JSON does not match schema from 'then'.",
                    "lineNumber": 0,
                    "linePosition": 0,
                    "path": "",
                    "schemaId": "#/then",
                    "errorType": "then",
                    "childErrors": []
                }
            ]
        }

任何帮助将不胜感激

json azure-logic-apps json-schema-validator
1个回答
0
投票

我已经在我的环境中重现并得到如下预期结果:

首先,我采用了一个 http 触发器,然后采用了解析 json 的步骤,并在其中给出了以下架构。

{
    "type": "object",
    "properties": {
        "address": {
            "type": "array",
            "items": {
                "type": "object",
                "properties": {
                    "contact": {
                        "type": "object",
                        "properties": {
                            "firstName": {
                                "type": "string",
                                "message": {
                                    "required": "name is required"
                                },
                                "required": true
                            },
                            "lastName": {
                                "type": "string"
                            }
                        }
                    },
                    "type": {
                        "type": "string"
                    }
                },
                "required": [
                    "contact",
                    "type"
                ]
            }
        }
    }
}

enter image description here

现在响应行动:

outputs('Parse_JSON')['errors'][0]['message']

enter image description here

在我保持 runAfter Failed 获取消息之后,您也可以使用任何并行操作。

输出:

enter image description here

逻辑应用程序中的输出:

enter image description here

enter image description here

enter image description here

代码视图:

{
    "definition": {
        "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
        "actions": {
            "Parse_JSON": {
                "inputs": {
                    "content": "@triggerBody()",
                    "schema": {
                        "properties": {
                            "address": {
                                "items": {
                                    "properties": {
                                        "contact": {
                                            "properties": {
                                                "firstName": {
                                                    "message": {
                                                        "required": "name is required"
                                                    },
                                                    "required": true,
                                                    "type": "string"
                                                },
                                                "lastName": {
                                                    "type": "string"
                                                }
                                            },
                                            "type": "object"
                                        },
                                        "type": {
                                            "type": "string"
                                        }
                                    },
                                    "required": [
                                        "contact",
                                        "type"
                                    ],
                                    "type": "object"
                                },
                                "type": "array"
                            }
                        },
                        "type": "object"
                    }
                },
                "runAfter": {},
                "type": "ParseJson"
            },
            "Response": {
                "inputs": {
                    "body": "@outputs('Parse_JSON')['errors'][0]['message']",
                    "statusCode": 200
                },
                "kind": "Http",
                "runAfter": {
                    "Parse_JSON": [
                        "Failed"
                    ]
                },
                "type": "Response"
            }
        },
        "contentVersion": "1.0.0.0",
        "outputs": {},
        "parameters": {},
        "triggers": {
            "manual": {
                "inputs": {
                    "schema": {}
                },
                "kind": "Http",
                "type": "Request"
            }
        }
    },
    "parameters": {}
}

你只能这样做,我同意@skin 的观点。

© www.soinside.com 2019 - 2024. All rights reserved.