ogen
ogen copied to clipboard
feat: optionally write generated code to a single Go file
Description
I would like to propose a new -target-file
flag, which, if provided would:
- Generate a single Go file instead of many files
- Preclude the use of
-target
Aesthetically, I think this would be an improvement, as the content of the generated code is (largely) irrelevant to me as an ogen
user. That said, my primary desire for this feature is technical in nature.
My organisation makes extensive use of a set of standardised make
include files throughout our Go projects. One difficulty I've had in building such an include file for ogen
is knowing the set of filenames that it will generate. We moved forward by simply hardcoding the list of files that we know ogen
produces right now, but this solution is not resilient to future changes to ogen
and/or differing ogen
versions across Go projects.
/cc @danilvpetrov
Perhaps a silly question, but why do you need to know a list of files it will generate for a Makefile? Can you not just refer to the directory containing the package when using the go tools?
It's about defining the dependency relationships between:
- The OpenAPI schema file(s), and the generated code
- The generated code and the other Make recipes that consume that code
When both of these relationships are properly defined, Make will invoke ogen
only when we are building something that uses the generated code AND the OpenAPI schema has changed since the code was last generated.
One problem with using the target directory instead of the filename(s) of the generated code is that the presence of the target directory does not actually mean that the generated code is current or exists at all.
Hopefully that makes sense :) let me know if anything needs clarification.