-
Notifications
You must be signed in to change notification settings - Fork 4
Codegen
Building (RESTful) APIs in Java Spring Boot requires many of the same components: Controllers, Services, Mappers, Repository interfaces and/or data-access objects (DAOs), data-transfer-objects (DTO), and entity models. The business logic to implement CRUD operations for each domain is similar as well. Thus, many of these components can be abstracted with parameterized dependencies so that implementing them at the concrete level can be done with minimal lines of code. This abstraction is provided by the components submodule.
Although the components submodule greatly improves a developer’s ability to quickly implement Spring Boot components with full CRUD functionality, the developer experience requires implementing and/or extending the interfaces and abstract classes that have been parameterized. This task can be tedious and reduce developer productivity.
To improve the developer experience by reducing the amount of code necessary to implement CRUD functionality for a domain’s Spring Boot components, the codegen project uses code generation technologies to auto implement the Controller, Service, Mapper, Repository interfaces and/or DAOs and DTOs based on a domain's Entity model. It is the Entity model that typically dictates differences in the business logic, after all.
This codegen project is in alpha and currently under active development to provide additional and more robust features.
As such, the following features are not yet supported:
-
Generating DTO objects
-
Attributes that are non-primitive objects (ie. Nested objects in an Entity)
-
IDs are only generated UUIDs
-
Business logic that
-
GraphQL
-
Search using criteria specification search
The roadmap can be viewed under the Codegen Project linked to this GitHub repository.
Please see [next steps](#next steps) for plans to address these limitations.
As a summary
There are concerns about generating APIs based on introspecting database schemas (ruslantalpa r/java on Reddit), which is related to how this project introspects Entity models to generate code for Spring Boot components. Indeed, this coupling is an anti-pattern to the DTO pattern and could expose sensitive attributes.
The codegen submodule generates Spring Boot components for RESTful APIs, with GraphQL support planned in the roadmap. At compile time, the project uses annotation processing with Java Poet to write Java files compile time based on the components submodule that
- Implement DTO 1:1 based on Entity model
- Ability to exclude attributes in the DTO that are present in the Entity model.