-
Notifications
You must be signed in to change notification settings - Fork 9.1k
/
Copy pathindex.html
84 lines (74 loc) · 2.85 KB
/
index.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
<!-- HTML for static distribution bundle build -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Swagger UI</title>
<link rel="stylesheet" type="text/css" href="./swagger-ui.css" />
<link rel="stylesheet" type="text/css" href="index.css" />
<link rel="icon" type="image/png" href="./favicon-32x32.png" sizes="32x32" />
<link rel="icon" type="image/png" href="./favicon-16x16.png" sizes="16x16" />
<link rel="stylesheet" href="swagger-ui-dist/swagger-ui.css" />
</head>
<body>
<div id="swagger-ui"></div>
<script src="./swagger-ui-bundle.js" charset="UTF-8"> </script>
<script src="./swagger-ui-standalone-preset.js" charset="UTF-8"> </script>
<script src="./swagger-initializer.js" charset="UTF-8"> </script>
<script src="swagger-ui-dist/swagger-ui-bundle.js"></script>
<script src="swagger-ui-dist/swagger-ui-standalone-preset.js"></script>
<script>
// Your custom plugin for wrapping long curl lines
const CurlWrapPlugin = function() {
return {
fn: {
curlify: (req) => {
const MAX_LINE_LENGTH = 100;
const wrapLine = (line) => {
if (line.length <= MAX_LINE_LENGTH) return line;
const parts = [];
while (line.length > MAX_LINE_LENGTH) {
parts.push(line.slice(0, MAX_LINE_LENGTH) + " \\");
line = line.slice(MAX_LINE_LENGTH);
}
parts.push(line);
return parts.join("\n");
};
const method = req.method || 'get';
let curl = [`curl -X ${method.toUpperCase()}`];
if (req.url) curl.push(`"${req.url}"`);
if (req.headers) {
Object.keys(req.headers).forEach(h => {
curl.push(`-H "${h}: ${req.headers[h]}"`);
});
}
if (req.body) {
try {
const body = typeof req.body === 'string' ? req.body : JSON.stringify(req.body);
curl.push(`-d '${body}'`);
} catch (e) {}
}
return wrapLine(curl.join(" "));
}
}
}
};
// Initialize Swagger UI with the custom plugin
const ui = SwaggerUIBundle({
url: "your-openapi-spec-url",
dom_id: '#swagger-ui',
deepLinking: true,
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIBundle.presets.plugins.DownloadUrl
],
layout: "BaseLayout",
requestInterceptor: (request) => {
// Force JSON if you don't want XML support
request.headers['Accept'] = 'application/json';
return request;
}
});
</script>
</body>
</html>