// used in development import { writeFileSync } from 'fs'; import { NestFactory } from '@nestjs/core'; import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger'; import { ValidationPipe, VersioningType } from '@nestjs/common'; import { AppModule } from './app.module'; import packageJson from '../package.json'; async function bootstrap() { const app = await NestFactory.create(AppModule); app.enableVersioning({ type: VersioningType.HEADER, header: 'Accept-Version', defaultVersion: '1', }); const config = new DocumentBuilder() .setTitle(packageJson.name) .setDescription(packageJson.description) .setVersion(packageJson.version) .addServer('http://localhost:3000', 'Local') .addServer( 'https://nx7uv2rfy4.execute-api.us-east-2.amazonaws.com/default/v1/email-message/', 'Sandbox', ) .build(); const document = SwaggerModule.createDocument(app, config); SwaggerModule.setup('api', app, document); // update the openapi-spec writeFileSync('./openapi-spec.json', JSON.stringify(document)); app.useGlobalPipes( new ValidationPipe({ transform: true, transformOptions: { enableImplicitConversion: true }, }), ); await app.listen(3000); } bootstrap();