From 607019063ab0cf4eb4c59e8fb55d12cb4bf23db4 Mon Sep 17 00:00:00 2001 From: Hyein Jeong Date: Tue, 12 Nov 2024 13:37:37 +0900 Subject: [PATCH] =?UTF-8?q?[BE][Feat]=20:=20#42=20:=20=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EC=9D=B8=20api=20swagger=20=EB=AC=B8=EC=84=9C=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 로그인 api swagger 문서 작성 --- backend/src/routes/authRouter.js | 24 ++++++++++++++++++++++ backend/swaggerConfig.js | 35 ++++++++++++++++++++++++++++++-- 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/backend/src/routes/authRouter.js b/backend/src/routes/authRouter.js index caf0b954..65d8dfcf 100644 --- a/backend/src/routes/authRouter.js +++ b/backend/src/routes/authRouter.js @@ -5,6 +5,30 @@ import { validationMiddleware } from '../middleware/validationMiddleware.js'; export const authRouter = express.Router(); +/** + * @swagger + * /api/auth/login: + * post: + * summary: User login + * description: Logs in a user with their ID and password. + * requestBody: + * required: true + * content: + * application/json: + * schema: + * $ref: '#/components/schemas/LoginRequest' + * responses: + * 200: + * description: Successfully logged in + * content: + * application/json: + * schema: + * $ref: '#/components/schemas/LoginResponse' + * 400: + * description: Invalid input (e.g. invalid ID or password) + * 500: + * description: Internal server error + */ authRouter.post( '/login', [ diff --git a/backend/swaggerConfig.js b/backend/swaggerConfig.js index 09ae4746..44349895 100644 --- a/backend/swaggerConfig.js +++ b/backend/swaggerConfig.js @@ -3,15 +3,46 @@ import swaggerJSDoc from 'swagger-jsdoc'; const swaggerDefinition = { openapi: '3.0.0', info: { - title: 'Your API Name', + title: 'DDara API', version: '1.0.0', - description: 'API documentation for Your Project', + description: 'API documentation for DDara Project', }, servers: [ { url: 'http://localhost:3001', }, ], + components: { + schemas: { + LoginRequest: { + type: 'object', + properties: { + id: { + type: 'string', + description: 'User ID', + }, + password: { + type: 'string', + description: 'User password', + }, + }, + }, + LoginResponse: { + type: 'object', + properties: { + token: { + type: 'string', + description: 'Authentication token', + }, + userId: { + type: 'string', + description: 'User ID', + }, + }, + }, + }, + }, + paths: {}, }; const options = {