understanding-json-schema icon indicating copy to clipboard operation
understanding-json-schema copied to clipboard

"Structuring a complex schema" incorrectly states that "$ref" must be the only key in an object

Open eliaslevy opened this issue 4 years ago • 1 comments

Structuring a complex schema states:

This can be used anywhere a schema is expected. You will always use $ref as the only key in an object: any other keys you put there will be ignored by the validator.

This is false. The JSON Schema Core draft provides examples that disprove this:

{
    "title": "Feature list",
    "type": "array",
    "items": [
        {
            "title": "Feature A",
            "properties": {
                "enabled": {
                    "$ref": "#/$defs/enabledToggle",
                    "default": true
                }
            }
        },
        {
            "title": "Feature B",
            "properties": {
                "enabled": {
                    "description": "If set to null, Feature B
                                    inherits the enabled
                                    value from Feature A",
                    "$ref": "#/$defs/enabledToggle"
                }
            }
        }
    ],
    "$defs": {
        "enabledToggle": {
            "title": "Enabled",
            "description": "Whether the feature is enabled (true),
                            disabled (false), or under
                            automatic control (null)",
            "type": ["boolean", "null"],
            "default": null
        }
    }
}

eliaslevy avatar Sep 25 '20 15:09 eliaslevy

Yup. The site in most places only reflects DRAFT-07. Updating it to reflect draft 2019-09 is a HUGE amount of work.

Having said that, if you want to attempt a PR which adds a banner stating this fact "These docs are draft-07 only" or something, please feel free to do so!

There's a blue box on the home page which specifies the understanding site is only draft-07.

Relequestual avatar Sep 25 '20 15:09 Relequestual