A written contract for your API that people, docs and tools can all read.
OpenAPI is a standard way to write down what your API does in one file (YAML or JSON): the paths, the inputs, the outputs, the errors and how to log in. Swagger is the older name for it, and today it mostly names the family of tools (like Swagger UI) built around it.
Imagine every team describing its API in an email, a wiki page, or just the code. Docs go out of date, two teams read the same page two different ways, and nobody knows if a change is safe. The fix is to write the API down once, in a format that machines can read.
That format is the OpenAPI Specification (OAS). A file says things like: "there is a POST /orders. It needs an item and a quantity. It answers 201 with an order, or 400 with an error. You must send an API key." The request and response shapes are written with JSON Schema.
You may hear three names. OpenAPI is the specification. Swagger was the original name of the specification, and now it is the brand for a set of tools, such as Swagger UI (a page where you can read the docs and try calls) and Swagger Editor. Many other tools read OpenAPI files too.
openapi: 3.0.3
info:
title: Shop API
version: 1.0.0
paths:
/orders:
post:
summary: Create an order
requestBody:
required: true
content:
application/json:
schema:
type: object
required: [item, quantity]
properties:
item: { type: string }
quantity: { type: integer, minimum: 1 }
responses:
"201": { description: Order created }
"400": { description: Invalid request }| Part | What it describes | Example |
|---|---|---|
| info | The name, version and description of the API | title: Shop API, version: 1.0.0 |
| servers | Where the API lives | https://api.example.com |
| paths | Each URL and the methods it supports | /orders with GET and POST |
| parameters | Inputs in the path, the query, a header or a cookie | ?page=2, or the id in /orders/{id} |
| requestBody | The shape of the data you send | A JSON order with item and quantity |
| responses | Each status code and the shape that comes back | 201 order created, 400 error |
| components | Shared pieces that you reuse in many places | An Order schema, a standard Error schema |
| security | How callers prove who they are | API key in a header, OAuth2 |
| Kind of tool | What it does | Examples (names only) |
|---|---|---|
| Doc viewers | Turn the file into a readable site, often with a try-it button | Swagger UI, Redoc |
| Editors | Help you write and check the file | Swagger Editor, IDE plugins |
| Code generators | Make clients and server stubs in many languages | OpenAPI Generator |
| Linters | Check style and rules (every operation has a description...) | Spectral |
| Diff tools | Find breaking changes between two versions | openapi-diff and similar |
| Mock servers | Answer fake requests from the examples | Prism and similar |
| Contract testers | Send real requests and compare with the file | Schemathesis, Dredd and similar |
paths:
/orders:
post:
summary: Create an order
requestBody:
required: true
content:
application/json:
schema:
type: object
required: [item, quantity]
properties:
item: { type: string }
quantity: { type: integer }
coupon: { type: string }
responses:
"201": { description: Order created }
"400": { description: Invalid request }POST /orders
X-API-Key: demo-key-123
{"item":"book","quantity":2,"coupon":"SAVE5"}A simplified model: a real validator follows the whole JSON Schema vocabulary. The order, the key and the six requests are made-up examples for teaching.
| Term | Meaning in easy words |
|---|---|
| OpenAPI Specification (OAS) | The standard format for describing an HTTP API in a YAML or JSON file |
| Swagger | The older name of the specification, and today the name of a family of tools around it |
| Swagger UI | A web page made from the file, where you can read the docs and try calls |
| Path / operation | A URL, and one method on it (like POST /orders) |
| Schema | A description of the shape of some data, using JSON Schema |
| Components | A place for shared, reusable pieces like schemas and security schemes |
| Security scheme | How a caller proves who they are (API key, OAuth2, HTTP bearer) |
| Design-first | Write and agree the contract before writing the code |
| Code-first | Write the code, then generate the contract from it |
| Breaking change | A change that makes requests that used to work fail |
| Contract testing | Checking that the real server behaves as the contract says |
| Choice | We gain | We lose |
|---|---|---|
| Design-first | Agreement early, parallel work, cleaner APIs | Slower start and more meetings |
| Code-first | Fast start, the file always matches the code | The API is shaped by the code, and is reviewed late |
| Strict schemas | Bad input is caught at the edge | Old clients may break when rules tighten |
| Loose schemas | Easy for clients to adopt | More bad data reaches your code |
| Generated clients | Less hand-written code, fewer typos | Harder to customise, generator quirks |
| One big file | Everything in one place | Hard to review. Split into files and merge in the build |