How can I add my license to the top of files autogenerated by openapi-generator?


I want to customize openapi-generator to auto generate code with a specific license header at the top of every file.

I figured I need to edit openapi-generator/src/main/resources/go/partial_header.mustache, is it a good idea just to paste a bunch of license text on top of that file?


According to their documentation, it depends on what the current generator provides, but in general, you will need to modify the templates and as such, maintain a custom template directory.

The only restriction you would face with adding the license content to the top of the partial_header.mustache template file you referenced, is that it should not contain any content that may be interpretable by the jmustache template engine.

Since the license text also does not involve actual code, there should be no issues with simply adding it to the template file, or even replacing the existing content in the template file.

It also seems as though you may not need to maintain an entire copy of the template structure, and only the template files you need, by using the external configuration files section during generation (According to this documentation).

Answered By – ShadowOfLies

Answer Checked By – Terry (GoLangFix Volunteer)

Leave a Reply

Your email address will not be published.