json_schema_fuzz
Schema-guided JSON value generation for Draft 2020-12 JSON Schema documents.
Installation
Add to your Cargo.toml:
[]
= "0.2.6"
Usage
use SchemaDocument;
use ;
use json;
let raw = json!;
// Keep the schema document around; it lazily builds the canonicalized graph
// and raw validator when generation needs them.
let schema = from_json.unwrap;
// Generate a random value with the default depth and retry budget.
let mut rng = rng;
let value = generate.unwrap;
println!;
For repeated generation from the same schema, keep the same SchemaDocument so its lazy
canonical graph and raw validator are reused.
Public Interface
ValueGenerator::generate(&SchemaDocument, GenerationConfig, rng) -> Result<Value, GenerateError>is the value-generation entry point.GenerationConfig::default()uses the default recursion depth and retry budget.GenerationConfig::new(depth)changes the recursion depth limit while keeping the default retry budget.GenerationConfig::with_max_generation_attempts(limit)overrides the retry budget with a non-zero limit.GenerateError::Unsatisfiablemeans the resolved schema is known to have no valid instances.GenerateError::ExhaustedAttemptsmeans the schema may still be satisfiable, but the heuristic generator did not find a raw-valid candidate within the configured retry budget.
The generator walks the canonicalized SchemaNode graph from json_schema_ast,
but every returned value is accepted by SchemaDocument::is_valid() against the
original raw schema.
License
Licensed under MIT. See LICENSE.