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.
Files changed (187) 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/theme/ApiDemoPanel/Accept/index.js +41 -0
  8. package/lib/theme/ApiDemoPanel/Accept/slice.js +32 -0
  9. package/lib/theme/ApiDemoPanel/Authorization/auth-types.js +32 -0
  10. package/lib/theme/ApiDemoPanel/Authorization/index.js +174 -0
  11. package/lib/theme/ApiDemoPanel/Authorization/slice.js +137 -0
  12. package/lib/theme/ApiDemoPanel/Body/index.js +185 -0
  13. package/lib/theme/ApiDemoPanel/Body/slice.js +105 -0
  14. package/lib/theme/ApiDemoPanel/ContentType/index.js +41 -0
  15. package/lib/theme/ApiDemoPanel/ContentType/slice.js +32 -0
  16. package/lib/theme/ApiDemoPanel/Curl/index.js +236 -0
  17. package/lib/theme/ApiDemoPanel/Curl/styles.module.css +84 -0
  18. package/lib/theme/ApiDemoPanel/Execute/index.js +85 -0
  19. package/lib/theme/ApiDemoPanel/Execute/makeRequest.js +202 -0
  20. package/lib/theme/ApiDemoPanel/FloatingButton/index.js +32 -0
  21. package/lib/theme/ApiDemoPanel/FloatingButton/styles.module.css +26 -0
  22. package/lib/theme/ApiDemoPanel/FormFileUpload/index.js +97 -0
  23. package/lib/theme/ApiDemoPanel/FormFileUpload/styles.module.css +75 -0
  24. package/lib/theme/ApiDemoPanel/FormItem/index.js +35 -0
  25. package/lib/theme/ApiDemoPanel/FormItem/styles.module.css +7 -0
  26. package/lib/theme/ApiDemoPanel/FormMultiSelect/index.js +52 -0
  27. package/lib/theme/ApiDemoPanel/FormMultiSelect/styles.module.css +38 -0
  28. package/lib/theme/ApiDemoPanel/FormSelect/index.js +39 -0
  29. package/lib/theme/ApiDemoPanel/FormSelect/styles.module.css +51 -0
  30. package/lib/theme/ApiDemoPanel/FormTextInput/index.js +30 -0
  31. package/lib/theme/ApiDemoPanel/FormTextInput/styles.module.css +21 -0
  32. package/lib/theme/ApiDemoPanel/MethodEndpoint/index.js +60 -0
  33. package/lib/theme/ApiDemoPanel/ParamOptions/index.js +248 -0
  34. package/lib/theme/ApiDemoPanel/ParamOptions/slice.js +35 -0
  35. package/lib/theme/ApiDemoPanel/ParamOptions/styles.module.css +180 -0
  36. package/lib/theme/ApiDemoPanel/Response/index.js +75 -0
  37. package/lib/theme/ApiDemoPanel/Response/slice.js +37 -0
  38. package/lib/theme/ApiDemoPanel/SecuritySchemes/index.js +51 -0
  39. package/lib/theme/ApiDemoPanel/Server/index.js +109 -0
  40. package/lib/theme/ApiDemoPanel/Server/slice.js +41 -0
  41. package/lib/theme/ApiDemoPanel/Server/styles.module.css +61 -0
  42. package/lib/theme/ApiDemoPanel/VSCode/index.js +252 -0
  43. package/lib/theme/ApiDemoPanel/VSCode/styles.module.css +19 -0
  44. package/lib/theme/ApiDemoPanel/buildPostmanRequest.js +329 -0
  45. package/lib/theme/ApiDemoPanel/hooks.js +20 -0
  46. package/lib/theme/ApiDemoPanel/index.js +134 -0
  47. package/lib/theme/ApiDemoPanel/persistanceMiddleware.js +44 -0
  48. package/lib/theme/ApiDemoPanel/postman-collection.d.ts +10 -0
  49. package/lib/theme/ApiDemoPanel/storage-utils.js +47 -0
  50. package/lib/theme/ApiDemoPanel/store.js +48 -0
  51. package/lib/theme/ApiDemoPanel/styles.module.css +44 -0
  52. package/lib/theme/ApiItem/index.js +160 -0
  53. package/lib/theme/ApiItem/styles.module.css +109 -0
  54. package/lib/theme/ParamsItem/index.js +68 -0
  55. package/lib/theme/ParamsItem/styles.module.css +24 -0
  56. package/lib/theme/SchemaItem/index.js +58 -0
  57. package/lib/theme/SchemaItem/styles.module.css +24 -0
  58. package/lib/theme/Tabs/index.js +258 -0
  59. package/lib/theme/Tabs/styles.module.css +118 -0
  60. package/lib/theme-classic.d.ts +8 -0
  61. package/lib/theme-openapi.d.ts +48 -0
  62. package/lib/theme-translations.d.ts +9 -0
  63. package/lib/types.js +1 -0
  64. package/lib-next/index.js +38 -0
  65. package/lib-next/markdown/createDescription.js +13 -0
  66. package/lib-next/markdown/schema.js +115 -0
  67. package/lib-next/markdown/utils.js +31 -0
  68. package/lib-next/theme/ApiDemoPanel/Accept/index.js +33 -0
  69. package/lib-next/theme/ApiDemoPanel/Accept/slice.js +19 -0
  70. package/lib-next/theme/ApiDemoPanel/Authorization/auth-types.js +22 -0
  71. package/lib-next/theme/ApiDemoPanel/Authorization/index.js +203 -0
  72. package/lib-next/theme/ApiDemoPanel/Authorization/slice.js +101 -0
  73. package/lib-next/theme/ApiDemoPanel/Body/index.js +210 -0
  74. package/lib-next/theme/ApiDemoPanel/Body/slice.js +89 -0
  75. package/lib-next/theme/ApiDemoPanel/ContentType/index.js +33 -0
  76. package/lib-next/theme/ApiDemoPanel/ContentType/slice.js +19 -0
  77. package/lib-next/theme/ApiDemoPanel/Curl/index.js +264 -0
  78. package/lib-next/theme/ApiDemoPanel/Curl/styles.module.css +84 -0
  79. package/lib-next/theme/ApiDemoPanel/Execute/index.js +74 -0
  80. package/lib-next/theme/ApiDemoPanel/Execute/makeRequest.js +183 -0
  81. package/lib-next/theme/ApiDemoPanel/FloatingButton/index.js +19 -0
  82. package/lib-next/theme/ApiDemoPanel/FloatingButton/styles.module.css +26 -0
  83. package/lib-next/theme/ApiDemoPanel/FormFileUpload/index.js +113 -0
  84. package/lib-next/theme/ApiDemoPanel/FormFileUpload/styles.module.css +75 -0
  85. package/lib-next/theme/ApiDemoPanel/FormItem/index.js +29 -0
  86. package/lib-next/theme/ApiDemoPanel/FormItem/styles.module.css +7 -0
  87. package/lib-next/theme/ApiDemoPanel/FormMultiSelect/index.js +49 -0
  88. package/lib-next/theme/ApiDemoPanel/FormMultiSelect/styles.module.css +38 -0
  89. package/lib-next/theme/ApiDemoPanel/FormSelect/index.js +28 -0
  90. package/lib-next/theme/ApiDemoPanel/FormSelect/styles.module.css +51 -0
  91. package/lib-next/theme/ApiDemoPanel/FormTextInput/index.js +23 -0
  92. package/lib-next/theme/ApiDemoPanel/FormTextInput/styles.module.css +21 -0
  93. package/lib-next/theme/ApiDemoPanel/MethodEndpoint/index.js +53 -0
  94. package/lib-next/theme/ApiDemoPanel/ParamOptions/index.js +284 -0
  95. package/lib-next/theme/ApiDemoPanel/ParamOptions/slice.js +22 -0
  96. package/lib-next/theme/ApiDemoPanel/ParamOptions/styles.module.css +180 -0
  97. package/lib-next/theme/ApiDemoPanel/Response/index.js +65 -0
  98. package/lib-next/theme/ApiDemoPanel/Response/slice.js +22 -0
  99. package/lib-next/theme/ApiDemoPanel/SecuritySchemes/index.js +48 -0
  100. package/lib-next/theme/ApiDemoPanel/Server/index.js +114 -0
  101. package/lib-next/theme/ApiDemoPanel/Server/slice.js +25 -0
  102. package/lib-next/theme/ApiDemoPanel/Server/styles.module.css +61 -0
  103. package/lib-next/theme/ApiDemoPanel/VSCode/index.js +265 -0
  104. package/lib-next/theme/ApiDemoPanel/VSCode/styles.module.css +19 -0
  105. package/lib-next/theme/ApiDemoPanel/buildPostmanRequest.js +310 -0
  106. package/lib-next/theme/ApiDemoPanel/hooks.js +9 -0
  107. package/lib-next/theme/ApiDemoPanel/index.js +110 -0
  108. package/lib-next/theme/ApiDemoPanel/persistanceMiddleware.js +38 -0
  109. package/lib-next/theme/ApiDemoPanel/postman-collection.d.ts +10 -0
  110. package/lib-next/theme/ApiDemoPanel/storage-utils.js +35 -0
  111. package/lib-next/theme/ApiDemoPanel/store.js +30 -0
  112. package/lib-next/theme/ApiDemoPanel/styles.module.css +44 -0
  113. package/lib-next/theme/ApiItem/index.js +171 -0
  114. package/lib-next/theme/ApiItem/styles.module.css +109 -0
  115. package/lib-next/theme/ParamsItem/index.js +68 -0
  116. package/lib-next/theme/ParamsItem/styles.module.css +24 -0
  117. package/lib-next/theme/SchemaItem/index.js +58 -0
  118. package/lib-next/theme/SchemaItem/styles.module.css +24 -0
  119. package/lib-next/theme/Tabs/index.js +258 -0
  120. package/lib-next/theme/Tabs/styles.module.css +118 -0
  121. package/lib-next/theme-classic.d.ts +8 -0
  122. package/lib-next/theme-openapi.d.ts +48 -0
  123. package/lib-next/theme-translations.d.ts +9 -0
  124. package/lib-next/types.js +1 -0
  125. package/package.json +68 -0
  126. package/src/index.ts +42 -0
  127. package/src/markdown/createDescription.ts +13 -0
  128. package/src/markdown/schema.ts +115 -0
  129. package/src/markdown/utils.ts +39 -0
  130. package/src/theme/ApiDemoPanel/Accept/index.tsx +35 -0
  131. package/src/theme/ApiDemoPanel/Accept/slice.ts +29 -0
  132. package/src/theme/ApiDemoPanel/Authorization/auth-types.ts +26 -0
  133. package/src/theme/ApiDemoPanel/Authorization/index.tsx +211 -0
  134. package/src/theme/ApiDemoPanel/Authorization/slice.ts +145 -0
  135. package/src/theme/ApiDemoPanel/Body/index.tsx +218 -0
  136. package/src/theme/ApiDemoPanel/Body/slice.ts +133 -0
  137. package/src/theme/ApiDemoPanel/ContentType/index.tsx +35 -0
  138. package/src/theme/ApiDemoPanel/ContentType/slice.ts +29 -0
  139. package/src/theme/ApiDemoPanel/Curl/index.tsx +280 -0
  140. package/src/theme/ApiDemoPanel/Curl/styles.module.css +84 -0
  141. package/src/theme/ApiDemoPanel/Execute/index.tsx +88 -0
  142. package/src/theme/ApiDemoPanel/Execute/makeRequest.ts +184 -0
  143. package/src/theme/ApiDemoPanel/FloatingButton/index.tsx +27 -0
  144. package/src/theme/ApiDemoPanel/FloatingButton/styles.module.css +26 -0
  145. package/src/theme/ApiDemoPanel/FormFileUpload/index.tsx +116 -0
  146. package/src/theme/ApiDemoPanel/FormFileUpload/styles.module.css +75 -0
  147. package/src/theme/ApiDemoPanel/FormItem/index.tsx +28 -0
  148. package/src/theme/ApiDemoPanel/FormItem/styles.module.css +7 -0
  149. package/src/theme/ApiDemoPanel/FormMultiSelect/index.tsx +54 -0
  150. package/src/theme/ApiDemoPanel/FormMultiSelect/styles.module.css +38 -0
  151. package/src/theme/ApiDemoPanel/FormSelect/index.tsx +36 -0
  152. package/src/theme/ApiDemoPanel/FormSelect/styles.module.css +51 -0
  153. package/src/theme/ApiDemoPanel/FormTextInput/index.tsx +32 -0
  154. package/src/theme/ApiDemoPanel/FormTextInput/styles.module.css +21 -0
  155. package/src/theme/ApiDemoPanel/MethodEndpoint/index.tsx +55 -0
  156. package/src/theme/ApiDemoPanel/ParamOptions/index.tsx +316 -0
  157. package/src/theme/ApiDemoPanel/ParamOptions/slice.ts +37 -0
  158. package/src/theme/ApiDemoPanel/ParamOptions/styles.module.css +180 -0
  159. package/src/theme/ApiDemoPanel/Response/index.tsx +66 -0
  160. package/src/theme/ApiDemoPanel/Response/slice.ts +31 -0
  161. package/src/theme/ApiDemoPanel/SecuritySchemes/index.tsx +49 -0
  162. package/src/theme/ApiDemoPanel/Server/index.tsx +103 -0
  163. package/src/theme/ApiDemoPanel/Server/slice.ts +40 -0
  164. package/src/theme/ApiDemoPanel/Server/styles.module.css +61 -0
  165. package/src/theme/ApiDemoPanel/VSCode/index.tsx +205 -0
  166. package/src/theme/ApiDemoPanel/VSCode/styles.module.css +19 -0
  167. package/src/theme/ApiDemoPanel/buildPostmanRequest.ts +307 -0
  168. package/src/theme/ApiDemoPanel/hooks.ts +13 -0
  169. package/src/theme/ApiDemoPanel/index.tsx +118 -0
  170. package/src/theme/ApiDemoPanel/persistanceMiddleware.ts +46 -0
  171. package/src/theme/ApiDemoPanel/postman-collection.d.ts +10 -0
  172. package/src/theme/ApiDemoPanel/storage-utils.ts +39 -0
  173. package/src/theme/ApiDemoPanel/store.ts +41 -0
  174. package/src/theme/ApiDemoPanel/styles.module.css +44 -0
  175. package/src/theme/ApiItem/index.tsx +171 -0
  176. package/src/theme/ApiItem/styles.module.css +109 -0
  177. package/src/theme/ParamsItem/index.js +68 -0
  178. package/src/theme/ParamsItem/styles.module.css +24 -0
  179. package/src/theme/SchemaItem/index.js +58 -0
  180. package/src/theme/SchemaItem/styles.module.css +24 -0
  181. package/src/theme/Tabs/index.js +258 -0
  182. package/src/theme/Tabs/styles.module.css +118 -0
  183. package/src/theme-classic.d.ts +8 -0
  184. package/src/theme-openapi.d.ts +48 -0
  185. package/src/theme-translations.d.ts +9 -0
  186. package/src/types.ts +70 -0
  187. package/tsconfig.json +10 -0
