0.2.58 • Published 3 days ago

@scalar/cli v0.2.58

Weekly downloads
-
License
MIT
Repository
github
Last release
3 days ago

Scalar CLI

Version Downloads License Discord

Command-line interface to work with OpenAPI files

Demo Video

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 help

Installation

If you really want to become friends you should install the CLI:

npm -g install @scalar/cli

Otherwise 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 format
scalar format openapi.json --output openapi.yaml
scalar format https://example.com/openapi.json --output openapi.json

validate

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 validate
scalar validate openapi.json
scalar validate https://example.com/openapi.json

share

To quickly share an OpenAPI file or reference with someone, you can use the share command:

scalar share
scalar share openapi.json

This 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.

reference

You can quickly spin up a local server with an API reference based on your OpenAPI file.

scalar reference
scalar reference openapi.json
scalar reference openapi.json --port 1234
scalar reference openapi.json --watch
scalar reference https://example.com/openapi.json --watch

mock

We can even mock your API, and it’s just one command:

scalar mock

This 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 --watch

You can also change the port like this:

scalar mock openapi.json --watch --port 8080

And it even works with URLs:

scalar mock https://example.com/openapi.json --watch

bundle

Warning! The bundle command isn’t ready for production yet. Circular dependencies are not supported yet.

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.json

If 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 init

This 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 --help

GitHub 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.json

Development

Set up the development environment:

pnpm install
pnpm @scalar/cli --version

To symlink the package and use it globally on your machine:

pnpm cli:link
scalar --version
0.2.58

3 days ago

0.2.57

4 days ago

0.2.56

4 days ago

0.2.55

5 days ago

0.2.54

6 days ago

0.2.53

6 days ago

0.2.52

8 days ago

0.2.51

9 days ago

0.2.50

10 days ago

0.2.49

10 days ago

0.2.48

11 days ago

0.2.47

12 days ago

0.2.46

12 days ago

0.2.45

12 days ago

0.2.44

13 days ago

0.2.43

13 days ago

0.2.42

13 days ago

0.2.41

16 days ago

0.2.40

16 days ago

0.2.39

16 days ago

0.2.38

17 days ago

0.2.37

19 days ago

0.2.36

20 days ago

0.2.35

22 days ago

0.2.34

23 days ago

0.2.33

23 days ago

0.2.30

26 days ago

0.2.32

26 days ago

0.2.31

26 days ago

0.2.29

27 days ago

0.2.28

30 days ago

0.2.27

1 month ago

0.2.26

1 month ago

0.2.25

1 month ago

0.2.24

1 month ago

0.2.23

1 month ago

0.2.22

1 month ago

0.2.21

1 month ago

0.2.20

1 month ago

0.2.19

1 month ago

0.2.18

1 month ago

0.2.17

1 month ago

0.2.16

1 month ago

0.2.15

1 month ago

0.2.14

1 month ago

0.2.13

1 month ago

0.2.12

1 month ago

0.2.11

1 month ago

0.2.10

1 month ago

0.2.7

2 months ago

0.2.6

2 months ago

0.2.8

2 months ago

0.2.5

2 months ago

0.2.3

2 months ago

0.2.4

2 months ago

0.2.1

2 months ago

0.2.0

2 months ago

0.0.1

3 months ago

0.0.0

3 months ago

0.1.0

3 months ago