Skip to content

Add Swagger API Documentation using swagger-ui-express and swagger-autogen #9

@akash-kumar-dev

Description

@akash-kumar-dev

Summary

Integrate Swagger API documentation into the BrowsePing backend using swagger-ui-express and swagger-autogen, ensuring compatibility with the current codebase.

Details

  • Add API documentation using Swagger UI so that developers can easily browse and test endpoints.
  • Use swagger-autogen for automatic generation of the Swagger JSON documentation from JSDoc/TSDoc comments in the codebase.
  • Expose Swagger UI at a route such as /docs or /api-docs.
  • Ensure minimal refactoring—prioritize compatibility with the existing Express.js/TypeScript application and folder structure.
  • Only generate Swagger documentation JSON locally (do not commit generated JSON to repo).
  • Add generated Swagger files to .gitignore / ensure no docs or generated JSON are pushed.

Implementation Suggestions

  • Install swagger-ui-express and swagger-autogen as devDependencies.
  • Create a standalone script file for documentation generation.
  • Add an npm script (e.g., npm run generate:swagger) to generate the documentation locally.
  • The API docs UI (/docs or /api-docs) should only appear when the Swagger JSON is present and should NOT be exposed in production.
  • Swagger docs must NOT break the server if the docs are not generated or not present.
  • Production server (npm run start) must not require or serve Swagger docs.
  • Add .env variable to control docs UI; default to enabled only for development/local environment.
  • users must generate docs locally; do not add generated files to version control.
  • Follow minimal-change principle—do not refactor existing routes beyond what's necessary for Swagger integration.

SWoC Friendly Guidance

  • Reference open source examples where Swagger docs are optional/local-only.
  • Keep the PR atomic and focused.
  • Confirm that production flow is untouched for users who do not generate docs.
  • Ask for help in Discord if you hit any blockers.

While working on this issue, please adhere to the guidelines outlined in contributing.md. Any pull requests that do not follow these rules will be marked as invalid.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions