-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- swagger 설치 - 예시 코드 작성 - 예시 코드 동작 확인
- Loading branch information
Showing
4 changed files
with
52 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,17 @@ | ||
const express = require('express'); | ||
import express from 'express'; | ||
import swaggerUi from 'swagger-ui-express'; | ||
import specs from '../swaggerConfig.js'; | ||
|
||
const app = express(); | ||
const port = process.env.PORT || 3000; | ||
const port = 3001; | ||
|
||
app.get('/', (req, res) => { | ||
res.json({ | ||
success: true, | ||
}); | ||
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(specs)); | ||
|
||
// 예제 라우터 (추가 예정인 라우터의 주석을 Swagger 주석 형식으로 문서화) | ||
app.get('/example', (req, res) => { | ||
res.send('Hello World'); | ||
}); | ||
|
||
app.listen(port, () => {}); | ||
app.listen(port, () => { | ||
console.log(`Server is running on http://localhost:${port}`); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/** | ||
* @swagger | ||
* /example: | ||
* get: | ||
* summary: Example endpoint | ||
* description: Returns a simple "Hello World" message | ||
* responses: | ||
* 200: | ||
* description: Successful response | ||
*/ | ||
app.get('/example', (req, res) => { | ||
res.send('Hello World'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import swaggerJSDoc from 'swagger-jsdoc'; | ||
|
||
const swaggerDefinition = { | ||
openapi: '3.0.0', | ||
info: { | ||
title: 'Your API Name', | ||
version: '1.0.0', | ||
description: 'API documentation for Your Project', | ||
}, | ||
servers: [ | ||
{ | ||
url: 'http://localhost:3001', | ||
}, | ||
], | ||
}; | ||
|
||
const options = { | ||
swaggerDefinition, | ||
apis: ['./routes/*.js'], | ||
}; | ||
|
||
const specs = swaggerJSDoc(options); | ||
|
||
export default specs; |