Package Exports
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@scalar/cli) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Scalar CLI
Command-line interface to work with OpenAPI files
Features
- Format & validate OpenAPI files
- Upload your OpenAPI files to Scalar
- Get a fully mocked API for testing purposes
- Preview your API reference
- Bundle multiple OpenAPI files
Quickstart
npx @scalar/cli helpInstallation
If you really want to become friends you should install the CLI:
npm -g install @scalar/cliOtherwise just prefix all commands with npx @scalar/cli instead of scalar. That’s fine, too.
Commands
format
The given JSON file will be formatted with Prettier.
scalar formatvalidate
To check whether your OpenAPI file adheres to the Swagger 2.0, OpenAPI 3.0 or OpenAPI 3.1 specification, run the following command:
scalar validateshare
To quickly share an OpenAPI file or reference with someone, you can use the share command:
scalar shareThis will upload your OpenAPI file to the Scalar Sandbox to give you a public reference URL and a public URL to your OpenAPI JSON file.
mock
We can even mock your API, and it’s just one command:
scalar mockThis will boot up a server on port 3000 which gives you an API returning the dummy data according to your schema.
If you’d like to watch for file changes (to the OpenAPI file), do it like this:
scalar mock openapi.json --watchYou can also change the port like this:
scalar mock openapi.json --watch --port 8080bundle
Some OpenAPI files reference other files from the file system or an URL. You can bundle those files and make them a single file:
scalar bundle openapi.json --output bundle.jsonIf you don’t provide an output file name, the input file will be overwritten.
init
If you’re tired of passing the file name again and again, just configure it once:
scalar initThis will create a scalar.config.json file for you. All commands will use the configured OpenAPI file by default.
Options
--version
If you want to check which version of the CLI is installed, just run this:
scalar --version--help
scalar --helpGitHub Actions
To validate your OpenAPI file in GitHub Actions, add this workflow:
# .github/workflows/validate-openapi-file.yml
name: Validate OpenAPI File
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: 20
- name: Validate OpenAPI File
# Replace `./my-openapi-file.json` with the correct path and filename for your project.
# Or: run `npx @scalar/cli init` and add the config file to your repository.
run: npx @scalar/cli validate ./my-openapi-file.jsonDevelopment
Set up the development environment:
pnpm install
pnpm @scalar/cli --versionTo symlink the package and use it globally on your machine:
pnpm cli:link
scalar --version