Debian Codegraph @

docs/usage/dto/2-creating-custom-dto-classes.rst

raw
1 Implementing Custom DTO Classes
2 ===============================
3
4 While Litestar maintains a suite of DTO factories, it is possible to create your own DTOs. To do so, you must implement
5 the :class:`AbstractDTO <litestar.dto.base_dto.AbstractDTO>` abc.
6
7 The following is a description of the methods of the protocol, and how they are used by Litestar. For detailed
8 information on the signature of each method, see the :class:`reference docs <litestar.dto.base_dto.AbstractDTO>`.
9
10 Abstract Methods
11 ~~~~~~~~~~~~~~~~
12
13 These methods must be implemented on any :class:`AbstractDTO <litestar.dto.base_dto.AbstractDTO>` subtype.
14
15 ``generate_field_definitions``
16 ------------------------------
17
18 This method receives the model type for the DTO and it should return a generator yielding
19 :class:`DTOFieldDefinition<litestar.dto.data_structures.DTOFieldDefinition>` instances corresponding with
20 the model fields.
21
22 ``detect_nested_field``
23 -----------------------
24
25 This method receives a :class:`FieldDefinition<litestar.typing.FieldDefinition>` instance and it should return a boolean
26 indicating whether the field is a nested model field.