Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat: swagger api docs#8

Merged
0-sayed merged 6 commits intomainfrom
feat/swagger-api-docs
Mar 3, 2026
Merged

feat: swagger api docs#8
0-sayed merged 6 commits intomainfrom
feat/swagger-api-docs

Conversation

@0-sayed
Copy link
Owner

@0-sayed 0-sayed commented Mar 3, 2026

No description provided.

0-sayed added 4 commits March 3, 2026 04:47
Enable Swagger CLI plugin with introspectComments for automatic DTO
property inference from TypeScript types and JSDoc comments.
Add typed response DTOs for purchases, wallets, and reports endpoints.
Add reusable ApiUserIdHeader decorator combining x-user-id header
and 401 response documentation.
Add @apitags, @apioperation, @ApiParam, @ApiHeader, and error response
decorators to all controllers. Set up SwaggerModule in main.ts gated
behind NODE_ENV !== production, serving UI at /api.
@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces comprehensive API documentation using Swagger for the NestJS application. It sets up the necessary dependencies and configurations to generate interactive API docs, enhancing the discoverability and usability of the API for developers. The changes include adding Swagger to the project, configuring it for automatic DTO inference, and annotating existing and new endpoints with detailed documentation, ensuring a clear and standardized API interface.

Highlights

  • API Documentation Setup: Integrated Swagger API documentation into the NestJS application, making API endpoints discoverable and testable via a web interface.
  • Automated DTO Inference: Configured the @nestjs/swagger CLI plugin to automatically infer DTO schemas, reducing the need for manual @ApiProperty annotations on DTO classes.
  • Endpoint Annotation: Applied Swagger decorators (@ApiTags, @ApiOperation, @ApiHeader, @ApiResponse, etc.) to key controllers (Health, Purchases, Reports, Wallets) to provide detailed API specifications.
  • New Response DTOs: Introduced dedicated DTOs for API responses across various modules to standardize output structures and enhance documentation clarity.
  • Development Environment Access: Enabled Swagger UI to be accessible at the /api endpoint and the OpenAPI JSON spec at /api-json in non-production environments, facilitating development and testing.
  • Custom API Header Decorator: Created a reusable ApiUserIdHeader decorator to simplify the annotation of endpoints requiring the x-user-id header.
Changelog
  • CLAUDE.md
    • Added a new section detailing API Documentation setup and access.
  • nest-cli.json
    • Configured the @nestjs/swagger plugin with introspectComments: true for automatic DTO inference.
  • package.json
    • Added @nestjs/swagger as a new dependency.
  • pnpm-lock.yaml
    • Updated the lockfile to include @nestjs/swagger, @microsoft/tsdoc, @nestjs/mapped-types, swagger-ui-dist, and @scarf/scarf dependencies and their resolutions.
  • src/common/guards/user-id-api.decorator.ts
    • Added a new decorator ApiUserIdHeader to apply ApiHeader and ApiUnauthorizedResponse for the x-user-id header.
  • src/health/health.controller.ts
    • Imported ApiOperation and ApiTags from @nestjs/swagger.
    • Added @ApiTags('health') to the controller.
    • Added @ApiOperation({ summary: 'Health check' }) to the health method.
  • src/main.ts
    • Imported DocumentBuilder and SwaggerModule from @nestjs/swagger.
    • Implemented Swagger setup logic to create and serve API documentation at /api and /api-json in non-production environments.
  • src/purchases/dto/purchase-response.dto.ts
    • Added a new DTO PurchaseResponseDto to define the structure of purchase responses.
  • src/purchases/purchases.controller.ts
    • Imported various API documentation decorators from @nestjs/swagger.
    • Added @ApiTags('purchases') and @ApiUserIdHeader() to the controller.
    • Annotated the purchase method with @ApiOperation, @ApiHeader, and multiple response decorators (ApiBadRequestResponse, ApiResponse, ApiForbiddenResponse, ApiNotFoundResponse, ApiConflictResponse).
    • Updated the return type of the purchase method to Promise<PurchaseResponseDto>.
  • src/reports/dto/report-request-response.dto.ts
    • Added a new DTO ReportRequestResponseDto to define the structure for report request responses.
  • src/reports/dto/report-response.dto.ts
    • Added a new DTO ReportResponseDto extending ReportRequestResponseDto to include report results.
  • src/reports/reports.controller.ts
    • Imported various API documentation decorators from @nestjs/swagger.
    • Added @ApiTags('reports') and @ApiUserIdHeader() to the controller.
    • Annotated the requestReport method with @ApiOperation, ApiCreatedResponse, and ApiBadRequestResponse.
    • Updated the return type of requestReport to Promise<ReportRequestResponseDto>.
    • Annotated the getReport method with @ApiOperation, @ApiParam, and ApiNotFoundResponse.
    • Updated the return type of getReport to Promise<ReportResponseDto>.
  • src/wallets/dto/wallet-response.dto.ts
    • Added a new DTO WalletResponseDto to define the structure of wallet responses.
  • src/wallets/wallets.controller.ts
    • Imported various API documentation decorators from @nestjs/swagger.
    • Added @ApiTags('wallets') and @ApiUserIdHeader() to the controller.
    • Annotated the deposit method with @ApiOperation, @ApiParam, ApiBadRequestResponse, and ApiNotFoundResponse.
    • Updated the return type of the deposit method to Promise<WalletResponseDto>.
