Specifications
plateforme.core.specs
This module provides utilities for managing schema within the Plateforme framework using Pydantic features.
Spec
module-attribute
Spec = TypeVar('Spec', bound='BaseSpec')
A type variable for a specification class.
SpecFacade
BaseSpec
Bases: Protocol
The base specification protocol for resources.
This protocol is used to define the specification for resources. It can be
derived to define custom model schemas either by specifying static nested
model classes within the base specification, or by implementing the
__apply__
method to dynamically generate model schemas based on the
resource provided by the specification facade or add custom logic.
Those models are then used to define the validation, serialization, and deserialization logic for resources within services.
CRUDSpec
apply_spec
apply_spec(spec: SpecType, facade: SpecFacade) -> None
Apply the specification to the facade.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
spec
|
SpecType
|
The specification to apply. |
required |
facade
|
SpecFacade
|
The facade to apply the specification to. |
required |
Source code in .venv/lib/python3.12/site-packages/plateforme/core/specs.py
resolve_schema_model
resolve_schema_model(
annotation: Any,
*,
root_schemas: tuple[str, ...] | None = None,
with_spec: tuple[SpecType, ResourceType] | None = None,
) -> Any
Resolve the schema models from the annotation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
annotation
|
Any
|
The annotation to resolve. |
required |
root_schemas
|
tuple[str, ...] | None
|
The schema model aliases to use as the root schema. When
the resolved path is empty, the resolved root type is returned if
set to |
None
|
with_spec
|
tuple[SpecType, ResourceType] | None
|
The specification and resource type to use for resolving
the schema models. When provided, it should be a tuple containing
the specification and the resource type to use for resolving the
schema models. When set to |
None
|
Returns:
Type | Description |
---|---|
Any
|
The annotation with the resolved schema models. |