31 lines
900 B
TypeScript
31 lines
900 B
TypeScript
import fs from 'fs';
|
|
import path from 'path';
|
|
import { buildApp } from '../src/app';
|
|
|
|
async function generateOpenApiSpec(): Promise<void> {
|
|
// eslint-disable-next-line no-console
|
|
console.log('📝 Generating OpenAPI specification...');
|
|
const app = await buildApp();
|
|
|
|
await app.ready();
|
|
|
|
const swaggerSpec = app.swagger();
|
|
const outputPath = path.resolve(__dirname, '../docs/openapi.json');
|
|
|
|
const dir = path.dirname(outputPath);
|
|
if (!fs.existsSync(dir)) {
|
|
fs.mkdirSync(dir, { recursive: true });
|
|
}
|
|
|
|
fs.writeFileSync(outputPath, JSON.stringify(swaggerSpec, null, 2));
|
|
// eslint-disable-next-line no-console
|
|
console.log(`✅ OpenAPI specification exported to ${outputPath}`);
|
|
await app.close();
|
|
}
|
|
|
|
generateOpenApiSpec().catch((err: unknown) => {
|
|
// eslint-disable-next-line no-console
|
|
console.error('❌ Failed to generate OpenAPI spec:', err);
|
|
process.exit(1);
|
|
});
|