Schema merging - sgpinkus/json-schema GitHub Wiki

THIS WIKI IS OBSOLETE. PLEASE SEE THE NEW JSON-SCHEMA-ORG/JSON-SCHEMA-SPEC REPOSITORY.



This page is entirely speculative. It does not represent behaviour in any existing specification.

The problem

A lot of questions are asked about how to "extend" a schema by refering to another. For instance, extending:

{
    "type": "object",
    "properties": {
        "p1": {}
    },
    "additionalProperties": false
}

with:

{
    "properties": {
        "p2": {}
    }
}

is expected to give:

{
    "type": "object",
    "properties": {
        "p1": {}
    },
    "additionalProperties": false
}

Unfortunately, no keyword exists to do that, since both extends (draft v3) or allOf (draft v4) add constraints and do not merge them.

What is really needed is schema merging.

This page is an attempt at defining both a keyword and rules for merging.

The proposed keyword is $include. Its valid value would be any JSON Schema.

Related pages

[Schema merging rules](Schema merging rules)

Open problems

Merging of $schema and id

Currently, I see no solution for that...