liveBook · Manning

Code generation

As explained in Microservices Patterns, Second Edition

Code generation is the automated production of source code or related implementation artifacts from higher-level specifications.

Code generation produces API-client DTOs from an interface definition. It is common for binary message payloads; for text-based payloads, clients can instead use generated, handwritten, or untyped models. section 8.1.7

Choose an implementation strategy by weighing:

  • Development effort, including initial creation and maintenance as the API evolves. section 8.1.7
  • Schema correctness, compile-time type safety, and design-time coupling to fields the client uses. 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.
defining api client dtos

Compare untyped, handwritten, and generated message models and their role in schema-aligned serialization and deserialization. section 8.1.7

How Microservices Patterns, Second Edition covers it

How deep it goes
Compares generated, handwritten, and untyped models using effort, correctness, type safety, and coupling.
Examples
Contrasts generated DTOs for binary payloads with generated, handwritten, or untyped options for text payloads.
What it assumes
Uses an interface definition as the basis for generating DTOs.
What you can do after
Evaluate DTO strategies against development effort, schema correctness, type safety, and design-time coupling.
How it connects
Connects API clients with DTOs, interface definitions, serialization, and deserialization.

Also explained in

Compare how 21 books explain code generation →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Microservices Patterns, Second Edition. The section links point to the parts of the book it draws on.