* Initial plan * Add OpenAPI/Swagger documentation infrastructure - Install swagger-ui-express and swagger-jsdoc packages - Create OpenAPI configuration with schemas, security schemes, and components - Add /api/docs endpoint for interactive Swagger UI - Add /api/openapi.json endpoint for OpenAPI spec - Document analytics routes (ghosts, heatmap, lurkers, roles, clients, shifts) - Document ban management routes (banned, ban, unban, whitelist operations) - Document key auth routes (discord callback, logout, me) Co-authored-by: onnwee <211922112+onnwee@users.noreply.github.com> * Add documentation for additional API routes - Document status and health check endpoints - Document suspicion analysis endpoints - Document timeline endpoints - Update OpenAPI config to include nested routes - Total of 20 documented API endpoints Co-authored-by: onnwee <211922112+onnwee@users.noreply.github.com> * Add ReDoc support and comprehensive API documentation - Install redoc-express for alternative documentation view - Add /api/redoc endpoint for clean documentation interface - Add more auth endpoints (refresh, sessions management) - Create comprehensive API_DOCUMENTATION.md guide - Total of 23 documented endpoints with full examples Co-authored-by: onnwee <211922112+onnwee@users.noreply.github.com> * Add screenshots and finalize API documentation - Capture screenshots of Swagger UI, ReDoc, and OpenAPI spec - Add screenshots to API_DOCUMENTATION.md - Update main README.md with links to interactive documentation - Fix redoc import statement - Complete OpenAPI/Swagger implementation with 23 documented endpoints Co-authored-by: onnwee <211922112+onnwee@users.noreply.github.com> * Add OpenAPI implementation summary documentation - Create comprehensive implementation summary - Document all 23 endpoints with details - Include usage examples and guidelines - Add maintenance and future enhancement sections - Complete OpenAPI/Swagger implementation Co-authored-by: onnwee <211922112+onnwee@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: onnwee <211922112+onnwee@users.noreply.github.com>
6.0 KiB
API Documentation
This document describes how to access and use the Spywatcher API documentation.
Screenshot of Swagger UI - Interactive API documentation interface
Interactive Documentation
Swagger UI (Recommended for Testing)
The interactive Swagger UI is available at:
http://localhost:3001/api/docs
Features:
- Interactive "Try it out" functionality
- Test API endpoints directly from the browser
- Authentication testing with JWT tokens
- Request/response examples
- Schema validation
How to use:
- Navigate to
/api/docsin your browser - Click "Authorize" button to add your JWT Bearer token
- Expand any endpoint to see details
- Click "Try it out" to test the endpoint
- Fill in parameters and click "Execute"
ReDoc (Clean Documentation View)
Screenshot of ReDoc - Clean, professional documentation view
An alternative, cleaner documentation view is available at:
http://localhost:3001/api/redoc
Features:
- Clean, professional appearance
- Better for reading and understanding API structure
- Mobile-friendly responsive design
- Print-friendly format
- Three-panel design with navigation
OpenAPI Specification
Screenshot of OpenAPI JSON specification
The raw OpenAPI 3.0 specification is available at:
http://localhost:3001/api/openapi.json
This JSON file can be used to:
- Generate client SDKs in various languages
- Import into API testing tools (Postman, Insomnia)
- Integrate with API gateways
- Generate documentation in other formats
API Overview
Base URL
Development: http://localhost:3001/api
Production: https://api.spywatcher.dev/api
Authentication
Most endpoints require authentication using JWT Bearer tokens:
Authorization: Bearer <your-jwt-token>
To obtain a token:
- Authenticate via Discord OAuth2:
GET /api/auth/discord?code=<code> - Use the returned
accessTokenin subsequent requests
Rate Limiting
The API implements rate limiting to prevent abuse:
- Global rate limit: Applied to all
/apiroutes - Analytics endpoints: Stricter limits for resource-intensive operations
- Auth endpoints: Separate limits for authentication operations
Rate limit headers are included in responses:
X-RateLimit-Limit: Maximum requests allowedX-RateLimit-Remaining: Requests remaining in windowX-RateLimit-Reset: Time when the limit resets
API Categories
Authentication (/api/auth/*)
User authentication, session management, and OAuth2 flows.
Key endpoints:
GET /auth/discord- Discord OAuth2 callbackPOST /auth/refresh- Refresh access tokenGET /auth/me- Get current user infoPOST /auth/logout- Logout userGET /auth/sessions- List user sessionsDELETE /auth/sessions/{sessionId}- Revoke a session
Analytics (/api/*)
User behavior analytics and insights.
Key endpoints:
GET /ghosts- Get ghost scores (high presence, low engagement)GET /heatmap- Channel activity heatmapGET /lurkers- Identify lurkersGET /roles- Role drift analysisGET /clients- Client usage patternsGET /shifts- Behavior shift detection
Bans (/api/*)
IP ban and whitelist management.
Key endpoints:
GET /banned- List banned IPsPOST /ban- Ban an IP addressPOST /unban- Unban an IP addressGET /whitelisted- List whitelisted IPsPOST /whitelist- Add IP to whitelistDELETE /whitelist- Remove IP from whitelist
Suspicion (/api/suspicion/*)
Suspicious activity detection and analysis.
Key endpoints:
GET /suspicion- Get suspicion scoresGET /suspicion/{userId}- Detailed user suspicion analysis
Timeline (/api/timeline/*)
User activity timelines.
Key endpoints:
GET /timeline/{userId}- Get user activity timeline
Status (/api/status, /health/*)
System status and health checks.
Key endpoints:
GET /status- Current system status (public)GET /health/live- Liveness probe (for orchestrators)GET /health/ready- Readiness probe (checks dependencies)
Common Response Codes
200 OK- Successful request400 Bad Request- Invalid input parameters401 Unauthorized- Missing or invalid authentication403 Forbidden- Insufficient permissions404 Not Found- Resource not found429 Too Many Requests- Rate limit exceeded500 Internal Server Error- Server error503 Service Unavailable- Service temporarily unavailable
Error Response Format
All error responses follow a consistent format:
{
"error": "Error Type",
"message": "Detailed error message",
"details": {
// Optional additional error details
}
}
Client SDK Generation
You can generate client SDKs from the OpenAPI specification using tools like:
OpenAPI Generator
# Install OpenAPI Generator
npm install @openapitools/openapi-generator-cli -g
# Generate TypeScript client
openapi-generator-cli generate \
-i http://localhost:3001/api/openapi.json \
-g typescript-fetch \
-o ./generated-client
# Generate Python client
openapi-generator-cli generate \
-i http://localhost:3001/api/openapi.json \
-g python \
-o ./generated-client
Swagger Codegen
# Generate Java client
swagger-codegen generate \
-i http://localhost:3001/api/openapi.json \
-l java \
-o ./generated-client
Postman Collection
To import the API into Postman:
- Open Postman
- Click "Import"
- Select "Link"
- Enter:
http://localhost:3001/api/openapi.json - Click "Continue" and then "Import"
Additional Resources
Support
For API support or questions:
- Email: support@spywatcher.dev
- GitHub Issues: subculture-collective/discord-spywatcher