httk.store.validation¶
Validate values offline against OPTIMADE property definitions with JSON Schema.
httk-core models each OPTIMADE property as a self-describing definition whose
as_optimade() document is a JSON Schema
(plus x-optimade-* annotations that validators ignore). This module uses
that document directly to validate concrete values with jsonschema’s Draft
2020-12 dialect.
The definitions are self-contained: they carry no $ref, so validation never
needs to resolve or fetch anything. The document’s $schema key points at the
OPTIMADE property-definition meta-schema URI (which describes definitions, not
values); it is removed before building the validator so jsonschema never
attempts to resolve it, and the dialect is pinned explicitly to
jsonschema.Draft202012Validator. Validation is therefore fully offline.
The local RFC 3339 date-time checker below supplies format validation
without network access or additional dependencies.
Exceptions¶
Report that a value did not conform to its OPTIMADE property definition. |
Functions¶
|
Validate a single |
|
Validate every property present in |
Module Contents¶
- exception httk.store.validation.PropertyValidationError(name, message)[source]¶
Bases:
ValueErrorReport that a value did not conform to its OPTIMADE property definition.
Carries the offending property
nameand a human-readablemessage. For single-value failures the message wraps the underlyingjsonschemaerror message, and thatjsonschema.exceptions.ValidationErroris preserved as the chained__cause__.- Parameters:
- httk.store.validation.validate_property(definition, value)[source]¶
Validate a single
valueagainstdefinition’s JSON-Schema payload.Builds a
jsonschema.Draft202012Validatordirectly from the definition’s document (with the$schemameta-schema reference removed) and validatesvalueagainst it using the local format checker. ReturnsNoneon success; raisesPropertyValidationErroron failure, chaining the underlyingjsonschema.exceptions.ValidationErroras the cause. No network access or registry lookup ever happens.- Parameters:
definition (httk.core.PropertyDefinition) – The self-contained OPTIMADE property definition.
value (Any) – The value to validate.
- Returns:
None.
- Raises:
PropertyValidationError – If
valueviolatesdefinition.- Return type:
None
- httk.store.validation.validate_record(entry_type, record)[source]¶
Validate every property present in
recordagainstentry_type.Each key in
recordmust be described byentry_type; unknown property names are rejected with aPropertyValidationErrornaming them and the entry type.idandtypemust both be present. Properties described by the definition but absent fromrecordare simply not checked (serving a subset of the described properties is normal). The value of every property that is present is validated viavalidate_property(). ReturnsNoneon success.- Parameters:
entry_type (httk.core.EntryTypeDefinition) – The entry definition describing allowed properties.
record (collections.abc.Mapping[str, Any]) – The record mapping to validate.
- Returns:
None.
- Raises:
PropertyValidationError – If a property is unknown,
idortypeis missing, or a value violates its property definition.- Return type:
None