-
Notifications
You must be signed in to change notification settings - Fork 0
/
swagger.js
58 lines (53 loc) · 1.67 KB
/
swagger.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
57
58
import swaggerJsdoc from 'swagger-jsdoc';
import configuration from './src/configuration/configuration.js';
import fs from 'fs'; // Import the fs module to write to a file
const swaggerDefinition = {
openapi: '3.0.0',
info: {
title: 'Node Express Boilerplate',
version: '1.0.0',
description:
'A boilerplate for building RESTful APIs using Node.js, Express, and MongoDB.',
},
servers: [
{
url: `http://localhost:${configuration.port}/api/${configuration.version}`,
description: 'Development server',
variables: {
version: {
default: configuration.version,
},
},
},
{
url: `http://stg.example.com/api/${configuration.version}`,
description: 'Staging server',
variables: {
version: {
default: configuration.version,
},
},
},
{
url: `http://production.example.com/api/${configuration.version}`,
description: 'Production server',
variables: {
version: {
default: configuration.version,
},
},
},
],
};
const options = {
swaggerDefinition,
apis: ['./src/**/*.routes.js', './src/**/routes.js'], // paths to files containing OpenAPI definitions
};
const swaggerSpec = swaggerJsdoc(options);
// Write the Swagger specification to a JSON file
fs.writeFileSync(
'./src/modules/api/documentation/api/swagger.json',
JSON.stringify(swaggerSpec, null, 2),
'utf8'
);
export default swaggerSpec;