| 1 | import 'dotenv/config'; |
| 2 | import { writeFileSync } |
| 3 | import morgan from 'morgan |
| 4 | import { join } |
| 5 | |
| 6 | import { ValidationPipe, VersioningType |
| 7 | import { NestFactory } |
| 8 | import { NestExpressApplication } |
| 9 | import { DocumentBuilder, SwaggerModule |
| 10 | import { apiReference } |
| 11 | |
| 12 | import { AppModule } |
| 13 | |
| 14 | async function bootstrap() |
| 15 | const app = |
| 16 | app.use(morgan |
| 17 | app.enableCors(); |
| 18 | app.enableVersioning({ |
| 19 | type: VersioningType.URI |
| 20 | defaultVersion: '1', |
| 21 | }); |
| 22 | app.useGlobalPipes( |
| 23 | new ValidationPipe({ |
| 24 | ); |
| 25 | const config = |
| 26 | .setTitle('Plane Pal') |
| 27 | .setDescription('Plane Pal API Documentation') |
| 28 | .addBearerAuth( |
| 29 | { |
| 30 | type: 'http', |
| 31 | scheme: 'bearer', |
| 32 | bearerFormat: 'JWT', |
| 33 | }, |
| 34 | 'JWT-auth', |
| 35 | ) |
| 36 | .build(); |
| 37 | |
| 38 | const document = |
| 39 | Object.values(document |
| 40 | Object.values(path |
| 41 | if (!method.responses |
| 42 | method.responses = |
| 43 | } |
| 44 | method.responses['500 |
| 45 | description: 'Internal server error', |
| 46 | content: { |
| 47 | 'application/json': { |
| 48 | schema: { |
| 49 | $ref: '#/components/schemas/GenericErrorEntity', |
| 50 | }, |
| 51 | }, |
| 52 | }, |
| 53 | }; |
| 54 | }); |
| 55 | }); |
| 56 | writeFileSync('./openapi.json', |
| 57 | app.use( |
| 58 | '/docs', |
| 59 | apiReference({ |
| 60 | spec: { |
| 61 | content: document, |
| 62 | }, |
| 63 | layout: 'modern', |
| 64 | isEditable: false, |
| 65 | metaData: { |
| 66 | title: 'Plane Pal', |
| 67 | description: 'Plane Pal API Documentation', |
| 68 | }, |
| 69 | }), |
| 70 | ); |
| 71 | await app.listen |
| 72 | } |
| 73 | bootstrap(); |