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

Add support for `unevaluatedProperties` for more efficient useage of `allOf` schemas

Open fulstadev opened this issue 6 months ago • 4 comments

When you have an allOf JSON schema of two objects with the unevaluatedProperties property, let's say:

{
    "type": "object",
    "unevaluatedProperties" : false,
    "allOf": [
        {
            "type": "object",
            "properties": {
                "hello" : {
                    "type" : "string"
                }
            },
            "required" : ["hello"]
        },
        {
            "type": "object",
            "properties": {
                "world": {
                    "type" : "string"
                }
            },
            "required" : ["world"]
        }
    ]
}

The validator should treat the validation equivalently to:

{
    "type": "object",
    "properties": {
        "hello" : {
            "type" : "string"
        },
        "world": {
            "type" : "string"
        }
    },
    "additionalProperties" : false,
    "required" : ["hello","world"]
}

Some tests on my side seem to ignore it. If you submit an object with additional properties (other than hello and world), validation does not fail as expected.

I suppose that the unevaluatedProperties thing is from a more recent draft, but it has been introduced for a reason and makes the usage of the very core allOf feature much more efficient, as it effectively allows you to reuse object schemas defined throughout the project in a much stricter way.

Do you think that it's possible to introduce this keyword ?

fulstadev avatar May 13 '26 14:05 fulstadev

🚀 @fulstadev, thanks for your contribution! Every idea, bug report, and discussion helps make this project better. Your input is invaluable, and we appreciate the time you took to share it. A maintainer will review it soon—stay awesome! 💡✨

⭐ Enjoying contributing? Star the project! ⭐Your contributions help this project grow, and we'd love your support in another way too! If you find this repo helpful, consider leaving a star 🌟 on GitHub.

github-actions[bot] avatar May 13 '26 14:05 github-actions[bot]

Hi @fulstadev

unevaluatedProperties was added in Draft-2019-09 which is a draft currently not yet support (nor is Draft-2020-12). In #885 I'm working on adding initial support for Draft-2019-09 but I'm planning to skip unevaluatedProperties due to the complexity.

You're free to work on a PR that targets either main once the PR is merged or target the PR and we can see if it can get merged. It might be quite a large amount of work due to the fact currently there is no keeping track of properties that have been evaluated.

DannyvdSluijs avatar May 13 '26 18:05 DannyvdSluijs

I was thinking of taking this on now that the Draft-2019 support PR is merged: first trace how object properties are marked during allOf evaluation, then add the smallest evaluation-set bookkeeping needed for unevaluatedProperties, with regression cases for the nested allOf example and an unexpected property. I checked the current open PRs and don't see an overlapping implementation. This looks like a larger change, so I would keep the first patch limited to the keyword and its tests. Does that direction still fit the project's plan?

tomatotomata avatar Jul 30 '26 23:07 tomatotomata

@tomatotomata contributions are very welcome. I'm not that familiar with unevaluatedProperties so it might be you running into blockers as the project has not been setup for keeping context throughout the flow. Feel free to ask if you need explaining or opinions.

Maybe the first version is more of a proof on concept than going to be the final version. I'm curious how far you can get.

DannyvdSluijs avatar Jul 31 '26 07:07 DannyvdSluijs