Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong properties evaluation while using "allOf" #325

Open
SkyKnight opened this issue Aug 17, 2023 · 0 comments
Open

Wrong properties evaluation while using "allOf" #325

SkyKnight opened this issue Aug 17, 2023 · 0 comments

Comments

@SkyKnight
Copy link

This is my intentionally complicated example JSON schema:

{
    "$id": "configuration-entry",
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "allOf": [
        {
            "if": {
                "properties": { "type": { "const": "form" } }
            },
            "then": {
                "allOf": [
                    {
                        "properties": {
                            "components": {
                                "type": "object",
                                "additionalProperties": {
                                    "type": "object",
                                    "allOf": [
                                        {
                                            "if": {
                                                "oneOf": [
                                                    {"properties": { "type": { "const": "text" } }},
                                                    {"properties": { "type": { "const": "text-plus" } }}
                                                ]
                                            },
                                            "then": {
                                                "allOf": [
                                                    {
                                                        "properties": {
                                                            "type": {
                                                                "type": "string"
                                                            }
                                                        }
                                                    },
                                                    {
                                                        "properties": {
                                                            "param1": {
                                                                "type": ["string", "number"]
                                                            },
                                                            "alignement": {
                                                                "type": "string"
                                                            }
                                                        }
                                                    }
                                                ],
                                                "unevaluatedProperties": false
                                            }
                                        },
                                        {
                                            "if": {
                                                "properties": { "type": { "const": "image" } }
                                            },
                                            "then": {
                                                "allOf": [
                                                    {
                                                        "properties": {
                                                            "type": {
                                                                "type": "string"
                                                            }
                                                        }
                                                    },
                                                    {
                                                        "properties": {
                                                            "meta": {
                                                                "type": "object"
                                                            },
                                                            "param1": {
                                                                "type": ["string", "number"]
                                                            }
                                                        }
                                                    }
                                                ],
                                                "unevaluatedProperties": false
                                            }
                                        }
                                    ],
                                    "properties": {
                                        "type": {
                                            "type": "string"
                                        }
                                    },
                                    "required": ["type"]
                                }
                            }
                        },
                        "required": ["components"]
                    }
                ]
            }
        }
    ],
    "properties": {
        "type": {
            "type": "string"
        }
    },
    "required": ["type"]
}

And my simple JSON document:

{
    "type": "form",
    "components": {
        "first": {
            "type": "text",
            "param1": 1,
            "alignement": "left"
        },
        "second": {
            "type": "image",
            "param1": "1",
            "meta": {
                "location": "nowhere",
                "date": "now"
            }
        },
        "third": {
            "type": "text-plus",
            "param1": 1,
            "alignement": "left"
        }
    }
}

Expected result: document is valid

Current situation:

        JSON does not match all schemas from 'allOf'. Invalid schema indexes: 0. Path '', line 1, position 1, schema 'configuration-entry'
                JSON does not match schema from 'then'. Path '', line 1, position 1, schema 'configuration-entry#/allOf/0/then'
                        JSON does not match all schemas from 'allOf'. Invalid schema indexes: 0. Path '', line 1, position 1, schema 'configuration-entry#/allOf/0/then'
                                JSON does not match all schemas from 'allOf'. Invalid schema indexes: 1. Path 'components.third', line 17, position 18, schema 'configuration-entry#/allOf/0/then/allOf/0/properties/components/additionalProperties'
                                        Property 'meta' has not been successfully evaluated and the schema does not allow unevaluated properties. Path 'components.third', line 17, position 18, schema 'configuration-entry#/allOf/0/then/allOf/0/properties/components/additionalProperties/allOf/1'

ajv command line shows document is valid

$ ajv -s schema.json -d data.json --spec=draft2020
strict mode: use allowUnionTypes to allow union type keyword at "configuration-entry#/allOf/0/then/allOf/0/properties/components/additionalProperties/allOf/0/then/allOf/1/properties/param1" (strictTypes)
strict mode: use allowUnionTypes to allow union type keyword at "configuration-entry#/allOf/0/then/allOf/0/properties/components/additionalProperties/allOf/1/then/allOf/1/properties/param1" (strictTypes)
data.json valid

same story with https://json-schema.hyperjump.io/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant