Skip to main content

bundle

Function bundle 

Source
pub fn bundle(schema: &Value) -> Result<Value, ReferencingError>
Expand description

Embed all external $ref targets into a draft-appropriate container, producing a Compound Schema Document that validates identically to the original. Draft 4/6/7 use definitions; Draft 2019-09/2020-12 use $defs. $ref values are preserved unchanged. For mixed-draft bundles, embedded resources may include both id and $id to maximize interoperability with downstream validators that differ in draft handling.

Limitation: $dynamicRef is not followed during bundling.

For custom resources or retrievers, use options() and call .bundle().

§Errors

Returns an error if draft detection fails, registry construction fails, subresource scope resolution fails, or any $ref cannot be resolved.

§Panics

This function must not be called from within an async runtime if the schema contains external references that require network requests, or it will panic when attempting to block. Use async_options().bundle() for async contexts, or run this in a separate blocking thread via tokio::task::spawn_blocking.

§Examples

use serde_json::json;

let schema = json!({"type": "string"});
let bundled = jsonschema::bundle(&schema).expect("bundling failed");
assert_eq!(bundled, schema); // no external refs, returned unchanged