feat: expose multiple Swagger UI endpoints grouped by modules#1608
feat: expose multiple Swagger UI endpoints grouped by modules#1608vaishnavijha12 wants to merge 3 commits into
Conversation
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>
|
Warning Rate limit exceeded
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 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 configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe Swagger initialization in the API gateway bootstrap now builds multiple filtered OpenAPI documents (by operation tags) and registers three additional Swagger UI endpoints ( Changes
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly related issues
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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
EcosystemSwaggerFilterconceptually but lives inline inbootstrap(). MovingfilterByTags(and the tag-group constants) into something likeapps/api-gateway/src/swagger/swagger-grouping.tswould keepmain.tsfocused on app wiring, make the groups unit-testable, and mirror the structure already used forEcosystemSwaggerFilter. 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 infilterByTags.ESLint flags valid issues here:
anyparameters and locals discard the availableOpenAPIObjecttype, the function lacks an explicit return type, and thefor…inloops 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
📒 Files selected for processing (1)
apps/api-gateway/src/main.ts
Signed-off-by: Kumari Vaishnavi <145796948+vaishnavijha12@users.noreply.github.com>
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
apps/api-gateway/src/main.ts (1)
91-148: Indentation regression insidebootstrap().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
📒 Files selected for processing (1)
apps/api-gateway/src/main.ts
| const didcommDoc = filterByTags(document, [ | ||
| 'connections', | ||
| 'verifications' | ||
| ]); | ||
|
|
||
| const oid4vcDoc = filterByTags(document, [ | ||
| 'OID4VC', | ||
| 'OID4VP' | ||
| ]); | ||
|
|
||
| const utilsDoc = filterByTags(document, [ | ||
| 'utilities', | ||
| 'ledgers', | ||
| 'webhooks', | ||
| 'geolocation', | ||
| 'notification' | ||
| ]); |
There was a problem hiding this comment.
🧩 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/nullRepository: 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 -80Repository: 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.tsRepository: 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.
|
Hi @RinkalBhojani Could you please review the PR when you get a chance? |
Signed-off-by: Kumari Vaishnavi <145796948+vaishnavijha12@users.noreply.github.com>
|



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