From 109ad279546c3455858355a0055f1b59092cafad Mon Sep 17 00:00:00 2001 From: IMHOJEONG <39ghwjd@naver.com> Date: Tue, 7 Nov 2023 14:05:11 +0900 Subject: [PATCH] [add]: add swagger in pwrcode-backend --- apps/pwrcode-backend/package.json | 1 + apps/pwrcode-backend/src/main.ts | 12 +++++ yarn.lock | 76 ++++++++++++++++++++++++++----- 3 files changed, 77 insertions(+), 12 deletions(-) diff --git a/apps/pwrcode-backend/package.json b/apps/pwrcode-backend/package.json index 27dd325..86a13e3 100644 --- a/apps/pwrcode-backend/package.json +++ b/apps/pwrcode-backend/package.json @@ -23,6 +23,7 @@ "@nestjs/common": "^10.0.0", "@nestjs/core": "^10.0.0", "@nestjs/platform-express": "^10.0.0", + "@nestjs/swagger": "^7.1.14", "@nestjs/typeorm": "^10.0.0", "mysql2": "^3.6.3", "reflect-metadata": "^0.1.13", diff --git a/apps/pwrcode-backend/src/main.ts b/apps/pwrcode-backend/src/main.ts index 13cad38..4d4d980 100644 --- a/apps/pwrcode-backend/src/main.ts +++ b/apps/pwrcode-backend/src/main.ts @@ -1,8 +1,20 @@ import { NestFactory } from '@nestjs/core'; +import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger'; import { AppModule } from './app.module'; async function bootstrap() { const app = await NestFactory.create(AppModule); + + const config = new DocumentBuilder() + .setTitle('Test Example') + .setDescription('Hojeong API description') + .setVersion('1.0') + .addTag('cats') + .build(); + + const document = SwaggerModule.createDocument(app, config); + SwaggerModule.setup('api', app, document); + await app.listen(3000); } bootstrap(); diff --git a/yarn.lock b/yarn.lock index f84b920..4385e16 100644 --- a/yarn.lock +++ b/yarn.lock @@ -978,6 +978,23 @@ __metadata: languageName: node linkType: hard +"@nestjs/mapped-types@npm:2.0.2": + version: 2.0.2 + resolution: "@nestjs/mapped-types@npm:2.0.2" + peerDependencies: + "@nestjs/common": ^8.0.0 || ^9.0.0 || ^10.0.0 + class-transformer: ^0.4.0 || ^0.5.0 + class-validator: ^0.13.0 || ^0.14.0 + reflect-metadata: ^0.1.12 + peerDependenciesMeta: + class-transformer: + optional: true + class-validator: + optional: true + checksum: 9a6d4c32242926aebc267d5a4a0b50f8aa8eeea8797e25aa9fb762637a45879c1ec103a9a0a30d24e8a6e3f75d0f4640208aaf4f9003e350b52f7e4acb07bab9 + languageName: node + linkType: hard + "@nestjs/platform-express@npm:^10.0.0": version: 10.2.8 resolution: "@nestjs/platform-express@npm:10.2.8" @@ -1009,6 +1026,33 @@ __metadata: languageName: node linkType: hard +"@nestjs/swagger@npm:^7.1.14": + version: 7.1.14 + resolution: "@nestjs/swagger@npm:7.1.14" + dependencies: + "@nestjs/mapped-types": "npm:2.0.2" + js-yaml: "npm:4.1.0" + lodash: "npm:4.17.21" + path-to-regexp: "npm:3.2.0" + swagger-ui-dist: "npm:5.9.0" + peerDependencies: + "@fastify/static": ^6.0.0 + "@nestjs/common": ^9.0.0 || ^10.0.0 + "@nestjs/core": ^9.0.0 || ^10.0.0 + class-transformer: "*" + class-validator: "*" + reflect-metadata: ^0.1.12 + peerDependenciesMeta: + "@fastify/static": + optional: true + class-transformer: + optional: true + class-validator: + optional: true + checksum: cb89a72b143f315d3cc102cf3b6f2d0655fd16aad6ea8bfedd43632e1170bcfb668746623e8c6185b804720ea061557feec0a234a1ecce77cb8574713644c48a + languageName: node + linkType: hard + "@nestjs/testing@npm:^10.0.0": version: 10.2.8 resolution: "@nestjs/testing@npm:10.2.8" @@ -5749,26 +5793,26 @@ __metadata: languageName: node linkType: hard -"js-yaml@npm:^3.13.1": - version: 3.14.1 - resolution: "js-yaml@npm:3.14.1" +"js-yaml@npm:4.1.0, js-yaml@npm:^4.1.0": + version: 4.1.0 + resolution: "js-yaml@npm:4.1.0" dependencies: - argparse: "npm:^1.0.7" - esprima: "npm:^4.0.0" + argparse: "npm:^2.0.1" bin: js-yaml: bin/js-yaml.js - checksum: 6746baaaeac312c4db8e75fa22331d9a04cccb7792d126ed8ce6a0bbcfef0cedaddd0c5098fade53db067c09fe00aa1c957674b4765610a8b06a5a189e46433b + checksum: 184a24b4eaacfce40ad9074c64fd42ac83cf74d8c8cd137718d456ced75051229e5061b8633c3366b8aada17945a7a356b337828c19da92b51ae62126575018f languageName: node linkType: hard -"js-yaml@npm:^4.1.0": - version: 4.1.0 - resolution: "js-yaml@npm:4.1.0" +"js-yaml@npm:^3.13.1": + version: 3.14.1 + resolution: "js-yaml@npm:3.14.1" dependencies: - argparse: "npm:^2.0.1" + argparse: "npm:^1.0.7" + esprima: "npm:^4.0.0" bin: js-yaml: bin/js-yaml.js - checksum: 184a24b4eaacfce40ad9074c64fd42ac83cf74d8c8cd137718d456ced75051229e5061b8633c3366b8aada17945a7a356b337828c19da92b51ae62126575018f + checksum: 6746baaaeac312c4db8e75fa22331d9a04cccb7792d126ed8ce6a0bbcfef0cedaddd0c5098fade53db067c09fe00aa1c957674b4765610a8b06a5a189e46433b languageName: node linkType: hard @@ -5963,7 +6007,7 @@ __metadata: languageName: node linkType: hard -"lodash@npm:^4.17.21": +"lodash@npm:4.17.21, lodash@npm:^4.17.21": version: 4.17.21 resolution: "lodash@npm:4.17.21" checksum: d8cbea072bb08655bb4c989da418994b073a608dffa608b09ac04b43a791b12aeae7cd7ad919aa4c925f33b48490b5cfe6c1f71d827956071dae2e7bb3a6b74c @@ -7151,6 +7195,7 @@ __metadata: "@nestjs/core": "npm:^10.0.0" "@nestjs/platform-express": "npm:^10.0.0" "@nestjs/schematics": "npm:^10.0.0" + "@nestjs/swagger": "npm:^7.1.14" "@nestjs/testing": "npm:^10.0.0" "@nestjs/typeorm": "npm:^10.0.0" "@types/express": "npm:^4.17.17" @@ -8164,6 +8209,13 @@ __metadata: languageName: node linkType: hard +"swagger-ui-dist@npm:5.9.0": + version: 5.9.0 + resolution: "swagger-ui-dist@npm:5.9.0" + checksum: e01c78d48dc6aa27049e218ebf6d6f16663c742eba6933788620a1b1d07187df9d48c85d963a6528245fc4af6b8362e42e2475b2eacb25b89c13165e42ac1454 + languageName: node + linkType: hard + "symbol-observable@npm:4.0.0": version: 4.0.0 resolution: "symbol-observable@npm:4.0.0"