Skip to content

bug: type order in 'allOf' has an impact #712

New issue

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

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

Already on GitHub? # to your account

Closed
kroc702 opened this issue Feb 13, 2024 · 5 comments
Closed

bug: type order in 'allOf' has an impact #712

kroc702 opened this issue Feb 13, 2024 · 5 comments

Comments

@kroc702
Copy link

kroc702 commented Feb 13, 2024

Hello,
When validate with multiple schema using 'allOf', definition order has a behavior impact.
cf attached code to test
testSchemaValidator2.zip

Correct:

input value: "true"
schema: {
    "allOf": [
        {
            "type": "string"
        },
        {
            "type": "boolean"
        }
    ]
}
value is valid

reverse order lead to incorrect validation:

input value: "true"
schema: {
    "allOf": [
        {
            "type": "boolean"
        },
        {
            "type": "string"
        }
    ]
}
Boolean value found, but a string is required
Failed to match all schemas
@kroc702
Copy link
Author

kroc702 commented Feb 13, 2024

I forget to mention version:

            "name": "justinrainbow/json-schema",
            "version": "v5.2.13",
            "source": {
                "type": "git",
                "url": "https://github.com/justinrainbow/json-schema.git",
                "reference": "fbbe7e5d79f618997bc3332a6f49246036c45793"
            },

@DannyvdSluijs
Copy link
Collaborator

@kroc702 thanks for the report. Based on your schema provided it seems no input data will be valid ever as the a single value cannot be boolean and string at the same time. Using https://jsonschemalint.com/ you can see that both versions of you schema should raise errors whereas you mention that in both cases you expect them to be valid.

@kroc702
Copy link
Author

kroc702 commented Feb 14, 2024

Well it's a choice, your choice ;)
As php is loosely typed, it doesn't hurt me to validate the strings "true" or "1" as boolean or number. Changing this behavior may be a braking change for the lib.

We just need a consistent behavior with all types and order shouldn't impact behavior of any/all/oneOf.

@DannyvdSluijs
Copy link
Collaborator

@kroc702 I now realise how the allOf would match the schemas in combination with the type coercion.

It seems the issue can be reproduced in the 5.2.13 and 5.3.0 releases and in the 5.x.x branch. In the releases 6.x and the master branch I can't reproduce the issue. The fixes have been made in #384 and are part of the 6.x release. although a backport was considered it was skipped for 5.x versions.

I would recommend to either update to version 6.x or see if you can alter your schema.

@DannyvdSluijs DannyvdSluijs closed this as not planned Won't fix, can't repro, duplicate, stale Feb 27, 2025
@kroc702
Copy link
Author

kroc702 commented Feb 27, 2025

Hi, and thank to keep track of this issue.

I'm not sure what "not planned" mean... It's fixed in version 6.x ?
I didn't test it yet but I understood yes, so thank !

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

2 participants