Skip to content

feat: expose multiple Swagger UI endpoints grouped by modules#1608

Open
vaishnavijha12 wants to merge 3 commits into
credebl:mainfrom
vaishnavijha12:feat/multiple-swagger-ui
Open

feat: expose multiple Swagger UI endpoints grouped by modules#1608
vaishnavijha12 wants to merge 3 commits into
credebl:mainfrom
vaishnavijha12:feat/multiple-swagger-ui

Conversation

@vaishnavijha12
Copy link
Copy Markdown

@vaishnavijha12 vaishnavijha12 commented Apr 26, 2026

Summary

This PR introduces multiple Swagger UI endpoints grouped by feature/domain to improve API discoverability and developer experience.

Changes

  • Added tag-based filtering utility to split Swagger document
  • Exposed new endpoints:
    • /api/didcomm
    • /api/oid4vc
    • /api/utils
  • Preserved existing /api endpoint for backward compatibility

Notes

  • Grouping is based on existing module tags (connection, issuance, verification, oid4vc, utility, etc.)
  • This improves navigation and reduces clutter in API documentation

Summary by CodeRabbit

  • New Features
    • API Gateway Swagger documentation is now split across multiple specialized endpoints: the full API remains at /api, with additional focused docs at /api/didcomm, /api/oid4vc, and /api/utils to surface DID Communication, OID4VC verification, and utility operations for easier discovery.

Added a helper function to filter APIs by tags and created separate Swagger documents for different API groups.

Signed-off-by: Kumari Vaishnavi <145796948+vaishnavijha12@users.noreply.github.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 26, 2026

Warning

Rate limit exceeded

@vaishnavijha12 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 49 minutes and 5 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 49 minutes and 5 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 7d529743-677d-46c5-b111-5f2d34e3d8b3

📥 Commits

Reviewing files that changed from the base of the PR and between 6ae310a and cc22166.

📒 Files selected for processing (1)
  • apps/api-gateway/src/main.ts
📝 Walkthrough

Walkthrough

The Swagger initialization in the API gateway bootstrap now builds multiple filtered OpenAPI documents (by operation tags) and registers three additional Swagger UI endpoints (/api/didcomm, /api/oid4vc, /api/utils) while preserving the original unfiltered UI at /api.

Changes

