-
Notifications
You must be signed in to change notification settings - Fork 82
feat: expose multiple Swagger UI endpoints grouped by modules #1608
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,8 @@ | |
| import * as dotenv from 'dotenv'; | ||
| import * as express from 'express'; | ||
|
|
||
| import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger'; | ||
|
Check warning on line 5 in apps/api-gateway/src/main.ts
|
||
| import { OpenAPIObject } from '@nestjs/swagger'; | ||
|
Check warning on line 6 in apps/api-gateway/src/main.ts
|
||
| import { Logger, VERSION_NEUTRAL, VersioningType } from '@nestjs/common'; | ||
| import * as cookieParser from 'cookie-parser'; | ||
| import { AppModule } from './app.module'; | ||
|
|
@@ -88,15 +89,64 @@ | |
| }); | ||
|
|
||
| // Create Swagger document | ||
| let document = SwaggerModule.createDocument(app, options); | ||
| try { | ||
| const ecosystemFilter = app.get(EcosystemSwaggerFilter); | ||
| document = await ecosystemFilter.filterDocument(document); | ||
| } catch (err) { | ||
| Logger.warn('Skipping EcosystemSwaggerFilter due to error', err as Error); | ||
| let document = SwaggerModule.createDocument(app, options); | ||
| try { | ||
| const ecosystemFilter = app.get(EcosystemSwaggerFilter); | ||
| document = await ecosystemFilter.filterDocument(document); | ||
| } catch (err) { | ||
| Logger.warn('Skipping EcosystemSwaggerFilter due to error', err as Error); | ||
| } | ||
|
|
||
| // 🔹 Helper to filter APIs by tag | ||
|
|
||
|
|
||
| function filterByTags(doc: OpenAPIObject, tagNames: string[]): OpenAPIObject { | ||
|
Check warning on line 103 in apps/api-gateway/src/main.ts
|
||
| const filteredPaths: OpenAPIObject['paths'] = {}; | ||
|
|
||
| for (const [path, methods] of Object.entries(doc.paths)) { | ||
| for (const [method, operation] of Object.entries(methods)) { | ||
| if ( | ||
| operation.tags && | ||
| operation.tags.some((tag: string) => tagNames.includes(tag)) | ||
|
Check warning on line 110 in apps/api-gateway/src/main.ts
|
||
| ) { | ||
| if (!filteredPaths[path]) { | ||
| filteredPaths[path] = {}; | ||
| } | ||
| filteredPaths[path][method] = operation; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| SwaggerModule.setup('api', app, document); | ||
| return { | ||
| ...doc, | ||
| paths: filteredPaths | ||
| }; | ||
| } | ||
| // 🔹 Create separate documents | ||
| const didcommDoc = filterByTags(document, [ | ||
| 'connections', | ||
| 'verifications' | ||
| ]); | ||
|
|
||
| const oid4vcDoc = filterByTags(document, [ | ||
| 'OID4VC', | ||
| 'OID4VP' | ||
| ]); | ||
|
|
||
| const utilsDoc = filterByTags(document, [ | ||
| 'utilities', | ||
| 'ledgers', | ||
| 'webhooks', | ||
| 'geolocation', | ||
| 'notification' | ||
| ]); | ||
|
Comment on lines
+126
to
+142
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 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 The credentials controller (issuance endpoints) uses The 🤖 Prompt for AI Agents |
||
| // 🔹 Default full Swagger | ||
| SwaggerModule.setup('api', app, document); | ||
|
|
||
| // 🔹 New grouped Swagger UIs | ||
| SwaggerModule.setup('api/didcomm', app, didcommDoc); | ||
| SwaggerModule.setup('api/oid4vc', app, oid4vcDoc); | ||
| SwaggerModule.setup('api/utils', app, utilsDoc); | ||
| const httpAdapter: HttpAdapterHost = app.get(HttpAdapterHost) as HttpAdapterHost; | ||
| app.useGlobalFilters(new AllExceptionsFilter(httpAdapter)); | ||
| const { ENABLE_CORS_IP_LIST } = process.env || {}; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.