| 1 | import 'dotenv/config'; |
| 2 | import { writeFileSync } |
| 3 | import morgan from 'morgan |
| 4 | |
| 5 | import { ValidationPipe, VersioningType |
| 6 | import { NestFactory } |
| 7 | import { NestExpressApplication } |
| 8 | import { DocumentBuilder, SwaggerModule |
| 9 | import { apiReference } |
| 10 | import { Request, Response |
| 11 | |
| 12 | import { AppModule } |
| 13 | |
| 14 | async function bootstrap() |
| 15 | const app = |
| 16 | app.use(morgan |
| 17 | app.enableCors(); |
| 18 | app.getHttpAdapter().get |
| 19 | return res.json |
| 20 | [{ |
| 21 | "relation": ["delegate_permission/common.handle_all_urls" |
| 22 | "target": { |
| 23 | "namespace": "android_app", |
| 24 | "package_name": "com.phantomknight287.planepal", |
| 25 | "sha256_cert_fingerprints": |
| 26 | ["9E:A9:13:EE:1A:D2:F8:58:56:8F:EA:F4:5E:61:CE:29:11:0A:1A:2B:59:4B:2B:43:07:1F:9A:2F:9F:71:FE:D4"] |
| 27 | } |
| 28 | }] |
| 29 | ) |
| 30 | }) |
| 31 | |
| 32 | app.enableVersioning({ |
| 33 | type: VersioningType.URI |
| 34 | defaultVersion: '1', |
| 35 | }); |
| 36 | app.useGlobalPipes( |
| 37 | new ValidationPipe({ |
| 38 | whitelist: true, |
| 39 | enableDebugMessages: true, |
| 40 | transform: true, |
| 41 | transformOptions: { |
| 42 | enableImplicitConversion: true, |
| 43 | }, |
| 44 | }), |
| 45 | ); |
| 46 | const config = |
| 47 | .setTitle('Plane Pal') |
| 48 | .setDescription('Plane Pal API Documentation') |
| 49 | .addBearerAuth( |
| 50 | { |
| 51 | type: 'http', |
| 52 | scheme: 'bearer', |
| 53 | bearerFormat: 'JWT', |
| 54 | }, |
| 55 | 'JWT-auth', |
| 56 | ) |
| 57 | .build(); |
| 58 | |
| 59 | const document = |
| 60 | Object.values(document |
| 61 | Object.values(path |
| 62 | if (!method.responses |
| 63 | method.responses = |
| 64 | } |
| 65 | method.responses['500 |
| 66 | description: 'Internal server error', |
| 67 | content: { |
| 68 | 'application/json': { |
| 69 | schema: { |
| 70 | $ref: '#/components/schemas/GenericErrorEntity', |
| 71 | }, |
| 72 | }, |
| 73 | }, |
| 74 | }; |
| 75 | }); |
| 76 | }); |
| 77 | writeFileSync('./openapi.json', |
| 78 | app.use( |
| 79 | '/docs', |
| 80 | apiReference({ |
| 81 | spec: { |
| 82 | content: document, |
| 83 | }, |
| 84 | layout: 'modern', |
| 85 | isEditable: false, |
| 86 | metaData: { |
| 87 | title: 'Plane Pal', |
| 88 | description: 'Plane Pal API Documentation', |
| 89 | }, |
| 90 | }), |
| 91 | ); |
| 92 | await app.listen |
| 93 | } |
| 94 | bootstrap(); |