Complete interactive API documentation generated from code using Swagger/OpenAPI 3.0 specification. Includes Swagger UI, ReDoc, and downloadable OpenAPI specs.
✅ Swagger UI loads correctly at /api/docs
- Interactive API exploration
- Try-it-out functionality
- Authentication support
✅ ReDoc loads at /api/redoc
- Alternative documentation view
- Organized by tags
- Responsive design
✅ Auto-generate OpenAPI spec from code
- JSDoc comments in route files
- Automatic parsing with swagger-jsdoc
- Real-time spec generation
✅ Document all endpoints
- 25+ endpoints documented
- Auth endpoints (register, login, verify, refresh)
- Event endpoints (list, create, update, delete, register)
- Team endpoints (list, create, update, delete)
- Activity endpoints (list, create, update, delete)
- Monitoring endpoints (health, metrics, errors)
- Admin endpoints (stream, notifications)
✅ Request/response examples provided
- Example request bodies
- Example responses
- Error responses
- Data types and validation
✅ Include error codes and auth requirements
- HTTP status codes
- Authentication schemes (Bearer, API Key)
- Authorization requirements
- Error messages
✅ Download OpenAPI spec
- JSON format: /api/swagger.json
- YAML format: /api/swagger.yaml
server/config/swagger.js- OpenAPI 3.0 configurationserver/routes/documentation.js- Documentation endpoints
server/swagger-docs/endpoints.js- Auth, events endpointsserver/swagger-docs/team-and-activities.js- Team, activities endpointsserver/swagger-docs/monitoring-and-admin.js- Monitoring, admin endpoints
BACKEND_INTEGRATION_EXAMPLE_ISSUE94.js- Integration guideAPI_DOCUMENTATION_GUIDE.md- This file
server/package.json- Added swagger-jsdoc, swagger-ui-express, redoc-express
GET /api/docs → Swagger UI (Interactive)
GET /api/redoc → ReDoc (Alternative view)
GET /api/swagger.json → OpenAPI spec (JSON)
GET /api/swagger.yaml → OpenAPI spec (YAML)
GET /api/docs-info → Documentation info
POST /api/auth/register- Register new userPOST /api/auth/login- Login userPOST /api/auth/verify- Verify emailPOST /api/auth/refresh- Refresh JWT token
GET /api/events- Get all eventsPOST /api/events- Create eventGET /api/events/{eventId}- Get event detailsPUT /api/events/{eventId}- Update eventDELETE /api/events/{eventId}- Delete eventPOST /api/events/{eventId}/register- Register for event
GET /api/core-team- Get all team membersPOST /api/core-team- Add team memberGET /api/core-team/{memberId}- Get member detailsPUT /api/core-team/{memberId}- Update memberDELETE /api/core-team/{memberId}- Delete member
GET /api/activity-events- Get all activitiesPOST /api/activity-events- Create activityGET /api/activity-events/{eventId}- Get activity detailsPUT /api/activity-events/{eventId}- Update activityDELETE /api/activity-events/{eventId}- Delete activity
GET /api/monitoring/health- Health checkGET /api/monitoring/metrics- Performance metricsGET /api/monitoring/errors/stats- Error statisticsGET /api/monitoring/errors/recent- Recent errorsGET /api/monitoring/errors/endpoint- Errors by endpointPOST /api/monitoring/test-error- Test error
GET /recommend/events/{user_id}
- Description: Get top 5 recommended events for a specific user.
- Input:
user_id(Path parameter, string) - Output: JSON List of Event Objects (containing
id,name,tags, and calculatedfinal_score). - Data Integration: Fetches user interests from the
"Profile"table and event tags from the"Events"table in PostgreSQL. - Logic Used: Hybrid Content + Collaborative Filtering.
- Content-Based: Uses
TfidfVectorizerand Cosine Similarity to match user interest keywords against event tags. - Collaborative Filtering: Implements user-user similarity logic to find similar users based on shared interests and boosts the score of events they have already joined.
- Combined Score: Creates a weighted final score combining both methods (70% content-based, 30% collaborative).
- Content-Based: Uses
- Performance Optimization: Utilizes Redis Caching. Checks Redis before executing the ML model. If not cached, the model runs and stores the result in Redis for 60 minutes (3600 seconds) to prevent redundant recalculations.
GET /api/admin/stream- Real-time SSE streamGET /api/admin/stream/info- Connected clients infoPOST /api/notifications/subscribe- Subscribe to pushPOST /api/notifications/unsubscribe- Unsubscribe from push
- Interactive API Explorer - Try endpoints directly from browser
- Request/Response Examples - See exact format of data
- Authentication Support - Test with Bearer tokens
- Automatic Validation - Validate request bodies
- Deep Linking - Share specific endpoint URLs
- Download OpenAPI Spec - Export for other tools
- Beautiful Documentation - Modern, clean interface
- Organized by Tags - Group related endpoints
- Searchable - Find endpoints quickly
- Responsive Design - Works on mobile
- Code Examples - Multiple language examples
- Machine Readable - Use with code generators
- Version Control - Track API changes
- Standards Compliant - OpenAPI 3.0.0
- Multiple Formats - JSON and YAML
- Auto-Generated - From code comments
/**
* @swagger
* /api/endpoint:
* get:
* summary: Brief description
* description: Detailed description
* tags:
* - Category
* parameters:
* - in: query
* name: paramName
* schema:
* type: string
* responses:
* 200:
* description: Success
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/ModelName'
*//**
* @swagger
* /api/users:
* get:
* summary: Get all users
* description: Retrieve paginated list of users
* tags:
* - Users
* parameters:
* - in: query
* name: page
* schema:
* type: integer
* default: 1
* responses:
* 200:
* description: List of users
* content:
* application/json:
* schema:
* type: object
* properties:
* data:
* type: array
* items:
* $ref: '#/components/schemas/User'
*/
app.get('/api/users', (req, res) => {
// Implementation
});/**
* @swagger
* /api/users:
* post:
* summary: Create new user
* tags:
* - Users
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* required:
* - email
* - name
* properties:
* email:
* type: string
* format: email
* name:
* type: string
* responses:
* 201:
* description: User created
* 400:
* description: Invalid input
*/
app.post('/api/users', (req, res) => {
// Implementation
});/**
* @swagger
* /api/admin/users:
* get:
* summary: Get all users (admin only)
* security:
* - bearerAuth: []
* responses:
* 200:
* description: Success
* 401:
* description: Unauthorized
* 403:
* description: Forbidden - admin only
*/
app.get('/api/admin/users', (req, res) => {
// Implementation
});In server/config/swagger.js:
User: {
type: 'object',
properties: {
id: { type: 'string' },
email: { type: 'string', format: 'email' },
name: { type: 'string' },
},
}responses:
200:
content:
application/json:
schema:
$ref: '#/components/schemas/User'npm install swagger-jsdoc swagger-ui-express redoc-express yamlimport documentationRoutes from './routes/documentation.js';
app.use('/api', documentationRoutes);Add JSDoc comments to all route files. swagger-jsdoc will automatically parse them.
- Swagger UI: http://localhost:3000/api/docs
- ReDoc: http://localhost:3000/api/redoc
- OpenAPI JSON: http://localhost:3000/api/swagger.json
{
"success": true,
"data": {
"id": "123",
"name": "Event Name"
},
"message": "Operation successful"
}{
"success": false,
"error": "Error message",
"statusCode": 400
}| Code | Meaning | Usage |
|---|---|---|
| 200 | OK | Successful GET, PUT, DELETE |
| 201 | Created | Successful POST |
| 400 | Bad Request | Invalid input |
| 401 | Unauthorized | Missing/invalid auth |
| 403 | Forbidden | Insufficient permissions |
| 404 | Not Found | Resource not found |
| 500 | Server Error | Unexpected error |
| 503 | Service Unavailable | Server down |
curl -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIs..." \
http://localhost:3000/api/eventscurl -H "X-API-Key: your-api-key" \
http://localhost:3000/api/events- Open Swagger UI: http://localhost:3000/api/docs
- Authorize: Click "Authorize" button, enter JWT token
- Try Endpoint: Expand endpoint, click "Try it out"
- Enter Parameters: Fill in required fields
- Execute: Click "Execute" button
- View Response: See status, headers, and body
curl http://localhost:3000/api/swagger.json > openapi.jsoncurl http://localhost:3000/api/swagger.yaml > openapi.yaml- OpenAPI Generator: Generate client libraries
- Swagger Codegen: Generate server stubs
- API documentation tools: Import specs
- Clear summaries and descriptions
- Include all parameters and responses
- Document error cases
- Provide examples
- Use consistent naming conventions
- Group related endpoints with tags
- Use standard HTTP methods
- Follow REST principles
- Include version in spec:
version: '1.0.0' - Track changes in CHANGELOG
- Update documentation with releases
- Document auth requirements
- Show auth schemes (Bearer, API Key)
- Indicate which endpoints require auth
- Document permission requirements
- Provide realistic examples
- Show error responses
- Include edge cases
- Update examples regularly
- Check file paths in swagger.js
- Ensure JSDoc comments are formatted correctly
- Verify swagger-ui-express is installed
- Check browser console for errors
- Verify JSDoc
@swaggertag - Check path format matches route
- Ensure comment is before function
- Verify HTTP method is correct
- Check schema name matches exactly
- Ensure schema defined in swagger.js
- Use correct reference format:
$ref: '#/components/schemas/Name'
- Verify securitySchemes defined
- Check security field in endpoint
- Ensure token format is correct
- Test token validity
- Lazy Loading: Swagger UI loads on demand
- Minimal Overhead: JSDoc comments in source
- Caching: Spec cached after generation
- CDN: Use CDN for UI assets
- Compression: Enable gzip compression
- Issue #92: Error Logging & Monitoring
- Issue #93: Real-Time Features (WebSocket, Push Notifications)
- Issue #91: Testing Suite
server/
config/
swagger.js - OpenAPI configuration
routes/
documentation.js - Documentation endpoints
swagger-docs/
endpoints.js - Auth, event endpoints
team-and-activities.js - Team, activity endpoints
monitoring-and-admin.js - Monitoring, admin endpoints
package.json - Added swagger packages
BACKEND_INTEGRATION_EXAMPLE_ISSUE94.js
API_DOCUMENTATION_GUIDE.md
PR_CONTENT_ISSUE_94.md
- Swagger UI loads at /api/docs
- ReDoc loads at /api/redoc
- OpenAPI spec downloadable
- 25+ endpoints documented
- Request/response examples included
- Error codes documented
- Authentication requirements shown
- Schemas defined and reusable
- Tags organized logically
- All endpoints have descriptions
- Verify Documentation: Test Swagger UI and ReDoc
- Share with Team: Provide documentation URLs
- API Testing: Use Swagger UI to test endpoints
- Client Generation: Generate client libraries from spec
- Continuous Updates: Keep documentation in sync with code
For questions or issues:
- Check this guide
- Review JSDoc comment examples
- Refer to OpenAPI 3.0 specification
- Check Swagger/OpenAPI documentation
Status: ✅ COMPLETE AND VERIFIED
All acceptance criteria met. API is fully documented and ready for use.