Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Wiki
  • Mustache Template Variables

Mustache Template Variables · Changes

Page history
Initial Wiki authored May 13, 2018 by Jeremie Bresson's avatar Jeremie Bresson
Show whitespace changes
Inline Side-by-side
Mustache-Template-Variables.md 0 → 100644
View page @ 016d8b1b
- [Mustache template variables in the model](#mustache-template-variables-in-the-model)
- [Mustache template variables in the operation](#mustache-template-variables-in-the-operation)
- [Usage](#usage)
- [Tips](#tips)
- [Explanations](#explanations)
## Mustache template variables in the model
To obtain a list of variables (tags) available in the mustache template. Please use `debugOperations` and `debugModels`. Heres is an example for variables in the model templates:
```
java -DdebugModels -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate \
-i http://petstore.swagger.io/v2/swagger.json \
-l csharp \
```
and here is part of the output:
```
############ Model info ############
[ {
"model" : {
"name" : "Order",
"classname" : "Order",
"classVarName" : "Order",
"modelJson" : "{\n \"type\" : \"object\",\n \"properties\" : {\n \"id\" : {\n \"type\" : \"integer\",\n \"format\" : \"int64\"\n },\n \"petId\" : {\n \"type\" : \"integer\",\n \"format\" : \"int64\"\n },\n \"quantity\" : {\n \"type\" : \"integer\",\n \"format\" : \"int32\"\n },\n \"shipDate\" : {\n \"type\" : \"string\",\n \"format\" : \"date-time\"\n },\n \"status\" : {\n \"type\" : \"string\",\n \"description\" : \"Order Status\",\n \"enum\" : [ \"placed\", \"approved\", \"delivered\" ]\n },\n \"complete\" : {\n \"type\" : \"boolean\",\n \"default\" : false\n }\n },\n \"xml\" : {\n \"name\" : \"Order\"\n }\n}",
"vars" : [ {
"baseName" : "id",
"getter" : "getId",
"setter" : "setId",
"datatype" : "long?",
"datatypeWithEnum" : "long?",
"name" : "Id",
"defaultValue" : "null",
"baseType" : "long?",
"jsonSchema" : "{\n \"type\" : \"integer\",\n \"format\" : \"int64\"\n}",
"hasMore" : true,
"isPrimitiveType" : true,
"isNotContainer" : true,
"isEnum" : false
}, {
```
## Mustache template variables in the operation
For operation (resource) templates, please use `debugOperations` instead:
```
java -DdebugOperations -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate \
-i http://petstore.swagger.io/v2/swagger.json \
-l csharp \
```
Here is part of the result
```
############ Operation info ############
[ {
"packageName" : "Org.OpenAPITools",
"hasImport" : true,
"modelPackage" : "Org.OpenAPITools.Model",
"package" : "Org.OpenAPITools.Api",
"clientPackage" : "Org.OpenAPITools.Client",
"version" : "1.0.0",
"classVarName" : "user",
"basePath" : "http://petstore.swagger.io/v2",
"packageVersion" : "1.0.0",
"infoEmail" : "some@email.com",
"importPath" : "Org.OpenAPITools.Api.User",
"licenseInfo" : "Apache 2.0",
"hasMore" : "true",
"generatedDate" : "2015-10-06T12:20:11.434+08:00",
"classname" : "UserApi",
"imports" : [ {
"import" : "Org.OpenAPITools.Model.User"
} ],
"appName" : "Swagger Petstore",
"appVersion" : "1.0.0",
"generatorClass" : "class io.swagger.codegen.languages.CSharpClientCodegen",
"baseName" : "User",
"contextPath" : "/v2",
"operations" : {
"operation" : [ {
"responseHeaders" : [ ],
"hasProduces" : true,
"hasParams" : true,
"hasMore" : true,
"isResponseBinary" : false,
"path" : "/user",
"operationId" : "CreateUser",
"httpMethod" : "POST",
"summary" : "Create user",
"notes" : "This can only be done by the logged in user.",
"baseName" : "User",
"produces" : [ {
"hasMore" : "true",
"mediaType" : "application/xml"
}, {
"hasMore" : null,
"mediaType" : "application/json"
} ],
"bodyParam" : {
"isBodyParam" : true,
"baseName" : "body",
"paramName" : "body",
"dataType" : "User",
"description" : "Created user object",
"jsonSchema" : "{\n \"in\" : \"body\",\n \"name\" : \"body\",\n \"description\" : \"Created user object\",\n \"required\" : true,\n \"schema\" : {\n \"$ref\" : \"#/definitions/User\"\n }\n}",
"isEnum" : false,
"vendorExtensions" : { },
"required" : true
},
"allParams" : [ {
"isBodyParam" : true,
"baseName" : "body",
"paramName" : "body",
"dataType" : "User",
"description" : "Created user object",
"jsonSchema" : "{\n \"in\" : \"body\",\n \"name\" : \"body\",\n \"description\" : \"Created user object\",\n \"required\" : true,\n \"schema\" : {\n \"$ref\" : \"#/definitions/User\"\n }\n}",
"isEnum" : false,
"vendorExtensions" : { },
"required" : true
} ],
"bodyParams" : [ {
"isBodyParam" : true,
"baseName" : "body",
"paramName" : "body",
"dataType" : "User",
"description" : "Created user object",
"jsonSchema" : "{\n \"in\" : \"body\",\n \"name\" : \"body\",\n \"description\" : \"Created user object\",\n \"required\" : true,\n \"schema\" : {\n \"$ref\" : \"#/definitions/User\"\n }\n}",
"isEnum" : false,
"vendorExtensions" : { },
"required" : true
} ],
"pathParams" : [ ],
"queryParams" : [ ],
"headerParams" : [ ],
"formParams" : [ ],
"tags" : [ "User" ],
"responses" : [ {
"headers" : [ ],
"code" : "0",
"message" : "successful operation",
"hasMore" : false,
"isDefault" : true,
"simpleType" : true,
"primitiveType" : true,
"isMapContainer" : false,
"isListContainer" : false,
"isBinary" : false,
"jsonSchema" : "{\n \"description\" : \"successful operation\"\n}",
"wildcard" : true
} ],
"imports" : [ "User" ],
"vendorExtensions" : { },
"nickname" : "CreateUser",
"hasBodyParam" : true,
"hasQueryParams" : false,
"hasHeaderParams" : false,
"hasPathParams" : false,
"hasFormParams" : false
}, {
```
## Usage
For usage of the template variable, enter the variable name (e.g. basePath) in the search box and submit. Then filter by `HTML & Django` under **Languages**, e.g. https://github.com/openapitools/openapi-generator/search?l=html%2Bdjango&q=basepath&utf8=%E2%9C%93
## Tips
To access the first or last element in a list
```
{{#vars}}{{#-first}} this is the first element {{.}} {{/-first}}{{/vars}}
{{#vars}}{{#-last}} this is the last element {{.}} {{/-last}}{{/vars}}
```
## Explanations
Here are the explanations for some of the mustache tags:
- **complexType**: stores the name of the model (e.g. Pet)
- **isContainer**: true if the parameter or property is an array or a map.
- **isPrimitiveType**: true if the parameter or property type is a primitive type (e.g. string, integer, etc) as defined in the spec.
Please feel free to update the list above with more tags. For any question, please open an issue.
Clone repository
  • API client generator HOWTO
  • Building your own Templates
  • Customizing client code generation
  • FAQ
  • Git Branches
  • Home
  • How to add a generator for a new language or framework
  • Integration Tests
  • Migration Guide
  • Mustache Template Variables
  • Pull Request Checklist
  • Release Checklist
  • Samples folder
  • Server stub generator HOWTO
  • Vendor Extensions
View All Pages