base_dto#
- class litestar.dto.base_dto.AbstractDTO#
Bases:
Generic[T]Base class for DTO types.
- model_type: type[T]#
If
annotationis an iterable, this is the inner type, otherwise will be the same asannotation.
- __init__(asgi_connection: ASGIConnection) None#
Create an AbstractDTOFactory type.
- Parameters:
asgi_connection¶ – A
ASGIConnectioninstance.
- classmethod get_config_for_model_type(config: DTOConfig, model_type: type[Any]) DTOConfig#
Create a new configuration for this specific
model_type, during the creation of the factory.The returned config object will be set as the
configattribute on the newly defined factory class.
- decode_builtins(value: dict[str, Any]) Any#
Decode a dictionary of Python values into an the DTO’s datatype.
- abstractmethod classmethod generate_field_definitions(model_type: type[Any]) Generator[DTOFieldDefinition, None, None]#
Generate
FieldDefinitioninstances frommodel_type.- Yields:
FieldDefinitioninstances.
- abstractmethod classmethod detect_nested_field(field_definition: FieldDefinition) bool#
Return
Trueiffield_definitionrepresents a nested model field.- Parameters:
field_definition¶ – inspect type to determine if field represents a nested model.
- Returns:
Trueiffield_definitionrepresents a nested model field.
- classmethod is_supported_model_type_field(field_definition: FieldDefinition) bool#
Check support for the given type.
- Parameters:
field_definition¶ – A
FieldDefinitioninstance.- Returns:
Whether the type of the field definition is supported by the DTO.
- classmethod create_for_field_definition(field_definition: FieldDefinition, handler_id: str, backend_cls: type[DTOBackend] | None = None) None#
Creates a DTO subclass for a field definition.
- Parameters:
field_definition¶ – A
FieldDefinitioninstance.handler_id¶ – ID of the route handler for which to create a DTO instance.
backend_cls¶ – Alternative DTO backend class to use
- Returns:
None
- classmethod create_openapi_schema(field_definition: FieldDefinition, handler_id: str, schema_creator: SchemaCreator) Reference | Schema#
Create an OpenAPI request body.
- Parameters:
field_definition¶ – A parsed type annotation that represents the annotation used on the handler.
handler_id¶ – ID of the route handler for which to create a DTO instance.
schema_creator¶ – A factory for creating schemas. Has a
for_field_definition()method that accepts aFieldDefinitioninstance.
- Returns:
OpenAPI request body.
- classmethod resolve_generic_wrapper_type(field_definition: FieldDefinition) tuple[FieldDefinition, FieldDefinition, str] | None#
Handle where DTO supported data is wrapped in a generic container type.
- Parameters:
field_definition¶ – A parsed type annotation that represents the annotation used to narrow the DTO type.
- Returns:
The data model type.
- static get_model_type_hints(model_type: type[Any], namespace: dict[str, Any] | None = None) dict[str, FieldDefinition]#
Retrieve type annotations for
model_type.
- static get_dto_config_from_annotated_type(field_definition: FieldDefinition) DTOConfig | None#
Extract data type and config instances from
Annotatedannotation.- Parameters:
field_definition¶ – A parsed type annotation that represents the annotation used to narrow the DTO type.
- Returns:
The type and config object extracted from the annotation.
- classmethod resolve_model_type(field_definition: FieldDefinition) FieldDefinition#
Resolve the data model type from a parsed type.
- Parameters:
field_definition¶ – A parsed type annotation that represents the annotation used to narrow the DTO type.
- Returns:
A
FieldDefinitionthat represents the data model type.