diff --git a/apps/armory/src/main.ts b/apps/armory/src/main.ts index 4cbfd111a..20c966ed8 100644 --- a/apps/armory/src/main.ts +++ b/apps/armory/src/main.ts @@ -1,8 +1,7 @@ +import { withSwagger } from '@narval/nestjs-shared' import { ClassSerializerInterceptor, INestApplication, Logger, ValidationPipe } from '@nestjs/common' import { ConfigService } from '@nestjs/config' import { NestFactory, Reflector } from '@nestjs/core' -import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger' -import { patchNestJsSwagger } from 'nestjs-zod' import { lastValueFrom, map, of, switchMap } from 'rxjs' import { Config } from './armory.config' import { ArmoryModule } from './armory.module' @@ -10,34 +9,6 @@ import { ApplicationExceptionFilter } from './shared/filter/application-exceptio import { HttpExceptionFilter } from './shared/filter/http-exception.filter' import { ZodExceptionFilter } from './shared/filter/zod-exception.filter' -/** - * Adds Swagger documentation to the application. - * - * @param app - The INestApplication instance. - * @returns The modified INestApplication instance. - */ -const withSwagger = (app: INestApplication): INestApplication => { - // IMPORTANT: This modifies the Nest Swagger module to be compatible with - // DTOs created by Zod schemas. The patch MUST be done before the - // configuration process. - patchNestJsSwagger() - - const document = SwaggerModule.createDocument( - app, - new DocumentBuilder() - .setTitle('Armory') - .setDescription('Armory is the most secure access management for web3') - .setVersion('1.0') - .build() - ) - - SwaggerModule.setup('docs', app, document, { - customSiteTitle: 'Armory API' - }) - - return app -} - /** * Adds global pipes to the application. * @@ -95,7 +66,13 @@ async function bootstrap(): Promise { await lastValueFrom( of(application).pipe( - map(withSwagger), + map( + withSwagger({ + title: 'Armory', + description: 'Armory is the most secure access management for web3', + version: '1.0' + }) + ), map(withGlobalPipes), map(withGlobalInterceptors), map(withGlobalFilters(configService)), diff --git a/apps/policy-engine/src/main.ts b/apps/policy-engine/src/main.ts index 88acf066f..233194674 100644 --- a/apps/policy-engine/src/main.ts +++ b/apps/policy-engine/src/main.ts @@ -1,40 +1,13 @@ import { ConfigService } from '@narval/config-module' +import { withSwagger } from '@narval/nestjs-shared' import { INestApplication, Logger, ValidationPipe } from '@nestjs/common' import { NestFactory } from '@nestjs/core' -import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger' -import { patchNestJsSwagger } from 'nestjs-zod' import { lastValueFrom, map, of, switchMap } from 'rxjs' import { Config } from './policy-engine.config' import { PolicyEngineModule } from './policy-engine.module' import { ApplicationExceptionFilter } from './shared/filter/application-exception.filter' import { HttpExceptionFilter } from './shared/filter/http-exception.filter' -/** - * Adds Swagger documentation to the application. - * - * @param app - The INestApplication instance. - * @returns The modified INestApplication instance. - */ -const withSwagger = (app: INestApplication): INestApplication => { - // IMPORTANT: This modifies the Nest Swagger module to be compatible with - // DTOs created by Zod schemas. The patch MUST be done before the - // configuration process. - patchNestJsSwagger() - - const document = SwaggerModule.createDocument( - app, - new DocumentBuilder() - .setTitle('Policy Engine') - .setDescription('The next generation of authorization for web3') - .setVersion('1.0') - .build() - ) - - SwaggerModule.setup('docs', app, document) - - return app -} - /** * Adds global pipes to the application. * @@ -74,7 +47,13 @@ async function bootstrap() { await lastValueFrom( of(application).pipe( - map(withSwagger), + map( + withSwagger({ + title: 'Policy Engine', + description: 'The next generation of authorization for web3', + version: '1.0' + }) + ), map(withGlobalPipes), map(withGlobalFilters(configService)), switchMap((app) => app.listen(port)) diff --git a/apps/vault/src/main.ts b/apps/vault/src/main.ts index 1f7a2c5ea..9464b685c 100644 --- a/apps/vault/src/main.ts +++ b/apps/vault/src/main.ts @@ -1,37 +1,10 @@ +import { withSwagger } from '@narval/nestjs-shared' import { INestApplication, Logger, ValidationPipe } from '@nestjs/common' import { ConfigService } from '@nestjs/config' import { NestFactory } from '@nestjs/core' -import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger' -import { patchNestJsSwagger } from 'nestjs-zod' import { lastValueFrom, map, of, switchMap } from 'rxjs' import { MainModule } from './main.module' -/** - * Adds Swagger documentation to the application. - * - * @param app - The INestApplication instance. - * @returns The modified INestApplication instance. - */ -const withSwagger = (app: INestApplication): INestApplication => { - // IMPORTANT: This modifies the Nest Swagger module to be compatible with - // DTOs created by Zod schemas. The patch MUST be done before the - // configuration process. - patchNestJsSwagger() - - const document = SwaggerModule.createDocument( - app, - new DocumentBuilder() - .setTitle('Vault') - .setDescription('The next generation of authorization for web3') - .setVersion('1.0') - .build() - ) - - SwaggerModule.setup('docs', app, document) - - return app -} - /** * Adds global pipes to the application. * @@ -56,7 +29,13 @@ async function bootstrap() { await lastValueFrom( of(application).pipe( - map(withSwagger), + map( + withSwagger({ + title: 'Vault', + description: 'The next generation of authorization for web3', + version: '1.0' + }) + ), map(withGlobalPipes), switchMap((app) => app.listen(port)) )