Skip to content
Development
Command

/generate-openapi

Generate an OpenAPI 3.1 specification from the existing codebase or API design.

From plugin
rohitg00-claude-code-toolkit
2.5k199 skills138 agents199 commands
Install
$ npx -y skills add rohitg00/awesome-claude-code-toolkit --agent claude-code

How it fires

How this command gets triggered: by you, by Claude, or both.

  • Fires itselfClaude auto-loads it when your prompt matches the work.
  • You can call itInvoke it directly when you want it.
  • Slash command/generate-openapi

Context preview

What this command does when you run it.

Generate an OpenAPI 3.1 specification from the existing codebase or API design.

Command definition

generate-openapi.md

/api-architect:generate-openapi

Generate an OpenAPI 3.1 specification from the existing codebase or API design.

Process

1. Discover existing API routes and handlers:

  • For Express/Fastify: search for `app.get`, `app.post`, `router.use` patterns
  • For FastAPI/Flask: search for `@app.route`, `@router.get` decorators
  • For Go: search for `http.HandleFunc`, `r.GET`, `mux.Handle` patterns
  • For Spring: search for `@GetMapping`, `@PostMapping`, `@RestController` annotations
  • Read each handler to understand request parameters, body, and response shape

2. Extract schema information:

  • Parse TypeScript interfaces, Python dataclasses/Pydantic models, Go structs, or Java DTOs
  • Map field types to OpenAPI types (string, integer, number, boolean, array, object)
  • Identify required vs optional fields from type annotations or validation rules
  • Extract enum values from code constants or type unions
  • Document field constraints (minLength, maxLength, pattern, minimum, maximum)

3. Build the OpenAPI specification:

Info Section

  • Set title from package.json name or project directory
  • Set version from package.json version or git tag
  • Write a concise description of the API's purpose

Servers

  • Add localhost development server
  • Add placeholder for production server URL

Paths

  • One path entry per route
  • Include all HTTP methods supported by each path
  • Define path parameters with types and descriptions
  • Define query parameters for list endpoints (pagination, filtering, sorting)
  • Reference request body schemas from components
  • Define response schemas for each status code (200, 201, 400, 401, 404, 500)

Components

  • Define reusable schemas for each domain entity
  • Create shared error response schema
  • Create pagination metadata schema
  • Define security schemes (Bearer JWT, API Key, OAuth2 as applicable)
  • Use `$ref` extensively to avoid duplication

Security

  • Apply security requirements globally or per-operation
  • Document which endpoints are public (override global security with empty array)

4. Validate the specification:

  • Ensure all `$ref` references resolve correctly
  • Verify that every path parameter has a corresponding parameter definition
  • Check that request bodies have content types specified
  • Confirm response schemas match the actual handler return types

5. Generate example values for each schema to make the spec immediately testable.

Output

Write the specification to `openapi.yaml` (or `openapi.json` if the project prefers JSON). If an existing spec file is found, present a diff and ask before overwriting.

Rules

  • Use OpenAPI 3.1.0 for JSON Schema compatibility
  • Every endpoint must have a summary, description, and at least one response defined
  • Use semantic operation IDs: `listUsers`, `getUserById`, `createOrder`
  • Include realistic example values, not placeholder text like "string" or "0"
  • Group related endpoints with tags matching the resource name
  • Add `x-codegen` extensions if the project uses code generation tools
  • Prefer YAML format for readability unless the project convention is JSON
Read more
Ships withrohitg00-claude-code-toolkit

The most comprehensive toolkit for Claude Code -- 135 agents, 35 curated skills (+400,000 via SkillKit), 42 commands, 176+ plugins, 20 hooks, 15 rules, 7 templates, 15 MCP configs, 26 companion apps, 53 ecosystem entries, and more.

Get the whole plugin