Skip to content

Conversation

@saumya1317
Copy link
Contributor

Description

This PR integrates Swagger/OpenAPI 3.0 documentation for the RBAC API, providing interactive, live documentation accessible at /api-docs. This implementation makes the API easy to explore and use for contributors and frontend developers.

✅ Acceptance Criteria Completed:

  • Installed and configured swagger-jsdoc and swagger-ui-express packages
  • Created dedicated /api-docs route serving interactive Swagger UI
  • Added comprehensive JSDoc comments to all API routes with request bodies, parameters, and responses
  • Documentation is accessible and accurately reflects the API behavior

🎯 What's Included:

Core Implementation:

  • Interactive Swagger UI at http://localhost:5000/api-docs
  • Complete OpenAPI 3.0 specification with schemas for User, Role, and Permission models
  • JWT Bearer authentication integration in Swagger
  • Custom styling for better user experience (hidden topbar, branded title)

API Documentation Coverage:

  • ✅ Authentication endpoints (register, login, forgotPassword, resetPassword)
  • ✅ Role management endpoints (full CRUD + permission assignment)
  • ✅ Permission management endpoints (full CRUD)
  • ✅ RBAC test endpoints (role-based access validation)

Additional Improvements:

  • Fixed critical double password hashing bug that prevented user login
  • Updated documentation to match actual validation requirements (added missing fullname field)
  • All endpoints include request/response examples, validation rules, and error codes

🚀 Features:

  • Interactive "Try it out" functionality for testing endpoints directly in browser
  • Organized API structure with tags (Authentication, Roles, Permissions, RBAC Tests)
  • Complete request/response schemas with validation constraints
  • Security scheme configuration for JWT token testing

Semver Changes

  • Minor (new features, no breaking changes)

Reasoning: Added new /api-docs endpoint and documentation packages without modifying any existing API functionality.


Issues

Closes #[issue-number]

Replace [issue-number] with the actual issue number for Swagger integration


Checklist

  • I have read the Contributing Guidelines
  • My code follows the project's code style (ESLint, Prettier)
  • I have tested the changes locally
  • All acceptance criteria have been met
  • Documentation is accurate and accessible

Testing Performed

✅ Swagger UI loads successfully at /api-docs
✅ All API endpoints are documented and visible
✅ "Try it out" functionality works for all endpoints
✅ JWT authentication integration tested
✅ User registration and login flow verified via Swagger UI
✅ Documentation matches actual API validation schemas


Files Changed

New Files:

  • src/config/swagger.js - Swagger/OpenAPI 3.0 configuration

Modified Files:

  • package.json, package-lock.json - Added swagger dependencies
  • src/app.js - Integrated Swagger UI middleware at /api-docs
  • src/routes/authRoutes.js - Added JSDoc for authentication endpoints
  • src/routes/role.routes.js - Added JSDoc for role management endpoints
  • src/routes/permission.routes.js - Added JSDoc for permission endpoints
  • src/routes/rbacRoutes.js - Added JSDoc for RBAC test endpoints
  • src/services/authService.js - Fixed double password hashing bug

Screenshots

image image
  1. Swagger UI homepage showing all API endpoint groups
  2. Expanded authentication section with all auth endpoints
  3. Example of "Try it out" feature on register endpoint
  4. Successful API response example

Additional Notes

While the acceptance criteria specified JSDoc comments for authentication routes only, I extended the documentation to cover all API endpoints (roles, permissions, RBAC tests) to provide comprehensive documentation that better serves the goal of making the API "easy to explore and use for contributors and frontend developers."

@saumya1317
Copy link
Contributor Author

I've verified that the PR includes documentation for all relevant project routes only:
✅ Authentication routes (/api/auth)
✅ Role management routes (/api/roles)
✅ Permission management routes (/api/permissions)
✅ RBAC test routes (/api/rbac-test)
No unnecessary or fake routes have been included. All documented endpoints match exactly what's implemented in the codebase and registered in app.js. do check @Somilg11

@Somilg11 Somilg11 merged commit f2477b3 into OPCODE-Open-Spring-Fest:main Oct 27, 2025
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants