Bharath Reddy
Bharath Reddy

Reputation: 746

Swift Auto code generation

I am new to Swift and I was working using SwagGen which generated Swift code from Swagger Style Json object. For generating code they have template files. I saw a wierd syntax for auto-generation in those files

public init({% if bodyParam %}_ {{ bodyParam.name}}: {{ bodyParam.optionalType }}{% if nonBodyParams %}, {% endif %}{% endif %}{% if nonBodyParams %}_ options: Options{% endif %}) {
        {% if bodyParam %}
        self.{{ bodyParam.name}} = {{ bodyParam.name}}
        {% endif %}
        {% if nonBodyParams %}
        self.options = options
        {% endif %}
        super.init(service: {{ operationId|upperCamelCase }}.service)
    }

What is this syntax({{% %}})? I have to make changes in this code for my personal purposes. Can any one suggest some links to learn this or explain what it is?

Upvotes: 0

Views: 755

Answers (2)

David Pasztor
David Pasztor

Reputation: 54745

Swagger uses .mustache files as template files. You should have a look at the official documentation of moustache if you don't understand its syntax.

Upvotes: 2

Retterdesdialogs
Retterdesdialogs

Reputation: 3210

{%%} <- is for controlling stuff, like

{% if %}

{% else %}

{% endif %}

{{}} <- is for printing something, like

{{ my_variable }} or {{ my_object.attribute }}

Upvotes: 2

Related Questions