You can use template files when creating API and 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.
Before you begin
To complete the steps that are described in this topic, you must have installed the
developer toolkit. For more information, see Installing the toolkit.
Procedure
- Create a Product or API definition template, either from scratch, or by copying one of
the examples provided in API and Product definition template examples. The
template file must have
.hbs
filename extension, and may contain any of the
handlebars variables described in Template variables for API and Product definitions.
-
To create a Product or API definition from a template, enter the following command:
apic create --type [api | product ] --template template_file --title product_title options
where template_file is the template .hbs
file to use,
product_title is the title of the Product to create, and
options is any additional command-line options. The path to the template file can
be either an absolute path or relative to the location where the command is executed. Alternatively,
you can set the template-path
configuration variable to the location of the
directory containing the template.
When the Product or API definition is created, the value of each command-line option is
substituted for the corresponding handlebars template variable. For example, the value of the
required --title
option is substituted for the info.title
field in
the template file. The command creates a Product definition YAML file with the name specified in
the --name
option. If you don't supply the --name
option, the
command derives the name of the Product YAML file from the specified title by down-casing the title
and replacing spaces with dashes.
In addition to the
--template
option, you can set default values for working
with templates by using these configuration variables:
template-default-product
- Base file name of the product template
(.hbs) file.
template-default-api
- Base file name of the API template
(.hbs) file.
template-path
- List of directories in which to search for templates. It may
specify one or more directories (absolute paths). Separate multiple directories by a space and
enclose in quotes. Note you can use this configuration variable along with the
--template
option.
As with all configuration variables, you can set these values locally (for a single application
project) or globally (for all projects). For more information, see
Toolkit command summary.