Skip to content
Custom templates

Custom templates

You can override any generated file by providing custom Go text/templates.

How it works

Copy a built-in template from the templates/ directory, customize it, and point the templates config option to your folder:

{
  "templates": "src/templates"
}

Any .go.tmpl file in your templates directory overrides the corresponding built-in template.


Available templates

TemplateGenerates
model.go.tmplModel interfaces
fn.go.tmplOperation functions
service.go.tmplService classes
apiService.go.tmplMain Api service
configuration.go.tmplApiConfiguration class
baseService.go.tmplBase service class
requestBuilder.go.tmplRequest builder
response.go.tmplStrictHttpResponse
module.go.tmplNgModule
index.go.tmplBarrel exports
functionIndex.go.tmplFunction index
modelIndex.go.tmplModel index
serviceIndex.go.tmplService index
enumArray.go.tmplEnum array export

Template functions

These functions are available inside templates in addition to Go’s built-in template functions:

FunctionDescription
upperFirstCapitalizes the first character
lowerFirstLowercases the first character
camelCaseConverts to camelCase
kebabCaseConverts to kebab-case
fileNameConverts a class name to kebab-case file name
typeNameConverts to a TypeScript type name
escapeJSEscapes a string for JavaScript
escapeIdReturns a valid JavaScript identifier
tsCommentsFormats TypeScript JSDoc comments
joinJoins strings with separator
addInteger addition
seqGenerates a sequence of integers
dictCreates a map from key-value pairs

Example: Extending model interfaces

Copy templates/model.go.tmpl to src/templates/model.go.tmpl and edit it to extend a base interface:

export interface {{ .TypeName }} extends BaseModel {
  {{- range .Properties }}
  {{ tsComments .Description 1 .Deprecated }}{{ .Name }}{{ if not .Required }}?{{ end }}: {{ .Type }};
  {{- end }}
}

Now all generated models extend BaseModel:

export interface Pet extends BaseModel {
  id: number;
  name: string;
  tag?: string;
}