An OpenAPI (formerly Swagger) document describes a REST API in a machine-readable way: its endpoints, parameters, request bodies, and responses. Tools generate clients, servers, and docs from it — but only if it is structurally correct. This validator parses your YAML or JSON spec in the browser and checks it against the rules that the most common mistakes violate.
How it works
The tool runs in two stages:
- Parse. If the input starts with
{or[it is parsed as JSON. Otherwise a built-in block-style YAML parser converts the document into an object, handling indentation,key: valuepairs, lists, and inline scalars. - Validate. It then walks the object and applies the structural rules — version format, the required
info.titleandinfo.version, thepathsobject, and for each operation aresponsesobject keyed by valid status codes ordefault. Inline parameters must declarenameandin, and OpenAPI 3.x parameters are expected to carry aschema.
Every problem is reported with a JSON-pointer-style path such as paths/pets/get/responses, so a long spec is quick to fix.
What the validator checks
| Rule | Why it matters |
|---|---|
Version field present (openapi or swagger) | Code generators and docs tools refuse to load without it |
info.title and info.version present | Required by the spec; many tools display these |
paths object exists | Without it the spec has no endpoints |
Every operation has a responses object | Clients cannot handle replies from undocumented operations |
Response keys are valid status codes or default | Invalid keys (e.g. "20A") cause parse failures in generators |
Inline parameters have name and in | Missing in is one of the most common silent bugs |
OpenAPI 3.x parameters carry a schema | Required by 3.x spec; Swagger 2.0 uses type directly instead |
Common validation failures and fixes
Missing responses on an operation. Every operation must have at least one response, even if it is just default. Add a minimal block:
responses:
"200":
description: OK
Invalid status code key. Status codes must be three-digit strings ("200", "404") or the literal default. A typo like "20A" or a bare integer like 200 (without quotes in YAML) is caught here.
Wrong version field. OpenAPI 3.x uses openapi: "3.0.3". Swagger 2.0 uses swagger: "2.0". Using the wrong key causes the tool — and many generators — to misidentify or reject the spec.
Parameter without in. The in field must be one of path, query, header, or cookie. Missing it entirely is a spec error that breaks client code generators.
Example
A response block keyed by an invalid code is caught:
responses:
"20A": # invalid — not a status code
description: Bad
The validator flags paths/.../responses/20A: invalid status code key. A valid spec instead uses "200", "404", or default.
Notes
This is a structural validator, not a full JSON Schema validator with external $ref resolution. It catches the errors that break code generators and doc tools — missing responses, malformed versions, parameters without a name — while keeping your spec entirely on your own device. For full schema validation including $ref resolution, run the spec through a dedicated tool like @redocly/cli or Spectral after confirming the structure here.