Skip to content

core: Define how to apply subschemas to child instances #161

Closed
@handrews

Description

@handrews

In #157 @awwright noted that:

Technically, "properties" and "items" are just keywords for validation. All they do is return true or false.
People have been reading in that we can recursively apply the semantics, and that's fine too. Maybe we should make that more explicit.

Without ways to declare which subschemas apply to which child instances, JSON Schema as a media type is very limited.

In theory, it should be possible to use some JSON Schema vocabulary without validation, which is not possible at the moment. We don't have such a vocabulary right now, but to demonstrate the idea, here is a hyper-schema that imposes no validation constraints:

{
    "links": [
        {
            "rel": "self",
            "href": "/foos"
        }
    ],
    "items": {
        "links": [
            {
                "rel": "item",
                "href": "/foos/{id}"
            }
        ]
    }
}

This schema uses items from the validation vocabulary, but only to apply the "item" link to each element of an array instance. The URI template implies that the elements of the array are objects with at least an "id" property, but this schema does not validate that at all. Obviously, this is not the most realistic schema, but we don't have other vocabularies right now and I can't come up with one off the top of my head.


I recently rewrote the items, additionalItems, properties, patternProperties, and additionalProperties to make it clear that they do not directly validate the instance, but instead control which subschemas are applied to which child instances. While I expressed that in terms of validation, reading back over the language shows that it is not necessary.

We could move those keywords into the core specification and simply reference their impact on validation in the validation specification. There would not be any changes to the current functionality, but it would allow for much more flexible definitions of new vocabularies.

This is all a bit abstract, and probably hard to grasp from just eyeballing the current validation spec wording. So I will write up a trial PR to demonstrate how that would look.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions