Skip to content

Conversation

mukeshdhadhariya
Copy link
Contributor

PR: Add Swagger docs + health, register, and login endpoints

Summary

This PR integrates Swagger (OpenAPI) documentation into the project and implements three basic API endpoints: /health, /register, and /login. The goal is to provide an interactive, discoverable API reference for developers and contributors and to make it easy to explore and test endpoints.

Changes included

  • Integrated swagger-jsdoc and swagger-ui-express to serve OpenAPI docs.
  • Added Swagger/OpenAPI documentation for the following endpoints:
    • GET /health — simple health check endpoint.
    • POST /api/auth/register — user registration (request body + responses documented).
    • POST /api/auth/login — user login (request body + success and error responses documented).
  • Added JSDoc (@openapi) comments above controllers/routes so swagger-jsdoc can auto-generate the spec.
  • Configured src/utils/swagger.js to scan routes and controllers and to expose the OpenAPI definition.
  • Mounted Swagger UI at /api-docs for interactive documentation and testing.
  • Added generation script to produce swagger.json for CI/CD / client generation.

Endpoints (short reference)

GET /health
Returns API health status. 200 with JSON response like { "message": "API is working", "status": 200 }.
POST /api/auth/register
Registers a new user. Request body:
{
  "username": "string",
  "email": "string",
  "fullname": "string",
  "password": "string",
  "role": "optional role id"
}
Responses: 201 (created), 400 (validation/duplicate), 500 (server error).
POST /api/auth/login
Authenticates a user and returns JWT + refresh token. Request body:
{
  "email": "string",
  "password": "string"
}
Responses: 200 (success with token and refreshToken), 400 (missing fields), 401 (invalid credentials).

/api-docs can see all docs Screenshot 2025-10-14 214756 Screenshot 2025-10-14 214743

@mukeshdhadhariya
Copy link
Contributor Author

@Somilg11 review , and i fix this issue #21(hard) and add register route(medium)

@mukeshdhadhariya
Copy link
Contributor Author

image

@Somilg11 review and merge , all swagger end points done with no conflicts
updated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant