Last updated

build-docs

Introduction

The build-docs command builds Redoc into an HTML file that contains your API documentation. The standalone HTML file can be easily shared or hosted on a platform of your choice.

Usage

redocly build-docs <api>
redocly build-docs <api> --output=custom.html
redocly build-docs <api> --theme.openapi.disableSearch
redocly build-docs <api> --template custom.hbs
redocly build-docs <api> -t custom.hbs --templateOptions.metaDescription "Page meta description"

Options

OptionTypeDescription
apistringPath to the API description filename or alias that you want to generate the build for. Refer to the API section for more details.
--configstringPath to the configuration file. Defaults to redocly.yaml in the local folder.
--disableGoogleFontbooleanDisable Google fonts. The default value is false.
--helpbooleanShow help.
--lint-configstringSpecify the severity level for the configuration file. Possible values: warn, error, off. Default value is warn.
--output, -ostringSet the path and name of the output file. The default value is redoc-static.html.
--template, -tstringUse custom Handlebars templates to render your OpenAPI description.
--templateOptionsstringAdd template options you want to pass to your custom Handlebars template. To add options, use dot notation.
--theme.openapistringCustomize your output with Redoc functionality options or Redoc theming options.
--titlestringSet the page title.
--versionbooleanShow version number.

Examples

Specify API

The build-docs command behaves differently depending on how you pass the API to it, and whether the configuration file exists.

Pass an API directly

redocly build-docs openapi.yaml

In this case, the build-docs command builds the API description that was passed to the command. Even if a configuration file exists, the command does not check for APIs listed in it.

Pass an API alias

Instead of a full path, you can use an API name from the apis object of your Redocly configuration file. For example, with a redocly.yaml configuration file containing the following entry for games@v1:

apis:
  games@v1:
    root: ./openapi/api-description.json

You can generate a build by including the API name with the command, as shown in the following example:

redocly build-docs games@v1

In this case, after resolving the path behind the games@v1 name, build-docs generates a build of the api-description.json file. For this approach, the Redocly configuration file is mandatory. Any additional configurations provided in the file are also used by the command.

Use an alternative configuration file

By default, the CLI tool looks for the Redocly configuration file in the current working directory. Use the optional --config argument to provide an alternative path to a configuration file.

redocly build-docs --config=./another/directory/config.yaml

The following command uses the optional --theme.openapi argument to build docs with the search box hidden:

redocly build-docs openapi.yaml --theme.openapi.disableSearch

Use a custom template

The following command builds docs using a custom Handlebars template and adds metadata to the meta tag in the head of the page using templateOptions:

redocly build-docs ./openapi/api.yaml -t custom.hbs --templateOptions.metaDescription "Page meta description"

Sample custom Handlebars template:

<html>
  <head>
    <meta charset='utf8' />
    <title>{{title}}</title>
    <!-- needed for adaptive design -->
    <meta description='{{{templateOptions.metaDescription}}}' />
    <meta name='viewport' content='width=device-width, initial-scale=1' />
    <style>
      body { padding: 0; margin: 0; }
    </style>
    {{{redocHead}}}
    {{#unless disableGoogleFont}}<link
        href='https://fonts.googleapis.com/css?family=Montserrat:300,400,700|Roboto:300,400,700'
        rel='stylesheet'
      />{{/unless}}
  </head>
  <body>
    {{{redocHTML}}}
  </body>
</html>