-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Switching template system from Mustache to Handlebars (or something else) #510
Comments
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:
If I remember well, @jimschubert wanted to organize responsibilities in an other way. |
If the interface to the generators, like 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 #503. Should we have some wiki or repo markdown pages to discuss? |
Is Handlebars in the 4.0.x branch already available? |
You can see work being done on this in PR #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. #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. |
Since #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. 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 |
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. |
When switching from mustache to handlebars one must:
|
I have made a tool that will allow us to automate conversion from mustache to handlebars templates If people want to use this tool to switch their openapi generator templates, they can invoke it like:
|
The python-experimental generator now successfully uses the handlebars templating engine by default. All templates for that generator are handlebars and must be handlebars for that generator to work. I specifically used that templating engine because it allows recursive indented partials. I use that to render schema definitions at any depth of inlining. |
I've tried to use https://github.com/spacether/mustache_to_handlebars for typescript fetch template - it does some work, but there's more work needed to be do manually. Where I got stuck and decided not to go further - seems that you need to register partials in code that is running templating engine - so in generator's javascript, which takes away lots of flexibility, like we're using partials to isolate custom code from original template, so that template upgrade would be much easier. Probably that could be easily solved by scanning template directory and registering all partials dynamically, but intent was not to touch generator's code. Without support from others and mass migration to handlebars, I don't see this initiative as viable. |
partials templates should work without registering them. If you have specific helper functions in java that are custom, they need to be registered. When using partials, partial templates need to indicate where they are relative to the root folder containing that generators templating files.
where The only helpers that I use are these:
|
Personally I have never missed logic in mustache when writing/modifying generator templates. (That doesn't mean it cannot improve things.) What I find more difficult, is knowing the data structure that I am actually working with in the templates. I was thinking about mustache in a different context and wanted to mention the following point here.
We are not only generating HTML here, but mostly source code. So wouldn't it be better to switch to a templating language that is geared towards code generation instead of website generation? |
This bug makes it impossible migrating to Handlebars - jknack/handlebars.java#940 (comment) It seems to me that HandlebarsEngineAdapter uses resolvers in incorrect order:
Handlebars maintainer said that FieldValueResolver must be the last one and be used to access public fields to avoid illegal access exception:
|
Description
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 swagger-api/swagger-codegen#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
openapi-generator version
Future major release (4.x or later)
Related issues/PRs
It was previously discussed in swagger-api/swagger-codegen#6077
The text was updated successfully, but these errors were encountered: