There were discussions about switching from Mustache to Handlebars (or something else) before. The goal was to simplify the templates as Mustache is a logicless template system and therefore we will need to create a lot of mustache tag(e.g. isInteger, isHttpBasic, etc) every time we need to compare values.
As discussed in https://github.com/swagger-api/swagger-codegen/issues/6077, Handlebars seems to be a good replacement. Here are a couple of questions we need to address:
The goal of this discussion is to collect feedback from the community and formula a plan to replace Mustache if needed
Future major release (4.x or later)
It was previously discussed in https://github.com/swagger-api/swagger-codegen/issues/6077
Here is my view:
Here are my thoughts:
I hope @jimschubert will join this discussion because I think that he has some vision to change the architecture of the responsabilities between the component.
For the moment we have:
JavaClientCodegen, GoClientCodegen, ...) that are a way to do language specific stuff.CodegenModel, CodegenParameter, ... that respresent the OpenAPI spec in a way that it is easy to write files (some treatment are made)If I remember well, @jimschubert wanted to organize responsibilities in an other way.
If you want to introduce multiple template engine, thinking about who is responsible for what make sense.
If the interface to the generators, like JavaClientCodegen, GoClientCodegen, changes and we decide we need to have old and new systems running simultaneously because not all generators should be required to move at the same time, then one decision is whether a new template system would (a) only be on the new architecture or (b) be on the old and new architectures.
If the new template system is only on the new architecture, then it becomes more important to know the timing of the re-architecture.
Some of the re-architecture discussion in https://github.com/OpenAPITools/openapi-generator/issues/503. Should we have some wiki or repo markdown pages to discuss?
Is Handlebars in the 4.0.x branch already available?
Is Handlebars in the 4.0.x branch already available?
You can see work being done on this in PR https://github.com/OpenAPITools/openapi-generator/pull/690 which hasn't been merged yet.
For now, you can get this in the rienafairefr/openapi-generator:templating branch.
What about adding additional template engines that are never meant to become the default?
I'm in DevOps at a Python+Java (+ some JS though I haven't touched that yet) shop and rarely work with mustache or handlebars. I had to learn mustache to write the templates in #2270. Plus, the handlebars templates I've seen in swagger-codegen seem even more obtuse to me than mustache. Both feel clunky even if there are implementations in many languages.
I work with Jinja almost every day thanks to my DevOps work with Ansible, StackStorm, and other DevOps tools. So, for the python generators (this is the one I'm writing: #2270) in particular, I would prefer to work with Jinja templates to craft the python code. So for a python-focused generator I would like to use HubSpot/jinjava or something like that, but only for that generator. Of course, it's possible to write awful templates no matter the language, but allowing different languages to choose different template engines (assuming a java implementation is available) would be really nice.
@cognifloyd the long-term idea of #690 is to allow users to extend the "custom" template engines with whatever they prefer. For instance, to use Jinja this would require the user to create an adapter (or pull one from the community and add to claaspath), then explicitly select the template engine at execution time.
Since https://github.com/OpenAPITools/openapi-generator/pull/2657 was merged, does that mean Handlebars is now fully supported?
I looking at migrating from Swagger-generator to Openapi-gen due to creating a issue on their git and not receiving any response for months
Currently have Handlebar templates for project so looking at running with it as template engine but found a issue with it:
In generateSupportingFiles in DefaultGenerator.java it looks if files end with correct template extension before compiling them as templates otherwise just writing them as files.
This works fine when mustache files registered for the different languages end with correct mustache but when switching engine it expects handlebars extension which isn't whats registered by "language" generator
The name conversion is done later in current setup (that is why it works for i.e. model files), which never gets called for Supporting files.
Any ideas on how to solve this properly?
Should I write separate issue for this?
My temporary workaround is to allow mustache named targets to pass into compile section
https://github.com/OpenAPITools/openapi-generator/compare/master...lindgrenfredrik:aspnetcore_handlebars#diff-bd1652e990ffe227072a5c8908fd3054
Looks like this is merged to master. Is there a version based on master available?
@behrangsa I'm not sure what you're referring to as merged. We've had handlebars support throughout the 4.0 release. We don't have any built-in handlebars templates, and no real plans on the horizon to convert from mustache to handlebars as this would be an enormous effort.
Most helpful comment
@cognifloyd the long-term idea of #690 is to allow users to extend the "custom" template engines with whatever they prefer. For instance, to use Jinja this would require the user to create an adapter (or pull one from the community and add to claaspath), then explicitly select the template engine at execution time.
690 gets us a lot closer to that use case than we are today. I plan to get #690 into master this week, with a note that only Mustache is supported for embedded templates.