Skip to content

Add Swagger documentation setup and update route parameters in controllers#289

Open
Akshat-Kalra wants to merge 5 commits intoubco-db:mainfrom
Akshat-Kalra:akshat/swagger2
Open

Add Swagger documentation setup and update route parameters in controllers#289
Akshat-Kalra wants to merge 5 commits intoubco-db:mainfrom
Akshat-Kalra:akshat/swagger2

Conversation

@Akshat-Kalra
Copy link
Collaborator

Description

Added Swagger UI integration only in development mode.

Will be available at port 3002 only in development mode.
image

Also updated the optional route parameters in some of the endpoints, /:param? is not supported anymore by path-to-regexp, changed all such instances to {/:param}. Referring to the documentation here: https://github.com/pillarjs/path-to-regexp

Closes # (issue number): none

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update
  • This requires a run of yarn install
  • This change requires an addition/change to the production .env variables. These changes are below:
  • This change requires developers to add new .env variables. The file and variables needed are below:
  • This change requires a database query to update old data on production. This query is below:

How Has This Been Tested?

Ran yarn test to check if the endpoints are still working correctly after the parameter change.

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code where needed
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any work that this PR is dependent on has been merged into the main branch
  • Any UI changes have been checked to work on desktop, tablet, and mobile

@Akshat-Kalra Akshat-Kalra requested a review from AdamFipke May 28, 2025 23:45
@Akshat-Kalra Akshat-Kalra self-assigned this May 28, 2025
@Akshat-Kalra Akshat-Kalra requested a review from Copilot May 29, 2025 01:41
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR integrates Swagger UI for API documentation in development mode and refactors several controller routes to replace unsupported optional path parameters (:param?) with query parameters.

  • Add SwaggerModule setup guarded by NODE_ENV === 'development'
  • Update route decorators in organization and course controllers to use @Query instead of optional :param?
  • Add @nestjs/swagger dependency in package.json

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

File Description
packages/server/src/organization/organization.controller.ts Converted :page? path params to @Query('page')
packages/server/src/course/course.controller.ts Made role a query param instead of optional path segment
packages/server/src/bootstrap.ts Imported SwaggerModule, built DocumentBuilder, and set up UI
packages/server/package.json Added @nestjs/swagger dependency
Comments suppressed due to low confidence (1)

packages/server/src/bootstrap.ts:66

  • [nitpick] The cats tag may be confusing—consider renaming it to match actual API domains (e.g., organizations, courses, etc.) for clarity in the Swagger UI.
.addTag('cats')

Akshat-Kalra and others added 3 commits May 28, 2025 19:28
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…eter from GET /organization/:oid/get_users and GET /organization/:oid/get_courses routes
.addTag('cats')
.build();
const document = SwaggerModule.createDocument(app, config);
if (process.env.NODE_ENV === 'development') {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would use the !isProd() helper for this since iirc something weird is set up with production's setup but isProd() is known to work

Copy link
Collaborator

@AdamFipke AdamFipke May 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also I guess I would wrap all of these new lines of code in the same if statement block, just so that no parts of swagger load in proud just an extra precaution, even though it probably doesn't matter

Comment on lines +1454 to 1462
@Get(':oid/get_users')
@UseGuards(JwtAuthGuard, OrganizationRolesGuard, EmailVerifiedGuard)
@Roles(OrganizationRole.ADMIN)
async getUsers(
@Param('oid', ParseIntPipe) oid: number,
@Param('page', ParseIntPipe) page: number,
@Query('page', new DefaultValuePipe(1), ParseIntPipe) page: number,
@Query('search') search: string,
): Promise<OrgUser[]> {
const pageSize = 50;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this new query syntax for some reason seems to be breaking the tests, I am not sure why but I would maybe try manually testing the endpoint first by opening localhost:3000/organization/users and seeing if the users load up

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I even tried the way listed on the path-to-regexp github, using this {/:param} for optionals

Copy link
Collaborator

@AdamFipke AdamFipke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see comments, sorry for taking a bit longer to get around to reviewing it

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.

3 participants