Cohort / File(s) Summary
Multiple Swagger UI Initialization
apps/api-gateway/src/main.ts
Extends Swagger setup to create filtered OpenAPI documents via a filterByTags() helper and registers three new Swagger UI endpoints (/api/didcomm, /api/oid4vc, /api/utils) in addition to the original /api.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant App as API Gateway (bootstrap)
    participant Swagger as SwaggerModule
    participant Filter as EcosystemSwaggerFilter
    participant UI as Swagger UI endpoints

    Client->>App: Start application
    App->>Swagger: createDocument(app, options)
    Swagger->>Filter: EcosystemSwaggerFilter.filterDocument(doc)
    Filter-->>Swagger: filteredDoc
    App->>App: filterByTags(filteredDoc) -> didcommDoc/oid4vcDoc/utilsDoc
    App->>UI: setup('/api', originalDoc)
    App->>UI: setup('/api/didcomm', didcommDoc)
    App->>UI: setup('/api/oid4vc', oid4vcDoc)
    App->>UI: setup('/api/utils', utilsDoc)
    Client->>UI: Request /api or /api/* => corresponding UI served
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related issues

Poem

🥕 I hopped through docs with glee tonight,

Split the spec by tags so each path shines bright,
DID and OID, utils on parade,
Three little UIs in a swaggering glade,
— from your rabbit reviewer, cheers and bite!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: introducing multiple Swagger UI endpoints grouped by modules, which aligns with the core functionality of tag-based filtering and exposing new Swagger documentation endpoints.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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
Copy Markdown

@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

🧹 Nitpick comments (2)
apps/api-gateway/src/main.ts (2)

99-141: Consider extracting Swagger filtering into its own module.

This logic sits alongside EcosystemSwaggerFilter conceptually but lives inline in bootstrap(). Moving filterByTags (and the tag-group constants) into something like apps/api-gateway/src/swagger/swagger-grouping.ts would keep main.ts focused on app wiring, make the groups unit-testable, and mirror the structure already used for EcosystemSwaggerFilter. Not blocking — purely organizational.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/api-gateway/src/main.ts` around lines 99 - 141, Extract the inline
filterByTags function and the tag group arrays (used to produce didcommDoc,
oid4vcDoc, utilsDoc) into a new module (e.g., swagger-grouping.ts) that exports
filterByTags and the tag group constants, then import them into main.ts and
replace the inline definitions with calls like const didcommDoc =
filterByTags(document, DIDCOMM_TAGS) and the other two; ensure the new module
exports are typed, the function signature remains filterByTags(doc: any,
tagNames: string[]), and update usages around SwaggerModule.setup('api/didcomm',
app, didcommDoc) etc. so main.ts only wires the app and calls
SwaggerModule.setup with the precomputed docs.

100-123: Tighten types and iteration in filterByTags.

ESLint flags valid issues here: any parameters and locals discard the available OpenAPIObject type, the function lacks an explicit return type, and the for…in loops iterate inherited keys. Switching to typed iteration also makes the intent clearer and improves performance.

♻️ Proposed typed rewrite
-// 🔹 Helper to filter APIs by tag
-function filterByTags(doc: any, tagNames: string[]) {
-  const filteredPaths: any = {};
-
-  for (const path in doc.paths) {
-    const methods = doc.paths[path];
-
-    for (const method in methods) {
-      const operation = methods[method];
-
-      if (
-        operation.tags &&
-        operation.tags.some((tag: string) => tagNames.includes(tag))
-      ) {
-        if (!filteredPaths[path]) filteredPaths[path] = {};
-        filteredPaths[path][method] = operation;
-      }
-    }
-  }
-
-  return {
-    ...doc,
-    paths: filteredPaths
-  };
-}
+// 🔹 Helper to filter APIs by tag
+function filterByTags(doc: OpenAPIObject, tagNames: readonly string[]): OpenAPIObject {
+  const wanted = new Set(tagNames);
+  const filteredPaths: OpenAPIObject['paths'] = {};
+
+  for (const [path, methods] of Object.entries(doc.paths ?? {})) {
+    for (const [method, operation] of Object.entries(methods as Record<string, { tags?: string[] }>)) {
+      if (operation?.tags?.some((tag) => wanted.has(tag))) {
+        (filteredPaths[path] ??= {} as never)[method] = operation as never;
+      }
+    }
+  }
+
+  return { ...doc, paths: filteredPaths };
+}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/api-gateway/src/main.ts` around lines 100 - 123, The function
filterByTags should use OpenAPI types and avoid for...in over inherited keys:
change the signature to accept doc: OpenAPIObject and return OpenAPIObject,
declare filteredPaths with the specific paths type (e.g., OpenAPIObject['paths']
or Record<string, PathItemObject | undefined>), iterate only own keys using
Object.keys(doc.paths || {}) and Object.keys(methods) (or Object.entries)
instead of for...in, and narrow operation types to OperationObject when checking
operation.tags; finally, construct and return a new OpenAPIObject with the
filtered paths. Use appropriate imports for
OpenAPIObject/PathItemObject/OperationObject to replace any usages.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@apps/api-gateway/src/main.ts`:
- Around line 125-133: The tag filters passed to filterByTags are using outdated
literals so the grouped docs are empty; update the arrays used when creating
didcommDoc, oid4vcDoc, and utilsDoc to match real `@ApiTags` in the repo: replace
didcommDoc's ['connection','issuance','verification'] with the intended tags
such as ['connections','OID4VC','verifications']; replace oid4vcDoc's
['oid4vc-issuance','oid4vc-verification'] with ['OID4VC','OID4VP']; and replace
utilsDoc's ['utility','ledger','webhook','geo-location','notification'] with
['utilities','ledgers','webhooks','geolocation','notification'] so filterByTags
(the call sites named didcommDoc, oid4vcDoc, utilsDoc) will actually match the
controllers.

---

Nitpick comments:
In `@apps/api-gateway/src/main.ts`:
- Around line 99-141: Extract the inline filterByTags function and the tag group
arrays (used to produce didcommDoc, oid4vcDoc, utilsDoc) into a new module
(e.g., swagger-grouping.ts) that exports filterByTags and the tag group
constants, then import them into main.ts and replace the inline definitions with
calls like const didcommDoc = filterByTags(document, DIDCOMM_TAGS) and the other
two; ensure the new module exports are typed, the function signature remains
filterByTags(doc: any, tagNames: string[]), and update usages around
SwaggerModule.setup('api/didcomm', app, didcommDoc) etc. so main.ts only wires
the app and calls SwaggerModule.setup with the precomputed docs.
- Around line 100-123: The function filterByTags should use OpenAPI types and
avoid for...in over inherited keys: change the signature to accept doc:
OpenAPIObject and return OpenAPIObject, declare filteredPaths with the specific
paths type (e.g., OpenAPIObject['paths'] or Record<string, PathItemObject |
undefined>), iterate only own keys using Object.keys(doc.paths || {}) and
Object.keys(methods) (or Object.entries) instead of for...in, and narrow
operation types to OperationObject when checking operation.tags; finally,
construct and return a new OpenAPIObject with the filtered paths. Use
appropriate imports for OpenAPIObject/PathItemObject/OperationObject to replace
any usages.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e7de5f89-7c71-4fd4-a890-434451f09b46

📥 Commits

Reviewing files that changed from the base of the PR and between 879dfbb and 1f27c93.

📒 Files selected for processing (1)
  • apps/api-gateway/src/main.ts

Comment thread apps/api-gateway/src/main.ts Outdated
Signed-off-by: Kumari Vaishnavi <145796948+vaishnavijha12@users.noreply.github.com>
Copy link
Copy Markdown

@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: 2

🧹 Nitpick comments (1)
apps/api-gateway/src/main.ts (1)

91-148: Indentation regression inside bootstrap().

Lines 92–148 are flush-left while the surrounding function body uses 2-space indentation (see lines 70–88 and 149+). This is purely cosmetic but will likely trip Prettier/ESLint formatting checks and clutters the diff.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/api-gateway/src/main.ts` around lines 91 - 148, Re-indent the Swagger
setup block inside bootstrap() to match the file's 2-space indentation style:
align the try/catch that gets EcosystemSwaggerFilter, the filterByTags function,
the creation of didcommDoc/oid4vcDoc/utilsDoc, and the SwaggerModule.setup(...)
calls so they are nested with the surrounding function body; specifically adjust
indentation for the symbols filterByTags, ecosystemFilter
(EcosystemSwaggerFilter try/catch), didcommDoc, oid4vcDoc, utilsDoc, and the
SwaggerModule.setup lines to remove the left-justified regression and satisfy
Prettier/ESLint.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@apps/api-gateway/src/main.ts`:
- Around line 125-141: Update the didcommDoc filter to include the 'credentials'
tag so the issuance controller endpoints (tagged with `@ApiTags`('credentials'))
are included under didcomm routes: modify the array passed to filterByTags for
the didcommDoc constant (where didcommDoc is defined) to add 'credentials'
alongside 'connections' and 'verifications', leaving other filters (e.g.,
utilsDoc and oid4vcDoc) unchanged.
- Around line 99-123: The filterByTags function currently uses any and for...in
loops; change its signature to accept doc: OpenAPIObject and add an explicit
return type (OpenAPIObject), import OpenAPIObject from `@nestjs/swagger`, replace
the any filteredPaths with a properly typed variable (e.g., Record<string,
Record<string, any>> or Partial<OpenAPIObject['paths']>), iterate using
Object.entries(doc.paths) and Object.entries(methods) instead of for...in, and
ensure all single-line ifs (e.g., creating filteredPaths[path]) use braces;
return a new OpenAPIObject with the filtered paths.

---

Nitpick comments:
In `@apps/api-gateway/src/main.ts`:
- Around line 91-148: Re-indent the Swagger setup block inside bootstrap() to
match the file's 2-space indentation style: align the try/catch that gets
EcosystemSwaggerFilter, the filterByTags function, the creation of
didcommDoc/oid4vcDoc/utilsDoc, and the SwaggerModule.setup(...) calls so they
are nested with the surrounding function body; specifically adjust indentation
for the symbols filterByTags, ecosystemFilter (EcosystemSwaggerFilter
try/catch), didcommDoc, oid4vcDoc, utilsDoc, and the SwaggerModule.setup lines
to remove the left-justified regression and satisfy Prettier/ESLint.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: fee99bf0-41cd-4b36-aed8-d83e9303491e

📥 Commits

Reviewing files that changed from the base of the PR and between 1f27c93 and 6ae310a.

📒 Files selected for processing (1)
  • apps/api-gateway/src/main.ts

Comment thread apps/api-gateway/src/main.ts
Comment on lines +125 to +141
const didcommDoc = filterByTags(document, [
'connections',
'verifications'
]);

const oid4vcDoc = filterByTags(document, [
'OID4VC',
'OID4VP'
]);

const utilsDoc = filterByTags(document, [
'utilities',
'ledgers',
'webhooks',
'geolocation',
'notification'
]);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Enumerate all distinct `@ApiTags` values to verify the literals used in main.ts.
echo "=== Distinct `@ApiTags` values across the repo ==="
rg -nP "@ApiTags\(\s*['\"\`]([^'\"\`]+)['\"\`]" -r '$1' --type=ts -o --no-filename \
  | sort -u

echo
echo "=== Issuance-related controllers & their tags ==="
rg -nP --type=ts -C2 "@ApiTags\([^)]*[Ii]ssuance[^)]*\)"

echo
echo "=== Notification controller(s) & their tags ==="
fd -t f -e ts notification | xargs -I{} rg -nP "@ApiTags\(" {} 2>/dev/null

Repository: credebl/platform

Length of output: 789


🏁 Script executed:

# Find the credentials controller and see what endpoints it covers
rg -l "@ApiTags\('credentials'\)" --type=ts

# Also check the context around the credentials tag
rg -B5 -A20 "@ApiTags\('credentials'\)" --type=ts | head -80

Repository: credebl/platform

Length of output: 2580


🏁 Script executed:

# Show the exact lines in main.ts around the didcommDoc filter
sed -n '125,141p' apps/api-gateway/src/main.ts

Repository: credebl/platform

Length of output: 337


Add 'credentials' tag to didcommDoc filter.

The credentials controller (issuance endpoints) uses @ApiTags('credentials'), not 'issuance'. Credential issuance is a core DIDComm capability, yet the didcommDoc filter currently only covers 'connections' and 'verifications'. The 'credentials' tag must be included so that issuance endpoints appear under /api/didcomm.

The 'notification' tag is correctly singular and matches the actual controller tag.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/api-gateway/src/main.ts` around lines 125 - 141, Update the didcommDoc
filter to include the 'credentials' tag so the issuance controller endpoints
(tagged with `@ApiTags`('credentials')) are included under didcomm routes: modify
the array passed to filterByTags for the didcommDoc constant (where didcommDoc
is defined) to add 'credentials' alongside 'connections' and 'verifications',
leaving other filters (e.g., utilsDoc and oid4vcDoc) unchanged.

@vaishnavijha12
Copy link
Copy Markdown
Author

Hi @RinkalBhojani
I’ve addressed the feedback regarding Swagger tag grouping and updated the implementation accordingly.

Could you please review the PR when you get a chance?
Thanks!

Signed-off-by: Kumari Vaishnavi <145796948+vaishnavijha12@users.noreply.github.com>
@sonarqubecloud
Copy link
Copy Markdown

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.

1 participant