docusaurus-theme-openapi-docs 1.0.0
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/LICENSE +21 -0
- package/babel.config.js +35 -0
- package/lib/index.js +48 -0
- package/lib/markdown/createDescription.js +20 -0
- package/lib/markdown/schema.js +121 -0
- package/lib/markdown/utils.js +45 -0
- package/lib/theme/ApiDemoPanel/Accept/index.js +41 -0
- package/lib/theme/ApiDemoPanel/Accept/slice.js +32 -0
- package/lib/theme/ApiDemoPanel/Authorization/auth-types.js +32 -0
- package/lib/theme/ApiDemoPanel/Authorization/index.js +174 -0
- package/lib/theme/ApiDemoPanel/Authorization/slice.js +137 -0
- package/lib/theme/ApiDemoPanel/Body/index.js +185 -0
- package/lib/theme/ApiDemoPanel/Body/slice.js +105 -0
- package/lib/theme/ApiDemoPanel/ContentType/index.js +41 -0
- package/lib/theme/ApiDemoPanel/ContentType/slice.js +32 -0
- package/lib/theme/ApiDemoPanel/Curl/index.js +236 -0
- package/lib/theme/ApiDemoPanel/Curl/styles.module.css +84 -0
- package/lib/theme/ApiDemoPanel/Execute/index.js +85 -0
- package/lib/theme/ApiDemoPanel/Execute/makeRequest.js +202 -0
- package/lib/theme/ApiDemoPanel/FloatingButton/index.js +32 -0
- package/lib/theme/ApiDemoPanel/FloatingButton/styles.module.css +26 -0
- package/lib/theme/ApiDemoPanel/FormFileUpload/index.js +97 -0
- package/lib/theme/ApiDemoPanel/FormFileUpload/styles.module.css +75 -0
- package/lib/theme/ApiDemoPanel/FormItem/index.js +35 -0
- package/lib/theme/ApiDemoPanel/FormItem/styles.module.css +7 -0
- package/lib/theme/ApiDemoPanel/FormMultiSelect/index.js +52 -0
- package/lib/theme/ApiDemoPanel/FormMultiSelect/styles.module.css +38 -0
- package/lib/theme/ApiDemoPanel/FormSelect/index.js +39 -0
- package/lib/theme/ApiDemoPanel/FormSelect/styles.module.css +51 -0
- package/lib/theme/ApiDemoPanel/FormTextInput/index.js +30 -0
- package/lib/theme/ApiDemoPanel/FormTextInput/styles.module.css +21 -0
- package/lib/theme/ApiDemoPanel/MethodEndpoint/index.js +60 -0
- package/lib/theme/ApiDemoPanel/ParamOptions/index.js +248 -0
- package/lib/theme/ApiDemoPanel/ParamOptions/slice.js +35 -0
- package/lib/theme/ApiDemoPanel/ParamOptions/styles.module.css +180 -0
- package/lib/theme/ApiDemoPanel/Response/index.js +75 -0
- package/lib/theme/ApiDemoPanel/Response/slice.js +37 -0
- package/lib/theme/ApiDemoPanel/SecuritySchemes/index.js +51 -0
- package/lib/theme/ApiDemoPanel/Server/index.js +109 -0
- package/lib/theme/ApiDemoPanel/Server/slice.js +41 -0
- package/lib/theme/ApiDemoPanel/Server/styles.module.css +61 -0
- package/lib/theme/ApiDemoPanel/VSCode/index.js +252 -0
- package/lib/theme/ApiDemoPanel/VSCode/styles.module.css +19 -0
- package/lib/theme/ApiDemoPanel/buildPostmanRequest.js +329 -0
- package/lib/theme/ApiDemoPanel/hooks.js +20 -0
- package/lib/theme/ApiDemoPanel/index.js +134 -0
- package/lib/theme/ApiDemoPanel/persistanceMiddleware.js +44 -0
- package/lib/theme/ApiDemoPanel/postman-collection.d.ts +10 -0
- package/lib/theme/ApiDemoPanel/storage-utils.js +47 -0
- package/lib/theme/ApiDemoPanel/store.js +48 -0
- package/lib/theme/ApiDemoPanel/styles.module.css +44 -0
- package/lib/theme/ApiItem/index.js +160 -0
- package/lib/theme/ApiItem/styles.module.css +109 -0
- package/lib/theme/ParamsItem/index.js +68 -0
- package/lib/theme/ParamsItem/styles.module.css +24 -0
- package/lib/theme/SchemaItem/index.js +58 -0
- package/lib/theme/SchemaItem/styles.module.css +24 -0
- package/lib/theme/Tabs/index.js +258 -0
- package/lib/theme/Tabs/styles.module.css +118 -0
- package/lib/theme-classic.d.ts +8 -0
- package/lib/theme-openapi.d.ts +48 -0
- package/lib/theme-translations.d.ts +9 -0
- package/lib/types.js +1 -0
- package/lib-next/index.js +38 -0
- package/lib-next/markdown/createDescription.js +13 -0
- package/lib-next/markdown/schema.js +115 -0
- package/lib-next/markdown/utils.js +31 -0
- package/lib-next/theme/ApiDemoPanel/Accept/index.js +33 -0
- package/lib-next/theme/ApiDemoPanel/Accept/slice.js +19 -0
- package/lib-next/theme/ApiDemoPanel/Authorization/auth-types.js +22 -0
- package/lib-next/theme/ApiDemoPanel/Authorization/index.js +203 -0
- package/lib-next/theme/ApiDemoPanel/Authorization/slice.js +101 -0
- package/lib-next/theme/ApiDemoPanel/Body/index.js +210 -0
- package/lib-next/theme/ApiDemoPanel/Body/slice.js +89 -0
- package/lib-next/theme/ApiDemoPanel/ContentType/index.js +33 -0
- package/lib-next/theme/ApiDemoPanel/ContentType/slice.js +19 -0
- package/lib-next/theme/ApiDemoPanel/Curl/index.js +264 -0
- package/lib-next/theme/ApiDemoPanel/Curl/styles.module.css +84 -0
- package/lib-next/theme/ApiDemoPanel/Execute/index.js +74 -0
- package/lib-next/theme/ApiDemoPanel/Execute/makeRequest.js +183 -0
- package/lib-next/theme/ApiDemoPanel/FloatingButton/index.js +19 -0
- package/lib-next/theme/ApiDemoPanel/FloatingButton/styles.module.css +26 -0
- package/lib-next/theme/ApiDemoPanel/FormFileUpload/index.js +113 -0
- package/lib-next/theme/ApiDemoPanel/FormFileUpload/styles.module.css +75 -0
- package/lib-next/theme/ApiDemoPanel/FormItem/index.js +29 -0
- package/lib-next/theme/ApiDemoPanel/FormItem/styles.module.css +7 -0
- package/lib-next/theme/ApiDemoPanel/FormMultiSelect/index.js +49 -0
- package/lib-next/theme/ApiDemoPanel/FormMultiSelect/styles.module.css +38 -0
- package/lib-next/theme/ApiDemoPanel/FormSelect/index.js +28 -0
- package/lib-next/theme/ApiDemoPanel/FormSelect/styles.module.css +51 -0
- package/lib-next/theme/ApiDemoPanel/FormTextInput/index.js +23 -0
- package/lib-next/theme/ApiDemoPanel/FormTextInput/styles.module.css +21 -0
- package/lib-next/theme/ApiDemoPanel/MethodEndpoint/index.js +53 -0
- package/lib-next/theme/ApiDemoPanel/ParamOptions/index.js +284 -0
- package/lib-next/theme/ApiDemoPanel/ParamOptions/slice.js +22 -0
- package/lib-next/theme/ApiDemoPanel/ParamOptions/styles.module.css +180 -0
- package/lib-next/theme/ApiDemoPanel/Response/index.js +65 -0
- package/lib-next/theme/ApiDemoPanel/Response/slice.js +22 -0
- package/lib-next/theme/ApiDemoPanel/SecuritySchemes/index.js +48 -0
- package/lib-next/theme/ApiDemoPanel/Server/index.js +114 -0
- package/lib-next/theme/ApiDemoPanel/Server/slice.js +25 -0
- package/lib-next/theme/ApiDemoPanel/Server/styles.module.css +61 -0
- package/lib-next/theme/ApiDemoPanel/VSCode/index.js +265 -0
- package/lib-next/theme/ApiDemoPanel/VSCode/styles.module.css +19 -0
- package/lib-next/theme/ApiDemoPanel/buildPostmanRequest.js +310 -0
- package/lib-next/theme/ApiDemoPanel/hooks.js +9 -0
- package/lib-next/theme/ApiDemoPanel/index.js +110 -0
- package/lib-next/theme/ApiDemoPanel/persistanceMiddleware.js +38 -0
- package/lib-next/theme/ApiDemoPanel/postman-collection.d.ts +10 -0
- package/lib-next/theme/ApiDemoPanel/storage-utils.js +35 -0
- package/lib-next/theme/ApiDemoPanel/store.js +30 -0
- package/lib-next/theme/ApiDemoPanel/styles.module.css +44 -0
- package/lib-next/theme/ApiItem/index.js +171 -0
- package/lib-next/theme/ApiItem/styles.module.css +109 -0
- package/lib-next/theme/ParamsItem/index.js +68 -0
- package/lib-next/theme/ParamsItem/styles.module.css +24 -0
- package/lib-next/theme/SchemaItem/index.js +58 -0
- package/lib-next/theme/SchemaItem/styles.module.css +24 -0
- package/lib-next/theme/Tabs/index.js +258 -0
- package/lib-next/theme/Tabs/styles.module.css +118 -0
- package/lib-next/theme-classic.d.ts +8 -0
- package/lib-next/theme-openapi.d.ts +48 -0
- package/lib-next/theme-translations.d.ts +9 -0
- package/lib-next/types.js +1 -0
- package/package.json +68 -0
- package/src/index.ts +42 -0
- package/src/markdown/createDescription.ts +13 -0
- package/src/markdown/schema.ts +115 -0
- package/src/markdown/utils.ts +39 -0
- package/src/theme/ApiDemoPanel/Accept/index.tsx +35 -0
- package/src/theme/ApiDemoPanel/Accept/slice.ts +29 -0
- package/src/theme/ApiDemoPanel/Authorization/auth-types.ts +26 -0
- package/src/theme/ApiDemoPanel/Authorization/index.tsx +211 -0
- package/src/theme/ApiDemoPanel/Authorization/slice.ts +145 -0
- package/src/theme/ApiDemoPanel/Body/index.tsx +218 -0
- package/src/theme/ApiDemoPanel/Body/slice.ts +133 -0
- package/src/theme/ApiDemoPanel/ContentType/index.tsx +35 -0
- package/src/theme/ApiDemoPanel/ContentType/slice.ts +29 -0
- package/src/theme/ApiDemoPanel/Curl/index.tsx +280 -0
- package/src/theme/ApiDemoPanel/Curl/styles.module.css +84 -0
- package/src/theme/ApiDemoPanel/Execute/index.tsx +88 -0
- package/src/theme/ApiDemoPanel/Execute/makeRequest.ts +184 -0
- package/src/theme/ApiDemoPanel/FloatingButton/index.tsx +27 -0
- package/src/theme/ApiDemoPanel/FloatingButton/styles.module.css +26 -0
- package/src/theme/ApiDemoPanel/FormFileUpload/index.tsx +116 -0
- package/src/theme/ApiDemoPanel/FormFileUpload/styles.module.css +75 -0
- package/src/theme/ApiDemoPanel/FormItem/index.tsx +28 -0
- package/src/theme/ApiDemoPanel/FormItem/styles.module.css +7 -0
- package/src/theme/ApiDemoPanel/FormMultiSelect/index.tsx +54 -0
- package/src/theme/ApiDemoPanel/FormMultiSelect/styles.module.css +38 -0
- package/src/theme/ApiDemoPanel/FormSelect/index.tsx +36 -0
- package/src/theme/ApiDemoPanel/FormSelect/styles.module.css +51 -0
- package/src/theme/ApiDemoPanel/FormTextInput/index.tsx +32 -0
- package/src/theme/ApiDemoPanel/FormTextInput/styles.module.css +21 -0
- package/src/theme/ApiDemoPanel/MethodEndpoint/index.tsx +55 -0
- package/src/theme/ApiDemoPanel/ParamOptions/index.tsx +316 -0
- package/src/theme/ApiDemoPanel/ParamOptions/slice.ts +37 -0
- package/src/theme/ApiDemoPanel/ParamOptions/styles.module.css +180 -0
- package/src/theme/ApiDemoPanel/Response/index.tsx +66 -0
- package/src/theme/ApiDemoPanel/Response/slice.ts +31 -0
- package/src/theme/ApiDemoPanel/SecuritySchemes/index.tsx +49 -0
- package/src/theme/ApiDemoPanel/Server/index.tsx +103 -0
- package/src/theme/ApiDemoPanel/Server/slice.ts +40 -0
- package/src/theme/ApiDemoPanel/Server/styles.module.css +61 -0
- package/src/theme/ApiDemoPanel/VSCode/index.tsx +205 -0
- package/src/theme/ApiDemoPanel/VSCode/styles.module.css +19 -0
- package/src/theme/ApiDemoPanel/buildPostmanRequest.ts +307 -0
- package/src/theme/ApiDemoPanel/hooks.ts +13 -0
- package/src/theme/ApiDemoPanel/index.tsx +118 -0
- package/src/theme/ApiDemoPanel/persistanceMiddleware.ts +46 -0
- package/src/theme/ApiDemoPanel/postman-collection.d.ts +10 -0
- package/src/theme/ApiDemoPanel/storage-utils.ts +39 -0
- package/src/theme/ApiDemoPanel/store.ts +41 -0
- package/src/theme/ApiDemoPanel/styles.module.css +44 -0
- package/src/theme/ApiItem/index.tsx +171 -0
- package/src/theme/ApiItem/styles.module.css +109 -0
- package/src/theme/ParamsItem/index.js +68 -0
- package/src/theme/ParamsItem/styles.module.css +24 -0
- package/src/theme/SchemaItem/index.js +58 -0
- package/src/theme/SchemaItem/styles.module.css +24 -0
- package/src/theme/Tabs/index.js +258 -0
- package/src/theme/Tabs/styles.module.css +118 -0
- package/src/theme-classic.d.ts +8 -0
- package/src/theme-openapi.d.ts +48 -0
- package/src/theme-translations.d.ts +9 -0
- package/src/types.ts +70 -0
- package/tsconfig.json +10 -0
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
/* ============================================================================
|
|
2
|
+
* Copyright (c) Palo Alto Networks
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
* ========================================================================== */
|
|
7
|
+
import React, { useRef, useState, useEffect } from "react";
|
|
8
|
+
import useDocusaurusContext from "@docusaurus/useDocusaurusContext"; // @ts-ignore
|
|
9
|
+
|
|
10
|
+
import codegen from "@paloaltonetworks/postman-code-generators"; // @ts-ignore
|
|
11
|
+
|
|
12
|
+
import clsx from "clsx";
|
|
13
|
+
import Highlight, { defaultProps } from "prism-react-renderer";
|
|
14
|
+
import { useTypedSelector } from "../hooks";
|
|
15
|
+
import buildPostmanRequest from "./../buildPostmanRequest";
|
|
16
|
+
import FloatingButton from "./../FloatingButton";
|
|
17
|
+
import styles from "./styles.module.css";
|
|
18
|
+
const languageSet = [
|
|
19
|
+
{
|
|
20
|
+
tabName: "cURL",
|
|
21
|
+
highlight: "bash",
|
|
22
|
+
language: "curl",
|
|
23
|
+
variant: "curl",
|
|
24
|
+
options: {
|
|
25
|
+
longFormat: false,
|
|
26
|
+
followRedirect: true,
|
|
27
|
+
trimRequestBody: true,
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
tabName: "Node",
|
|
32
|
+
highlight: "javascript",
|
|
33
|
+
language: "nodejs",
|
|
34
|
+
variant: "axios",
|
|
35
|
+
options: {
|
|
36
|
+
ES6_enabled: true,
|
|
37
|
+
followRedirect: true,
|
|
38
|
+
trimRequestBody: true,
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
tabName: "Go",
|
|
43
|
+
highlight: "go",
|
|
44
|
+
language: "go",
|
|
45
|
+
variant: "native",
|
|
46
|
+
options: {
|
|
47
|
+
followRedirect: true,
|
|
48
|
+
trimRequestBody: true,
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
tabName: "Python",
|
|
53
|
+
highlight: "python",
|
|
54
|
+
language: "python",
|
|
55
|
+
variant: "requests",
|
|
56
|
+
options: {
|
|
57
|
+
followRedirect: true,
|
|
58
|
+
trimRequestBody: true,
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
];
|
|
62
|
+
const languageTheme = {
|
|
63
|
+
plain: {
|
|
64
|
+
color: "var(--ifm-code-color)",
|
|
65
|
+
},
|
|
66
|
+
styles: [
|
|
67
|
+
{
|
|
68
|
+
types: ["inserted", "attr-name"],
|
|
69
|
+
style: {
|
|
70
|
+
color: "var(--openapi-code-green)",
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
types: ["string", "url"],
|
|
75
|
+
style: {
|
|
76
|
+
color: "var(--openapi-code-green)",
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
types: ["builtin", "char", "constant", "function"],
|
|
81
|
+
style: {
|
|
82
|
+
color: "var(--openapi-code-blue)",
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
types: ["punctuation", "operator"],
|
|
87
|
+
style: {
|
|
88
|
+
color: "var(--openapi-code-dim)",
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
types: ["class-name"],
|
|
93
|
+
style: {
|
|
94
|
+
color: "var(--openapi-code-orange)",
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
types: ["tag", "arrow", "keyword"],
|
|
99
|
+
style: {
|
|
100
|
+
color: "var(--openapi-code-purple)",
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
types: ["boolean"],
|
|
105
|
+
style: {
|
|
106
|
+
color: "var(--openapi-code-red)",
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
],
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
function Curl({ postman, codeSamples }) {
|
|
113
|
+
// TODO: match theme for vscode.
|
|
114
|
+
const { siteConfig } = useDocusaurusContext();
|
|
115
|
+
const [copyText, setCopyText] = useState("Copy");
|
|
116
|
+
const contentType = useTypedSelector((state) => state.contentType.value);
|
|
117
|
+
const accept = useTypedSelector((state) => state.accept.value);
|
|
118
|
+
const server = useTypedSelector((state) => state.server.value);
|
|
119
|
+
const body = useTypedSelector((state) => state.body);
|
|
120
|
+
const pathParams = useTypedSelector((state) => state.params.path);
|
|
121
|
+
const queryParams = useTypedSelector((state) => state.params.query);
|
|
122
|
+
const cookieParams = useTypedSelector((state) => state.params.cookie);
|
|
123
|
+
const headerParams = useTypedSelector((state) => state.params.header);
|
|
124
|
+
const auth = useTypedSelector((state) => state.auth); // TODO
|
|
125
|
+
|
|
126
|
+
const langs = [
|
|
127
|
+
...(siteConfig?.themeConfig?.languageTabs ?? languageSet),
|
|
128
|
+
...codeSamples,
|
|
129
|
+
];
|
|
130
|
+
const [language, setLanguage] = useState(langs[0]);
|
|
131
|
+
const [codeText, setCodeText] = useState("");
|
|
132
|
+
useEffect(() => {
|
|
133
|
+
if (language && !!language.options) {
|
|
134
|
+
const postmanRequest = buildPostmanRequest(postman, {
|
|
135
|
+
queryParams,
|
|
136
|
+
pathParams,
|
|
137
|
+
cookieParams,
|
|
138
|
+
contentType,
|
|
139
|
+
accept,
|
|
140
|
+
headerParams,
|
|
141
|
+
body,
|
|
142
|
+
server,
|
|
143
|
+
auth,
|
|
144
|
+
});
|
|
145
|
+
codegen.convert(
|
|
146
|
+
language.language,
|
|
147
|
+
language.variant,
|
|
148
|
+
postmanRequest,
|
|
149
|
+
language.options,
|
|
150
|
+
(error, snippet) => {
|
|
151
|
+
if (error) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
setCodeText(snippet);
|
|
156
|
+
}
|
|
157
|
+
);
|
|
158
|
+
} else if (language && !!language.source) {
|
|
159
|
+
setCodeText(language.source);
|
|
160
|
+
} else {
|
|
161
|
+
setCodeText("");
|
|
162
|
+
}
|
|
163
|
+
}, [
|
|
164
|
+
accept,
|
|
165
|
+
body,
|
|
166
|
+
contentType,
|
|
167
|
+
cookieParams,
|
|
168
|
+
headerParams,
|
|
169
|
+
language,
|
|
170
|
+
pathParams,
|
|
171
|
+
postman,
|
|
172
|
+
queryParams,
|
|
173
|
+
server,
|
|
174
|
+
auth,
|
|
175
|
+
]);
|
|
176
|
+
const ref = useRef(null);
|
|
177
|
+
|
|
178
|
+
const handleCurlCopy = () => {
|
|
179
|
+
setCopyText("Copied");
|
|
180
|
+
setTimeout(() => {
|
|
181
|
+
setCopyText("Copy");
|
|
182
|
+
}, 2000);
|
|
183
|
+
|
|
184
|
+
if (ref.current?.innerText) {
|
|
185
|
+
navigator.clipboard.writeText(ref.current.innerText);
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
if (language === undefined) {
|
|
190
|
+
return null;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
return (
|
|
194
|
+
<>
|
|
195
|
+
<div className={clsx(styles.buttonGroup, "api-code-tab-group")}>
|
|
196
|
+
{langs.map((lang) => {
|
|
197
|
+
return (
|
|
198
|
+
<button
|
|
199
|
+
key={lang.tabName || lang.label}
|
|
200
|
+
className={clsx(
|
|
201
|
+
language === lang ? styles.selected : undefined,
|
|
202
|
+
language === lang ? "api-code-tab--active" : undefined,
|
|
203
|
+
"api-code-tab"
|
|
204
|
+
)}
|
|
205
|
+
onClick={() => setLanguage(lang)}
|
|
206
|
+
>
|
|
207
|
+
{lang.tabName || lang.label}
|
|
208
|
+
</button>
|
|
209
|
+
);
|
|
210
|
+
})}
|
|
211
|
+
</div>
|
|
212
|
+
|
|
213
|
+
<Highlight
|
|
214
|
+
{...defaultProps}
|
|
215
|
+
theme={languageTheme}
|
|
216
|
+
code={codeText}
|
|
217
|
+
language={language.highlight || language.lang}
|
|
218
|
+
>
|
|
219
|
+
{({ className, tokens, getLineProps, getTokenProps }) => (
|
|
220
|
+
<FloatingButton onClick={handleCurlCopy} label={copyText}>
|
|
221
|
+
<pre
|
|
222
|
+
className={className}
|
|
223
|
+
style={{
|
|
224
|
+
background: "var(--openapi-card-background-color)",
|
|
225
|
+
paddingRight: "60px",
|
|
226
|
+
borderRadius:
|
|
227
|
+
"2px 2px var(--openapi-card-border-radius) var(--openapi-card-border-radius)",
|
|
228
|
+
}}
|
|
229
|
+
>
|
|
230
|
+
<code ref={ref}>
|
|
231
|
+
{tokens.map((line, i) => (
|
|
232
|
+
<span
|
|
233
|
+
{...getLineProps({
|
|
234
|
+
line,
|
|
235
|
+
key: i,
|
|
236
|
+
})}
|
|
237
|
+
>
|
|
238
|
+
{line.map((token, key) => {
|
|
239
|
+
if (token.types.includes("arrow")) {
|
|
240
|
+
token.types = ["arrow"];
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
return (
|
|
244
|
+
<span
|
|
245
|
+
{...getTokenProps({
|
|
246
|
+
token,
|
|
247
|
+
key,
|
|
248
|
+
})}
|
|
249
|
+
/>
|
|
250
|
+
);
|
|
251
|
+
})}
|
|
252
|
+
{"\n"}
|
|
253
|
+
</span>
|
|
254
|
+
))}
|
|
255
|
+
</code>
|
|
256
|
+
</pre>
|
|
257
|
+
</FloatingButton>
|
|
258
|
+
)}
|
|
259
|
+
</Highlight>
|
|
260
|
+
</>
|
|
261
|
+
);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
export default Curl;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
.buttonGroup {
|
|
2
|
+
background: var(--openapi-card-background-color);
|
|
3
|
+
color: var(--ifm-pre-color);
|
|
4
|
+
font-family: var(--ifm-font-family-monospace);
|
|
5
|
+
/* font-size: var(--ifm-code-font-size); */
|
|
6
|
+
/* line-height: var(--ifm-pre-line-height); */
|
|
7
|
+
/* margin-bottom: calc(var(--ifm-spacing-vertical) / 4); */
|
|
8
|
+
margin-bottom: 1px;
|
|
9
|
+
margin-top: 0;
|
|
10
|
+
border-radius: var(--openapi-card-border-radius)
|
|
11
|
+
var(--openapi-card-border-radius) 2px 2px;
|
|
12
|
+
display: flex;
|
|
13
|
+
justify-content: flex-end;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.buttonGroup button {
|
|
17
|
+
-webkit-appearance: none;
|
|
18
|
+
-moz-appearance: none;
|
|
19
|
+
appearance: none;
|
|
20
|
+
|
|
21
|
+
cursor: pointer;
|
|
22
|
+
/* font-size: calc(0.875rem * var(--ifm-button-size-multiplier)); */
|
|
23
|
+
/* line-height: 1.5; */
|
|
24
|
+
/* font-weight: var(--ifm-button-font-weight); */
|
|
25
|
+
|
|
26
|
+
/* font-size: var(--ifm-code-font-size); */
|
|
27
|
+
font-size: 13.3333px;
|
|
28
|
+
line-height: var(--ifm-pre-line-height);
|
|
29
|
+
font-weight: var(--ifm-font-weight-semibold);
|
|
30
|
+
|
|
31
|
+
padding: calc(
|
|
32
|
+
var(--ifm-button-padding-vertical) * var(--ifm-button-size-multiplier)
|
|
33
|
+
)
|
|
34
|
+
calc(
|
|
35
|
+
var(--ifm-button-padding-horizontal) * var(--ifm-button-size-multiplier)
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
text-align: center;
|
|
39
|
+
|
|
40
|
+
transition: color var(--ifm-button-transition-duration)
|
|
41
|
+
cubic-bezier(0.08, 0.52, 0.52, 1),
|
|
42
|
+
background var(--ifm-button-transition-duration)
|
|
43
|
+
cubic-bezier(0.08, 0.52, 0.52, 1),
|
|
44
|
+
border-color var(--ifm-button-transition-duration)
|
|
45
|
+
cubic-bezier(0.08, 0.52, 0.52, 1);
|
|
46
|
+
-webkit-user-select: none;
|
|
47
|
+
user-select: none;
|
|
48
|
+
white-space: nowrap;
|
|
49
|
+
|
|
50
|
+
background: transparent;
|
|
51
|
+
|
|
52
|
+
color: var(--ifm-menu-color);
|
|
53
|
+
border: 0px solid transparent;
|
|
54
|
+
/* border-radius: var(--ifm-pre-border-radius); */
|
|
55
|
+
|
|
56
|
+
--margin: 0.25rem;
|
|
57
|
+
|
|
58
|
+
border-radius: calc(var(--margin));
|
|
59
|
+
/* border-radius: 0.25rem; */
|
|
60
|
+
|
|
61
|
+
display: block;
|
|
62
|
+
width: 100%;
|
|
63
|
+
|
|
64
|
+
/* margin: 2px; */
|
|
65
|
+
margin: var(--margin);
|
|
66
|
+
margin-right: 0;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
.buttonGroup button:last-child {
|
|
70
|
+
margin-right: 0.25rem;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
.buttonGroup button:hover {
|
|
74
|
+
background: var(--ifm-menu-color-background-active);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
.buttonGroup button:focus {
|
|
78
|
+
outline: 0;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
.buttonGroup button.selected {
|
|
82
|
+
background: var(--ifm-menu-color-background-active);
|
|
83
|
+
color: var(--ifm-menu-color-active);
|
|
84
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/* ============================================================================
|
|
2
|
+
* Copyright (c) Palo Alto Networks
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
* ========================================================================== */
|
|
7
|
+
import React from "react"; // @ts-ignore
|
|
8
|
+
|
|
9
|
+
import { useTypedDispatch, useTypedSelector } from "../hooks";
|
|
10
|
+
import { setResponse } from "../Response/slice";
|
|
11
|
+
import buildPostmanRequest from "./../buildPostmanRequest";
|
|
12
|
+
import makeRequest from "./makeRequest";
|
|
13
|
+
|
|
14
|
+
function validateRequest(params) {
|
|
15
|
+
for (let paramList of Object.values(params)) {
|
|
16
|
+
for (let param of paramList) {
|
|
17
|
+
if (param.required && !param.value) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function Execute({ postman, proxy }) {
|
|
27
|
+
const pathParams = useTypedSelector((state) => state.params.path);
|
|
28
|
+
const queryParams = useTypedSelector((state) => state.params.query);
|
|
29
|
+
const cookieParams = useTypedSelector((state) => state.params.cookie);
|
|
30
|
+
const headerParams = useTypedSelector((state) => state.params.header);
|
|
31
|
+
const contentType = useTypedSelector((state) => state.contentType.value);
|
|
32
|
+
const body = useTypedSelector((state) => state.body);
|
|
33
|
+
const accept = useTypedSelector((state) => state.accept.value);
|
|
34
|
+
const server = useTypedSelector((state) => state.server.value);
|
|
35
|
+
const params = useTypedSelector((state) => state.params);
|
|
36
|
+
const auth = useTypedSelector((state) => state.auth);
|
|
37
|
+
const isValidRequest = validateRequest(params);
|
|
38
|
+
const dispatch = useTypedDispatch();
|
|
39
|
+
const postmanRequest = buildPostmanRequest(postman, {
|
|
40
|
+
queryParams,
|
|
41
|
+
pathParams,
|
|
42
|
+
cookieParams,
|
|
43
|
+
contentType,
|
|
44
|
+
accept,
|
|
45
|
+
headerParams,
|
|
46
|
+
body,
|
|
47
|
+
server,
|
|
48
|
+
auth,
|
|
49
|
+
});
|
|
50
|
+
return (
|
|
51
|
+
<button
|
|
52
|
+
className="button button--block button--primary"
|
|
53
|
+
style={{
|
|
54
|
+
height: "48px",
|
|
55
|
+
marginBottom: "var(--ifm-spacing-vertical)",
|
|
56
|
+
}}
|
|
57
|
+
disabled={!isValidRequest}
|
|
58
|
+
onClick={async () => {
|
|
59
|
+
dispatch(setResponse("loading..."));
|
|
60
|
+
|
|
61
|
+
try {
|
|
62
|
+
const res = await makeRequest(postmanRequest, proxy, body);
|
|
63
|
+
dispatch(setResponse(res));
|
|
64
|
+
} catch (e) {
|
|
65
|
+
dispatch(setResponse(e.message ?? "Error fetching."));
|
|
66
|
+
}
|
|
67
|
+
}}
|
|
68
|
+
>
|
|
69
|
+
Execute
|
|
70
|
+
</button>
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export default Execute;
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
/* ============================================================================
|
|
2
|
+
* Copyright (c) Palo Alto Networks
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
* ========================================================================== */
|
|
7
|
+
// @ts-ignore
|
|
8
|
+
async function loadImage(content) {
|
|
9
|
+
return new Promise((accept, reject) => {
|
|
10
|
+
const reader = new FileReader();
|
|
11
|
+
|
|
12
|
+
reader.onabort = () => {
|
|
13
|
+
console.log("file reading was aborted");
|
|
14
|
+
reject();
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
reader.onerror = () => {
|
|
18
|
+
console.log("file reading has failed");
|
|
19
|
+
reject();
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
reader.onload = () => {
|
|
23
|
+
// Do whatever you want with the file contents
|
|
24
|
+
const binaryStr = reader.result;
|
|
25
|
+
accept(binaryStr);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
reader.readAsArrayBuffer(content);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async function makeRequest(request, proxy, _body) {
|
|
33
|
+
const headers = request.toJSON().header;
|
|
34
|
+
let myHeaders = new Headers();
|
|
35
|
+
|
|
36
|
+
if (headers) {
|
|
37
|
+
// @ts-ignore
|
|
38
|
+
headers.forEach((header) => {
|
|
39
|
+
if (header.key && header.value) {
|
|
40
|
+
myHeaders.append(header.key, header.value);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
} // The following code handles multiple files in the same formdata param.
|
|
44
|
+
// It removes the form data params where the src property is an array of filepath strings
|
|
45
|
+
// Splits that array into different form data params with src set as a single filepath string
|
|
46
|
+
// TODO:
|
|
47
|
+
// if (request.body && request.body.mode === 'formdata') {
|
|
48
|
+
// let formdata = request.body.formdata,
|
|
49
|
+
// formdataArray = [];
|
|
50
|
+
// formdata.members.forEach((param) => {
|
|
51
|
+
// let key = param.key,
|
|
52
|
+
// type = param.type,
|
|
53
|
+
// disabled = param.disabled,
|
|
54
|
+
// contentType = param.contentType;
|
|
55
|
+
// // check if type is file or text
|
|
56
|
+
// if (type === 'file') {
|
|
57
|
+
// // if src is not of type string we check for array(multiple files)
|
|
58
|
+
// if (typeof param.src !== 'string') {
|
|
59
|
+
// // if src is an array(not empty), iterate over it and add files as separate form fields
|
|
60
|
+
// if (Array.isArray(param.src) && param.src.length) {
|
|
61
|
+
// param.src.forEach((filePath) => {
|
|
62
|
+
// addFormParam(
|
|
63
|
+
// formdataArray,
|
|
64
|
+
// key,
|
|
65
|
+
// param.type,
|
|
66
|
+
// filePath,
|
|
67
|
+
// disabled,
|
|
68
|
+
// contentType
|
|
69
|
+
// );
|
|
70
|
+
// });
|
|
71
|
+
// }
|
|
72
|
+
// // if src is not an array or string, or is an empty array, add a placeholder for file path(no files case)
|
|
73
|
+
// else {
|
|
74
|
+
// addFormParam(
|
|
75
|
+
// formdataArray,
|
|
76
|
+
// key,
|
|
77
|
+
// param.type,
|
|
78
|
+
// '/path/to/file',
|
|
79
|
+
// disabled,
|
|
80
|
+
// contentType
|
|
81
|
+
// );
|
|
82
|
+
// }
|
|
83
|
+
// }
|
|
84
|
+
// // if src is string, directly add the param with src as filepath
|
|
85
|
+
// else {
|
|
86
|
+
// addFormParam(
|
|
87
|
+
// formdataArray,
|
|
88
|
+
// key,
|
|
89
|
+
// param.type,
|
|
90
|
+
// param.src,
|
|
91
|
+
// disabled,
|
|
92
|
+
// contentType
|
|
93
|
+
// );
|
|
94
|
+
// }
|
|
95
|
+
// }
|
|
96
|
+
// // if type is text, directly add it to formdata array
|
|
97
|
+
// else {
|
|
98
|
+
// addFormParam(
|
|
99
|
+
// formdataArray,
|
|
100
|
+
// key,
|
|
101
|
+
// param.type,
|
|
102
|
+
// param.value,
|
|
103
|
+
// disabled,
|
|
104
|
+
// contentType
|
|
105
|
+
// );
|
|
106
|
+
// }
|
|
107
|
+
// });
|
|
108
|
+
// request.body.update({
|
|
109
|
+
// mode: 'formdata',
|
|
110
|
+
// formdata: formdataArray,
|
|
111
|
+
// });
|
|
112
|
+
// }
|
|
113
|
+
|
|
114
|
+
const body = request.body?.toJSON();
|
|
115
|
+
let myBody = undefined;
|
|
116
|
+
|
|
117
|
+
if (body !== undefined && Object.keys(body).length > 0) {
|
|
118
|
+
switch (body.mode) {
|
|
119
|
+
case "urlencoded": {
|
|
120
|
+
myBody = new URLSearchParams();
|
|
121
|
+
|
|
122
|
+
if (Array.isArray(body.urlencoded)) {
|
|
123
|
+
for (const data of body.urlencoded) {
|
|
124
|
+
if (data.key && data.value) {
|
|
125
|
+
myBody.append(data.key, data.value);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
case "raw": {
|
|
134
|
+
myBody = (body.raw ?? "").toString();
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
case "formdata": {
|
|
139
|
+
myBody = new FormData();
|
|
140
|
+
|
|
141
|
+
if (Array.isArray(body.formdata)) {
|
|
142
|
+
for (const data of body.formdata) {
|
|
143
|
+
if (data.key && data.value) {
|
|
144
|
+
myBody.append(data.key, data.value);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
break;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
case "file": {
|
|
153
|
+
if (_body.type === "raw" && _body.content?.type === "file") {
|
|
154
|
+
myBody = await loadImage(_body.content.value.content);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
break;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
default:
|
|
161
|
+
break;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const requestOptions = {
|
|
166
|
+
method: request.method,
|
|
167
|
+
headers: myHeaders,
|
|
168
|
+
body: myBody,
|
|
169
|
+
};
|
|
170
|
+
let finalUrl = request.url.toString();
|
|
171
|
+
|
|
172
|
+
if (proxy) {
|
|
173
|
+
// Ensure the proxy ends with a slash.
|
|
174
|
+
let normalizedProxy = proxy.replace(/\/$/, "") + "/";
|
|
175
|
+
finalUrl = normalizedProxy + request.url.toString();
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
return await fetch(finalUrl, requestOptions).then((response) => {
|
|
179
|
+
return response.text();
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export default makeRequest;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/* ============================================================================
|
|
2
|
+
* Copyright (c) Palo Alto Networks
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
* ========================================================================== */
|
|
7
|
+
import React from "react";
|
|
8
|
+
import styles from "./styles.module.css";
|
|
9
|
+
|
|
10
|
+
function FloatingButton({ label, onClick, children }) {
|
|
11
|
+
return (
|
|
12
|
+
<div className={styles.floatingButton}>
|
|
13
|
+
{label && <button onClick={onClick}>{label}</button>}
|
|
14
|
+
{children}
|
|
15
|
+
</div>
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export default FloatingButton;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
.floatingButton {
|
|
2
|
+
position: relative;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
.floatingButton button {
|
|
6
|
+
position: relative;
|
|
7
|
+
background: rgba(25, 26, 27, 0.9);
|
|
8
|
+
border: none;
|
|
9
|
+
border-radius: var(--ifm-global-radius);
|
|
10
|
+
color: var(--ifm-color-white);
|
|
11
|
+
cursor: pointer;
|
|
12
|
+
outline: none;
|
|
13
|
+
padding: 0.4rem 0.5rem;
|
|
14
|
+
opacity: 0;
|
|
15
|
+
visibility: hidden;
|
|
16
|
+
transition: opacity 0.2s ease-in-out, visibility 0.2s ease-in-out,
|
|
17
|
+
bottom 0.2s ease-in-out;
|
|
18
|
+
position: absolute;
|
|
19
|
+
top: calc(var(--ifm-pre-padding) / 2);
|
|
20
|
+
right: calc(var(--ifm-pre-padding) / 2);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.floatingButton:hover button {
|
|
24
|
+
visibility: visible;
|
|
25
|
+
opacity: 1;
|
|
26
|
+
}
|