ogen icon indicating copy to clipboard operation
ogen copied to clipboard

feat: optionally write generated code to a single Go file

Open jmalloc opened this issue 1 year ago • 3 comments

Description

I would like to propose a new -target-file flag, which, if provided would:

  1. Generate a single Go file instead of many files
  2. 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.

jmalloc avatar Sep 11 '23 20:09 jmalloc

/cc @danilvpetrov

jmalloc avatar Sep 12 '23 01:09 jmalloc

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?

dotwaffle avatar Sep 14 '23 13:09 dotwaffle

It's about defining the dependency relationships between:

  1. The OpenAPI schema file(s), and the generated code
  2. 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.

jmalloc avatar Sep 14 '23 21:09 jmalloc