OpenAPI Spec Writer
Prerequisites & Dependencies
- Read access to the backend source: router/controller + validation/schema annotations
- Node 18+ with
npm i -g @redocly/cli or @stoplight/spectral-cli for lint/preview
- Framework-generated annotations (FastAPI, NestJS, SpringDoc) as ground-truth DTO references if available
Execution Steps
- Inventory all routes: HTTP method, path (convert framework placeholders to
{param}), assigned tags, and auth requirements from middleware/decorators.
- Extract request contracts: path/query/header parameters, request body schema, content types — read from validators or DTOs, never guess.
- Extract response contracts: status codes, response shapes, error envelope structure; promote reused models to
components/schemas.
- Document auth under
components/securitySchemes and indicate global vs per-operation security requirements.
- Assemble
openapi.yaml (3.0.3) with info, servers (dev/staging/prod), consistent operationIds, and full path/item documentation.
- Lint and fix:
spectral lint openapi.yaml; preview with redocly preview-docs and verify all operations render correctly.
openapi: 3.0.3
info: { title: Orders API, version: 1.2.0 }
servers: [{ url: https://api.example.com/v1 }]
paths:
/orders/{id}:
get:
operationId: getOrder
tags: [orders]
security: [{ bearerAuth: [] }]
parameters:
- { name: id, in: path, required: true, schema: { type: string, format: uuid } }
responses:
"200": { description: OK, content: { application/json: { schema: { $ref: "#/components/schemas/Order" } } } }
"404": { $ref: "#/components/responses/NotFound" }
components:
securitySchemes: { bearerAuth: { type: http, scheme: bearer, bearerFormat: JWT } }
schemas:
Order:
type: object
required: [id, status]
properties: { id: { type: string, format: uuid }, status: { type: string, enum: [open, paid, shipped] } }
spectral lint openapi.yaml
redocly preview-docs openapi.yaml
1---2name: openapi-spec-writer3description: Extract backend API code into OpenAPI/Swagger 3.0 documentation.4---56# OpenAPI Spec Writer78## Prerequisites & Dependencies9- Read access to the backend source: router/controller + validation/schema annotations10- Node 18+ with `npm i -g @redocly/cli` or `@stoplight/spectral-cli` for lint/preview11- Framework-generated annotations (FastAPI, NestJS, SpringDoc) as ground-truth DTO references if available1213## Execution Steps141. Inventory all routes: HTTP method, path (convert framework placeholders to `{param}`), assigned tags, and auth requirements from middleware/decorators.152. Extract request contracts: path/query/header parameters, request body schema, content types — read from validators or DTOs, never guess.163. Extract response contracts: status codes, response shapes, error envelope structure; promote reused models to `components/schemas`.174. Document auth under `components/securitySchemes` and indicate global vs per-operation security requirements.185. Assemble `openapi.yaml` (3.0.3) with `info`, `servers` (dev/staging/prod), consistent `operationId`s, and full path/item documentation.196. Lint and fix: `spectral lint openapi.yaml`; preview with `redocly preview-docs` and verify all operations render correctly.2021```yaml22openapi: 3.0.323info: { title: Orders API, version: 1.2.0 }24servers: [{ url: https://api.example.com/v1 }]25paths:26 /orders/{id}:27 get:28 operationId: getOrder29 tags: [orders]30 security: [{ bearerAuth: [] }]31 parameters:32 - { name: id, in: path, required: true, schema: { type: string, format: uuid } }33 responses:34 "200": { description: OK, content: { application/json: { schema: { $ref: "#/components/schemas/Order" } } } }35 "404": { $ref: "#/components/responses/NotFound" }36components:37 securitySchemes: { bearerAuth: { type: http, scheme: bearer, bearerFormat: JWT } }38 schemas:39 Order:40 type: object41 required: [id, status]42 properties: { id: { type: string, format: uuid }, status: { type: string, enum: [open, paid, shipped] } }43```4445```bash46spectral lint openapi.yaml47redocly preview-docs openapi.yaml48```