Last updated

push

Introduction

Redocly Workflows integrates with popular version control services and uses them as the source of your API descriptions to help you automatically validate, build, and deploy API reference docs and developer portals. This approach requires you to give Redocly Workflows access to your repositories.

The Redocly CLI push command helps you automate API description updates without granting Redocly Workflows access to your repositories. This is useful when you can't or don't want to grant Redocly Workflows permissions to your repositories, or when your API descriptions are generated automatically from code annotations in a CI/CD pipeline

This allows you to:

  • Use Redocly Workflows to preview documentation and portal builds.
  • Manage versions in the API registry.

Apart from uploading your API description file, the push command can automatically upload other files that are detected or referenced in the API description:

  • The Redocly configuration file and any configuration files referenced in the extends list.
  • The package.json file (if it exists) from the folder where you're executing the push command. Redocly Workflows uses the @redocly/cli version specified in package.json.
  • The HTML template and the full contents of the folder specified as the theme.openapi.htmlTemplate parameter in the Redocly configuration file.

If a plugin is referenced in the Redocly configuration file, the push command recursively scans the folder containing the plugin and uploads all .js, .json, .mjs and .ts files.

Make sure that each plugin has all the required files in its folder; otherwise, they are not uploaded.

By default, the push command only updates an existing API description version. If an API with the provided name and version doesn't exist in your organization, it isn't created automatically. For details on how to create an API, check the Upsert an API with push section.

Only API descriptions with a CI source can be updated with the push command. Attempting to update API definitions created from other sources fails with an error.

Prerequisites

Before using the push command, ensure the following prerequisites are met:

  1. Active user account in a Redocly Workflows organization.
  2. Active personal API key or organization API key.

Authentication

To authenticate to the API registry, you can use several approaches:

  • Use the login command. In this case, the command is as follows:

    redocly login
    redocly push ...
    

    Refer to the login command documentation for more details.

  • Set the REDOCLY_AUTHORIZATION environment variable to either your personal API key or an organization-wide API key (configurable by organization owners in Redocly Workflows > Settings > API keys). In this case, the command may look as follows:

    REDOCLY_AUTHORIZATION=yourPersonalApiKey redocly push ...
    

    Treat the API keys as secrets and work with them accordingly. Consult the documentation for your CI system to learn more about handling secrets:

Usage

redocly push
redocly push [api] [--destination] [--organization]
redocly push [-u] [--job-id id] [--batch-size number] <path/to/api-description.yaml> [--destination] [--organization] [--branch]

Options

OptionTypeDescription
apistringThe API description that you want to push to the Redocly API registry. Provide it as a path to the root API description file (or as an alias). See set options explicitly for more information.
--batch-sizenumberNumber of CI pushes expected within one batch. Must be used only in combination with the --job-id option. Must be an integer bigger than 1. See the pushes per batch section for more information.
--branch, -bstringThe branch where your API description is pushed or upserted. Default value is main.
--destinationstringThe location in the API registry where you want to push or upsert your API description. Provide it in the following format: api-name@api-version.
--files[string]List of other folders and files to upload. See the files section for more information.
--helpbooleanShow help.
--job-idstringThe ID of the CI job that the current push is associated with. Must be used only in combination with the --batch-size option. See the job ID section for more information.
--lint-configstringSpecify the severity level for the configuration file.
Possible values: warn, error, off. Default value is warn.
--organizationstringID of organization that the API description is being pushed to. Overrides the one defined in the configuration file.
--publicbooleanMake API descriptions publicly accessible from the API Registry. Read more about using the public option.
--region,-rstringSpecify which region to use when logging in. Supported values: us, eu. The eu region is limited to enterprise customers. Default value is us. Alternatively, set an environment variable REDOCLY_DOMAIN with the value of the appropriate Redocly API.
--skip-decorator[string]Ignore one or more decorators. See the skip decorator section for usage examples.
--upsert, -ubooleanCreate a new version of an API when pushing to the API registry if the version doesn't exist. See the upsert an API with push section for more information.
--versionbooleanShow version number.

Examples

The command behaves differently depending on the options you pass to it, and whether the configuration file exists in your working directory.

You can choose any of the following approaches:

Specify destination

To properly push your API description to the Redocly API registry, you need the following information:

Organization ID

The push command uses the following order of precedence:

  1. First, it takes the organization ID from command-line arguments (if provided).
  2. If the organization ID is not provided explicitly, it takes it from the configuration file.

To find your organization ID required for the command:

  1. Log into Workflows.
  2. Access the API registry page.
  3. In your browser's address bar, find the URL of this page.
  4. Inspect the segment after app.redocly.com/org/. This part is your organization ID.

For example, if the URL is app.redocly.com/org/test_docs, the organization ID is test_docs. When using the push command, you would provide this ID as --organization=test_docs.

