Choosing the Tech Stack
The complete generation of types, server stubs, and clients based on the OpenAPI spec is now delegated to ogen. The
generation of mocks, however, remains a core component of Spec CLI.
Technical Implementation
Thanks to go/ast, go/token, go/parser, go/printer, and go/format, the Go code is generated entirely without
external dependencies. The files are marked with the header // Code generated by Spec CLI – DO NOT EDIT, making them
immediately recognizable as generated code within the project and preventing accidental manual modifications.
The mocks are currently designed as a closed system; extension through custom code is not planned for the time being. Should practical experience show that this need exists, I will adjust the concept accordingly.
The mock server and accompanying examples will initially be implemented based on http.ServeMux—a consistent step to
avoid additional dependencies. Since the handlers are implemented according to standards, switching to alternative
routers later poses no problem. Handler validation is done classically with net/http/httptest.
Pragmatic Use of Dependencies
For the CLI itself, I deliberately rely on established libraries: primarily spf13/cobra and spf13/viper. Here, the
standard library reaches its limits, and a custom implementation would be unnecessarily cumbersome. It’s not about
categorically excluding external libraries, but using them selectively and sensibly—which is exactly the case here.
Conclusion
In summary, the crucial framework conditions are now set: Code is not generated through error-prone templates or string concatenation, but structurally via the AST.
With these decisions, nothing stands in the way of the actual project implementation.
The use of the Go AST for mock generation underscores the high quality standards for the generated code. While
cobraandviperare practically industry standards for CLIs, the choice ofhttp.ServeMuxfor the internals shows a refreshing return to the strengths of the standard library. This keeps the toolchain stable and low-maintenance.