-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSwagger.js
More file actions
118 lines (114 loc) · 3.29 KB
/
Copy pathSwagger.js
File metadata and controls
118 lines (114 loc) · 3.29 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
bodyParser = require("body-parser"),
swaggerJsdoc = require("swagger-jsdoc"),
swaggerUi = require("swagger-ui-express");
const path = require("path");
const options = {
swaggerDefinition: {
openapi: '3.0.0',
info: {
title: process.env.APP_NAME || 'ExpressJS Backend API',
version: process.env.APP_VERSION || '1.0.0',
description: process.env.APP_DESCRIPTION || 'Template for ExpressJS backend application',
},
servers: [
{
url: `http://localhost:${process.env.PORT || 5000}`,
description: 'Serveur de développement',
},
],
components: {
securitySchemes: {
bearerAuth: {
type: 'http',
scheme: 'bearer',
bearerFormat: 'JWT',
description: 'Entrez votre token JWT (récupéré via /users/auth/login)',
},
},
schemas: {
User: {
type: 'object',
properties: {
id: { type: 'integer', example: 1 },
nom_prenom: { type: 'string', example: 'John Doe' },
username: { type: 'string', example: 'johndoe' },
createdAt: { type: 'string', format: 'date-time' },
updatedAt: { type: 'string', format: 'date-time' },
},
},
LoginRequest: {
type: 'object',
required: ['username', 'password'],
properties: {
username: {
type: 'string',
example: 'admin',
description: 'Nom d\'utilisateur'
},
password: {
type: 'string',
format: 'password',
example: 'admin',
description: 'Mot de passe'
},
},
},
LoginResponse: {
type: 'object',
properties: {
statusCode: { type: 'integer', example: 200 },
message: { type: 'string', example: 'ok' },
data: {
type: 'object',
properties: {
access_token: {
type: 'string',
description: 'Token JWT à copier dans le bouton Authorize'
},
token_type: { type: 'string', example: 'Bearer' },
username: { type: 'string', example: 'admin' },
nom_prenom: { type: 'string', example: 'Administrator' },
},
},
},
},
ErrorResponse: {
type: 'object',
properties: {
statusCode: { type: 'integer' },
message: { type: 'string' },
data: { nullable: true },
},
},
},
responses: {
UnauthorizedError: {
description: 'Non autorisé - Token manquant ou invalide',
content: {
'application/json': {
schema: { $ref: '#/components/schemas/ErrorResponse' },
},
},
},
},
},
security: [
{
bearerAuth: [],
},
],
},
apis: ['./routes/*.js'],
};
const swaggerSpec = swaggerJsdoc(options);
const swaggerUiOptions = {
explorer: true,
swaggerOptions: {
persistAuthorization: true,
docExpansion: 'none',
filter: true,
tryItOutEnabled: true,
},
};
module.exports.swaggerSpec = swaggerSpec;
module.exports.swaggerUiOptions = swaggerUiOptions;