@@ -0,0 +1,133 @@
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 FileContent {
11
+ type: "file";
12
+ value: {
13
+ src: string;
14
+ content: Blob;
15
+ };
16
+ }
17
+
18
+ export interface StringContent {
19
+ type: "string";
20
+ value?: string;
21
+ }
22
+
23
+ export type Content = FileContent | StringContent | undefined;
24
+
25
+ export interface FormBody {
26
+ type: "form";
27
+ content: {
28
+ [key: string]: Content;
29
+ };
30
+ }
31
+
32
+ export interface RawBody {
33
+ type: "raw";
34
+ content: Content;
35
+ }
36
+
37
+ export interface EmptyBody {
38
+ type: "empty";
39
+ }
40
+
41
+ export type Body = EmptyBody | FormBody | RawBody;
42
+
43
+ export type State = Body;
44
+
45
+ const initialState: State = {} as any;
46
+
47
+ export const slice = createSlice({
48
+ name: "body",
49
+ initialState,
50
+ reducers: {
51
+ clearRawBody: (_state) => {
52
+ return {
53
+ type: "empty",
54
+ };
55
+ },
56
+ setStringRawBody: (_state, action: PayloadAction<string>) => {
57
+ return {
58
+ type: "raw",
59
+ content: {
60
+ type: "string",
61
+ value: action.payload,
62
+ },
63
+ };
64
+ },
65
+ setFileRawBody: (_state, action: PayloadAction<FileContent["value"]>) => {
66
+ return {
67
+ type: "raw",
68
+ content: {
69
+ type: "file",
70
+ value: action.payload,
71
+ },
72
+ };
73
+ },
74
+ clearFormBodyKey: (state, action: PayloadAction<string>) => {
75
+ if (state?.type === "form") {
76
+ delete state.content[action.payload];
77
+ }
78
+ },
79
+ setStringFormBody: (
80
+ state,
81
+ action: PayloadAction<{ key: string; value: string }>
82
+ ) => {
83
+ if (state?.type !== "form") {
84
+ return {
85
+ type: "form",
86
+ content: {
87
+ [action.payload.key]: {
88
+ type: "string",
89
+ value: action.payload.value,
90
+ },
91
+ },
92
+ };
93
+ }
94
+ state.content[action.payload.key] = {
95
+ type: "string",
96
+ value: action.payload.value,
97
+ };
98
+ return state;
99
+ },
100
+ setFileFormBody: (
101
+ state,
102
+ action: PayloadAction<{ key: string; value: FileContent["value"] }>
103
+ ) => {
104
+ if (state?.type !== "form") {
105
+ return {
106
+ type: "form",
107
+ content: {
108
+ [action.payload.key]: {
109
+ type: "file",
110
+ value: action.payload.value,
111
+ },
112
+ },
113
+ };
114
+ }
115
+ state.content[action.payload.key] = {
116
+ type: "file",
117
+ value: action.payload.value,
118
+ };
119
+ return state;
120
+ },
121
+ },
122
+ });
123
+
124
+ export const {
125
+ clearRawBody,
126
+ setStringRawBody,
127
+ setFileRawBody,
128
+ clearFormBodyKey,
129
+ setStringFormBody,
130
+ setFileFormBody,
131
+ } = slice.actions;
132
+
133
+ export default slice.reducer;
@@ -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,280 @@
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
+ // @ts-ignore
12
+ import codegen from "@paloaltonetworks/postman-code-generators";
13
+ // @ts-ignore
14
+ import sdk from "@paloaltonetworks/postman-collection";
15
+ import clsx from "clsx";
16
+ import Highlight, { defaultProps } from "prism-react-renderer";
17
+
18
+ import { useTypedSelector } from "../hooks";
19
+ import buildPostmanRequest from "./../buildPostmanRequest";
20
+ import FloatingButton from "./../FloatingButton";
21
+ import styles from "./styles.module.css";
22
+
23
+ interface Language {
24
+ tabName: string;
25
+ highlight: string;
26
+ language: string;
27
+ variant: string;
28
+ options: { [key: string]: boolean };
29
+ }
30
+
31
+ const languageSet: Language[] = [
32
+ {
33
+ tabName: "cURL",
34
+ highlight: "bash",
35
+ language: "curl",
36
+ variant: "curl",
37
+ options: {
38
+ longFormat: false,
39
+ followRedirect: true,
40
+ trimRequestBody: true,
41
+ },
42
+ },
43
+ {
44
+ tabName: "Node",
45
+ highlight: "javascript",
46
+ language: "nodejs",
47
+ variant: "axios",
48
+ options: {
49
+ ES6_enabled: true,
50
+ followRedirect: true,
51
+ trimRequestBody: true,
52
+ },
53
+ },
54
+ {
55
+ tabName: "Go",
56
+ highlight: "go",
57
+ language: "go",
58
+ variant: "native",
59
+ options: {
60
+ followRedirect: true,
61
+ trimRequestBody: true,
62
+ },
63
+ },
64
+ {
65
+ tabName: "Python",
66
+ highlight: "python",
67
+ language: "python",
68
+ variant: "requests",
69
+ options: {
70
+ followRedirect: true,
71
+ trimRequestBody: true,
72
+ },
73
+ },
74
+ ];
75
+
76
+ const languageTheme = {
77
+ plain: {
78
+ color: "var(--ifm-code-color)",
79
+ },
80
+ styles: [
81
+ {
82
+ types: ["inserted", "attr-name"],
83
+ style: {
84
+ color: "var(--openapi-code-green)",
85
+ },
86
+ },
87
+ {
88
+ types: ["string", "url"],
89
+ style: {
90
+ color: "var(--openapi-code-green)",
91
+ },
92
+ },
93
+ {
94
+ types: ["builtin", "char", "constant", "function"],
95
+ style: {
96
+ color: "var(--openapi-code-blue)",
97
+ },
98
+ },
99
+ {
100
+ types: ["punctuation", "operator"],
101
+ style: {
102
+ color: "var(--openapi-code-dim)",
103
+ },
104
+ },
105
+ {
106
+ types: ["class-name"],
107
+ style: {
108
+ color: "var(--openapi-code-orange)",
109
+ },
110
+ },
111
+ {
112
+ types: ["tag", "arrow", "keyword"],
113
+ style: {
114
+ color: "var(--openapi-code-purple)",
115
+ },
116
+ },
117
+ {
118
+ types: ["boolean"],
119
+ style: {
120
+ color: "var(--openapi-code-red)",
121
+ },
122
+ },
123
+ ],
124
+ };
125
+
126
+ interface Props {
127
+ postman: sdk.Request;
128
+ codeSamples: any; // TODO: Type this...
129
+ }
130
+
131
+ function Curl({ postman, codeSamples }: Props) {
132
+ // TODO: match theme for vscode.
133
+
134
+ const { siteConfig } = useDocusaurusContext();
135
+
136
+ const [copyText, setCopyText] = useState("Copy");
137
+
138
+ const contentType = useTypedSelector((state) => state.contentType.value);
139
+ const accept = useTypedSelector((state) => state.accept.value);
140
+ const server = useTypedSelector((state) => state.server.value);
141
+ const body = useTypedSelector((state) => state.body);
142
+
143
+ const pathParams = useTypedSelector((state) => state.params.path);
144
+ const queryParams = useTypedSelector((state) => state.params.query);
145
+ const cookieParams = useTypedSelector((state) => state.params.cookie);
146
+ const headerParams = useTypedSelector((state) => state.params.header);
147
+
148
+ const auth = useTypedSelector((state) => state.auth);
149
+
150
+ // TODO
151
+ const langs = [
152
+ ...((siteConfig?.themeConfig?.languageTabs as Language[] | undefined) ??
153
+ languageSet),
154
+ ...codeSamples,
155
+ ];
156
+
157
+ const [language, setLanguage] = useState(langs[0]);
158
+
159
+ const [codeText, setCodeText] = useState("");
160
+
161
+ useEffect(() => {
162
+ if (language && !!language.options) {
163
+ const postmanRequest = buildPostmanRequest(postman, {
164
+ queryParams,
165
+ pathParams,
166
+ cookieParams,
167
+ contentType,
168
+ accept,
169
+ headerParams,
170
+ body,
171
+ server,
172
+ auth,
173
+ });
174
+
175
+ codegen.convert(
176
+ language.language,
177
+ language.variant,
178
+ postmanRequest,
179
+ language.options,
180
+ (error: any, snippet: string) => {
181
+ if (error) {
182
+ return;
183
+ }
184
+ setCodeText(snippet);
185
+ }
186
+ );
187
+ } else if (language && !!language.source) {
188
+ setCodeText(language.source);
189
+ } else {
190
+ setCodeText("");
191
+ }
192
+ }, [
193
+ accept,
194
+ body,
195
+ contentType,
196
+ cookieParams,
197
+ headerParams,
198
+ language,
199
+ pathParams,
200
+ postman,
201
+ queryParams,
202
+ server,
203
+ auth,
204
+ ]);
205
+
206
+ const ref = useRef<HTMLDivElement>(null);
207
+
208
+ const handleCurlCopy = () => {
209
+ setCopyText("Copied");
210
+ setTimeout(() => {
211
+ setCopyText("Copy");
212
+ }, 2000);
213
+ if (ref.current?.innerText) {
214
+ navigator.clipboard.writeText(ref.current.innerText);
215
+ }
216
+ };
217
+
218
+ if (language === undefined) {
219
+ return null;
220
+ }
221
+
222
+ return (
223
+ <>
224
+ <div className={clsx(styles.buttonGroup, "api-code-tab-group")}>
225
+ {langs.map((lang) => {
226
+ return (
227
+ <button
228
+ key={lang.tabName || lang.label}
229
+ className={clsx(
230
+ language === lang ? styles.selected : undefined,
231
+ language === lang ? "api-code-tab--active" : undefined,
232
+ "api-code-tab"
233
+ )}
234
+ onClick={() => setLanguage(lang)}
235
+ >
236
+ {lang.tabName || lang.label}
237
+ </button>
238
+ );
239
+ })}
240
+ </div>
241
+
242
+ <Highlight
243
+ {...defaultProps}
244
+ theme={languageTheme}
245
+ code={codeText}
246
+ language={language.highlight || language.lang}
247
+ >
248
+ {({ className, tokens, getLineProps, getTokenProps }) => (
249
+ <FloatingButton onClick={handleCurlCopy} label={copyText}>
250
+ <pre
251
+ className={className}
252
+ style={{
253
+ background: "var(--openapi-card-background-color)",
254
+ paddingRight: "60px",
255
+ borderRadius:
256
+ "2px 2px var(--openapi-card-border-radius) var(--openapi-card-border-radius)",
257
+ }}
258
+ >
259
+ <code ref={ref}>
260
+ {tokens.map((line, i) => (
261
+ <span {...getLineProps({ line, key: i })}>
262
+ {line.map((token, key) => {
263
+ if (token.types.includes("arrow")) {
264
+ token.types = ["arrow"];
265
+ }
266
+ return <span {...getTokenProps({ token, key })} />;
267
+ })}
268
+ {"\n"}
269
+ </span>
270
+ ))}
271
+ </code>
272
+ </pre>
273
+ </FloatingButton>
274
+ )}
275
+ </Highlight>
276
+ </>
277
+ );
278
+ }
279
+
280
+ 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,88 @@
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
+ // @ts-ignore
11
+ import sdk from "@paloaltonetworks/postman-collection";
12
+
13
+ import { useTypedDispatch, useTypedSelector } from "../hooks";
14
+ import { Param } from "../ParamOptions/slice";
15
+ import { setResponse } from "../Response/slice";
16
+ import buildPostmanRequest from "./../buildPostmanRequest";
17
+ import makeRequest from "./makeRequest";
18
+
19
+ function validateRequest(params: {
20
+ path: Param[];
21
+ query: Param[];
22
+ header: Param[];
23
+ cookie: Param[];
24
+ }) {
25
+ for (let paramList of Object.values(params)) {
26
+ for (let param of paramList) {
27
+ if (param.required && !param.value) {
28
+ return false;
29
+ }
30
+ }
31
+ }
32
+ return true;
33
+ }
34
+
35
+ interface Props {
36
+ postman: sdk.Request;
37
+ proxy?: string;
38
+ }
39
+
40
+ function Execute({ postman, proxy }: Props) {
41
+ const pathParams = useTypedSelector((state) => state.params.path);
42
+ const queryParams = useTypedSelector((state) => state.params.query);
43
+ const cookieParams = useTypedSelector((state) => state.params.cookie);
44
+ const headerParams = useTypedSelector((state) => state.params.header);
45
+ const contentType = useTypedSelector((state) => state.contentType.value);
46
+ const body = useTypedSelector((state) => state.body);
47
+ const accept = useTypedSelector((state) => state.accept.value);
48
+ const server = useTypedSelector((state) => state.server.value);
49
+ const params = useTypedSelector((state) => state.params);
50
+ const auth = useTypedSelector((state) => state.auth);
51
+
52
+ const isValidRequest = validateRequest(params);
53
+
54
+ const dispatch = useTypedDispatch();
55
+
56
+ const postmanRequest = buildPostmanRequest(postman, {
57
+ queryParams,
58
+ pathParams,
59
+ cookieParams,
60
+ contentType,
61
+ accept,
62
+ headerParams,
63
+ body,
64
+ server,
65
+ auth,
66
+ });
67
+
68
+ return (
69
+ <button
70
+ className="button button--block button--primary"
71
+ style={{ height: "48px", marginBottom: "var(--ifm-spacing-vertical)" }}
72
+ disabled={!isValidRequest}
73
+ onClick={async () => {
74
+ dispatch(setResponse("loading..."));
75
+ try {
76
+ const res = await makeRequest(postmanRequest, proxy, body);
77
+ dispatch(setResponse(res));
78
+ } catch (e: any) {
79
+ dispatch(setResponse(e.message ?? "Error fetching."));
80
+ }
81
+ }}
82
+ >
83
+ Execute
84
+ </button>
85
+ );
86
+ }
87
+
88
+ export default Execute;