|
2 | 2 |
|
3 | 3 | Choose the most appropriate installation method for your needs: |
4 | 4 |
|
5 | | -- [Install locally, using `npm`](#install-globally) to make the `redocly` command available on your system. |
| 5 | +- [Install locally, using `npm`](#install-locally) to make the `redocly` command available on your system. |
6 | 6 | - [Use `npx` to get the tool at runtime](#use-the-command-at-runtime) rather than installing it. |
7 | | -- The command is also [available via Docker](#docker) if you'd prefer to use it that way. |
| 7 | +- The command is also [available through Docker](#docker). |
8 | 8 |
|
9 | | -## Install globally |
| 9 | +## Install locally |
10 | 10 |
|
11 | | -{% admonition type="success" name="Tip" %} |
12 | | -Make sure you have the newest version of `npm` before you begin. |
13 | | -{% /admonition %} |
| 11 | +Before you begin, make sure you have the newest version of `npm`. |
14 | 12 |
|
15 | | -Install the tool with the following command: |
| 13 | +To install Redocly CLI locally: |
16 | 14 |
|
17 | | -```shell |
18 | | -npm i -g @redocly/cli@latest |
| 15 | +1. In your CLI, `cd` to your project's directory. |
| 16 | +1. Enter the following command: |
| 17 | + |
| 18 | +```bash |
| 19 | +npm i @redocly/cli@latest |
19 | 20 | ``` |
20 | 21 |
|
21 | | -Running `redocly --version` confirms that the installation was successful, and the currently-installed version of the tool. |
| 22 | +1. (Optional) Run `redocly --version` to confirm that the installation was successful and the currently-installed version of the tool. |
22 | 23 |
|
23 | 24 | ## Use the command at runtime |
24 | 25 |
|
25 | | -[npx](https://docs.npmjs.com/cli/v9/commands/npx/) is npm's package runner. It installs and runs a command without installing it globally. You might use this where you can't install a new command, or in a CI context where the command is only used a handful of times. |
| 26 | +[npx](https://docs.npmjs.com/cli/v9/commands/npx/) is `npm`'s package runner. |
| 27 | +It installs and runs a command without installing it globally. |
26 | 28 |
|
27 | | -To run Redocly CLI with `npx`, the command looks like the following example: |
| 29 | +Use this approach where you can't install a new command, or in a CI context where the command is only used a handful of times. |
28 | 30 |
|
29 | | -```shell |
30 | | -npx @redocly/cli@latest <command> [options] |
31 | | -``` |
| 31 | +To run Redocly CLI with `npx`: |
| 32 | + |
| 33 | +- Replace `redocly` with `npx @redocly/cli@latest` to prepend Redocly CLI commands. |
| 34 | + |
| 35 | + ```bash |
| 36 | + npx @redocly/cli@latest <command> [options] |
| 37 | + ``` |
32 | 38 |
|
33 | 39 | For example, to run `redocly lint` on a file named `openapi.yaml`, use the following command: |
34 | 40 |
|
35 | | -```shell |
| 41 | +```bash |
36 | 42 | npx @redocly/cli@latest lint openapi.yaml |
37 | 43 | ``` |
38 | 44 |
|
39 | | -Replace `redocly` with `npx @redocly/cli@latest` to prepend to other commands you see in documentation. |
40 | | - |
41 | 45 | ## <a id="docker"></a>Run commands inside Docker |
42 | 46 |
|
43 | 47 | Redocly CLI is available as a pre-built Docker image in [Docker Hub](https://hub.docker.com/r/redocly/cli) and [GitHub Packages](https://github.com/Redocly/redocly-cli/pkgs/container/cli). |
44 | 48 |
|
45 | | -Install [Docker](https://docs.docker.com/get-docker/) if you don't have it already, then pull the image with the following command: |
| 49 | +Before you begin, make sure you have Docker [installed](https://docs.docker.com/get-docker/). |
| 50 | + |
| 51 | +To run Redocly CLI commands inside a docker container: |
| 52 | + |
| 53 | +1. Pull the image: |
| 54 | + |
46 | 55 | {% tabs %} |
47 | 56 | {% tab label="Docker Hub" %} |
48 | 57 |
|
49 | | -```shell |
| 58 | +```bash |
50 | 59 | docker pull redocly/cli |
51 | 60 | ``` |
52 | 61 |
|
53 | 62 | {% /tab %} |
54 | 63 | {% tab label="GitHub Packages" %} |
55 | 64 |
|
56 | | -```shell |
| 65 | +```bash |
57 | 66 | docker pull ghcr.io/redocly/cli |
58 | 67 | ``` |
59 | 68 |
|
60 | 69 | {% /tab %} |
61 | 70 | {% /tabs %} |
62 | | -To give a Docker container access to your OpenAPI description files, you need to mount the containing directory as a volume. Assuming the API description is in the current working directory, the command to use is: |
63 | 71 |
|
64 | | -```shell Example with lint command |
| 72 | +1. To give a Docker container access to your OpenAPI description files, mount the containing directory as a volume: |
| 73 | + |
| 74 | +```bash Example with lint command |
65 | 75 | docker run --rm -v $PWD:/spec redocly/cli lint openapi.yaml |
66 | 76 | ``` |
67 | 77 |
|
| 78 | +This example assumes that the API description file is in your current working folder. |
| 79 | + |
68 | 80 | ## Run CLI behind a proxy |
69 | 81 |
|
70 | | -If you need to run the CLI tool behind a proxy, you can use the `HTTP_PROXY` and `HTTPS_PROXY` environment variables to configure the proxy settings. These environment variables are commonly used to specify the proxy server for HTTP and HTTPS traffic, respectively. |
| 82 | +To run the CLI tool behind a proxy, you can use the `HTTP_PROXY` and `HTTPS_PROXY` environment variables to configure the proxy settings. |
| 83 | +These environment variables specify the proxy server for HTTP and HTTPS traffic, respectively. |
71 | 84 |
|
72 | 85 | ### Set up Proxy Environment Variables |
73 | 86 |
|
74 | | -Before running the CLI behind a proxy, make sure to set the appropriate proxy environment variables. Open a terminal and use the following commands: |
| 87 | +To set the proxy environment variables: |
| 88 | + |
| 89 | +- Open a terminal and use the following command: |
| 90 | + |
| 91 | +{% tabs %} |
| 92 | +{% tab label="HTTP proxy" %} |
75 | 93 |
|
76 | 94 | ```bash |
77 | | -# For HTTP proxy |
78 | 95 | export HTTP_PROXY=http://your-http-proxy-server:port |
| 96 | +``` |
79 | 97 |
|
80 | | -# For HTTPS proxy |
| 98 | +{% /tab %} |
| 99 | +{% tab label="HTTPS proxy" %} |
| 100 | + |
| 101 | +```bash |
81 | 102 | export HTTPS_PROXY=https://your-https-proxy-server:port |
82 | 103 | ``` |
83 | 104 |
|
| 105 | +{% /tab %} |
| 106 | +{% /tabs %} |
| 107 | + |
84 | 108 | ### Use Environment Variables with CLI Commands |
85 | 109 |
|
86 | | -You can also directly include the proxy environment variables in the command itself. For example: |
| 110 | +To directly include the proxy environment variables in a Redocly CLI command: |
87 | 111 |
|
88 | | -```bash |
89 | | -HTTPS_PROXY=https://your-https-proxy-server:port redocly lint --extends minimal openapi.yaml |
90 | | -``` |
| 112 | +- Prepend the command with the environment variable and its value. |
| 113 | + |
| 114 | + For example: |
| 115 | + |
| 116 | + ```bash |
| 117 | + HTTPS_PROXY=https://your-https-proxy-server:port redocly lint --extends minimal openapi.yaml |
| 118 | + ``` |
91 | 119 |
|
92 | 120 | ## Next steps |
93 | 121 |
|
|
0 commit comments