This project uses Swagger UI for API documentation. The documentation is automatically generated from JSDoc comments in your route files.
Once the server is running, you can access the API documentation at:
http://localhost:5000/api-docs
Add JSDoc comments above your route handlers using the @swagger tag:
/**
* @swagger
* /api/users:
* get:
* summary: Get all users
* tags: [Users]
* responses:
* 200:
* description: List of users retrieved successfully
* content:
* application/json:
* schema:
* type: object
* properties:
* success:
* type: boolean
* data:
* type: array
* items:
* $ref: '#/components/schemas/User'
*/
router.get("/", asyncHandler(async (req, res) => {
// Your route logic here
}));Schemas are defined in the swaggerConfig.js file under the components.schemas section. You can add new schemas there or reference them in your JSDoc comments.
User: Complete user object with all propertiesUserInput: Input schema for creating users
- Main Swagger configuration
- Defines schemas and API options
- Sets up Swagger UI with custom styling
- Example route file with JSDoc comments
- Shows how to document different HTTP methods
- Includes request/response schemas
- ✅ Automatic documentation generation from JSDoc comments
- ✅ Interactive API testing interface
- ✅ Custom styling and branding
- ✅ Schema validation and examples
- ✅ Error handling and logging
- Create your route file in
src/routes/ - Add JSDoc comments above each route handler
- Import and use the route in
app.js - The documentation will be automatically updated
- Make sure JSDoc comments are properly formatted
- Check that route files are included in the
apisarray inswaggerConfig.js - Verify that the server is running on the correct port
- Check console logs for any Swagger setup errors
/**
* @swagger
* /api/endpoint:
* method:
* summary: Brief description
* tags: [TagName]
* parameters:
* - in: path/query/header
* name: paramName
* required: true/false
* schema:
* type: string/number/boolean
* requestBody:
* required: true/false
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/SchemaName'
* responses:
* 200:
* description: Success response
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/ResponseSchema'
*/