ts-gyb uses mustache template to generate code. Refer to mustache Manual for supported syntax.
ts-gyb needs two templates: module template and named type template.
ts-gyb uses this template to generate a file for every module. Typically, generated file includes a module class and all types used in the method parameters and return values of the module.
When a TypeScript interface
or an enum
is used by more than one module, it is not suitable to place the generated type in any module file. ts-gyb uses this template to generate a single file that hosts all shared TypeScript types found in method parameters and return types.
ts-gyb defines some variables that can be directly used in templates.
- Module template: this template has access to all properties of
Module
. For example, you can use{{moduleName}}
to render the name of the module. If theoutputPath
is a file, this template would have access to an array ofModule
. - Named type template: this template has only one array variable of type
NamedType
which includes all named types. For example, use{{#.}}{{typeName}}{{/.}}
to enumerate the array and get all type names.
Both associatedTypes
in Module template and the variable of Named type template is an array of NamedType
. It is recommended to create a template to render a single NamedType
, then import the template in other templates.
moduleName
: the name of the module.members
: an array ofField
. It includes all properties of the module.methods
: an array ofMethod
.associatedTypes
: an array ofNamedType
. This includes all types used only in this module.customTags
: an object of all custom defined values in module interface. Refer to Custom tags for how to define these tags. For example, you can access@foobar { "key": "value" }
via{{customTags.foobar.key}}
.documentationLines
: an array of documentation text divided to string lines. It is divided for easier use with mustache.
methodName
: the name of the method.parameters
: an array ofParameter
to include all parameters of the method.parametersDeclaration
: a single line parameters declaration. It can be directly used inside()
to declare all parameters of this method.returnType
: a string to represent the return type of the method.nonOptionalReturnType
: a string to represent the return type but stripped optional syntax. For non optional types, this would be the same asreturnType
.documentationLines
: an array of documentation text divided to string lines. It is divided for easier use with mustache.
name
: the name of the parameter.type
: a string to represent the type of the parameter.last
: a boolean to indicate whether this is the last parameter. It is for convenience of writing mustache templates.
custom
: a boolean to indicate whether this is an interface type.enum
: a boolean to indicate whether this is an enum type.
For interface type:
typeName
: the name of the type.members
: an array ofField
. It includes all members of the interface type.documentationLines
: an array of documentation text divided to string lines. It is divided for easier use with mustache.
For enum type:
typeName
: the name of the type.valueType
: a string to represent the type of the raw value of the enum.isNumberType
: a boolean to indicate whether this is a numeric enum.isStringType
: a boolean to indicate whether this is a string enum.members
: an array ofEnumMember
. It includes all members of the enum type.documentationLines
: an array of documentation text divided to string lines. It is divided for easier use with mustache.
name
: the name of the interface member.type
: a string to represent the type of the member.documentationLines
: an array of documentation text divided to string lines. It is divided for easier use with mustache.last
: a boolean to indicate whether this is the last member. It is for convenience of writing mustache templates.
key
: the key of the enum membervalue
: a string to represent the value of the enum memberdocumentationLines
: an array of documentation text divided to string lines. It is divided for easier use with mustache.last
: a boolean to indicate whether this is the last member. It is for convenience of writing mustache templates.