-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
56 lines (47 loc) · 1.09 KB
/
index.js
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
const express = require('express');
const swaggerUi = require('swagger-ui-express');
const swaggerJSDoc = require('swagger-jsdoc');
const app = express();
const port = 3000;
const swaggerDefinition = {
openapi: '3.0.0',
info: {
title: 'My API',
version: '1.0.0',
description: 'A simple Express API with Swagger',
},
servers: [
{
url: 'http://localhost:3000'
}
]
};
const options = {
swaggerDefinition,
apis: ['./index.js'],
};
const swaggerSpec = swaggerJSDoc(options);
// Swagger UI setup
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerSpec));
/**
* @swagger
* tags:
* name: Hello
* description: Hello management
*/
/**
* @swagger
* /api/hello:
* get:
* summary: Returns a hello messageですよえ
* tags: [Hello]
* responses:
* 200:
* description: A JSON object with hello message
*/
app.get('/api/hello', (req, res) => {
res.json({ message: 'Hello, world!' });
});
app.listen(port, () => {
console.log(`Server is running at http://localhost:${port}`);
});