Swagger CLI
The Swagger CLI enables teams to build automation and workflows around Swagger. Teams can use it in places like their CI/CD pipeline to create new APIs, create and update API versions, and mark API versions as published and default among other features. Every team has their own workflow, and the Swagger CLI can help teams build the workflow that fits their needs.
Requirements
- Node.js 22.12 or later.
- Swagger SaaS, or Swagger Studio On-Premise 2.x. On-Premise 1.x is not supported.
Installation
$ npm i -g swaggerhub-cli
Setup
The Swagger CLI can be configured through environment variables or through the swaggerhub configure command. The CLI will look for the following environment variables.
SWAGGERHUB_API_KEY (required) – Important: keep this key secure. This is the Swagger API key the CLI will use for authentication. You can find your API key on the user settings page in Swagger.
SWAGGERHUB_URL (optional, default is https://api.swaggerhub.com) – Customers with on-premise installations (version 2.x) need to point this to their on-premise API, which is http(s)://{swaggerhub-host}/v1 (do not append a trailing slash).
Alternatively, you can use the swaggerhub configure command to create a configuration file for the CLI to use. This command will walk you through the steps to set up the necessary configurations.
$ swaggerhub configure
? Swagger URL: https://api.swaggerhub.com
? API Key: <your-api-key>
Environment variables take precedence over the configuration file created by this command.
Using a proxy
The CLI honors the standard proxy environment variables (lowercase variants also work):
export HTTPS_PROXY=http://proxy.example.com:8080 # used for https:// URLs, including the default https://api.swaggerhub.com
export HTTP_PROXY=http://proxy.example.com:8080 # used for http:// URLs, e.g. an on-premise instance served over HTTP
export NO_PROXY=localhost,.internal.example.com # hosts that should bypass the proxy
Proxy credentials can be included in the URL: http://user:password@proxy.example.com:8080. Always include the scheme (http:// or https://) in the proxy URL.
HTTPS requests are tunnelled through the proxy using CONNECT. If your proxy intercepts TLS, see NODE_EXTRA_CA_CERTS below. SOCKS proxies are not supported.
Additional configuration for Swagger Studio On-Premise
If your Swagger Studio On-Premise instance uses a self-signed or privately signed SSL certificate, there are additional steps required to make the Swagger CLI trust this certificate.
By default, Node.js rejects self-signed or privately signed SSL certificates because their root CA is not known. You will see an error like this in the CLI output:
FetchError: request to https://... failed, reason: self signed certificate
The solution is to use the NODE_EXTRA_CA_CERTS environment variable to specify custom trusted certificates for Node.js.
Start by creating a .pem file containing your custom trusted certificates in the PEM format.
- If the certificate is self-signed (so that it is its own CA), include the certificate itself.
- If the certificate is signed by a private CA, include the CA root and any intermediate certificates, in any order. Blank lines are allowed, but optional, between individual certificates.
-----BEGIN CERTIFICATE-----
CA root certificate
-----END CERTIFICATE-----
-----BEGIN CERTIFICATE-----
Intermediate certificate 1
-----END CERTIFICATE-----
-----BEGIN CERTIFICATE-----
Intermediate certificate 2
-----END CERTIFICATE-----
Specify the path to this PEM file in the NODE_EXTRA_CA_CERTS environment variable.
macOS/*nix/bash examples:
export NODE_EXTRA_CA_CERTS=~/Work/extra-ca-certs.pem # '~' means the home folder of the logged-in user
export NODE_EXTRA_CA_CERTS=$HOME/.ssh/extra-ca-certs.pem
export NODE_EXTRA_CA_CERTS=/Users/username/Work/extra-ca-certs.pem
Windows examples:
:: Both forward and backslashes are OK
set NODE_EXTRA_CA_CERTS=C:\Work\extra-ca-certs.pem
set NODE_EXTRA_CA_CERTS=C:/Work/extra-ca-certs.pem
:: You can also define the path itself using environment variables
set NODE_EXTRA_CA_CERTS=%USERPROFILE%\extra-ca-certs.pem
Using with AI agents
The repository ships an agent skill that teaches AI coding agents (Claude Code, Cursor, Codex and others) how to use the swaggerhub CLI. It can be installed with the skills CLI.
The skill only provides instructions. The agent still needs the CLI installed (see Installation) and SWAGGERHUB_API_KEY set (see Setup).
- List the skills available in this repository without installing:
npx skills add SmartBear/swaggerhub-cli --list
- Install into the current project:
npx skills add SmartBear/swaggerhub-cli
- Install only this skill, globally, for a specific agent:
npx skills add SmartBear/swaggerhub-cli --skill swaggerhub-cli -g -a claude-code
- See what is installed, check for updates, update, remove:
npx skills list, npx skills check, npx skills update, npx skills remove swaggerhub-cli
Once installed, the agent loads the skill automatically when a task matches its description, for example "fetch the definition of my API from Swagger" or "publish this API version". You can also ask for it by name, e.g. "use the swaggerhub-cli skill to ...". In Claude Code it is also available as /swaggerhub-cli.
Run npx skills add --help for all options. Skills are installed from the repository's default branch, so re-run npx skills update after a new CLI release to pick up changes.
Usage
$ swaggerhub COMMAND
running command...
$ swaggerhub --version
swaggerhub-cli/0.14.0 linux-x64 node-v22.9.0
$ swaggerhub --help [COMMAND]
USAGE
$ swaggerhub COMMAND
...
Commands
swaggerhub api:clone
clone an API version as a new version
USAGE
$ swaggerhub api:clone OWNER/API_NAME/VERSION NEW_VERSION [--visibility public|private] [-h]
ARGUMENTS
OWNER/API_NAME/VERSION API version to clone
NEW_VERSION Version identifier of the new API version
FLAGS
-h, --help Show CLI help.
--visibility=<option> visibility of the new version (defaults to the server setting)
<options: public|private>
DESCRIPTION
clone an API version as a new version
EXAMPLES
$ swaggerhub api:clone organization/api/1.0.0 1.0.1
$ swaggerhub api:clone organization/api/1.0.0 1.0.1 --visibility public
See code: src/commands/api/clone.js
swaggerhub api:comment:list
list the comments of an API version
USAGE
$ swaggerhub api:comment:list OWNER/API_NAME/VERSION [-j] [-h]
ARGUMENTS
OWNER/API_NAME/VERSION API version to list comments for
FLAGS
-h, --help Show CLI help.
-j, --json prints the comments, including replies and ranges, as JSON
DESCRIPTION
list the comments of an API version
EXAMPLES
$ swaggerhub api:comment:list organization/api/1.0.0
$ swaggerhub api:comment:list organization/api/1.0.0 --json
See code: src/commands/api/comment/list.js
swaggerhub api:create
creates a new API / API version from a YAML/JSON file