Add support for user-provided templates#136
Add support for user-provided templates#136deepmap-marcinr merged 2 commits intooapi-codegen:masterfrom
Conversation
This change introduces a new `-templates` command flag to enable users to override code generation templates at runtime instead of having to recompile the binary after having edited the built-in templates.
|
@deepmap-marcinr let me know if this is an acceptable change to be merged upstream: we'd like to use your software at Exoscale and we'd greatly appreciate not having to fork it 😉 |
deepmap-marcinr
left a comment
There was a problem hiding this comment.
Sorry, i didn't notice this PR, been super busy.
What do you think about not using a hard coded file list - comment inline.
cmd/oapi-codegen/oapi-codegen.go
Outdated
|
|
||
| func loadTemplateOverrides(templatesDir string) (map[string]string, error) { | ||
| var ( | ||
| knownTemplates = map[string]interface{}{ |
There was a problem hiding this comment.
I don't like having a hard coded file list - it's another place to forget to update.
We also don't really need to load all templates either, since the Chi and Echo stuff is mutually exclusive, for example.
It's a bummer that that the templates compiler I'm using doesn't export the file map, then this would be much nicer!
Can we simply enumerate the files in the templates directory? - if the filename matches, good, it'll override the original, if it doesn't match, you get no behavior change.
There was a problem hiding this comment.
I've just pushed a follow-up commit (a9a410b) that implements your suggestion, WDYT?
|
Thanks for doing this. |
|
No problem, thank you for merging! |
* Add support for user-provided templates This change introduces a new `-templates` command flag to enable users to override code generation templates at runtime instead of having to recompile the binary after having edited the built-in templates. * fixup! Add support for user-provided templates
This change introduces a new
-templatescommand flag to enable usersto override code generation templates at runtime instead of having to
recompile the binary after having edited the built-in templates.