2

输入

{
    "createResponse": {
        "backResponse": {
            "status": {
                "code": "000",
                "message": "success"
            }
        }
    }
}

或者

{
    "updateResponse": {
        "backResponse": {
            "status": {
                "code": "000",
                "message": "success"
            }
        }
    }
}

这是我的 json 架构:

{
    "properties": {
        "backResponse": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
                "status": {
                    "type": "object",
                    "required": false,
                    "properties": {
                        "code": {
                            "type": "string",
                            "required": false
                        },
                        "message": {
                            "type": "string",
                            "required": false
                        }
                    }
                }
            }
        }
    },
    "anyOf": [{
        "additionalProperties": false,
        "properties": {
            "createResponse": {
                "type": "object",
                "properties": {
                    "$ref": "#/properties/backResponse"
                }
            }
        }
    }, {
        "additionalProperties": false,
        "properties": {
            "updateResponse": {
                "type": "object",
                "properties": {
                    "$ref": "#/properties/backResponse"
                }
            }
        }
    }]
}

在 datapower 中将此错误作为属性“$ref”的意外值。预期值类型:“对象”。得到:'"#/properties/backResponse" ...'。

我在做什么错

4

1 回答 1

1

如果您只想强制 updateResponse 是 backResponse 类型,您可以像这样引用它:

"createResponse" : {"$ref" : "#/properties/backResponse"}

JSON 参考解析从 6.0.1 版本添加到 DataPower 固件。您还应该检查您的版本。

最后,我必须警告您使用的是 Json-Schema Draft3。required 需要 Draft4 中的一个数组。

于 2014-11-04T23:15:55.823 回答