# Publishing an API

> Publish an OpenAPI spec to Dockito from a file, a zip of split files or the CLI, and run its checks in CI.

## A file or a zip

Drop a spec on a project or Docs in the app, or use **Replace file** on an API doc. A spec split across files goes up as a `.zip`: Dockito finds the root, follows its `$ref`s to the other files and publishes one bundled document.

## The CLI

```sh
dockito publish openapi.yaml --to team/apis
```

The CLI reads the file and every file its relative `$ref`s name, bundles them on your machine and publishes one document. Publishing the same file again changes nothing. The reply says the version, the checks and what changed:

```text
v3 (2.3.0 → 2.4.0): 1 breaking, 0 likely, 0 not.
ERR GET /projects: param "session" (cookie): now required
```

## Checks in CI

`dockito check` runs on your machine; the file never leaves it. With `--against`, it downloads the published doc and compares:

```sh
dockito check openapi.yaml --against bookings-api --format markdown
```

| Exit code | Means |
|---|---|
| 0 | Clean |
| 1 | Check errors (or a `$ref` that points nowhere) |
| 2 | The file differs from the published doc |
| 3 | Breaking changes against the published doc |

The highest wins. `--json` prints the same as JSON; `--format markdown` prints a table for a pull request comment.

A GitHub Actions workflow that comments on each pull request, and publishes on merge:

```yaml
# .github/workflows/openapi.yml
on:
  pull_request:
  push:
    branches: [main]
jobs:
  api:
    runs-on: ubuntu-latest
    env: { DOCKITO_TOKEN: "${{ secrets.DOCKITO_TOKEN }}" }
    steps:
      - uses: actions/checkout@v4
      - run: npm install -g dockito
      - if: github.event_name == 'pull_request'
        run: dockito check openapi.yaml --against ${{ vars.DOCKITO_API_DOC }} --format markdown > check.md || true
      - if: github.event_name == 'pull_request'
        run: gh pr comment ${{ github.event.number }} --body-file check.md
        env: { GH_TOKEN: "${{ github.token }}" }
      - if: github.event_name == 'push'
        run: dockito publish openapi.yaml --to ${{ vars.DOCKITO_API_FOLDER }} -m "${{ github.sha }}"
```

To fail the pull request on a breaking change, drop `|| true` (exit code 3 fails the step). A [token](/help/agents/tokens) with Publish on the workspace goes in `DOCKITO_TOKEN`.
