Skip to content

Add support for user-provided templates#136

Merged
deepmap-marcinr merged 2 commits intooapi-codegen:masterfrom
exoscale:feature/user-templates
Feb 19, 2020
Merged

Add support for user-provided templates#136
deepmap-marcinr merged 2 commits intooapi-codegen:masterfrom
exoscale:feature/user-templates

Conversation

@falzm
Copy link
Contributor

@falzm falzm commented Feb 18, 2020

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.

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.
@falzm
Copy link
Contributor Author

falzm commented Feb 18, 2020

@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 😉

Copy link
Contributor

@deepmap-marcinr deepmap-marcinr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, i didn't notice this PR, been super busy.

What do you think about not using a hard coded file list - comment inline.


func loadTemplateOverrides(templatesDir string) (map[string]string, error) {
var (
knownTemplates = map[string]interface{}{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've just pushed a follow-up commit (a9a410b) that implements your suggestion, WDYT?

@deepmap-marcinr
Copy link
Contributor

Thanks for doing this.

@deepmap-marcinr deepmap-marcinr merged commit fdf4894 into oapi-codegen:master Feb 19, 2020
@falzm
Copy link
Contributor Author

falzm commented Feb 19, 2020

No problem, thank you for merging!

@falzm falzm deleted the feature/user-templates branch February 18, 2021 13:51
adrianpk pushed a commit to foorester/oapi-codegen that referenced this pull request Jan 16, 2024
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants