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.4metadata:5 source: skills/openapi-spec-writer/openapi-spec-writer.md6---78# OpenAPI Spec Writer910## Prerequisites & Dependencies11- Read access to the backend source: router/controller + validation/schema annotations12- Node 18+ with `npm i -g @redocly/cli` or `@stoplight/spectral-cli` for lint/preview13- Framework-generated annotations (FastAPI, NestJS, SpringDoc) as ground-truth DTO references if available1415## Execution Steps161. Inventory all routes: HTTP method, path (convert framework placeholders to `{param}`), assigned tags, and auth requirements from middleware/decorators.172. Extract request contracts: path/query/header parameters, request body schema, content types — read from validators or DTOs, never guess.183. Extract response contracts: status codes, response shapes, error envelope structure; promote reused models to `components/schemas`.194. Document auth under `components/securitySchemes` and indicate global vs per-operation security requirements.205. Assemble `openapi.yaml` (3.0.3) with `info`, `servers` (dev/staging/prod), consistent `operationId`s, and full path/item documentation.216. Lint and fix: `spectral lint openapi.yaml`; preview with `redocly preview-docs` and verify all operations render correctly.2223```yaml24openapi: 3.0.325info: { title: Orders API, version: 1.2.0 }26servers: [{ url: https://api.example.com/v1 }]27paths:28 /orders/{id}:29 get:30 operationId: getOrder31 tags: [orders]32 security: [{ bearerAuth: [] }]33 parameters:34 - { name: id, in: path, required: true, schema: { type: string, format: uuid } }35 responses:36 "200": { description: OK, content: { application/json: { schema: { $ref: "#/components/schemas/Order" } } } }37 "404": { $ref: "#/components/responses/NotFound" }38components:39 securitySchemes: { bearerAuth: { type: http, scheme: bearer, bearerFormat: JWT } }40 schemas:41 Order:42 type: object43 required: [id, status]44 properties: { id: { type: string, format: uuid }, status: { type: string, enum: [open, paid, shipped] } }45```4647```bash48spectral lint openapi.yaml49redocly preview-docs openapi.yaml50```