Skip to content

OpenAPI

OpenAPI (formerly Swagger) is a standard, machine-readable way to describe a REST API: its paths, operations, parameters, request/response schemas, and status codes. A single document drives docs, client generation, mock servers, and tests.

Here is one endpoint described in OpenAPI 3.1 (YAML):

openapi: 3.1.0
info:
title: Blog API
version: 1.0.0
paths:
/articles/{id}:
get:
summary: Get an article by id
parameters:
- name: id
in: path
required: true
schema:
type: string
responses:
'200':
description: The article
content:
application/json:
schema:
$ref: '#/components/schemas/Article'
'404':
description: Not found
components:
schemas:
Article:
type: object
required: [id, title]
properties:
id: { type: string }
title: { type: string }
body: { type: string }

Each operation lists its parameters and every response it can return, each tied to a schema. The components/schemas section defines reusable shapes referenced with $ref.

  • Spec-first — write the OpenAPI document, then implement against it. The contract is agreed before code exists; great for teams and external consumers.
  • Code-first — annotate your handlers/schemas and generate the spec from them. Less drift between code and spec, since one produces the other.

Either way, tooling turns the spec into value: Swagger UI / Redoc render interactive docs, generators produce typed clients, and validators check requests against it.

What does an OpenAPI document describe?
What distinguishes spec-first from code-first?
Which is a direct benefit of a maintained OpenAPI spec?