Activity
  • No human activity has been recorded on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@0-sayed
Copy link
Owner Author

0-sayed commented Mar 3, 2026

@coderabbitai review
@greptileai review
@gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces Swagger API documentation for the existing endpoints, which is a great addition for developer experience. The implementation is solid, using @nestjs/swagger with its CLI plugin for DTO inference and providing detailed decorators for operations, parameters, and responses. The documentation is also correctly guarded to not be exposed in production environments. I've added a few suggestions to leverage NestJS's built-in validation pipes for cleaner code and to improve consistency in how user IDs are accessed where appropriate, while ensuring alignment with the project's architectural decisions.

@coderabbitai
Copy link

coderabbitai bot commented Mar 3, 2026

@0-sayed, I'll review the changes in this PR for you.

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces Swagger API documentation for the application, which is a great addition for developers. The setup is well-implemented, including enabling it only for non-production environments and using the NestJS Swagger plugin for DTO introspection. My review includes a suggestion to improve maintainability by dynamically setting the API version. Additionally, for the wallets controller, I've suggested standardizing how the userId is retrieved, which aligns with our POC guidelines for temporary authentication mechanisms.

@coderabbitai
Copy link

coderabbitai bot commented Mar 3, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1cc1a7f and 93c86b4.

📒 Files selected for processing (3)
  • CLAUDE.md
  • src/main.ts
  • src/purchases/purchases.controller.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • CLAUDE.md

Walkthrough

Adds Swagger/OpenAPI support: new dependency @nestjs/swagger, a compiler plugin in nest-cli.json, and conditional SwaggerModule setup in main.ts (mounted at /api when enabled). Introduces DTOs for purchases, reports, and wallets; updates controllers with @ApiTags, @ApiOperation and response decorators; adds a reusable ApiUserIdHeader decorator for the X-User-Id header; and annotates several controller methods with explicit DTO return types.

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning No description was provided by the author; the pull request is missing a description section entirely. Add a pull request description explaining the motivation, implementation approach, and any relevant context for the Swagger API documentation changes.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding Swagger API documentation support to the project.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/swagger-api-docs

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/main.ts`:
- Around line 18-28: Current check uses NODE_ENV !== 'production' to gate
Swagger which can enable docs if NODE_ENV is missing; change the guard to an
explicit opt-in flag (e.g., process.env.SWAGGER_ENABLED === 'true') before
calling DocumentBuilder, SwaggerModule.createDocument(app, config) and
SwaggerModule.setup('api', app, document); update the condition where
DocumentBuilder, createDocument and setup are invoked (references:
DocumentBuilder, SwaggerModule.createDocument, SwaggerModule.setup,
process.env.NODE_ENV, app) so Swagger is only mounted when the explicit
env/config flag is true (default false).

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ae23763 and 1cc1a7f.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (13)
  • CLAUDE.md
  • nest-cli.json
  • package.json
  • src/common/guards/user-id-api.decorator.ts
  • src/health/health.controller.ts
  • src/main.ts
  • src/purchases/dto/purchase-response.dto.ts
  • src/purchases/purchases.controller.ts
  • src/reports/dto/report-request-response.dto.ts
  • src/reports/dto/report-response.dto.ts
  • src/reports/reports.controller.ts
  • src/wallets/dto/wallet-response.dto.ts
  • src/wallets/wallets.controller.ts

@coderabbitai
Copy link

coderabbitai bot commented Mar 3, 2026

Walkthrough

This pull request integrates Swagger/OpenAPI documentation into a NestJS application. Changes include adding the @nestjs/swagger package dependency, configuring the Swagger plugin in nest-cli.json, creating new Data Transfer Objects (PurchaseResponseDto, WalletResponseDto, ReportRequestResponseDto, ReportResponseDto), applying Swagger decorators to controller classes and methods, and initializing Swagger UI at the /api endpoint for non-production environments. The ApiUserIdHeader decorator factory was introduced to standardize x-user-id header documentation across endpoints.

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning No pull request description was provided by the author, making it impossible to assess relatedness to the changeset. Add a description explaining the Swagger integration changes, new DTOs, decorators, and configuration updates to help reviewers understand the motivation and scope.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat: swagger api docs' directly and clearly describes the main change: adding Swagger/OpenAPI documentation integration to the API.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/swagger-api-docs

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (1)
src/main.ts (1)

18-28: ⚠️ Potential issue | 🟠 Major

Harden Swagger exposure to explicit opt-in.

At Line 18, NODE_ENV !== 'production' enables docs when NODE_ENV is missing/mis-set, which can expose /api and /api-json unintentionally in production deployments.

Suggested hardening
-  if (process.env.NODE_ENV !== 'production') {
+  const enableSwagger = process.env.SWAGGER_ENABLED === 'true';
+  if (enableSwagger) {
     const config = new DocumentBuilder()
       .setTitle('Wallet API')
       .setDescription(
         'Digital wallet POC — deposits, purchases, royalties, reports',
       )
       .setVersion('0.0.1')
       .build();
     const document = SwaggerModule.createDocument(app, config);
     SwaggerModule.setup('api', app, document);
   }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main.ts` around lines 18 - 28, Current check uses process.env.NODE_ENV