Note that the organization ID can differ from the organization name. Owners can change the organization name at any time in the Workflows Settings page, but the organization ID cannot be changed.

API name and version

The name and version of your API should contain only supported characters (a-z, A-Z, 0-9, -, .). Using a restricted character results in an error, and your API doesn't get created.

To find your API name required for the command:

  1. Log into Workflows.
  2. Access the API registry page.
  3. Check the list of APIs displayed on this page.
  4. Inspect the title of each list item to the left of the New version and Edit API action buttons. This title is an API name.

To find your API version required for the command:

  1. Log into Workflows.
  2. Access the API registry page.
  3. Check the list of APIs displayed on this page.
  4. The version is displayed in the title after the @ in format <name> @ <version>.

When using the push command, you would provide the API name and version in the format api-name@api-version. For example: --destination=petstore-api@v1.

Set options explicitly

Provide the api as a path to the root API description file, and specify the organization ID, API name, and API version.

redocly push openapi/petstore.yaml --destination=petstore-api@v1 --organization=openapi-org

In this case, push uploads only the API description that was passed to the command. The configuration file is ignored.

To push the API description to a particular branch, specify the branch name.

redocly push openapi/petstore.yaml --destination=petstore-api@v1 --organization=openapi-org -b develop

Set options in the configuration file

Depending on the contents of your Redocly configuration file, you can use simplified push syntax instead of providing the full path to the API description file.

Here's an example configuration file:

organization: organization-id
apis:
  api-name@api-version:
    root: path/to/root/api-description.yaml
  another-api:
    root: openapi/openapi.yaml

With a configuration file like this, you can use any of the following approaches:

  • Push all configured APIs
redocly push

Push every API listed in the apis section of the configuration file. You must specify your Workflows organization ID in the configuration file for this approach to work. APIs without an explicitly defined version are automatically pushed to @latest.

  • Push specified API and version
redocly push --destination=api-name@api-version

Push the specified API and version from the apis section of the configuration file. You must specify your organization ID in the configuration file for this approach to work.

  • Push specified API and version with organization ID
redocly push --destination=api-name@api-version --organization=organization-id

Push the specified API and version from the apis section of the configuration file to the Workflows organization matching the provided organization ID. In this case, you don't have to specify the organization ID in the configuration file.

Upsert an API with push

To upsert an API in the registry with the push command, use the --upsert or -u option. The upsert creates the destination if it doesn't exist, or updates it if it does.

redocly push -u test-api-v1.yaml --destination=test-api@v1 --organization=redocly

To upsert the API description to a particular branch, specify the branch name with the --branch or -b option.

redocly push openapi/petstore.yaml --destination=petstore-api@v1 --organization=openapi-org -b develop

Specify job ID

The --job-id option can be used by Redocly Workflows to associate multiple pushes with a single CI job.

Below are possible use cases for the --job-id option:

  • CI/CD systems: group pushes from a single CI job together so that each push does not trigger separate reference docs/portals rebuild.
  • External systems: a parameter that can be used in reports, metrics, or analytics to refer to a specific application service state.

Must be used only in combination with the --batch-size option.

Determine how many pushes are performed per batch

The --batch-size option can be used by Redocly Workflows to understand how many pushes in total are performed within one batch to properly handle parallel pushes.

Must be used only in combination with the --job-id option. Must be an integer bigger than 1.

Skip decorator

You may want to skip specific decorators upon running the command.

redocly push openapi/petstore.yaml --destination=petstore-api@v1 --organization=openapi-org --skip-decorator=test/remove-internal-operations

Make API descriptions publicly accessible

The --public option allows you to upload your API description and make it publicly accessible from the API Registry. By default, API descriptions uploaded with the push command are not available to the public. For more information on how to configure access to your APIs, check the registry access section.

redocly push openapi/petstore.yaml --destination=petstore-api@v1 --organization=openapi-org --public

Upload other folders and files

The --files option allows you to upload other folders and files.

redocly push openapi/petstore.yaml --destination=petstore-api@v1 --organization=openapi-org --files ./path/to/folder

You can also add files and folders by providing them in the redocly.yaml configuration file:

apis:
  main:
    root: ./openapi.yam;
files:
  - ./path/to/folder
  - ./path/to/another-folder/file.md
  - ./file.md

Note that the --files option has higher priority than the redocly.yaml configuration file.

Set up CI from Redocly Workflows

The Redocly Workflows interface can help you get started with the push command.

  1. In API registry, select Add API.
  2. In the Definition name step, provide a name for your new API description.
  3. In the Choose source step, select Upload from CI/CD. This generates syntax for the push command that you can copy and use to upload a new API description file. Or use the redocly push -u command directly from the command-line interface.