This project includes comprehensive OpenAPI 3.0 documentation powered by express-jsdoc-swagger.
API documentation is only available in development mode for security and performance reasons. The documentation endpoints are completely disabled in production.
- URL:
http://localhost:3000/api-docs - Available: Development mode only (
NODE_ENV=development) - Features: Interactive API testing, request/response examples, schema validation
- URL:
http://localhost:3000/v3/api-docs - Format: JSON
- Available: Development mode only (
NODE_ENV=development) - Use: For integration with API clients, testing tools, or documentation generators
In production mode (NODE_ENV=production), both /api-docs and /v3/api-docs will return 404 Not Found.
-
Start the development server:
npm run dev
-
Access API Documentation:
- Open your browser and navigate to
http://localhost:3000/api-docs - You'll see interactive API documentation with all available endpoints
- Open your browser and navigate to
-
Test the API:
- Use the Swagger UI to make API calls directly from your browser
- Authenticate using Google OAuth or test public endpoints
GET /api/auth/session- Get current user sessionPOST /api/auth/signout- Sign out current user- Better Auth endpoints (Google OAuth, email/password, etc.)
GET /api/users- Get all users (with pagination and filtering)GET /api/users/me- Get current user profileGET /api/users/:id- Get user by IDPUT /api/users/:id- Update user by IDDELETE /api/users/:id- Delete user by ID
GET /health- Health check endpointGET /api- API information and available endpoints
The API supports multiple authentication methods:
- Interactive authentication via Google
- Configured in
src/config/auth.ts
- Automatic session management by Better Auth
- Bearer token authentication for API requests
- Input validation using Joi schemas
- Automatic error responses for invalid requests
- Type-safe request/response handling
- Consistent error response format
- Proper HTTP status codes
- Detailed error messages
- Users endpoint supports pagination
- Filter by role, status, search terms
- Sortable results
-
Define the route in your route file
-
Add JSDoc comments following the existing pattern:
/** * POST /api/endpoint * @summary Brief description of the endpoint * @tags CategoryName * @security BearerAuth * @param {number} id.path.required - Description * @param {CreateRequest} request.body.required - Description * @return {SuccessResponse<ResponseData>} 200 - Success description * @return {ErrorResponse} 400 - Error description */
-
Update types in
src/types/api.tsif needed -
Test the documentation by restarting the server
Edit the configuration in src/config/swagger.ts:
- API information (title, description, version)
- Security schemes
- Server URLs
- Swagger UI styling
For production environments:
- Update server URLs in
swaggerOptions.servers - Ensure security schemes are properly configured
- Consider restricting access to documentation endpoints if needed
- Set up proper CORS configuration for the Swagger UI
- Ensure the server is running with
npm run dev - Check that
express-jsdoc-swaggeris properly installed - Verify file paths in
swaggerOptions.filesPattern
- Check JSDoc comments for proper syntax
- Ensure type definitions exist in
src/types/api.ts - Verify parameter types match actual route handlers
- Verify Better Auth configuration
- Check environment variables for OAuth setup
- Ensure security schemes are properly defined