docusaurus-theme-openapi-docs 2.0.0 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/theme/ApiExplorer/Request/_Request.scss +4 -0
- package/lib/theme/ApiExplorer/Request/makeRequest.js +50 -1
- package/lib/theme/ApiExplorer/index.js +4 -0
- package/package.json +3 -3
- package/src/theme/ApiExplorer/Request/_Request.scss +4 -0
- package/src/theme/ApiExplorer/Request/makeRequest.ts +59 -4
- package/src/theme/ApiExplorer/index.tsx +3 -0
|
@@ -112,6 +112,10 @@
|
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
+
.openapi-security__summary-container {
|
|
116
|
+
background: var(--ifm-pre-background);
|
|
117
|
+
}
|
|
118
|
+
|
|
115
119
|
// Prevent auto zoom on mobile iOS devices when focusing on input elmenents
|
|
116
120
|
@media screen and (-webkit-min-device-pixel-ratio: 0) and (max-device-width: 1024px) {
|
|
117
121
|
.prism-code,
|
|
@@ -141,6 +141,10 @@ async function makeRequest(request, proxy, _body) {
|
|
|
141
141
|
if (data.key && data.value.content) {
|
|
142
142
|
myBody.append(data.key, data.value.content);
|
|
143
143
|
}
|
|
144
|
+
// handle generic key-value payload
|
|
145
|
+
if (data.key && typeof data.value === "string") {
|
|
146
|
+
myBody.append(data.key, data.value);
|
|
147
|
+
}
|
|
144
148
|
}
|
|
145
149
|
}
|
|
146
150
|
break;
|
|
@@ -166,7 +170,52 @@ async function makeRequest(request, proxy, _body) {
|
|
|
166
170
|
let normalizedProxy = proxy.replace(/\/$/, "") + "/";
|
|
167
171
|
finalUrl = normalizedProxy + request.url.toString();
|
|
168
172
|
}
|
|
169
|
-
return
|
|
173
|
+
return fetchWithtimeout(finalUrl, requestOptions).then((response) => {
|
|
174
|
+
const contentType = response.headers.get("content-type");
|
|
175
|
+
let fileExtension = "";
|
|
176
|
+
if (contentType) {
|
|
177
|
+
if (contentType.includes("application/pdf")) {
|
|
178
|
+
fileExtension = ".pdf";
|
|
179
|
+
} else if (contentType.includes("image/jpeg")) {
|
|
180
|
+
fileExtension = ".jpg";
|
|
181
|
+
} else if (contentType.includes("image/png")) {
|
|
182
|
+
fileExtension = ".png";
|
|
183
|
+
} else if (contentType.includes("image/gif")) {
|
|
184
|
+
fileExtension = ".gif";
|
|
185
|
+
} else if (contentType.includes("image/webp")) {
|
|
186
|
+
fileExtension = ".webp";
|
|
187
|
+
} else if (contentType.includes("video/mpeg")) {
|
|
188
|
+
fileExtension = ".mpeg";
|
|
189
|
+
} else if (contentType.includes("video/mp4")) {
|
|
190
|
+
fileExtension = ".mp4";
|
|
191
|
+
} else if (contentType.includes("audio/mpeg")) {
|
|
192
|
+
fileExtension = ".mp3";
|
|
193
|
+
} else if (contentType.includes("audio/ogg")) {
|
|
194
|
+
fileExtension = ".ogg";
|
|
195
|
+
} else if (contentType.includes("application/octet-stream")) {
|
|
196
|
+
fileExtension = ".bin";
|
|
197
|
+
} else if (contentType.includes("application/zip")) {
|
|
198
|
+
fileExtension = ".zip";
|
|
199
|
+
}
|
|
200
|
+
if (fileExtension) {
|
|
201
|
+
return response.blob().then((blob) => {
|
|
202
|
+
const url = window.URL.createObjectURL(blob);
|
|
203
|
+
const link = document.createElement("a");
|
|
204
|
+
link.href = url;
|
|
205
|
+
// Now the file name includes the extension
|
|
206
|
+
link.setAttribute("download", `file${fileExtension}`);
|
|
207
|
+
// These two lines are necessary to make the link click in Firefox
|
|
208
|
+
link.style.display = "none";
|
|
209
|
+
document.body.appendChild(link);
|
|
210
|
+
link.click();
|
|
211
|
+
// After link is clicked, it's safe to remove it.
|
|
212
|
+
setTimeout(() => document.body.removeChild(link), 0);
|
|
213
|
+
return response;
|
|
214
|
+
});
|
|
215
|
+
} else {
|
|
216
|
+
return response;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
170
219
|
return response;
|
|
171
220
|
});
|
|
172
221
|
}
|
|
@@ -20,11 +20,15 @@ const CodeSnippets_1 = __importDefault(
|
|
|
20
20
|
);
|
|
21
21
|
const Request_1 = __importDefault(require("@theme/ApiExplorer/Request"));
|
|
22
22
|
const Response_1 = __importDefault(require("@theme/ApiExplorer/Response"));
|
|
23
|
+
const SecuritySchemes_1 = __importDefault(require("./SecuritySchemes"));
|
|
23
24
|
function ApiExplorer({ item, infoPath }) {
|
|
24
25
|
const postman = new postman_collection_1.default.Request(item.postman);
|
|
25
26
|
return react_1.default.createElement(
|
|
26
27
|
react_1.default.Fragment,
|
|
27
28
|
null,
|
|
29
|
+
react_1.default.createElement(SecuritySchemes_1.default, {
|
|
30
|
+
infoPath: infoPath,
|
|
31
|
+
}),
|
|
28
32
|
item.method !== "event" &&
|
|
29
33
|
react_1.default.createElement(CodeSnippets_1.default, {
|
|
30
34
|
postman: postman,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "docusaurus-theme-openapi-docs",
|
|
3
3
|
"description": "OpenAPI theme for Docusaurus.",
|
|
4
|
-
"version": "2.0.
|
|
4
|
+
"version": "2.0.2",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"openapi",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"clsx": "^1.1.1",
|
|
44
44
|
"copy-text-to-clipboard": "^3.1.0",
|
|
45
45
|
"crypto-js": "^4.1.1",
|
|
46
|
-
"docusaurus-plugin-openapi-docs": "^2.0.
|
|
46
|
+
"docusaurus-plugin-openapi-docs": "^2.0.2",
|
|
47
47
|
"docusaurus-plugin-sass": "^0.2.3",
|
|
48
48
|
"file-saver": "^2.0.5",
|
|
49
49
|
"lodash": "^4.17.20",
|
|
@@ -68,5 +68,5 @@
|
|
|
68
68
|
"engines": {
|
|
69
69
|
"node": ">=14"
|
|
70
70
|
},
|
|
71
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "7f9528595b373f7691fd63845d84870549e6895c"
|
|
72
72
|
}
|
|
@@ -112,6 +112,10 @@
|
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
+
.openapi-security__summary-container {
|
|
116
|
+
background: var(--ifm-pre-background);
|
|
117
|
+
}
|
|
118
|
+
|
|
115
119
|
// Prevent auto zoom on mobile iOS devices when focusing on input elmenents
|
|
116
120
|
@media screen and (-webkit-min-device-pixel-ratio: 0) and (max-device-width: 1024px) {
|
|
117
121
|
.prism-code,
|
|
@@ -161,6 +161,10 @@ async function makeRequest(
|
|
|
161
161
|
if (data.key && data.value.content) {
|
|
162
162
|
myBody.append(data.key, data.value.content);
|
|
163
163
|
}
|
|
164
|
+
// handle generic key-value payload
|
|
165
|
+
if (data.key && typeof data.value === "string") {
|
|
166
|
+
myBody.append(data.key, data.value);
|
|
167
|
+
}
|
|
164
168
|
}
|
|
165
169
|
}
|
|
166
170
|
break;
|
|
@@ -189,11 +193,62 @@ async function makeRequest(
|
|
|
189
193
|
finalUrl = normalizedProxy + request.url.toString();
|
|
190
194
|
}
|
|
191
195
|
|
|
192
|
-
return
|
|
193
|
-
|
|
194
|
-
|
|
196
|
+
return fetchWithtimeout(finalUrl, requestOptions).then((response: any) => {
|
|
197
|
+
const contentType = response.headers.get("content-type");
|
|
198
|
+
let fileExtension = "";
|
|
199
|
+
|
|
200
|
+
if (contentType) {
|
|
201
|
+
if (contentType.includes("application/pdf")) {
|
|
202
|
+
fileExtension = ".pdf";
|
|
203
|
+
} else if (contentType.includes("image/jpeg")) {
|
|
204
|
+
fileExtension = ".jpg";
|
|
205
|
+
} else if (contentType.includes("image/png")) {
|
|
206
|
+
fileExtension = ".png";
|
|
207
|
+
} else if (contentType.includes("image/gif")) {
|
|
208
|
+
fileExtension = ".gif";
|
|
209
|
+
} else if (contentType.includes("image/webp")) {
|
|
210
|
+
fileExtension = ".webp";
|
|
211
|
+
} else if (contentType.includes("video/mpeg")) {
|
|
212
|
+
fileExtension = ".mpeg";
|
|
213
|
+
} else if (contentType.includes("video/mp4")) {
|
|
214
|
+
fileExtension = ".mp4";
|
|
215
|
+
} else if (contentType.includes("audio/mpeg")) {
|
|
216
|
+
fileExtension = ".mp3";
|
|
217
|
+
} else if (contentType.includes("audio/ogg")) {
|
|
218
|
+
fileExtension = ".ogg";
|
|
219
|
+
} else if (contentType.includes("application/octet-stream")) {
|
|
220
|
+
fileExtension = ".bin";
|
|
221
|
+
} else if (contentType.includes("application/zip")) {
|
|
222
|
+
fileExtension = ".zip";
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
if (fileExtension) {
|
|
226
|
+
return response.blob().then((blob: any) => {
|
|
227
|
+
const url = window.URL.createObjectURL(blob);
|
|
228
|
+
|
|
229
|
+
const link = document.createElement("a");
|
|
230
|
+
link.href = url;
|
|
231
|
+
// Now the file name includes the extension
|
|
232
|
+
link.setAttribute("download", `file${fileExtension}`);
|
|
233
|
+
|
|
234
|
+
// These two lines are necessary to make the link click in Firefox
|
|
235
|
+
link.style.display = "none";
|
|
236
|
+
document.body.appendChild(link);
|
|
237
|
+
|
|
238
|
+
link.click();
|
|
239
|
+
|
|
240
|
+
// After link is clicked, it's safe to remove it.
|
|
241
|
+
setTimeout(() => document.body.removeChild(link), 0);
|
|
242
|
+
|
|
243
|
+
return response;
|
|
244
|
+
});
|
|
245
|
+
} else {
|
|
246
|
+
return response;
|
|
247
|
+
}
|
|
195
248
|
}
|
|
196
|
-
|
|
249
|
+
|
|
250
|
+
return response;
|
|
251
|
+
});
|
|
197
252
|
}
|
|
198
253
|
|
|
199
254
|
export default makeRequest;
|
|
@@ -13,6 +13,8 @@ import Request from "@theme/ApiExplorer/Request";
|
|
|
13
13
|
import Response from "@theme/ApiExplorer/Response";
|
|
14
14
|
import { ApiItem } from "docusaurus-plugin-openapi-docs/src/types";
|
|
15
15
|
|
|
16
|
+
import SecuritySchemes from "./SecuritySchemes";
|
|
17
|
+
|
|
16
18
|
function ApiExplorer({
|
|
17
19
|
item,
|
|
18
20
|
infoPath,
|
|
@@ -24,6 +26,7 @@ function ApiExplorer({
|
|
|
24
26
|
|
|
25
27
|
return (
|
|
26
28
|
<>
|
|
29
|
+
<SecuritySchemes infoPath={infoPath} />
|
|
27
30
|
{item.method !== "event" && (
|
|
28
31
|
<CodeSnippets
|
|
29
32
|
postman={postman}
|