-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswagger.js
More file actions
28 lines (25 loc) · 804 Bytes
/
swagger.js
File metadata and controls
28 lines (25 loc) · 804 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// file: swagger.js
const swaggerJsdoc = require('swagger-jsdoc');
const swaggerUi = require('swagger-ui-express');
// Cấu hình Swagger
const setupSwagger = (app, port) => {
const swaggerOptions = {
definition: {
openapi: '3.0.0',
info: {
title: 'CRUD API với Node.js và JSON Files',
version: '1.0.0',
description: 'API đơn giản để quản lý dữ liệu JSON với folder riêng cho mỗi key.'
},
servers: [
{
url: `http://localhost:${port}`
}
]
},
apis: ['./server.js'], // Đường dẫn tới file chứa các tài liệu API
};
const swaggerDocs = swaggerJsdoc(swaggerOptions);
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocs));
};
module.exports = setupSwagger;