Skip to main content
Web DevAPIs & NetworkingDiagramBeginner

OpenAPI (Swagger)

KO: OpenAPI (Swagger)·EN: OpenAPI (Swagger)·JA: OpenAPI(Swagger)·OAS (OpenAPI Specification)

A machine-readable YAML/JSON specification for describing REST APIs that automates interactive docs, typed client SDK generation, mocks, and contract tests

Table of Contents

Structure Diagram

OpenAPI Single-Source-of-Truth Automation Loop
openapi.yaml1. Author OA…2. Generate …3. Mock & Co…4. Interacti…
1/41. Author OAS 3.1 Spec
Paths, schemas & errors
Quick Answer

What is OpenAPI (Swagger)?

A machine-readable YAML/JSON specification for describing REST APIs that automates interactive docs, typed client SDK generation, mocks, and contract tests. It is a core concept in APIs & Networking within Web Dev.

Core Principles

The OpenAPI Specification (formerly Swagger) is a language-agnostic YAML/JSON standard for describing REST APIs—endpoints, HTTP methods, parameters, JSON Schema request/response bodies, status codes, and security schemes.

Because it is machine-readable, a single openapi.yaml acts as a Single Source of Truth powering interactive documentation (Swagger UI, Scalar, Redoc), auto-generated TypeScript/Swift/Kotlin clients, mock servers, and request validation.

Practical Takeaways

  • Choose Schema-First or Code-First intentionally: Use Schema-First when external partners or separate FE/BE teams must agree on contracts before coding; use Code-First (FastAPI, NestJS, Zod-to-OpenAPI) in fast-moving monorepos so docs never drift from implementation.
  • Gate breaking changes in CI: Run tools like oasdiff on pull requests to catch removed fields or narrowed types before they break mobile clients.
  • Automate frontend types: Pair openapi-typescript or orval with your OpenAPI spec to eliminate hand-written API interfaces.

Notable Examples

  • FastAPI, NestJS, and SpringDoc: Generate live OpenAPI 3.1 schemas and interactive playgrounds straight from route definitions.
  • Stripe and OpenAI developer portals: Drive multi-language SDK generation and reference docs from centralized OpenAPI specs.