'$id' property usage in JSON Schema

前端 未结 2 696
礼貌的吻别
礼貌的吻别 2021-01-17 22:04

I\'m using JSON Schema for validating data.

I think that I may have a mistake on my schema by using the reserved keywords $id. The intention of this field was to des

2条回答
  •  無奈伤痛
    2021-01-17 22:55

    Since $id changes the base URI of your schema, any $ref values in that same schema or any of its subschemas will be resolved differently.

    For instance, if your base URI was "https://example.com/thing" and you had this schema

    {
        "allOf": [
            {"$ref": "foo"},
            {
                "$id": "stuff/and/nonsense",
                "allOf": {"$ref": "bar"}
            }
        ]
    }
    

    then the "$ref" to "foo" resolves to "https://example.com/foo". But the "$ref" to "bar" resolves to "https://example.com/stuff/and/bar"

    So whatever you put in "$id" for another purpose, it is likely to cause problems, particularly with "$ref" resolution.

提交回复
热议问题