Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'$id' property usage in JSON Schema

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 designate what the REMOTE ID of the property on another platform was. So it was the "origin ID".

Can you please advise what $id is and if I have made a critical mistake and this value needs changing. Because in the documentation I have found this definition:

If present, the value for this keyword MUST be a string, and MUST represent a valid URI-reference [RFC3986]. This value SHOULD be normalized, and SHOULD NOT be an empty fragment <#> or an empty string <>.

like image 204
sevenwithawp Avatar asked Oct 10 '17 16:10

sevenwithawp


People also ask

How do you make a property required in JSON Schema?

Required Properties By default, the properties defined by the properties keyword are not required. However, one can provide a list of required properties using the required keyword. The required keyword takes an array of zero or more strings. Each of these strings must be unique.

What does Exclusiveminimum property in JSON Schema mean?

Gets or sets a flag indicating whether the value can not equal the number defined by the minimum attribute (Minimum).

What is a property in JSON?

A JSON object contains zero, one, or more key-value pairs, also called properties. The object is surrounded by curly braces {} . Every key-value pair is separated by a comma. The order of the key-value pair is irrelevant.

What is additional properties in JSON Schema?

The value of "additionalProperties" MUST be a boolean or an object. If it is an object, it MUST also be a valid JSON Schema. The value of "properties" MUST be an object. Each value of this object MUST be an object, and each object MUST be a valid JSON Schema.


1 Answers

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.

like image 111
Henry Andrews Avatar answered Sep 20 '22 19:09

Henry Andrews