httk.serve.http.openapi.contract¶
Bundle a parsed OpenAPI contract with its offline schema registry.
Classes¶
Bundle a parsed OpenAPI contract with its offline JSON Schema registry. |
Module Contents¶
- class httk.serve.http.openapi.contract.OpenAPIContract[source]¶
Bundle a parsed OpenAPI contract with its offline JSON Schema registry.
- Parameters:
operations – Supported operations in document order.
schemas – Offline schema registry for external body references.
- operations: tuple[httk.serve.http.openapi.app.OpenAPIOperation, Ellipsis][source]¶
- classmethod from_package(package, *, contract=('schemas', 'openapi.yaml'), schemas=('schemas',), schema_transform=None)[source]¶
Load and parse a packaged OpenAPI contract and its bundled schemas.
Results are cached by the exact
package,contract,schemas, andschema_transformarguments, so repeated calls with the same arguments do not re-parse or re-validate the packaged data.- Parameters:
package (str) – Importable package that ships the contract as package data.
contract (collections.abc.Sequence[str]) – Path segments below the package to the OpenAPI document.
schemas (collections.abc.Sequence[str]) – Path segments below the package to the schema root.
schema_transform (collections.abc.Callable[[dict[str, Any]], dict[str, Any]] | None) – Optional per-document transform applied to each bundled JSON Schema document before it is registered. It is not applied to the OpenAPI document itself. Must be a stable module-level function: it is part of the cache key by identity, so a lambda or closure never hits the cache and instead retains a fully parsed contract for its own lifetime.
- Returns:
The parsed contract and its offline schema registry.
- Raises:
httk.serve.http.openapi.OpenAPIContractError – If the OpenAPI document uses an unsupported construct.
httk.serve.http.openapi.OpenAPISchemaError – If any bundled schema document is invalid.
- Return type:
Self
- operation(operation_id)[source]¶
Return the operation registered under an operation id.
- Parameters:
operation_id (str) – Operation identifier to look up.
- Returns:
The matching operation.
- Raises:
httk.serve.http.openapi.OpenAPIContractError – If no operation has that id.
- Return type:
- validate(schema_id, document)[source]¶
Validate a JSON-compatible value against a bundled schema.
- Parameters:
schema_id (str) – Schema
$id.document (Any) – JSON-compatible value to validate.
- Raises:
httk.serve.http.openapi.OpenAPISchemaError – If the schema is unavailable or validation fails.