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.
A minimal description
Section titled “A minimal description”Here is one endpoint described in OpenAPI 3.1 (YAML):
openapi: 3.1.0info: title: Blog API version: 1.0.0paths: /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 foundcomponents: 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 vs code-first
Section titled “Spec-first vs code-first”- 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.