# Check an OpenAPI document

The Skmtc API checks an OpenAPI document and gives you a short report. The
report says how many problems the document has, and shows the first problems of
each rule. This page gives you the two operations and their `curl` commands,
the limits and what the report holds.

The check uses the recommended rules of the Spectral `spectral:oas` ruleset, on
one document. It does not read the files that a `$ref` points to. You cannot
send your own ruleset. Skmtc does not log or cache the document or the report,
and does not keep the document after the check.

An agent can do the same check with the `lint_schema` tool of the
[Skmtc MCP server](/docs/mcp).

## Check a file [#check-a-file]

Send the document, in JSON or YAML, as the body of `POST /v1/lint`:

```sh
curl --fail-with-body --data-binary @openapi.yaml https://api.skmtc.dev/v1/lint
```

The request must have a `content-length`. `--data-binary` sends one, and sends
the bytes of the file without a change.

## Check a document at a URL [#check-a-document-at-a-url]

Send the address of the document to `POST /v1/lint/url`:

```sh
curl --fail-with-body \
  --header 'content-type: application/json' \
  --data '{"url": "https://example.com/openapi.yaml"}' \
  https://api.skmtc.dev/v1/lint/url
```

The address must use `https` and a public host. Skmtc checks each redirect in
the same way.

## Read the report [#read-the-report]

```json
{
  "counts": { "error": 1, "warn": 9, "info": 0, "hint": 0 },
  "rules": [
    {
      "code": "operation-operationId",
      "severity": "warn",
      "count": 2,
      "problems": [
        {
          "message": "Operation must have \"operationId\".",
          "path": ["paths", "/a", "get"],
          "line": 5,
          "character": 9
        }
      ]
    }
  ]
}
```

The example shows only one of the rules.

- `counts`: the number of problems of each severity in the whole document.
- `rules`: one item for each rule and severity that the document breaks. Rules
  with errors come first, then the rules with the most problems.
- `count`: the number of problems of that item in the document.
- `problems`: a page of those problems, in the order of the document.
- `path`: the keys from the root of the document to the value that has the
  problem.
- `line` and `character`: where the problem starts. Each starts at 1.
  `character` counts UTF-16 code units.

## Read more of one rule [#read-more-of-one-rule]

The report has the first 5 problems of each rule. To read more of one rule, add
`rule` to the address of either operation. The report then has only that rule:

```sh
curl --fail-with-body --data-binary @openapi.yaml \
  'https://api.skmtc.dev/v1/lint?rule=operation-operationId&offset=100&limit=100'
```

| Query    | Meaning                          | Default | Values   |
| -------- | -------------------------------- | ------- | -------- |
| `rule`   | The one rule to report           | None    | A rule   |
| `offset` | The problems of the rule to skip | 0       | 0 or more |
| `limit`  | The problems of the rule to give | 100     | 1 to 200 |

Send `offset` and `limit` only with `rule`.

## Limits [#limits]

- No sign-in is necessary.
- Each IP address can send 20 requests a minute to the two operations together.
- A document can be at most 60 MiB.
- The body of `POST /v1/lint` must arrive in 60 seconds.
- The body of `POST /v1/lint/url` can be at most 16 KiB.
- At a URL, Skmtc waits 20 seconds for the response headers and 60 seconds for
  the document.
- The check of one document can use 30 seconds of CPU time. Some very large
  documents are too large to check.
- Documents larger than 10 MiB can wait for their turn.

## Errors [#errors]

An error has a `code`, a `message` and a `requestId`.

| Status | Cause                                                                                                  |
| ------ | ------------------------------------------------------------------------------------------------------ |
| `400`  | The query or the JSON body is not correct, `content-length` is missing, or the body is incomplete      |
| `403`  | The request has a token without the `read:catalog` scope                                               |
| `413`  | The document of `POST /v1/lint` is larger than 60 MiB, or the body of `/v1/lint/url` is over 16 KiB   |
| `422`  | The document is not OpenAPI 2 or 3, cannot be read or is too large to check, or the URL cannot be used |
| `429`  | More than 20 requests in a minute from your IP address                                                 |
| `503`  | The check, or the host of the URL, cannot answer now. Wait the time in `Retry-After`, then try again   |

For a URL, `422` also covers a document larger than 60 MiB. It also covers a
host that Skmtc cannot reach, and a host status other than `429` or `5xx`.
