-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswagger-ui.html
More file actions
108 lines (104 loc) · 3.84 KB
/
Copy pathswagger-ui.html
File metadata and controls
108 lines (104 loc) · 3.84 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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>SaQshi API Swagger</title>
<link rel="stylesheet" href="https://unpkg.com/swagger-ui-dist@5/swagger-ui.css">
<style>
body {
margin: 0;
background: #f4f7fb;
}
.sq-swagger-header {
padding: 14px 18px;
border-bottom: 1px solid #d7e0ec;
background: #ffffff;
color: #10233f;
font-family: Arial, sans-serif;
}
.sq-swagger-header h1 {
margin: 0 0 4px;
font-size: 22px;
}
.sq-swagger-header p {
margin: 0;
color: #52677f;
font-size: 14px;
}
.sq-swagger-status {
margin-top: 8px;
padding: 8px 10px;
border-radius: 6px;
background: #eaf1ff;
color: #1d4ed8;
font-family: Consolas, monospace;
font-size: 13px;
}
.sq-swagger-error {
margin: 14px 18px;
padding: 12px 14px;
border: 1px solid #fecaca;
border-radius: 8px;
background: #fff1f2;
color: #991b1b;
font-family: Arial, sans-serif;
}
</style>
</head>
<body>
<header class="sq-swagger-header">
<h1>SaQshi API Swagger</h1>
<p>Loads docs/api/openapi.yaml. Open this page from the same {main_url} host as the SaQshi application so session-cookie APIs can be tested.</p>
<div id="sqSwaggerStatus" class="sq-swagger-status">Preparing API base URL...</div>
</header>
<div id="swagger-ui"></div>
<script src="https://unpkg.com/swagger-ui-dist@5/swagger-ui-bundle.js"></script>
<script>
window.addEventListener("load", async function () {
const status = document.getElementById("sqSwaggerStatus");
const sameOriginApi = window.location.origin + "/api";
status.textContent = "Swagger API base URL: " + sameOriginApi;
try {
const specResponse = await fetch("./openapi.yaml", { cache: "no-store" });
if (!specResponse.ok) {
throw new Error("Unable to load openapi.yaml. HTTP " + specResponse.status);
}
const specText = await specResponse.text();
const parser = window.jsyaml;
if (!parser) {
throw new Error("YAML parser not loaded.");
}
const spec = parser.load(specText);
spec.servers = [
{
url: sameOriginApi,
description: "Current browser origin API"
}
];
window.ui = SwaggerUIBundle({
spec: spec,
dom_id: "#swagger-ui",
deepLinking: true,
validatorUrl: null,
requestCredentials: "include",
requestInterceptor: function (request) {
request.credentials = "include";
return request;
},
presets: [
SwaggerUIBundle.presets.apis
],
layout: "BaseLayout"
});
} catch (error) {
document.getElementById("swagger-ui").innerHTML =
'<div class="sq-swagger-error"><strong>Swagger could not start.</strong><br>' +
String(error.message || error) +
'<br><br>Check that <code>docs/api/openapi.yaml</code> opens from the same host and that CDN JavaScript is available.</div>';
}
});
</script>
<script src="https://cdn.jsdelivr.net/npm/js-yaml@4/dist/js-yaml.min.js"></script>
</body>
</html>