Ask Claude to Generate an OpenAPI Spec from Your Actual API Code
API documentation that's written separately from the code is always wrong eventually. Claude can read your actual implementation and produce an OpenAPI spec that's accurate by construction — because it's generated from the source of truth.
> read all the API routes and their controllers, then generate
> an OpenAPI 3.1 spec in YAML that documents every endpoint
Claude traces each route through its controller, reads the validation rules to determine required parameters and types, checks the response shapes from return statements and resources, and assembles a complete OpenAPI document.
For a Laravel API, Claude reads your routes, form requests, and API resources:
> generate an OpenAPI spec from routes/api.php — use the form
> request classes for request body schemas and the API resources
> for response schemas
For Express, it reads your route handlers and middleware:
> read the routes in src/routes/ and generate a Swagger spec —
> infer request params from the validation middleware and response
> shapes from what the handlers return
Claude captures details that manual documentation misses:
- Path parameters — extracted from your route definitions
- Query parameters — found in your controller's request parsing
- Request bodies — derived from your validation rules with correct types, formats, and required flags
- Response schemas — inferred from your serializers, resources, or return types
- Status codes — detected from your error handling and conditional returns
- Auth requirements — identified from middleware applied to each route
After generation, you can ask Claude to keep it updated:
> I just added a new endpoint for order refunds — update the
> OpenAPI spec to include it
Save the spec as openapi.yaml in your repo, and tools like Swagger UI, Redoc, or Stoplight render it into browsable documentation automatically.
Generate the spec from the code, not the other way around — Claude reads your API and writes docs that are accurate by definition.
via Claude Code
Log in to leave a comment.
Set up Claude Code as an automated reviewer in your CI pipeline — on every pull request, it reads the diff, checks for bugs, security issues, missing tests, and convention violations, then posts its findings as a PR comment. Your human reviewers get a head start because the obvious issues are already flagged before they look.
Before deploying, tell Claude to read your project — migrations, environment variables, queue workers, scheduled tasks, caching, third-party integrations — and generate a deployment checklist that's specific to your app. Not a generic "did you run migrations?" list, but one that knows YOUR infrastructure and catches the things YOUR deploy can break.
Instead of writing a README from memory or copying a template, tell Claude to read your project and generate one that's actually accurate — real setup instructions from your config, real architecture from your directory structure, real API examples from your routes, and real prerequisites from your dependency files.