import process from 'node:process'; import { NestFactory } from '@nestjs/core'; import { AppModule } from '../src/app.module'; import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger'; import * as fs from 'fs'; import * as path from 'path'; import * as yaml from 'js-yaml'; async function generateOpenApi() { process.env.JWT_ACCESS_SECRET = process.env.JWT_ACCESS_SECRET || 'test_access_secret_32_characters_minimum_entropy'; process.env.JWT_REFRESH_SECRET = process.env.JWT_REFRESH_SECRET || 'test_refresh_secret_32_characters_minimum_entropy'; const app = await NestFactory.create(AppModule, { logger: false }); app.setGlobalPrefix('api'); const config = new DocumentBuilder() .setTitle('Canino Iran API') .setDescription( 'API Documentation for Canino Iran Pet Health & Supplement Platform', ) .setVersion('1.0.0') .addBearerAuth() .build(); const document = SwaggerModule.createDocument(app, config); const yamlContent = yaml.dump(document, { noRefs: true, lineWidth: -1 }); const rootSwaggerPath = path.resolve(__dirname, '../../swagger.yml'); fs.writeFileSync(rootSwaggerPath, yamlContent, 'utf8'); console.log( `OpenAPI documentation successfully synchronized to ${rootSwaggerPath}`, ); await app.close(); } generateOpenApi().catch((err) => { console.error('Error generating OpenAPI spec:', err); process.exit(1); });