1.5 KiB
1.5 KiB
ADR-0011: Code Generation Tools
Status
Accepted
Context
The platform will use code generation for:
- Permission constants from module manifests
- Ent ORM code generation
- Mock generation for testing
- OpenAPI client/server code (future)
We need to decide on tooling and workflow.
Decision
Use standard Go generation tools with go generate:
- Ent ORM:
entgo.io/ent/cmd/entfor schema code generation - Mocks:
github.com/vektra/mockery/v2orgithub.com/golang/mock/mockgen - Permissions: Custom
scripts/generate-permissions.go - OpenAPI:
github.com/deepmap/oapi-codegen(future)
Workflow:
- Use
//go:generatedirectives in source files - Run
go generate ./...before commits - Document in
Makefilewithmake generatetarget - CI should verify generated code is up-to-date
Rationale:
- Standard Go tooling, well-supported
go generateis the idiomatic way to run code generation- Easy to integrate into CI/CD
- Reduces manual code maintenance
Consequences
Positive
- Automated code generation reduces errors
- Consistent code style
- Easy to maintain
- Standard Go workflow
Negative
- Requires developers to run generation before commits
- Generated code must be committed (or verified in CI)
- Slight learning curve for new developers
Implementation Notes
- Add
//go:generatedirectives where needed - Create
Makefiletarget:make generate - Add CI step to verify generated code:
go generate ./... && git diff --exit-code - Document in
CONTRIBUTING.md