-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathswagger.ts
41 lines (36 loc) · 1.01 KB
/
swagger.ts
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
29
30
31
32
33
34
35
36
37
38
39
40
41
import { Express, RequestHandler } from 'express'; // Import specific types
import swaggerJsdoc from 'swagger-jsdoc';
import swaggerUi from 'swagger-ui-express';
const options = {
definition: {
openapi: '3.0.0',
info: {
title: 'Documents for CRMs app',
description: `APIs endpoints for a CRMs app documented on Swagger`,
contact: {
name: 'Need CRMs app',
email: 'need@need.co.th',
url: 'https://crm.need.co.th/',
},
version: '1.0.0',
},
servers: [
{
url: 'http://localhost:5500/',
description: 'Live server',
},
],
},
apis: ['./routers/*.ts'],
};
const swaggerSpec = swaggerJsdoc(options);
function swaggerDocs(app: Express, port: number) {
// Swagger Page
app.use('/docs', swaggerUi.serve, swaggerUi.setup(swaggerSpec));
// Documentation in JSON format
app.get('/docs.json', (req, res) => {
res.setHeader('Content-Type', 'application/json');
res.send(swaggerSpec);
});
}
export default swaggerDocs;