JSONSchema draft v3 验证错误

JSONSchema draft v3 validation error

我已经按照 v3 规范草案创建了一个 JSON 架构。架构如下所示:

{
"housePolicies": {
    "properties": {
        "guaranteePolicies": {
            "items": {
                "$ref": "#/housePolicies/guaranteePolicy"
            },
            "type": "array"
        },
        "specialRequirements": {
            "items": {
                "$ref": "#/housePolicies/specialRequirement"
            },
            "type": "array"
        },
        "chainCode": {
            "required": true,
            "type": "string",
            "description": "Unique identifier of the chain"
        },
        "losRestrictions": {
            "items": {
                "$ref": "#/housePolicies/losRestriction"
            },
            "type": "array"
        },
        "specialEvents": {
            "items": {
                "$ref": "#/housePolicies/specialEvent"
            },
            "type": "array"
        },
        "propertyCode": {
            "required": true,
            "type": "string",
            "description": "Unique identifier of the property in the chain"
        }
    },
    "specialRequirement": {
        "id": "specialRequirement",
        "properties": {
            "minLOS": {
                "type": "integer",
                "description": "Minimum stay, in days, that applies for a special requirement restriction.\nOptional: If no input provided, there is no minimum LOS required for that period.",
                "format": "int64"
            },
            "startDate": {
                "required": true,
                "type": "string",
                "description": "Date when a special requirement restriction starts",
                "format": "date"
            },
            "endDate": {
                "required": true,
                "type": "string",
                "description": "Date when a special requirement restriction ends",
                "format": "date"
            }
        }
    },
    "guaranteePolicy": {
        "dow": {
            "id": "dow",
            "properties": {
                "monday": {
                    "required": true,
                    "type": "boolean"
                },
                "tuesday": {
                    "required": true,
                    "type": "boolean"
                },
                "friday": {
                    "required": true,
                    "type": "boolean"
                },
                "wednesday": {
                    "required": true,
                    "type": "boolean"
                },
                "thursday": {
                    "required": true,
                    "type": "boolean"
                },
                "sunday": {
                    "required": true,
                    "type": "boolean"
                },
                "saturday": {
                    "required": true,
                    "type": "boolean"
                }
            }
        },
        "id": "guaranteePolicy",
        "properties": {
            "startDate": {
                "required": true,
                "type": "string",
                "description": "Date when a guarantee policy starts",
                "format": "date"
            },
            "endDate": {
                "required": true,
                "type": "string",
                "description": "Date when a guarantee policy ends",
                "format": "date"
            },
            "guaranteeRequiredDow": {
                "items": {
                    "$ref": "#/housePolicies/guaranteePolicy/dow"
                },
                "required": true
            }
        }
    },
    "losRestriction": {
        "id": "losRestriction",
        "properties": {
            "startDate": {
                "required": true,
                "type": "string",
                "description": "Date when a length of stay restriction starts",
                "format": "date"
            },
            "max": {
                "type": "integer",
                "description": "In case max is not provided it measn that there is no maximum length of stay restrictions.\nOptional: If no input provided, there is no maximum length restriction.",
                "format": "int64"
            },
            "endDate": {
                "required": true,
                "type": "string",
                "description": "Date when a length of stay restriction ends",
                "format": "date"
            },
            "min": {
                "type": "integer",
                "description": "In case min is not provided it means that there is no minimum length of stay restrictions.\nOptional: If no input provided, there is no minimum length restriction.",
                "format": "int64"
            }
        }
    },
    "specialEvent": {
        "id": "specialEvent",
        "properties": {
            "startDate": {
                "required": true,
                "type": "string",
                "description": "Date when a special event restriction starts",
                "format": "date"
            },
            "endDate": {
                "required": true,
                "type": "string",
                "description": "Date when a special event restriction ends",
                "format": "date"
            }
        }
    },
    "id": "housePolicies"
},
"$schema": "http://json-schema.org/draft-03/schema#",
"id": "request",
"properties": {
    "housePolicies": {
        "items": {
            "$ref": "#/housePolicies"
        },
        "required": true
    }
}
}

我现在正尝试验证一些 JSON 反对它,但 jsonschemavalidator complains about the schema, giving error when resolving schema reference '#/housePolicies/guaranteePolicy/dow'. I verified in the documentation 参考文献以正确的格式放置。谁能指出这个模式中的错误在哪里?

您在 $ref 中使用了 json 路径,但仍对对象使用 id。您不需要两者,它们似乎相互矛盾。如果您删除 id,您的架构将起作用。