-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathswagger.js
More file actions
74 lines (67 loc) · 2 KB
/
Copy pathswagger.js
File metadata and controls
74 lines (67 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
const fs = require('fs');
const path = require('path');
const swaggerJSDoc = require('swagger-jsdoc');
const bundledOpenApiPath = path.join(__dirname, 'OPENAPI', 'openapi.json');
const swaggerDefinition = {
openapi: '3.0.0',
info: {
title: 'Zettelrobbe API Documentation',
version: '1.0.0',
description: 'API documentation for the Zettelrobbe application',
license: {
name: 'MIT',
url: 'https://opensource.org/licenses/MIT',
},
contact: {
name: 'admonstrator',
url: 'https://github.com/admonstrator',
},
},
servers: [
{
url: 'http://localhost:3000',
description: 'Development server',
},
// Add production server details if applicable
],
components: {
securitySchemes: {
BearerAuth: {
type: 'http',
scheme: 'bearer',
bearerFormat: 'JWT',
description: 'JWT authentication token obtained from the /login endpoint. The token should be included in the Authorization header as "Bearer {token}".'
},
ApiKeyAuth: {
type: 'apiKey',
in: 'header',
name: 'x-api-key',
description: 'API key for programmatic access. This key can be generated or regenerated using the /api/key-regenerate endpoint. Include the key in the x-api-key header for authentication.'
},
},
},
security: [
{ BearerAuth: [] },
{ ApiKeyAuth: [] }
]
};
const options = {
swaggerDefinition,
apis: ['./server.js', './routes/*.js', './schemas.js'], // Path to the API docs
};
function loadBundledOpenApiSpec() {
try {
const fileContent = fs.readFileSync(bundledOpenApiPath, 'utf8');
return JSON.parse(fileContent);
} catch (error) {
if (error.code !== 'ENOENT') {
console.warn(`Could not load bundled OpenAPI spec from ${bundledOpenApiPath}: ${error.message}`);
}
return null;
}
}
function generateOpenApiSpec() {
return swaggerJSDoc(options);
}
const swaggerSpec = loadBundledOpenApiSpec() || generateOpenApiSpec();
module.exports = swaggerSpec;