cdm_data_loaders.schemas.jsonschema ¶
JSON Schema validation, custom KBase XSV metaschema, and $ref/allOf dereferencing utilities.
ValidatedSchema
pydantic-model
¶
Bases: BaseModel
A validated JSON Schema.
Show JSON schema:
Fields:
-
jsonschema(dict[str, Any])
Validators:
-
validate_jsonschema→jsonschema
Source code in src/cdm_data_loaders/schemas/jsonschema.py
validate_jsonschema
pydantic-validator
¶
Validate the schema in the jsonschema field.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema
|
dict[str, Any]
|
a JSON schema |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
validated schema |
Raises:
| Type | Description |
|---|---|
ValueError
|
if there is no |
jsonschema.exceptions.SchemaError
|
if the schema is invalid |
jsonschema.exceptions.ValidationError
|
if the schema fails validation |
Source code in src/cdm_data_loaders/schemas/jsonschema.py
DereferencingError ¶
DereferenceContext
dataclass
¶
Mutable state for a single dereference_schema() call.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
resolver
|
Resolver
|
the |
required |
spec
|
Any
|
the JSON Schema specification/dialect in effect |
required |
max_ref_depth
|
int
|
maximum depth of a |
required |
ref_sibling_mode
|
RefSiblingMode
|
how to handle keywords declared alongside |
required |
active_refs
|
set[str]
|
the set of |
set()
|
Source code in src/cdm_data_loaders/schemas/jsonschema.py
load_xsv_meta_schema ¶
load_xsv_meta_schema(
local_schema_path: Path | Traversable | None = None,
remote_url: str = CUSTOM_META_SCHEMA_URI,
) -> frozendict[str, Any]
Load the custom XSV metaschema and validate it against its declared metaschema.
Reads the custom metaschema from schemas/xsv_config/0.1.0/schema.json if available,
or from https://kbase.github.io/cdm-data-loaders/schemas/xsv_config/0.1.0/schema.json
otherwise, and validates the document against its own $schema metaschema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
local_schema_path
|
Path | Traversable | None
|
optional local schema path or |
None
|
remote_url
|
str
|
fallback URL to fetch the metaschema from when unavailable locally |
CUSTOM_META_SCHEMA_URI
|
Returns:
| Type | Description |
|---|---|
frozendict[str, Any]
|
validated custom metaschema as an immutable mapping |
Raises:
| Type | Description |
|---|---|
TypeError
|
if the document is not a JSON object |
ValueError
|
if the document omits |
jsonschema.exceptions.SchemaError
|
if the custom metaschema fails validation against its metaschema |
Source code in src/cdm_data_loaders/schemas/jsonschema.py
get_xsv_meta_schema
cached
¶
Lazily load, validate, and cache the custom KBase XSV metaschema.
Returns:
| Type | Description |
|---|---|
frozendict[str, Any]
|
validated custom metaschema mapping |
Source code in src/cdm_data_loaders/schemas/jsonschema.py
get_xsv_config_schema ¶
Lazily extract the x-xsv-config extension schema from the custom XSV metaschema.
Returns:
| Type | Description |
|---|---|
frozendict[str, Any]
|
immutable |
Raises:
| Type | Description |
|---|---|
ValueError
|
if the custom metaschema does not define |
TypeError
|
if |
Source code in src/cdm_data_loaders/schemas/jsonschema.py
register_xsv_validator ¶
Lazily load, validate, and register the custom validator for the KBase XSV metaschema.
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in src/cdm_data_loaders/schemas/jsonschema.py
dereference_schema ¶
dereference_schema(
schema: dict[str, Any],
additional_resources: (
Mapping[str, dict[str, Any]] | None
) = None,
*,
max_ref_depth: int = 50,
ref_sibling_mode: RefSiblingMode = "auto"
) -> dict[str, Any]
Resolve every $ref in a schema using additional_resources where needed.
Merges any allOf tags to return a fully self-contained schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema
|
dict[str, Any]
|
the JSON Schema document to dereference |
required |
additional_resources
|
Mapping[str, dict[str, Any]] | None
|
mapping of URI to schema dict, used to resolve external |
None
|
max_ref_depth
|
int
|
maximum depth of a |
50
|
ref_sibling_mode
|
RefSiblingMode
|
how to handle keywords declared alongside |
'auto'
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
an equivalent, |
Raises:
| Type | Description |
|---|---|
DereferencingError
|
if a |