A handwritten DTO is a client-maintained data model for messages exchanged with a service. Teams can write DTOs from scratch or generate them once from a schema and maintain the result manually. section 8.1.7
Handwritten DTOs trade tighter client control for more manual work:
- They include only needed fields, can follow team conventions and contain logic, and avoid a code-generation build step. section 8.1.7
- Complex schemas take longer to model; API changes require manual updates and can cause schema drift. Consumer-driven contract tests or schema validation can reduce that risk. Teams may also model the same messages inconsistently. section 8.1.7
Figure 8.3 An API client must have a data model of the messages that it exchanges with the service. The data model must serialize and deserialize correctly as defined by the schema. It can either be untyped (e.g. hash maps) or consist of handwritten or code-generated classes.
Compare handwritten classes with generated classes and untyped data models in an API client. section 8.1.7
