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,101 @@
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 { createSlice } from "@reduxjs/toolkit";
8
+ import { createStorage, hashArray } from "../storage-utils";
9
+ import { getAuthDataKeys } from "./auth-types"; // The global definitions
10
+ // "securitySchemes": {
11
+ // "BearerAuth": { "type": "http", "scheme": "BeAreR" },
12
+ // "BasicAuth": { "type": "http", "scheme": "basic" }
13
+ // },
14
+ // The operation level requirements
15
+ // "security": [
16
+ // { "BearerAuth": [] },
17
+ // { "BearerAuth": [], "BasicAuth": [] }
18
+ // ],
19
+ // SLICE_STATE
20
+ // data:
21
+ // BearerAuth:
22
+ // token=xxx
23
+ // BasicAuth:
24
+ // username=xxx
25
+ // password=xxx
26
+ //
27
+ // options:
28
+ // "BearerAuth": [{ key: "BearerAuth", scopes: [], ...rest }]
29
+ // "BearerAuth and BasicAuth": [{ key: "BearerAuth", scopes: [], ...rest }, { key: "BasicAuth", scopes: [], ...rest }]
30
+ //
31
+ // selected: "BearerAuth and BasicAuth"
32
+ // LOCAL_STORAGE
33
+ // hash(SLICE_STATE.options) -> "BearerAuth and BasicAuth"
34
+ // BearerAuth -> { token: xxx }
35
+ // BasicAuth -> { username: xxx, password: xxx }
36
+
37
+ export function createAuth({ security, securitySchemes, options: opts }) {
38
+ const storage = createStorage(opts?.authPersistance);
39
+ let data = {};
40
+ let options = {};
41
+
42
+ for (const option of security ?? []) {
43
+ const id = Object.keys(option).join(" and ");
44
+
45
+ for (const [schemeID, scopes] of Object.entries(option)) {
46
+ const scheme = securitySchemes?.[schemeID];
47
+
48
+ if (scheme) {
49
+ if (options[id] === undefined) {
50
+ options[id] = [];
51
+ }
52
+
53
+ const dataKeys = getAuthDataKeys(scheme);
54
+
55
+ for (const key of dataKeys) {
56
+ if (data[schemeID] === undefined) {
57
+ data[schemeID] = {};
58
+ }
59
+
60
+ let persisted = undefined;
61
+
62
+ try {
63
+ persisted = JSON.parse(storage.getItem(schemeID) ?? "")[key];
64
+ } catch {}
65
+
66
+ data[schemeID][key] = persisted;
67
+ }
68
+
69
+ options[id].push({ ...scheme, key: schemeID, scopes });
70
+ }
71
+ }
72
+ }
73
+
74
+ let persisted = undefined;
75
+
76
+ try {
77
+ persisted = storage.getItem(hashArray(Object.keys(options))) ?? undefined;
78
+ } catch {}
79
+
80
+ return {
81
+ data,
82
+ options,
83
+ selected: persisted ?? Object.keys(options)[0],
84
+ };
85
+ }
86
+ const initialState = {};
87
+ export const slice = createSlice({
88
+ name: "auth",
89
+ initialState,
90
+ reducers: {
91
+ setAuthData: (state, action) => {
92
+ const { scheme, key, value } = action.payload;
93
+ state.data[scheme][key] = value;
94
+ },
95
+ setSelectedAuth: (state, action) => {
96
+ state.selected = action.payload;
97
+ },
98
+ },
99
+ });
100
+ export const { setAuthData, setSelectedAuth } = slice.actions;
101
+ export default slice.reducer;
@@ -0,0 +1,210 @@
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 ContentType from "../ContentType";
9
+ import FormSelect from "../FormSelect";
10
+ import { useTypedDispatch, useTypedSelector } from "../hooks";
11
+ import FormFileUpload from "./../FormFileUpload";
12
+ import FormItem from "./../FormItem";
13
+ import FormTextInput from "./../FormTextInput";
14
+ import VSCode from "./../VSCode";
15
+ import {
16
+ clearFormBodyKey,
17
+ clearRawBody,
18
+ setFileFormBody,
19
+ setFileRawBody,
20
+ setStringFormBody,
21
+ setStringRawBody,
22
+ } from "./slice";
23
+
24
+ function BodyWrap({ requestBodyMetadata, jsonRequestBodyExample }) {
25
+ const contentType = useTypedSelector((state) => state.contentType.value); // NOTE: We used to check if body was required, but opted to always show the request body
26
+ // to reduce confusion, see: https://github.com/cloud-annotations/docusaurus-openapi/issues/145
27
+ // No body
28
+
29
+ if (contentType === undefined) {
30
+ return null;
31
+ }
32
+
33
+ return (
34
+ <>
35
+ <ContentType />
36
+ <Body
37
+ requestBodyMetadata={requestBodyMetadata}
38
+ jsonRequestBodyExample={jsonRequestBodyExample}
39
+ />
40
+ </>
41
+ );
42
+ }
43
+
44
+ function Body({ requestBodyMetadata, jsonRequestBodyExample }) {
45
+ const contentType = useTypedSelector((state) => state.contentType.value);
46
+ const dispatch = useTypedDispatch(); // Lot's of possible content-types:
47
+ // - application/json
48
+ // - application/xml
49
+ // - text/plain
50
+ // - text/css
51
+ // - text/html
52
+ // - text/javascript
53
+ // - application/javascript
54
+ // - multipart/form-data
55
+ // - application/x-www-form-urlencoded
56
+ // - image/svg+xml;charset=US-ASCII
57
+ // Show editor:
58
+ // - application/json
59
+ // - application/xml
60
+ // - */*
61
+ // Show form:
62
+ // - multipart/form-data
63
+ // - application/x-www-form-urlencoded
64
+
65
+ const schema = requestBodyMetadata?.content?.[contentType]?.schema;
66
+
67
+ if (schema?.format === "binary") {
68
+ return (
69
+ <FormItem label="Body">
70
+ <FormFileUpload
71
+ placeholder={schema.description || "Body"}
72
+ onChange={(file) => {
73
+ if (file === undefined) {
74
+ dispatch(clearRawBody());
75
+ return;
76
+ }
77
+
78
+ dispatch(
79
+ setFileRawBody({
80
+ src: `/path/to/${file.name}`,
81
+ content: file,
82
+ })
83
+ );
84
+ }}
85
+ />
86
+ </FormItem>
87
+ );
88
+ }
89
+
90
+ if (
91
+ (contentType === "multipart/form-data" ||
92
+ contentType === "application/x-www-form-urlencoded") &&
93
+ schema?.type === "object"
94
+ ) {
95
+ return (
96
+ <FormItem label="Body">
97
+ <div
98
+ style={{
99
+ marginTop: "calc(var(--ifm-pre-padding) / 2)",
100
+ borderRadius: "4px",
101
+ padding: "var(--ifm-pre-padding)",
102
+ border: "1px solid var(--openapi-monaco-border-color)",
103
+ }}
104
+ >
105
+ {Object.entries(schema.properties ?? {}).map(([key, val]) => {
106
+ if (val.format === "binary") {
107
+ return (
108
+ <FormItem key={key} label={key}>
109
+ <FormFileUpload
110
+ placeholder={val.description || key}
111
+ onChange={(file) => {
112
+ if (file === undefined) {
113
+ dispatch(clearFormBodyKey(key));
114
+ return;
115
+ }
116
+
117
+ dispatch(
118
+ setFileFormBody({
119
+ key: key,
120
+ value: {
121
+ src: `/path/to/${file.name}`,
122
+ content: file,
123
+ },
124
+ })
125
+ );
126
+ }}
127
+ />
128
+ </FormItem>
129
+ );
130
+ }
131
+
132
+ if (val.enum) {
133
+ return (
134
+ <FormItem key={key} label={key}>
135
+ <FormSelect
136
+ options={["---", ...val.enum]}
137
+ onChange={(e) => {
138
+ const val = e.target.value;
139
+
140
+ if (val === "---") {
141
+ dispatch(clearFormBodyKey(key));
142
+ } else {
143
+ dispatch(
144
+ setStringFormBody({
145
+ key: key,
146
+ value: val,
147
+ })
148
+ );
149
+ }
150
+ }}
151
+ />
152
+ </FormItem>
153
+ );
154
+ } // TODO: support all the other types.
155
+
156
+ return (
157
+ <FormItem key={key} label={key}>
158
+ <FormTextInput
159
+ placeholder={val.description || key}
160
+ onChange={(e) => {
161
+ dispatch(
162
+ setStringFormBody({
163
+ key: key,
164
+ value: e.target.value,
165
+ })
166
+ );
167
+ }}
168
+ />
169
+ </FormItem>
170
+ );
171
+ })}
172
+ </div>
173
+ </FormItem>
174
+ );
175
+ }
176
+
177
+ let language = "plaintext";
178
+ let exampleBodyString = ""; //"body content";
179
+
180
+ if (contentType === "application/json") {
181
+ if (jsonRequestBodyExample) {
182
+ exampleBodyString = JSON.stringify(jsonRequestBodyExample, null, 2);
183
+ }
184
+
185
+ language = "json";
186
+ }
187
+
188
+ if (contentType === "application/xml") {
189
+ language = "xml";
190
+ }
191
+
192
+ return (
193
+ <FormItem label="Body">
194
+ <VSCode
195
+ value={exampleBodyString}
196
+ language={language}
197
+ onChange={(value) => {
198
+ if (value.trim() === "") {
199
+ dispatch(clearRawBody());
200
+ return;
201
+ }
202
+
203
+ dispatch(setStringRawBody(value));
204
+ }}
205
+ />
206
+ </FormItem>
207
+ );
208
+ }
209
+
210
+ export default BodyWrap;
@@ -0,0 +1,89 @@
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 { createSlice } from "@reduxjs/toolkit";
8
+ const initialState = {};
9
+ export const slice = createSlice({
10
+ name: "body",
11
+ initialState,
12
+ reducers: {
13
+ clearRawBody: (_state) => {
14
+ return {
15
+ type: "empty",
16
+ };
17
+ },
18
+ setStringRawBody: (_state, action) => {
19
+ return {
20
+ type: "raw",
21
+ content: {
22
+ type: "string",
23
+ value: action.payload,
24
+ },
25
+ };
26
+ },
27
+ setFileRawBody: (_state, action) => {
28
+ return {
29
+ type: "raw",
30
+ content: {
31
+ type: "file",
32
+ value: action.payload,
33
+ },
34
+ };
35
+ },
36
+ clearFormBodyKey: (state, action) => {
37
+ if (state?.type === "form") {
38
+ delete state.content[action.payload];
39
+ }
40
+ },
41
+ setStringFormBody: (state, action) => {
42
+ if (state?.type !== "form") {
43
+ return {
44
+ type: "form",
45
+ content: {
46
+ [action.payload.key]: {
47
+ type: "string",
48
+ value: action.payload.value,
49
+ },
50
+ },
51
+ };
52
+ }
53
+
54
+ state.content[action.payload.key] = {
55
+ type: "string",
56
+ value: action.payload.value,
57
+ };
58
+ return state;
59
+ },
60
+ setFileFormBody: (state, action) => {
61
+ if (state?.type !== "form") {
62
+ return {
63
+ type: "form",
64
+ content: {
65
+ [action.payload.key]: {
66
+ type: "file",
67
+ value: action.payload.value,
68
+ },
69
+ },
70
+ };
71
+ }
72
+
73
+ state.content[action.payload.key] = {
74
+ type: "file",
75
+ value: action.payload.value,
76
+ };
77
+ return state;
78
+ },
79
+ },
80
+ });
81
+ export const {
82
+ clearRawBody,
83
+ setStringRawBody,
84
+ setFileRawBody,
85
+ clearFormBodyKey,
86
+ setStringFormBody,
87
+ setFileFormBody,
88
+ } = slice.actions;
89
+ export default slice.reducer;
@@ -0,0 +1,33 @@
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 { useTypedDispatch, useTypedSelector } from "../hooks";
9
+ import FormItem from "./../FormItem";
10
+ import FormSelect from "./../FormSelect";
11
+ import { setContentType } from "./slice";
12
+
13
+ function ContentType() {
14
+ const value = useTypedSelector((state) => state.contentType.value);
15
+ const options = useTypedSelector((state) => state.contentType.options);
16
+ const dispatch = useTypedDispatch();
17
+
18
+ if (options.length <= 1) {
19
+ return null;
20
+ }
21
+
22
+ return (
23
+ <FormItem label="Content-Type">
24
+ <FormSelect
25
+ value={value}
26
+ options={options}
27
+ onChange={(e) => dispatch(setContentType(e.target.value))}
28
+ />
29
+ </FormItem>
30
+ );
31
+ }
32
+
33
+ export default ContentType;
@@ -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 { createSlice } from "@reduxjs/toolkit";
8
+ const initialState = {};
9
+ export const slice = createSlice({
10
+ name: "contentType",
11
+ initialState,
12
+ reducers: {
13
+ setContentType: (state, action) => {
14
+ state.value = action.payload;
15
+ },
16
+ },
17
+ });
18
+ export const { setContentType } = slice.actions;
19
+ export default slice.reducer;