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 schema_path in errors #426

Closed
Kixiron opened this issue Apr 13, 2023 · 2 comments · Fixed by #483
Closed

Incorrect schema_path in errors #426

Kixiron opened this issue Apr 13, 2023 · 2 comments · Fixed by #483

Comments

@Kixiron
Copy link

Kixiron commented Apr 13, 2023

Validating this json with this schema yields a schema_path of [PathChunk::Keyword("oneOf")] which points to nothing, I'd expect the schema path to be something like /definitions/Neg or /definitions/Node/3, something that actually points to the definition at hand

@tommy
Copy link

tommy commented May 23, 2023

I've encountered what I beleive is the same error. I believe it's related to multiple iterations of $ref schemas. In the following minimal repro, you can see the first error has the correct schema_path, but the second just returns "/enum"

Cargo.toml

[package]
name = "scratch"
version = "0.1.0"
edition = "2021"

[dependencies]
jsonschema = "0.17.0"
serde_json = "1.0.96"

main.rs

fn main() {
    let json = serde_json::json!({
        "things": [
            { "code": "CC" },
            { "code": "CC" },
        ]
    });

    let schema = serde_json::json!({
        "type": "object",
        "properties": {
            "things": {
                "type": "array",
                "items": {
                    "type": "object",
                    "properties": {
                        "code": {
                            "type": "string",
                            "$ref": "#/$defs/codes"
                        }
                    },
                    "required": ["code"]
                }
            }
        },
        "required": ["things"],
        "$defs": { "codes": { "enum": ["AA", "BB"] } }
    });

    let compiled = jsonschema::JSONSchema::options().compile(&schema).unwrap();

    let result = compiled.validate(&json);
    if let Err(err_iter) = result {
        for err in err_iter {
            println!("Schema path {}", err.schema_path);
        }
    }
}

output

Schema path /properties/things/items/properties/code/enum
Schema path /enum

@Stranger6667
Copy link
Owner

Sorry for the delay - the fix will be released soon

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.

3 participants