base_dto

class litestar.dto.base_dto.AbstractDTO[原始碼]

基底類別:Generic[T]

Base class for DTO types.

config: ClassVar[DTOConfig]

Config objects to define properties of the DTO.

model_type: type[T]

If annotation is an iterable, this is the inner type, otherwise will be the same as annotation.

attribute_accessor()

getattr() like callable to access attributes on the data source

__init__(asgi_connection: ASGIConnection) None[原始碼]

Create an AbstractDTOFactory type.

參數:

asgi_connection -- A ASGIConnection instance.

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 config attribute 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.

decode_bytes(value: bytes) Any[原始碼]

Decode a byte string into an the DTO's datatype.

abstractmethod classmethod generate_field_definitions(model_type: type[Any]) Generator[DTOFieldDefinition, None, None][原始碼]

Generate FieldDefinition instances from model_type.

產出:

FieldDefinition instances.

abstractmethod classmethod detect_nested_field(field_definition: FieldDefinition) bool[原始碼]

Return True if field_definition represents a nested model field.

參數:

field_definition -- inspect type to determine if field represents a nested model.

回傳:

True if field_definition represents a nested model field.

classmethod is_supported_model_type_field(field_definition: FieldDefinition) bool[原始碼]

Check support for the given type.

參數:

field_definition -- A FieldDefinition instance.

回傳:

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.

參數:
  • field_definition -- A FieldDefinition instance.

  • handler_id -- ID of the route handler for which to create a DTO instance.

  • backend_cls -- Alternative DTO backend class to use

回傳:

None

classmethod create_openapi_schema(field_definition: FieldDefinition, handler_id: str, schema_creator: SchemaCreator) Reference | Schema[原始碼]

Create an OpenAPI request body.

參數:
  • 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 a FieldDefinition instance.

回傳:

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.

參數:

field_definition -- A parsed type annotation that represents the annotation used to narrow the DTO type.

回傳:

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.

參數:
  • model_type -- Any type-annotated class.

  • namespace -- Optional namespace to use for resolving type hints.

回傳:

Parsed type hints for model_type resolved within the scope of its module.

static get_dto_config_from_annotated_type(field_definition: FieldDefinition) DTOConfig | None[原始碼]

Extract data type and config instances from Annotated annotation.

參數:

field_definition -- A parsed type annotation that represents the annotation used to narrow the DTO type.

回傳:

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.

參數:

field_definition -- A parsed type annotation that represents the annotation used to narrow the DTO type.

回傳:

A FieldDefinition that represents the data model type.