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

Incorrect/inconsistent validation result when combining unevaluatedProperties/allOf/oneOf #496

Closed
GREsau opened this issue Sep 9, 2024 · 1 comment · Fixed by #509
Closed

Comments

@GREsau
Copy link
Contributor

GREsau commented Sep 9, 2024

Thanks for the crate, I've started using this to reimplement the tests in schemars to validate its outputs, and doing so has already revealed a few schemars bugs!

I also stumbled upon this odd case though - full repro:

use jsonschema::{Draft, JSONSchema};
use serde_json::json;

fn main() {
    let schema = JSONSchema::options()
        .with_draft(Draft::Draft202012)
        .compile(&json!({
            "$schema": "https://json-schema.org/draft/2020-12/schema",
            "allOf": [{}],
            "oneOf": [
                {
                    "properties": {
                        "blah": true
                    }
                }
            ],
            "unevaluatedProperties": false
        }))
        .unwrap();

    let value = json!({
        "blah": 1
    });

    println!(
        "Is valid: {}, validate is OK: {}",
        schema.is_valid(&value),
        schema.validate(&value).is_ok()
    );
}

I believe that schema is functionally equivalent to

{
  "properties": {
    "blah": true
  },
  "additionalProperties": false
}

So I'd expect the output to be Is valid: true, validate is OK: true, but it's actually Is valid: false, validate is OK: true. i.e. validate correctly passes validation, but is_valid fails it for some reason

@Stranger6667
Copy link
Owner

Thanks for the crate, I've started using this to reimplement the tests in schemars to validate its outputs, and doing so has already revealed a few schemars bugs!

Delighted to hear it!

Indeed, it is a bug! Thanks for reporting :)

Stranger6667 added a commit that referenced this issue Sep 13, 2024
Ref: #496

Signed-off-by: Dmitry Dygalo <dmitry@dygalo.dev>
Stranger6667 added a commit that referenced this issue Sep 13, 2024
Ref: #496

Signed-off-by: Dmitry Dygalo <dmitry@dygalo.dev>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants