Template variables for API and Product definitions

You can use template files when creating OpenAPI 2.0 and OpenAPI 3.0 APIs, and when creating Product definitions. Template files are Handlebars templates containing variables of the form {{variable-name}} that are substituted with values when you create the API or Product definition.

Product definition variables

The following table describes the Handlebars template variables that can be used in a product definition file. For more information on Handlebars, see https://handlebarsjs.com/. Product definition template files must have a .hbs filename extension.

Table 1. Product definition Handlebars template variables
Variable Type Description
{{apis}} Array of string The APIs to which the product definition refers. After substitution, the array values become the values of apis.routes[n].$ref fields, for example:
apis:
  'routes':
    $ref: apidef.yaml
    ...
{{name}} String Value of info.x-ibm-name field.
{{title}} String Value of info.title field.
{{version}} String Value of info.version field.

API definition variables

The following table describes the Handlebars template variables that can be used in an API definition file. For more information on Handlebars, see https://handlebarsjs.com/. API definition template files must have a .hbs filename extension.

Table 2. API definition Handlebars template variables
Variable Type Description
{{basepath}} String Base path on which the API is served, which is relative to the host.
{{definitions}} OpenAPI definitions objectconverted to a YAML string ("stringified"). API contains data types that can be consumed and produced by operations. These data types can be primitives, arrays or models.
{{definitionsObj}} OpenAPI definitions objectconverted to a YAML string ("stringified"). API contains data types that can be consumed and produced by operations. These data types can be primitives, arrays or models.
{{hostname}} String Value of the host field.
{{name}} String Value of info.x-ibm-name field.
{{paths}} OpenAPI paths object API contains the relative paths to the individual endpoints. The path is appended to {{basePath}} to construct the full URL.
{{pathsObj}} OpenAPI paths object API contains the relative paths to the individual endpoints. The path is appended to {{basePath}} to construct the full URL.
{{schemes}} Array of string Transfer protocol of the API. Values must be one of: "http","https", "ws", or "wss".
{{targeturl}} String Value of x-ibm-configuration.assembly.execute[invoke]. Default is $(runtime-url)$(request.path).
{{title}} String Value of info.title field.
{{version}} String Value of info.version field.