Install Redocly CLI

There are two ways to install Redocly CLI: global and runtime.

Global installation

npm

Tip

This is the recommended method. Ensure you have the latest version of npm before you begin.

CommandOutput
Copy
Copied
npm i -g @redocly/cli@latest
Copy
Copied
npm i -g @redocly/cli@latest
added 1 package, removed 1 package, changed 87 packages, and audited 89 packages in 4s
found 0 vulnerabilities

Yarn

CommandOutput
Copy
Copied
yarn global add @redocly/cli
Copy
Copied
yarn global add @redocly/cli
yarn global v1.22.11
[1/4] 🔍  Resolving packages...
[2/4] 🚚  Fetching packages...
[3/4] 🔗  Linking dependencies...
[4/4] 🔨  Building fresh packages...

success Installed "@redocly/cli@1.0.0-beta.96" with binaries:
      - openapi
      - redocly
✨  Done in 6.90s.

Verify the installation

Running redocly --version will confirm that the installation was successful:

Copy
Copied
redocly --version
1.0.0-beta.96

Runtime installation

npx

info

npx is npm's package runner. It will install and run a command at the same time without installing globally.

CommandExample with lint commandOutput (lint failed)Output (lint succeeded)
Copy
Copied
npx @redocly/cli <command> [options]
Copy
Copied
npx @redocly/cli@latest lint petstore.yaml
Copy
Copied
npx @redocly/cli@latest lint petstore.yaml
No configurations were defined in extends -- using built in recommended configuration by default.

validating petstore.yaml...
[1] petstore.yaml:3:3 at #/info

Info object should contain `description` field.

1 | swagger: "2.0"
2 | info:
3 |   version: 1.0.0
4 |   title: Swagger Petstore
5 |   license:
6 |     name: MIT
7 | host: petstore.swagger.io
8 | basePath: /v1

Warning was generated by the info-description rule.


[2] petstore.yaml:6:5 at #/info/license

License object should contain `url` field.

4 |   title: Swagger Petstore
5 |   license:
6 |     name: MIT
7 | host: petstore.swagger.io
8 | basePath: /v1

Warning was generated by the info-license-url rule.


petstore.yaml: validated in 70ms

Woohoo! Your OpenAPI definition is valid. 🎉
You have 2 warnings.
Copy
Copied
npx @redocly/cli@latest lint petstore.yaml
No configurations were defined in extends -- using built in recommended configuration by default.

validating petstore.yaml...
petstore.yaml: validated in 43ms

Woohoo! Your OpenAPI definition is valid. 🎉

Docker

To give a Docker container access to your OpenAPI definition files, you need to mount the containing directory as a volume. Assuming the definition is rooted in the current working directory, the command to use is:

Example with lint commandOutput (lint succeeded)
Copy
Copied
docker run --rm -v $PWD:/spec redocly/openapi-cli lint petstore.yaml
Copy
Copied
Unable to find image 'redocly/openapi-cli:latest' locally
latest: Pulling from redocly/openapi-cli
540db60ca938: Pull complete
fe289da0f830: Pull complete
c5a1e48e74e5: Pull complete
63ccc02b1289: Pull complete
4b42ba54a874: Pull complete
3f76218e8e91: Pull complete
Digest: sha256:fa95c9a8b9e282b21779e8ffa86ed28b87f9d97517e46d96af7a6676d47b0430
Status: Downloaded newer image for redocly/openapi-cli:latest
No configurations were defined in extends -- using built in recommended configuration by default.

validating petstore.yaml...
petstore.yaml: validated in 51ms

Woohoo! Your OpenAPI definition is valid. 🎉

Set up tab completion (optional)

After a successful install, you can set up tab completion for the terminal if you wish. Generate the completion script using the following command:

CommandOutput
Copy
Copied
redocly completion
Copy
Copied
###-begin-openapi-completions-###
#
# yargs command completion script
#
# Installation: /Users/gold/.npm/_npx/b36cbb32e525fe97/node_modules/.bin/openapi completion >> ~/.bashrc
#    or /Users/gold/.npm/_npx/b36cbb32e525fe97/node_modules/.bin/openapi completion >> ~/.bash_profile on OSX.
#
_openapi_yargs_completions()
{
    local cur_word args type_list

    cur_word="${COMP_WORDS[COMP_CWORD]}"
    args=("${COMP_WORDS[@]}")

    # ask yargs to generate completions.
    type_list=$(/Users/gold/.npm/_npx/b36cbb32e525fe97/node_modules/.bin/openapi --get-yargs-completions "${args[@]}")

    COMPREPLY=( $(compgen -W "${type_list}" -- ${cur_word}) )

    # if no match was found, fall back to filename completion
    if [ ${#COMPREPLY[@]} -eq 0 ]; then
      COMPREPLY=()
    fi

    return 0
}
complete -o default -F _openapi_yargs_completions openapi
###-end-openapi-completions-###

The command output contains installation instructions. For example, to install the completion script in bash, use:

Copy
Copied
openapi completion >> ~/.bashrc

The approach is similar for other shells. After the installation, restart your terminal for the changes to take effect.

Next steps