|
2 | 2 |
|
3 | 3 | ## Upgrading from 0.33.x to 0.34.0 |
4 | 4 |
|
5 | | -Meta-schema helpers moved to `draftX::meta::validator()` so `MetaValidator` exposes the same handle on native and wasm targets. Dropping the `Send + Sync` bounds for retrievers means the old `LazyLock` statics can’t store validators on `wasm32` anymore, so the new helper borrows cached validators on native platforms and builds owned copies on WebAssembly. |
| 5 | +### Removed `Validator::config()` |
| 6 | + |
| 7 | +The `Validator::config()` method has been removed to reduce memory footprint. The validator no longer stores the configuration internally. |
6 | 8 |
|
7 | 9 | ```rust |
8 | 10 | // Old (0.33.x) |
9 | | -let validator = jsonschema::draft7::meta::VALIDATOR; |
10 | | -validator.is_valid(&schema); |
| 11 | +let validator = jsonschema::validator_for(&schema)?; |
| 12 | +let config = validator.config(); // Returns Arc<ValidationOptions> |
| 13 | + |
| 14 | +// New (0.34.x) |
| 15 | +// No replacement - the config is not stored after compilation |
| 16 | +// If you need config values, keep a reference to your ValidationOptions |
| 17 | +let options = jsonschema::options().with_draft(Draft::Draft7); |
| 18 | +let validator = options.build(&schema)?; |
| 19 | +// Keep `options` around if you need to access configuration later |
| 20 | +``` |
| 21 | + |
| 22 | +### Meta-validator statics replaced with functions |
| 23 | + |
| 24 | +Public `DRAFT*_META_VALIDATOR` statics have been removed. Use the new `draftX::meta::validator()` helper functions instead. Dropping the `Send + Sync` bounds for retrievers means the old `LazyLock` statics can't store validators on `wasm32` anymore, so the new helper borrows cached validators on native platforms and builds owned copies on WebAssembly. |
| 25 | + |
| 26 | +```rust |
| 27 | +// Old (0.33.x) |
| 28 | +use jsonschema::DRAFT7_META_VALIDATOR; |
| 29 | +DRAFT7_META_VALIDATOR.is_valid(&schema); |
| 30 | + |
| 31 | +// Also removed: |
| 32 | +use jsonschema::DRAFT4_META_VALIDATOR; |
| 33 | +use jsonschema::DRAFT6_META_VALIDATOR; |
| 34 | +use jsonschema::DRAFT201909_META_VALIDATOR; |
| 35 | +use jsonschema::DRAFT202012_META_VALIDATOR; |
11 | 36 |
|
12 | 37 | // New (0.34.x) |
13 | 38 | let validator = jsonschema::draft7::meta::validator(); |
14 | 39 | validator.is_valid(&schema); |
| 40 | + |
| 41 | +// Or use the module-specific helper: |
| 42 | +jsonschema::draft7::meta::is_valid(&schema); |
15 | 43 | ``` |
16 | 44 |
|
| 45 | +### Lifetime parameters removed from output types |
| 46 | + |
| 47 | +`BasicOutput` and `Annotations` no longer have lifetime parameters. This simplifies the API and uses `Arc` for internal ownership. |
| 48 | + |
| 49 | +```rust |
| 50 | +// Old (0.33.x) |
| 51 | +fn process_output<'a>(output: BasicOutput<'a>) -> Result<(), Error> { |
| 52 | + match output { |
| 53 | + BasicOutput::Valid(units) => { |
| 54 | + for unit in units { |
| 55 | + let annotations: &Annotations<'a> = unit.annotations(); |
| 56 | + // ... |
| 57 | + } |
| 58 | + } |
| 59 | + BasicOutput::Invalid(errors) => { /* ... */ } |
| 60 | + } |
| 61 | + Ok(()) |
| 62 | +} |
| 63 | + |
| 64 | +// New (0.34.x) |
| 65 | +fn process_output(output: BasicOutput) -> Result<(), Error> { |
| 66 | + match output { |
| 67 | + BasicOutput::Valid(units) => { |
| 68 | + for unit in units { |
| 69 | + let annotations: &Annotations = unit.annotations(); |
| 70 | + // ... |
| 71 | + } |
| 72 | + } |
| 73 | + BasicOutput::Invalid(errors) => { /* ... */ } |
| 74 | + } |
| 75 | + Ok(()) |
| 76 | +} |
| 77 | +``` |
| 78 | + |
| 79 | +### WASM: Relaxed `Send + Sync` bounds |
| 80 | + |
17 | 81 | `Retrieve` / `AsyncRetrieve` on `wasm32` no longer require `Send + Sync`. |
18 | 82 |
|
19 | 83 | ```rust |
|
0 commit comments