Extend $ref object properties

717 views Asked by At

I am using JSON schema to build a form and I have an object in "definitions" which I am referencing using $ref in two different places on the schema. At one of the instances I need to have one more property added to the referenced object, how can I achieve this?

{
    "definitions": {
        "settingsProperties": {
            "$id": "#/definitions/settingsProperties",
            "type": "object",
            "properties": {
                "thickness": {
                    "$id": "#/properties/defaultLayerSettings/thickness",
                    "type": "number",
                    "title": "Thickness:",
                }
            }
        }
    },
    "properties": {
        "layerSettings": {
            "$id": "#/properties/layerSettings",
            "type": "array",
            "title": "Dynamic Layer Settings:",
            "items": {
                "title": "Dynamic Settings",
                "type": "object",
                "$ref": "#/definitions/settingsProperties", PLUS startLayer PROPERTY!!!!!!!!!!!!!!
                "required": [
                    "startLayer"    
                ]
            }
        }
}
1

There are 1 answers

0
Ether On BEST ANSWER

Just add "properties": { "startLayer": { ... } } underneath the required keyword.

Note that if you are using any specification version earlier than draft 2019-09 (the current latest version), you will have to nest the $ref keyword inside an allOf. Additionally, the use of fragments (strings that include #) are not permitted in the $id keyword, although some outdated tools are generating schemas with this structure.