Skip to content

Issue #92: Backend — Swagger / OpenAPI Setup #245

@wumibals

Description

@wumibals

Labels: good first issue backend documentation setup
Area: backend/src/main.ts
Difficulty: Beginner

Description

The backend needs interactive API documentation so frontend developers and contributors can explore endpoints without reading source code. NestJS integrates with Swagger via @nestjs/swagger to auto-generate this from decorators.

Acceptance Criteria

  • Create backend/src/main.ts as the NestJS application bootstrap file
  • Configure SwaggerModule with a DocumentBuilder that sets:
    • title: "The Lighted API"
    • description: "Restaurant management platform API"
    • version: "1.0"
    • addBearerAuth() for JWT authentication
  • Mount Swagger UI at /api/docs using SwaggerModule.setup("api/docs", app, document)
  • Enable app.enableCors() with origin: process.env.FRONTEND_URL, credentials: true
  • Enable global ValidationPipe with whitelist: true, forbidNonWhitelisted: true, transform: true
  • Enable global ClassSerializerInterceptor to respect @Exclude() decorators on entities
  • App listens on process.env.PORT falling back to 3001
  • Log the listening URL to the console on startup

Technical Notes

  • transform: true on ValidationPipe enables automatic type coercion for query params (strings → numbers)
  • Swagger should only be mounted when NODE_ENV !== "production" to avoid exposing docs in production

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions