CLI Reference
login
optic login
interactively logs the CLI into Optic Cloud.
> optic login
Example
> optic login
Generate a token below
Create an account and generate a personal access token at https://app.useoptic.com/user-settings/personal-access-token/new
✔ Enter your token here: … ***********************************************************************************************************
Verifying your token
Successfully saved your personal access token to /Users/user/.config/optic/config.json
run
optic run
tests every OpenAPI specification in your repo is accurate (capture
), has no breaking changes (diff
) and follows the standards you defined in the optic.yml
file.
Usage
> optic run
Options
--match <match-glob> Select local OpenAPI specifications files to handle.
Comma separated glob patterns list.
--ignore <ignore-glob> Select local OpenAPI specifications files to ignore.
Comma separated glob patterns list.
--severity <severity> Use `none` to prevent Optic from exiting 1 when
issues are found. (choices: "none", "error", default:
"error")
capture
optic capture
runs a starts your API and a reverse proxy, then sends and records requests made through the proxy.
By default, Optic will capture requests but not persist them to your OpenAPI spec. Create or update your OpenAPI spec by including the --update <mode>
option documented below.
Usage
> optic capture [command] [options] <openapi-file>
Arguments
openapi-file an OpenAPI spec file to add an operation to
Options
--proxy-port <proxy-port> specify the port the proxy should be running on
-u, --update [mode] update the OpenAPI spec to match the traffic. specify the mode to
change the update behavior on how to handle undocumented endpoints
(endpoints not in your spec). documented will only update
documented endpoints. interactive will prompt you for new endpoint
paths. automatic will guess the correct path (choices:
"interactive", "automatic", "documented", preset: "documented")
--postman <postman-collection-file> path to postman collection
--har <har-file, directory> path to har file (v1.2, v1.3), or directory containing har files
-s, --server-override <url> Skip executing `capture[].server.command` and forward proxy
traffic to this URL instead
--upload upload coverage results to Optic Cloud (default: false)
-h, --help display help for command
capture clear
optic capture clear
clears any saved capture data.
Usage
> optic capture clear
capture init
optic capture init
displays a complete, commented, capture configuration block or write it to Optic.yml
.
Usage
> optic capture init [options] <openapi-file>
Options
--stdout Print the capture config to stdout instead of writing to optic.yml (default: false)
-h, --help display help for command
update
Updates an OpenAPI spec based on captured requests.
Usage
> optic update [options] <openapi-file> [operations...]
Arguments
openapi-file an OpenAPI spec
operations update specific operations in format "get /path/{id}" (default: [])
Options
--har <har-file> path to HttpArchive file (v1.2, v1.3)
--postman <postman-collection-file> path to postman collection
--all update all operations
Examples
history
Browse an OpenAPI specification file history and create a changelog in markdown format.
Usage
> optic history <path_to_spec.yml> > changelog.md
> cat changelog.md
# Swagger Petstore
### Sun Jan 01 2023
- \`PUT\` \`/user/{username}\`:
- removed \`requestBody\` \`phone\` property
- added \`requestBody\` \`bio\` property
- changed \`requestBody\` \`userStatus\`.\`type\`
Options
-D, --history-depth <history-depth> Sets the depth of how far to crawl through to historic API data. history-depth=0 will crawl the entire history (default: "0")