!== 'production' which enables Swagger when NODE_ENV is missing; change the
guard to require an explicit opt-in flag (e.g., process.env.SWAGGER_ENABLED ===
'true' or a dedicated config flag) before creating the DocumentBuilder and
calling SwaggerModule.createDocument/SwaggerModule.setup (references:
DocumentBuilder, SwaggerModule.createDocument, SwaggerModule.setup, app); update
the conditional to only run the Swagger setup when the explicit opt-in variable
is set (optionally keep an additional safeguard checking NODE_ENV ===
'development' but do not rely on NODE_ENV alone).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/purchases/purchases.controller.ts`:
- Around line 53-57: The purchase controller is reading x-user-id from headers
instead of using the guard-populated identity; change the purchase method
signature to accept the request object (e.g. `@Req`() req: Request & { userId:
string }) instead of `@Headers`('x-user-id') and use req.userId when calling the
service (the call in purchase that currently uses the header value should be
passed req.userId); ensure UserIdGuard remains applied and remove the raw header
parameter to keep a single trusted source of userId consistent with other
controllers.

---

Duplicate comments:
In `@src/main.ts`:
- Around line 18-28: Current check uses process.env.NODE_ENV !== 'production'
which enables Swagger when NODE_ENV is missing; change the guard to require an
explicit opt-in flag (e.g., process.env.SWAGGER_ENABLED === 'true' or a
dedicated config flag) before creating the DocumentBuilder and calling
SwaggerModule.createDocument/SwaggerModule.setup (references: DocumentBuilder,
SwaggerModule.createDocument, SwaggerModule.setup, app); update the conditional
to only run the Swagger setup when the explicit opt-in variable is set
(optionally keep an additional safeguard checking NODE_ENV === 'development' but
do not rely on NODE_ENV alone).

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ae23763 and 1cc1a7f.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (13)
  • CLAUDE.md
  • nest-cli.json
  • package.json
  • src/common/guards/user-id-api.decorator.ts
  • src/health/health.controller.ts
  • src/main.ts
  • src/purchases/dto/purchase-response.dto.ts
  • src/purchases/purchases.controller.ts
  • src/reports/dto/report-request-response.dto.ts
  • src/reports/dto/report-response.dto.ts
  • src/reports/reports.controller.ts
  • src/wallets/dto/wallet-response.dto.ts
  • src/wallets/wallets.controller.ts

0-sayed added 2 commits March 3, 2026 05:16
- Replace NODE_ENV negation with explicit SWAGGER_ENABLED opt-in
- Use guard-validated req.userId instead of raw x-user-id header
@idris-builds
Copy link
Collaborator

@coderabbitai review
@greptileai review
@gemini review

@coderabbitai
Copy link

coderabbitai bot commented Mar 3, 2026

@idris-builds, I'll review the changes in this PR for you.

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces Swagger API documentation, which is a great addition for improving the API's discoverability and developer experience. The implementation is solid, including adding the necessary dependencies, configuring Swagger, creating response DTOs, and annotating controller endpoints. I've included a couple of suggestions: one to further improve type safety in a DTO, and another to enhance code clarity in user-specific controllers by using a custom parameter decorator.

@0-sayed 0-sayed merged commit 327415c into main Mar 3, 2026
7 checks passed
@0-sayed 0-sayed deleted the feat/swagger-api-docs branch March 3, 2026 03:29
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.

2 participants