diff --git a/apps/api-gateway/src/main.ts b/apps/api-gateway/src/main.ts index 67f0d0bb4..0ea946306 100755 --- a/apps/api-gateway/src/main.ts +++ b/apps/api-gateway/src/main.ts @@ -3,6 +3,7 @@ import * as dotenv from 'dotenv'; import * as express from 'express'; import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger'; +import { OpenAPIObject } from '@nestjs/swagger'; import { Logger, VERSION_NEUTRAL, VersioningType } from '@nestjs/common'; import * as cookieParser from 'cookie-parser'; import { AppModule } from './app.module'; @@ -88,15 +89,64 @@ async function bootstrap(): Promise { }); // 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 { + 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)) + ) { + 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' +]); +// 🔹 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 || {};