docusaurus-theme-openapi-docs 0.0.0-345

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