-
-
Notifications
You must be signed in to change notification settings - Fork 246
Expand file tree
/
Copy pathswagger.js
More file actions
350 lines (343 loc) · 12.8 KB
/
Copy pathswagger.js
File metadata and controls
350 lines (343 loc) · 12.8 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
const swaggerJsdoc = require('swagger-jsdoc');
const path = require('path');
const API_VERSION = process.env.API_VERSION || 'v1';
const API_BASE_PATH = `/api/${API_VERSION}`;
const options = {
definition: {
openapi: '3.0.0',
info: {
title: 'Tududi API',
version: '1.0.0',
description: 'REST API for Tududi task management application',
contact: {
name: 'Tududi',
url: 'https://github.com/chrisvel/tududi',
},
license: {
name: 'MIT',
url: 'https://opensource.org/licenses/MIT',
},
},
servers: [
{
url: 'http://localhost:3002',
description: `Backend server (base path ${API_BASE_PATH})`,
},
{
url: 'http://localhost:8080',
description: `Frontend dev server (proxy to ${API_BASE_PATH})`,
},
],
components: {
securitySchemes: {
cookieAuth: {
type: 'apiKey',
in: 'cookie',
name: 'connect.sid',
description: 'Session cookie authentication',
},
BearerAuth: {
type: 'http',
scheme: 'bearer',
bearerFormat: 'JWT',
description:
'JWT token authentication via Authorization header',
},
},
schemas: {
Error: {
type: 'object',
properties: {
error: {
type: 'string',
description: 'Error type',
},
message: {
type: 'string',
description: 'Error message',
},
},
},
Task: {
type: 'object',
properties: {
id: {
type: 'integer',
description: 'Task ID',
},
uid: {
type: 'string',
description: 'Task unique identifier',
},
name: {
type: 'string',
description: 'Task name',
},
note: {
type: 'string',
description:
'Task description (Markdown supported)',
},
status: {
type: 'string',
enum: ['pending', 'completed', 'archived'],
description: 'Task status',
},
priority: {
type: 'string',
enum: ['low', 'medium', 'high'],
description: 'Task priority',
},
due_date: {
type: 'string',
format: 'date-time',
description: 'Task due date',
},
project_id: {
type: 'integer',
description: 'Associated project ID',
},
recurring_pattern: {
type: 'string',
enum: ['daily', 'weekly', 'monthly', 'yearly'],
description: 'Recurring pattern',
},
created_at: {
type: 'string',
format: 'date-time',
},
updated_at: {
type: 'string',
format: 'date-time',
},
},
},
Project: {
type: 'object',
properties: {
id: {
type: 'integer',
description: 'Project ID',
},
uid: {
type: 'string',
description: 'Project unique identifier',
},
name: {
type: 'string',
description: 'Project name',
},
description: {
type: 'string',
description: 'Project description',
},
status: {
type: 'string',
enum: [
'not_started',
'planned',
'in_progress',
'waiting',
'done',
'cancelled',
],
description: 'Project status',
},
priority: {
type: 'string',
enum: ['low', 'medium', 'high'],
description: 'Project priority',
},
created_at: {
type: 'string',
format: 'date-time',
},
updated_at: {
type: 'string',
format: 'date-time',
},
},
},
Note: {
type: 'object',
properties: {
id: {
type: 'integer',
description: 'Note ID',
},
uid: {
type: 'string',
description: 'Note unique identifier',
},
title: {
type: 'string',
description: 'Note title',
},
content: {
type: 'string',
description: 'Note content (Markdown supported)',
},
color: {
type: 'string',
description: 'Note background color (hex)',
},
project_id: {
type: 'integer',
description: 'Associated project ID',
},
created_at: {
type: 'string',
format: 'date-time',
},
updated_at: {
type: 'string',
format: 'date-time',
},
},
},
Tag: {
type: 'object',
properties: {
id: {
type: 'integer',
description: 'Tag ID',
},
uid: {
type: 'string',
description: 'Tag unique identifier',
},
name: {
type: 'string',
description: 'Tag name',
},
created_at: {
type: 'string',
format: 'date-time',
},
updated_at: {
type: 'string',
format: 'date-time',
},
},
},
InboxItem: {
type: 'object',
properties: {
id: {
type: 'integer',
description: 'Inbox item ID',
},
uid: {
type: 'string',
description: 'Inbox item unique identifier',
},
content: {
type: 'string',
description: 'Inbox item content',
},
status: {
type: 'string',
enum: ['added', 'processed', 'ignored'],
description: 'Processing status',
},
created_at: {
type: 'string',
format: 'date-time',
},
updated_at: {
type: 'string',
format: 'date-time',
},
},
},
Area: {
type: 'object',
properties: {
id: {
type: 'integer',
description: 'Area ID',
},
uid: {
type: 'string',
description: 'Area unique identifier',
},
name: {
type: 'string',
description: 'Area name',
},
description: {
type: 'string',
description: 'Area description',
},
created_at: {
type: 'string',
format: 'date-time',
},
updated_at: {
type: 'string',
format: 'date-time',
},
},
},
ApiKey: {
type: 'object',
properties: {
id: { type: 'integer' },
name: {
type: 'string',
description: 'Friendly label for the API key',
},
token_prefix: {
type: 'string',
description:
'First characters displayed to help identify the key',
},
created_at: {
type: 'string',
format: 'date-time',
},
updated_at: {
type: 'string',
format: 'date-time',
},
last_used_at: {
type: 'string',
format: 'date-time',
},
expires_at: {
type: 'string',
format: 'date-time',
},
revoked_at: {
type: 'string',
format: 'date-time',
},
},
},
},
},
security: [
{
cookieAuth: [],
},
],
},
apis: [path.join(__dirname, '..', 'docs', 'swagger', '*.js')], // Path to centralized Swagger documentation files
};
const swaggerSpec = swaggerJsdoc(options);
if (swaggerSpec?.paths) {
const updatedPaths = {};
Object.entries(swaggerSpec.paths).forEach(([pathKey, pathValue]) => {
if (pathKey.startsWith('/api/')) {
const versionedPath =
API_BASE_PATH === '/api'
? pathKey
: `${API_BASE_PATH}${pathKey.slice(4)}`;
updatedPaths[versionedPath] = pathValue;
} else {
updatedPaths[pathKey] = pathValue;
}
});
swaggerSpec.paths = updatedPaths;
}
module.exports = swaggerSpec;