Skip to content

Swagger Codegen migration from Mustache and Handlebars templates.

Jérémie Bresson edited this page Mar 8, 2018 · 7 revisions

Mustaches and Handlebars use a similar syntax, the implementing changes have been small in order to migrate to handlebars, but there are some details that must be kept in mind.

Here is a list of the main changes done on .mustache files in order to support handlebars:

Blank spaces

To avoid blank spaces between elements we need to use ~ character. This sample {{#elem}} ... {{/elem}} should be used this way: {{#elem}} ... {{/elem~}} to avoid an extra line on the result.

First and last elements

  • For {{#-last}} element we should replace the - character with @. We'll need to use: {{#@last}}
  • The same with {{#-first}} that becomes {{#@first}}

Properties: is, isNot, has, hasNot...

The main change that affects templates is that is*, isNot*, has*, hasNot* properties have been removed from codegen pojo (CodegenModel, CodegenProperty, etc) and replaced for extensions. So one option to access those values is: {{#vendorExtension.x-is-enum}}. However we've created handlebar helpers in order to keep using this in a similar way, the sample before can also be expressed this way: {{#is this 'enum'}}, where this references to a codegen pojo in the template.

Custom delimiters

A solution is requested for custom delimiters. See: swagger-codegen-generators/#33.


So these are basically the changes implemented in order to reuse a mustache template in handlebars. I understand that there are more considerations and features in handlebars that can be described, but till now these have been the required changes for migration.

Navigation

Codegen Usage

Clone this wiki locally