Stranger6667 / jsonschema-rs

JSON Schema validation library
https://docs.rs/jsonschema
MIT License
482 stars 90 forks source link

Incorrect validation of uuid #489

Closed Toveal closed 1 month ago

Toveal commented 1 month ago

Hello. I'm facing a problem. I specify the string type and UUID format. I write not UUID in the field, but JSON passes validation jsonschema version 0.18 Code:

use jsonschema::JSONSchema;

const SCHEMA: &str = r#"
{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "type": "object",
    "properties": {
        "test": {
            "type": "string",
            "format": "uuid"
        }
    },
    "required": [
        "test"
    ]
}"#;

const JSON_VAL: &str = r#"
{
    "test": "Hello world!"
}
"#;

fn main() {
    let schema_json: serde_json::Value = serde_json::from_str(SCHEMA).unwrap();
    let compiled_schema = JSONSchema::compile(&schema_json).unwrap();

    let instance = serde_json::from_str(JSON_VAL).unwrap();
    let result = compiled_schema.validate(&instance);

    if result.is_ok() {
        println!("JSON is valid");
    } else {
        for error in result.expect_err("Expected validation errors") {
            println!("Validation error: {}", error);
        }
    }
}
Toveal commented 1 month ago

I apologize, I thought UUID was available in Draft 7