--- allowed-tools: Read, Write, Edit, Bash argument-hint: [api-type] | --openapi | --graphql | --rest | --grpc | --interactive description: Generate comprehensive API documentation from code with interactive examples and testing capabilities --- # API Documentation Generator Generate API documentation from code: $ARGUMENTS ## Current API Context - API endpoints: !`find . -name "*route*" -o -name "*controller*" -o -name "*api*" | head -5` - API specs: !`find . -name "*openapi*" -o -name "*swagger*" -o -name "*.graphql" | head -3` - Server framework: @package.json or detect from imports - Existing docs: @docs/api/ or @api-docs/ (if exists) - Test files: !`find . -name "*test*" -path "*/api/*" | head -3` ## Task Generate comprehensive API documentation with interactive features: $ARGUMENTS 1. **Code Analysis and Discovery** - Scan the codebase for API endpoints, routes, and handlers - Identify REST APIs, GraphQL schemas, and RPC services - Map out controller classes, route definitions, and middleware - Discover request/response models and data structures 2. **Documentation Tool Selection** - Choose appropriate documentation tools based on stack: - **OpenAPI/Swagger**: REST APIs with interactive documentation - **GraphQL**: GraphiQL, GraphQL Playground, or Apollo Studio - **Postman**: API collections and documentation - **Insomnia**: API design and documentation - **Redoc**: Alternative OpenAPI renderer - **API Blueprint**: Markdown-based API documentation 3. **API Specification Generation** **For REST APIs with OpenAPI:** ```yaml openapi: 3.0.0 info: title: $ARGUMENTS API version: 1.0.0 description: Comprehensive API for $ARGUMENTS servers: - url: https://api.example.com/v1 paths: /users: get: summary: List users parameters: - name: page in: query schema: type: integer responses: '200': description: Successful response content: application/json: schema: type: array items: $ref: '#/components/schemas/User' components: schemas: User: type: object properties: id: type: integer name: type: string email: type: string ``` 4. **Endpoint Documentation** - Document all HTTP methods (GET, POST, PUT, DELETE, PATCH) - Specify request parameters (path, query, header, body) - Define response schemas and status codes - Include error responses and error codes - Document authentication and authorization requirements 5. **Request/Response Examples** - Provide realistic request examples for each endpoint - Include sample response data with proper formatting - Show different response scenarios (success, error, edge cases) - Document content types and encoding 6. **Authentication Documentation** - Document authentication methods (API keys, JWT, OAuth) - Explain authorization scopes and permissions - Provide authentication examples and token formats - Document session management and refresh token flows 7. **Data Model Documentation** - Define all data schemas and models - Document field types, constraints, and validation rules - Include relationships between entities - Provide example data structures 8. **Error Handling Documentation** - Document all possible error responses - Explain error codes and their meanings - Provide troubleshooting guidance - Include rate limiting and throttling information 9. **Interactive Documentation Setup** **Swagger UI Integration:** ```html