API documentation, validation, and SDK generation, from one YAML file
OpenAPI 3.x (formerly Swagger) describes HTTP APIs in a YAML or JSON document. Tools render docs (Redoc, Swagger UI), validate requests/responses (Stoplight, Spectral), and generate SDKs in dozens of languages — all from the same source file.
Top-level shape
openapi:— spec version (3.1.0currently).info:— title, version, description.paths:— endpoints. Each path → method (get/post/etc.) → parameters/requestBody/responses.components:— reusable schemas, parameters, responses, security schemes.
Why YAML over JSON
OpenAPI specs are often hundreds of lines with deeply nested schemas. Comments, anchors, and folded strings make YAML readable where the equivalent JSON would be a wall. The spec accepts both; teams choose YAML by majority.
Schema-first vs code-first: two valid workflows. Schema-first writes the OpenAPI YAML by hand, then generates server stubs and clients. Code-first writes the server (FastAPI, NestJS, ASP.NET) and emits the OpenAPI from decorators. Schema-first gives a stricter contract; code-first gives a tighter feedback loop. Pick based on team size — small team → code-first, multi-team API → schema-first.