jsonschema-rs icon indicating copy to clipboard operation
jsonschema-rs copied to clipboard

stack overflow

Open sigoden opened this issue 2 years ago • 0 comments

use jsonschema::JSONSchema;
use serde_json::json;

fn main() {
    let schema = json!({
  "$defs": {
    "root": {
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "a": {
              "type": "number"
            }
          }
        },
        {
          "$ref": "#/$defs/root"
        }
      ]
    }
  },
  "type": "object",
  "patternProperties": {
    ".*": {
      "$ref": "#/$defs/root"
    }
  }
});
    let instance = json!({
  "x": {
    "a": 3
  },
  "y": {
    "x": {
      "a": 3
    }
  }
});
    let compiled = JSONSchema::compile(&schema)
        .expect("A valid schema");
    let result = compiled.validate(&instance);
    if let Err(errors) = result {
        for error in errors {
            println!("Validation error: {}", error);
            println!(
                "Instance path: {}", error.instance_path
            );
        }
    }
}
thread 'main' has overflowed its stack
fatal runtime error: stack overflow
Aborted
[dependencies]
jsonschema = "0.16.0"
serde_json = "1.0.82"

sigoden avatar Jul 25 '22 01:07 sigoden