forked from seokho-son/cb-mapui
-
Notifications
You must be signed in to change notification settings - Fork 1
/
swagger.html
119 lines (109 loc) · 3.93 KB
/
swagger.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>CB-Tumblebug API Dashboard</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
display: flex;
flex-direction: column;
height: 100vh;
width: 100vw;
overflow: hidden;
}
#swagger-container {
width: 100%; /* Swagger UI takes the full width */
height: 100%;
display: flex;
flex-direction: column;
}
#swagger-header {
height: 50px; /* Header height */
background-color: #262626;
color: #fcfcfc;
display: flex;
align-items: center;
justify-content: center;
font-size: 20px;
font-weight: bold;
}
#swagger-ui-container {
height: calc(100% - 50px); /* Adjust height based on header */
overflow-y: scroll;
}
</style>
<!-- Load Swagger UI styles -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/5.17.14/swagger-ui.css">
</head>
<body>
<div id="swagger-header">CB-Tumblebug API Dashboard</div>
<div id="swagger-container">
<div id="swagger-ui-container"></div>
</div>
<!-- Load the latest Swagger UI scripts -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/5.17.14/swagger-ui-bundle.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/5.17.14/swagger-ui-standalone-preset.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js-yaml.min.js"></script>
<script>
// Basic authentication details
const username = 'default';
const password = 'default';
const credentials = btoa(username + ':' + password);
const authHeader = 'Basic ' + credentials;
const protocol = window.location.protocol;
const hostname = window.location.hostname;
const apiPort = '1323';
const apiDocPath = '/tumblebug/api/doc.yaml';
const apiDocUrl = `${protocol}//${hostname}:${apiPort}${apiDocPath}`;
console.log('API Document URL:', apiDocUrl);
// Fetch the YAML file with authentication
fetch(apiDocUrl, {
headers: {
'Authorization': authHeader
}
})
.then(response => {
console.log('Fetch response:', response);
if (!response.ok) {
throw new Error('Authentication failed: ' + response.statusText);
}
return response.text();
})
.then(yamlText => {
console.log('YAML fetched successfully');
const spec = jsyaml.load(yamlText);
console.log('YAML parsed successfully');
// Initialize Swagger UI
const ui = SwaggerUIBundle({
url: apiDocUrl,
dom_id: '#swagger-ui-container',
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
docExpansion: "list",
layout: "BaseLayout",
deepLinking: true, // Enable deep linking
tagsSorter: "alpha",
operationsSorter: "alpha",
requestInterceptor: (request) => {
request.headers['Authorization'] = authHeader;
return request;
},
validatorUrl: null,
onComplete: () => {
console.log('Swagger UI loaded');
}
});
console.log('Swagger UI initialized');
})
.catch(error => {
console.error('Failed to load API specification:', error);
alert('Failed to load API specification: ' + error.message);
});
</script>
</body>
</html>