Skip to content

Schema validation

schema_validation

Draft 2020-12 JSON Schema validation for serialized bundles.

Functions:

prepare_bundle_schema

prepare_bundle_schema(schema: Mapping[str, Any]) -> Draft202012Validator

Compile and check a producer schema before bundle processing.

Parameters:

Name Type Description Default
schema Mapping[str, Any]

Producer JSON Schema to prepare.

required

Returns:

Type Description
Draft202012Validator

The cached validator for schema.

Raises:

Type Description
BundleSerializationError

If the schema is invalid or cannot be prepared for validation, including when it does not declare Draft 2020-12.

validate_bundle_schema

validate_bundle_schema(document: Mapping[str, Any], schema: Mapping[str, Any], *, validator: Draft202012Validator | None = None) -> None

Validate a bundle document against its producer JSON Schema.

Bundle-local JSON Pointers are expanded before validation so schemas can describe the referenced objects rather than their serialized pointers.

Parameters:

Name Type Description Default
document Mapping[str, Any]

Decoded bundle document to validate.

required
schema Mapping[str, Any]

Producer JSON Schema used for validation.

required
validator Draft202012Validator | None

Prepared validator for schema, when already available.

None

Raises:

Type Description
BundleSerializationError

If the schema is invalid or a reference cannot be resolved locally.

BundleValidationError

If the document violates the schema.