Skip to content

Swagger Codegen migration from Mustache and Handlebars templates.

HugoMario edited this page Jan 22, 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:

  • 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 result.

  • For {{#-last}} element we should replace the -character for @'. We'll need to use: {{#@last}}`

The main change that affect 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 template.

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