-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswaggerConfig.js
More file actions
76 lines (72 loc) · 2 KB
/
Copy pathswaggerConfig.js
File metadata and controls
76 lines (72 loc) · 2 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
const swaggerJsDoc = require('swagger-jsdoc');
const swaggerUi = require('swagger-ui-express');
const swaggerOptions = {
swaggerDefinition: {
openapi: '3.0.0',
info: {
title: 'Simple Blog API',
version: '1.0.0',
description: 'This is a simple CRUD API for managing blog articles, categories, users, and comments.',
contact: {
name: 'Eljefe_213',
email: 'abdelghani.hamaz.pro@gmail.com'
}
},
servers: [
{
url: 'http://localhost:3000'
}
],
components: {
schemas: {
Article: {
type: 'object',
properties: {
id: {
type: 'string',
description: 'The unique identifier of the article',
example: '1'
},
title: {
type: 'string',
description: 'The title of the article',
example: 'How to Learn JavaScript'
},
content: {
type: 'string',
description: 'The content of the article',
example: 'JavaScript is essential for frontend development...'
},
authorId: {
type: 'string',
description: 'The identifier of the author',
example: '2'
}
},
required: ['title', 'content', 'authorId']
},
Error: {
type: 'object',
properties: {
message: {
type: 'string',
description: 'A message describing the error',
example: 'Not found'
},
statusCode: {
type: 'integer',
description: 'The HTTP status code',
example: 404
}
}
}
}
}
},
apis: ['./src/infrastructure/web/routes/*.js'],
};
const swaggerSpec = swaggerJsDoc(swaggerOptions);
function setupSwagger(app) {
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerSpec));
}
module.exports = setupSwagger;