docusaurus-theme-openapi-docs 1.2.2 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/theme/ApiDemoPanel/Accept/index.js +1 -1
- package/lib/theme/ApiDemoPanel/Authorization/index.js +2 -2
- package/lib/theme/ApiDemoPanel/Body/index.js +104 -9
- package/lib/theme/ApiDemoPanel/ContentType/index.js +1 -1
- package/lib/theme/ApiDemoPanel/Curl/index.js +2 -2
- package/lib/theme/ApiDemoPanel/Execute/index.js +1 -1
- package/lib/theme/ApiDemoPanel/ParamOptions/index.js +1 -1
- package/lib/theme/ApiDemoPanel/Request/index.js +2 -2
- package/lib/theme/ApiDemoPanel/Response/index.js +1 -1
- package/lib/theme/ApiDemoPanel/SecuritySchemes/index.js +1 -1
- package/lib/theme/ApiDemoPanel/Server/index.js +27 -10
- package/lib/theme/ApiDemoPanel/Server/slice.js +3 -2
- package/lib/theme/ApiDemoPanel/index.js +8 -72
- package/lib/theme/ApiDemoPanel/persistanceMiddleware.js +22 -0
- package/lib/theme/ApiItem/Layout/styles.module.css +11 -3
- package/lib/theme/{ApiDemoPanel → ApiItem}/hooks.js +0 -0
- package/lib/theme/ApiItem/index.js +101 -22
- package/lib/theme/{ApiDemoPanel → ApiItem}/store.js +7 -7
- package/lib/theme/MimeTabs/index.js +29 -1
- package/lib/theme/MimeTabs/styles.module.css +1 -0
- package/lib/theme/ParamsItem/index.js +6 -1
- package/lib/theme/SchemaItem/index.js +6 -1
- package/lib/theme/SchemaTabs/index.js +4 -1
- package/lib-next/theme/ApiDemoPanel/Accept/index.js +1 -1
- package/lib-next/theme/ApiDemoPanel/Authorization/index.js +1 -1
- package/lib-next/theme/ApiDemoPanel/Body/index.js +114 -7
- package/lib-next/theme/ApiDemoPanel/ContentType/index.js +1 -1
- package/lib-next/theme/ApiDemoPanel/Curl/index.js +1 -1
- package/lib-next/theme/ApiDemoPanel/Execute/index.js +1 -1
- package/lib-next/theme/ApiDemoPanel/ParamOptions/index.js +1 -1
- package/lib-next/theme/ApiDemoPanel/Request/index.js +1 -1
- package/lib-next/theme/ApiDemoPanel/Response/index.js +1 -1
- package/lib-next/theme/ApiDemoPanel/SecuritySchemes/index.js +1 -1
- package/lib-next/theme/ApiDemoPanel/Server/index.js +38 -10
- package/lib-next/theme/ApiDemoPanel/Server/slice.js +5 -3
- package/lib-next/theme/ApiDemoPanel/index.js +7 -69
- package/lib-next/theme/ApiDemoPanel/persistanceMiddleware.js +20 -0
- package/lib-next/theme/ApiItem/Layout/styles.module.css +11 -3
- package/lib-next/theme/{ApiDemoPanel → ApiItem}/hooks.js +0 -0
- package/lib-next/theme/ApiItem/index.js +104 -26
- package/lib-next/theme/{ApiDemoPanel → ApiItem}/store.js +7 -7
- package/lib-next/theme/MimeTabs/index.js +29 -1
- package/lib-next/theme/MimeTabs/styles.module.css +1 -0
- package/lib-next/theme/ParamsItem/index.js +6 -1
- package/lib-next/theme/SchemaItem/index.js +6 -1
- package/lib-next/theme/SchemaTabs/index.js +4 -1
- package/package.json +4 -3
- package/src/theme/ApiDemoPanel/Accept/index.tsx +1 -1
- package/src/theme/ApiDemoPanel/Authorization/index.tsx +1 -1
- package/src/theme/ApiDemoPanel/Body/index.tsx +107 -7
- package/src/theme/ApiDemoPanel/ContentType/index.tsx +1 -1
- package/src/theme/ApiDemoPanel/Curl/index.tsx +1 -1
- package/src/theme/ApiDemoPanel/Execute/index.tsx +1 -1
- package/src/theme/ApiDemoPanel/ParamOptions/index.tsx +1 -1
- package/src/theme/ApiDemoPanel/Request/index.tsx +1 -1
- package/src/theme/ApiDemoPanel/Response/index.tsx +1 -1
- package/src/theme/ApiDemoPanel/SecuritySchemes/index.tsx +1 -1
- package/src/theme/ApiDemoPanel/Server/index.tsx +34 -6
- package/src/theme/ApiDemoPanel/Server/slice.ts +6 -7
- package/src/theme/ApiDemoPanel/index.tsx +10 -73
- package/src/theme/ApiDemoPanel/persistanceMiddleware.ts +21 -1
- package/src/theme/ApiItem/Layout/styles.module.css +11 -3
- package/src/theme/{ApiDemoPanel → ApiItem}/hooks.ts +0 -0
- package/src/theme/ApiItem/index.tsx +103 -27
- package/src/theme/{ApiDemoPanel → ApiItem}/store.ts +7 -7
- package/src/theme/MimeTabs/index.js +29 -1
- package/src/theme/MimeTabs/styles.module.css +1 -0
- package/src/theme/ParamsItem/index.js +6 -1
- package/src/theme/SchemaItem/index.js +6 -1
- package/src/theme/SchemaTabs/index.js +4 -1
|
@@ -7,12 +7,15 @@
|
|
|
7
7
|
|
|
8
8
|
import React from "react";
|
|
9
9
|
|
|
10
|
+
import TabItem from "@theme/TabItem";
|
|
10
11
|
import { RequestBodyObject } from "docusaurus-plugin-openapi-docs/src/openapi/types";
|
|
11
12
|
import format from "xml-formatter";
|
|
12
13
|
|
|
14
|
+
import { useTypedDispatch, useTypedSelector } from "../../ApiItem/hooks";
|
|
15
|
+
// @ts-ignore
|
|
16
|
+
import SchemaTabs from "../../SchemaTabs";
|
|
13
17
|
import ContentType from "../ContentType";
|
|
14
18
|
import FormSelect from "../FormSelect";
|
|
15
|
-
import { useTypedDispatch, useTypedSelector } from "../hooks";
|
|
16
19
|
import LiveApp from "../LiveEditor";
|
|
17
20
|
import FormFileUpload from "./../FormFileUpload";
|
|
18
21
|
import FormItem from "./../FormItem";
|
|
@@ -82,6 +85,8 @@ function Body({ requestBodyMetadata, jsonRequestBodyExample }: Props) {
|
|
|
82
85
|
// - application/x-www-form-urlencoded
|
|
83
86
|
|
|
84
87
|
const schema = requestBodyMetadata?.content?.[contentType]?.schema;
|
|
88
|
+
const example = requestBodyMetadata?.content?.[contentType]?.example;
|
|
89
|
+
const examples = requestBodyMetadata?.content?.[contentType]?.examples;
|
|
85
90
|
|
|
86
91
|
if (schema?.format === "binary") {
|
|
87
92
|
return (
|
|
@@ -209,34 +214,129 @@ function Body({ requestBodyMetadata, jsonRequestBodyExample }: Props) {
|
|
|
209
214
|
}
|
|
210
215
|
|
|
211
216
|
let language = "plaintext";
|
|
212
|
-
let
|
|
217
|
+
let defaultBody = ""; //"body content";
|
|
218
|
+
let exampleBody;
|
|
219
|
+
let examplesBodies = [] as any;
|
|
213
220
|
|
|
214
221
|
if (contentType === "application/json" || contentType.endsWith("+json")) {
|
|
215
222
|
if (jsonRequestBodyExample) {
|
|
216
|
-
|
|
223
|
+
defaultBody = JSON.stringify(jsonRequestBodyExample, null, 2);
|
|
224
|
+
}
|
|
225
|
+
if (example) {
|
|
226
|
+
exampleBody = JSON.stringify(example, null, 2);
|
|
227
|
+
}
|
|
228
|
+
if (examples) {
|
|
229
|
+
for (const [key, example] of Object.entries(examples)) {
|
|
230
|
+
examplesBodies.push({
|
|
231
|
+
label: key,
|
|
232
|
+
body: JSON.stringify(example.value, null, 2),
|
|
233
|
+
summary: example.summary,
|
|
234
|
+
});
|
|
235
|
+
}
|
|
217
236
|
}
|
|
218
237
|
language = "json";
|
|
219
238
|
}
|
|
220
239
|
|
|
221
|
-
if (contentType === "application/xml") {
|
|
240
|
+
if (contentType === "application/xml" || contentType.endsWith("+xml")) {
|
|
222
241
|
if (jsonRequestBodyExample) {
|
|
223
242
|
try {
|
|
224
|
-
|
|
243
|
+
defaultBody = format(json2xml(jsonRequestBodyExample, ""), {
|
|
244
|
+
indentation: " ",
|
|
245
|
+
lineSeparator: "\n",
|
|
246
|
+
collapseContent: true,
|
|
247
|
+
});
|
|
248
|
+
} catch {
|
|
249
|
+
defaultBody = json2xml(jsonRequestBodyExample);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
if (example) {
|
|
253
|
+
try {
|
|
254
|
+
exampleBody = format(json2xml(example, ""), {
|
|
225
255
|
indentation: " ",
|
|
226
256
|
lineSeparator: "\n",
|
|
227
257
|
collapseContent: true,
|
|
228
258
|
});
|
|
229
259
|
} catch {
|
|
230
|
-
|
|
260
|
+
exampleBody = json2xml(example);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
if (examples) {
|
|
264
|
+
for (const [key, example] of Object.entries(examples)) {
|
|
265
|
+
let formattedXmlBody;
|
|
266
|
+
try {
|
|
267
|
+
formattedXmlBody = format(example.value, {
|
|
268
|
+
indentation: " ",
|
|
269
|
+
lineSeparator: "\n",
|
|
270
|
+
collapseContent: true,
|
|
271
|
+
});
|
|
272
|
+
} catch {
|
|
273
|
+
formattedXmlBody = example.value;
|
|
274
|
+
}
|
|
275
|
+
examplesBodies.push({
|
|
276
|
+
label: key,
|
|
277
|
+
body: formattedXmlBody,
|
|
278
|
+
summary: example.summary,
|
|
279
|
+
});
|
|
231
280
|
}
|
|
232
281
|
}
|
|
233
282
|
language = "xml";
|
|
234
283
|
}
|
|
235
284
|
|
|
285
|
+
if (exampleBody) {
|
|
286
|
+
return (
|
|
287
|
+
<FormItem label="Body" required={required}>
|
|
288
|
+
<SchemaTabs lazy>
|
|
289
|
+
<TabItem label="Default" value="default" default>
|
|
290
|
+
<LiveApp action={dispatch} language={language}>
|
|
291
|
+
{defaultBody}
|
|
292
|
+
</LiveApp>
|
|
293
|
+
</TabItem>
|
|
294
|
+
<TabItem label="Example" value="example">
|
|
295
|
+
{exampleBody && (
|
|
296
|
+
<LiveApp action={dispatch} language={language}>
|
|
297
|
+
{exampleBody}
|
|
298
|
+
</LiveApp>
|
|
299
|
+
)}
|
|
300
|
+
</TabItem>
|
|
301
|
+
</SchemaTabs>
|
|
302
|
+
</FormItem>
|
|
303
|
+
);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
if (examplesBodies && examplesBodies.length > 0) {
|
|
307
|
+
return (
|
|
308
|
+
<FormItem label="Body" required={required}>
|
|
309
|
+
<SchemaTabs lazy>
|
|
310
|
+
<TabItem label="Default" value="default" default>
|
|
311
|
+
<LiveApp action={dispatch} language={language}>
|
|
312
|
+
{defaultBody}
|
|
313
|
+
</LiveApp>
|
|
314
|
+
</TabItem>
|
|
315
|
+
{examplesBodies.map((example: any) => {
|
|
316
|
+
return (
|
|
317
|
+
<TabItem
|
|
318
|
+
label={example.label}
|
|
319
|
+
value={example.label}
|
|
320
|
+
key={example.label}
|
|
321
|
+
>
|
|
322
|
+
{example.summary && <p>{example.summary}</p>}
|
|
323
|
+
{example.body && (
|
|
324
|
+
<LiveApp action={dispatch} language={language}>
|
|
325
|
+
{example.body}
|
|
326
|
+
</LiveApp>
|
|
327
|
+
)}
|
|
328
|
+
</TabItem>
|
|
329
|
+
);
|
|
330
|
+
})}
|
|
331
|
+
</SchemaTabs>
|
|
332
|
+
</FormItem>
|
|
333
|
+
);
|
|
334
|
+
}
|
|
335
|
+
|
|
236
336
|
return (
|
|
237
337
|
<FormItem label="Body" required={required}>
|
|
238
338
|
<LiveApp action={dispatch} language={language}>
|
|
239
|
-
{
|
|
339
|
+
{defaultBody}
|
|
240
340
|
</LiveApp>
|
|
241
341
|
</FormItem>
|
|
242
342
|
);
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
import React from "react";
|
|
9
9
|
|
|
10
|
-
import { useTypedDispatch, useTypedSelector } from "
|
|
10
|
+
import { useTypedDispatch, useTypedSelector } from "../../ApiItem/hooks";
|
|
11
11
|
import FormItem from "./../FormItem";
|
|
12
12
|
import FormSelect from "./../FormSelect";
|
|
13
13
|
import { setContentType } from "./slice";
|
|
@@ -13,8 +13,8 @@ import sdk from "@paloaltonetworks/postman-collection";
|
|
|
13
13
|
import CodeBlock from "@theme/CodeBlock";
|
|
14
14
|
import clsx from "clsx";
|
|
15
15
|
|
|
16
|
+
import { useTypedSelector } from "../../ApiItem/hooks";
|
|
16
17
|
import CodeTabs from "../CodeTabs";
|
|
17
|
-
import { useTypedSelector } from "../hooks";
|
|
18
18
|
import buildPostmanRequest from "./../buildPostmanRequest";
|
|
19
19
|
import styles from "./styles.module.css";
|
|
20
20
|
|
|
@@ -10,7 +10,7 @@ import React from "react";
|
|
|
10
10
|
import sdk from "@paloaltonetworks/postman-collection";
|
|
11
11
|
import Modal from "react-modal";
|
|
12
12
|
|
|
13
|
-
import { useTypedDispatch, useTypedSelector } from "
|
|
13
|
+
import { useTypedDispatch, useTypedSelector } from "../../ApiItem/hooks";
|
|
14
14
|
import { Param } from "../ParamOptions/slice";
|
|
15
15
|
import { setResponse } from "../Response/slice";
|
|
16
16
|
import buildPostmanRequest from "./../buildPostmanRequest";
|
|
@@ -9,7 +9,7 @@ import React, { useState, useEffect } from "react";
|
|
|
9
9
|
|
|
10
10
|
import { nanoid } from "@reduxjs/toolkit";
|
|
11
11
|
|
|
12
|
-
import { useTypedDispatch, useTypedSelector } from "
|
|
12
|
+
import { useTypedDispatch, useTypedSelector } from "../../ApiItem/hooks";
|
|
13
13
|
import FormItem from "./../FormItem";
|
|
14
14
|
import FormMultiSelect from "./../FormMultiSelect";
|
|
15
15
|
import FormSelect from "./../FormSelect";
|
|
@@ -13,11 +13,11 @@ import { ParameterObject } from "docusaurus-plugin-openapi-docs/src/openapi/type
|
|
|
13
13
|
import { ApiItem } from "docusaurus-plugin-openapi-docs/src/types";
|
|
14
14
|
|
|
15
15
|
import { ThemeConfig } from "../../../types";
|
|
16
|
+
import { useTypedSelector } from "../../ApiItem/hooks";
|
|
16
17
|
import Accept from "../Accept";
|
|
17
18
|
import Authorization from "../Authorization";
|
|
18
19
|
import Body from "../Body";
|
|
19
20
|
import Execute from "../Execute";
|
|
20
|
-
import { useTypedSelector } from "../hooks";
|
|
21
21
|
import ParamOptions from "../ParamOptions";
|
|
22
22
|
import Server from "../Server";
|
|
23
23
|
import styles from "./styles.module.css";
|
|
@@ -9,7 +9,7 @@ import React from "react";
|
|
|
9
9
|
|
|
10
10
|
import CodeBlock from "@theme/CodeBlock";
|
|
11
11
|
|
|
12
|
-
import { useTypedDispatch, useTypedSelector } from "
|
|
12
|
+
import { useTypedDispatch, useTypedSelector } from "../../ApiItem/hooks";
|
|
13
13
|
import { clearResponse } from "./slice";
|
|
14
14
|
|
|
15
15
|
// TODO: We probably shouldn't attempt to format XML...
|
|
@@ -9,7 +9,7 @@ import React from "react";
|
|
|
9
9
|
|
|
10
10
|
import Link from "@docusaurus/Link";
|
|
11
11
|
|
|
12
|
-
import { useTypedSelector } from "
|
|
12
|
+
import { useTypedSelector } from "../../ApiItem/hooks";
|
|
13
13
|
|
|
14
14
|
function SecuritySchemes(props: any) {
|
|
15
15
|
const options = useTypedSelector((state) => state.auth.options);
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
|
|
8
8
|
import React, { useState } from "react";
|
|
9
9
|
|
|
10
|
+
import { useTypedDispatch, useTypedSelector } from "../../ApiItem/hooks";
|
|
10
11
|
import FloatingButton from "../FloatingButton";
|
|
11
|
-
import { useTypedDispatch, useTypedSelector } from "../hooks";
|
|
12
12
|
import FormItem from "./../FormItem";
|
|
13
13
|
import FormSelect from "./../FormSelect";
|
|
14
14
|
import FormTextInput from "./../FormTextInput";
|
|
@@ -19,7 +19,6 @@ function Server() {
|
|
|
19
19
|
const [isEditing, setIsEditing] = useState(false);
|
|
20
20
|
const value = useTypedSelector((state) => state.server.value);
|
|
21
21
|
const options = useTypedSelector((state) => state.server.options);
|
|
22
|
-
|
|
23
22
|
const dispatch = useTypedDispatch();
|
|
24
23
|
|
|
25
24
|
if (options.length <= 0) {
|
|
@@ -30,6 +29,20 @@ function Server() {
|
|
|
30
29
|
return null;
|
|
31
30
|
}
|
|
32
31
|
|
|
32
|
+
if (!value) {
|
|
33
|
+
const defaultOption = options[0];
|
|
34
|
+
dispatch(setServer(JSON.stringify(defaultOption)));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Default to first option when existing server state is mismatched
|
|
38
|
+
if (value) {
|
|
39
|
+
const urlExists = options.find((s) => s.url === value.url);
|
|
40
|
+
if (!urlExists) {
|
|
41
|
+
const defaultOption = options[0];
|
|
42
|
+
dispatch(setServer(JSON.stringify(defaultOption)));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
33
46
|
if (!isEditing) {
|
|
34
47
|
let url = "";
|
|
35
48
|
if (value) {
|
|
@@ -58,14 +71,21 @@ function Server() {
|
|
|
58
71
|
</FloatingButton>
|
|
59
72
|
);
|
|
60
73
|
}
|
|
61
|
-
|
|
62
74
|
return (
|
|
63
75
|
<div className={styles.optionsPanel}>
|
|
64
76
|
<FloatingButton onClick={() => setIsEditing(false)} label="Hide">
|
|
65
77
|
<FormItem label="Base URL">
|
|
66
78
|
<FormSelect
|
|
67
79
|
options={options.map((s) => s.url)}
|
|
68
|
-
onChange={(e) =>
|
|
80
|
+
onChange={(e) => {
|
|
81
|
+
dispatch(
|
|
82
|
+
setServer(
|
|
83
|
+
JSON.stringify(
|
|
84
|
+
options.filter((s) => s.url === e.target.value)[0]
|
|
85
|
+
)
|
|
86
|
+
)
|
|
87
|
+
);
|
|
88
|
+
}}
|
|
69
89
|
value={value?.url}
|
|
70
90
|
/>
|
|
71
91
|
<small>{value?.description}</small>
|
|
@@ -79,9 +99,12 @@ function Server() {
|
|
|
79
99
|
options={value.variables[key].enum}
|
|
80
100
|
onChange={(e) => {
|
|
81
101
|
dispatch(
|
|
82
|
-
setServerVariable(
|
|
102
|
+
setServerVariable(
|
|
103
|
+
JSON.stringify({ key, value: e.target.value })
|
|
104
|
+
)
|
|
83
105
|
);
|
|
84
106
|
}}
|
|
107
|
+
value={value?.variables[key].default}
|
|
85
108
|
/>
|
|
86
109
|
</FormItem>
|
|
87
110
|
);
|
|
@@ -91,8 +114,13 @@ function Server() {
|
|
|
91
114
|
<FormTextInput
|
|
92
115
|
placeholder={value.variables?.[key].default}
|
|
93
116
|
onChange={(e) => {
|
|
94
|
-
dispatch(
|
|
117
|
+
dispatch(
|
|
118
|
+
setServerVariable(
|
|
119
|
+
JSON.stringify({ key, value: e.target.value })
|
|
120
|
+
)
|
|
121
|
+
);
|
|
95
122
|
}}
|
|
123
|
+
value={value?.variables?.[key].default}
|
|
96
124
|
/>
|
|
97
125
|
</FormItem>
|
|
98
126
|
);
|
|
@@ -21,15 +21,14 @@ export const slice = createSlice({
|
|
|
21
21
|
initialState,
|
|
22
22
|
reducers: {
|
|
23
23
|
setServer: (state, action: PayloadAction<string>) => {
|
|
24
|
-
state.value = state.options.find(
|
|
24
|
+
state.value = state.options.find(
|
|
25
|
+
(s) => s.url === JSON.parse(action.payload).url
|
|
26
|
+
);
|
|
25
27
|
},
|
|
26
|
-
setServerVariable: (
|
|
27
|
-
state,
|
|
28
|
-
action: PayloadAction<{ key: string; value: string }>
|
|
29
|
-
) => {
|
|
28
|
+
setServerVariable: (state, action: PayloadAction<string>) => {
|
|
30
29
|
if (state.value?.variables) {
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
const parsedPayload = JSON.parse(action.payload);
|
|
31
|
+
state.value.variables[parsedPayload.key].default = parsedPayload.value;
|
|
33
32
|
}
|
|
34
33
|
},
|
|
35
34
|
},
|
|
@@ -7,21 +7,14 @@
|
|
|
7
7
|
|
|
8
8
|
import React from "react";
|
|
9
9
|
|
|
10
|
-
import useDocusaurusContext from "@docusaurus/useDocusaurusContext";
|
|
11
10
|
import sdk from "@paloaltonetworks/postman-collection";
|
|
12
|
-
import { ParameterObject } from "docusaurus-plugin-openapi-docs/src/openapi/types";
|
|
13
11
|
import { ApiItem } from "docusaurus-plugin-openapi-docs/src/types";
|
|
14
|
-
import { Provider } from "react-redux";
|
|
15
12
|
|
|
16
|
-
import { ThemeConfig } from "../../types";
|
|
17
|
-
import { createAuth } from "./Authorization/slice";
|
|
18
13
|
import Curl from "./Curl";
|
|
19
14
|
import MethodEndpoint from "./MethodEndpoint";
|
|
20
|
-
import { createPersistanceMiddleware } from "./persistanceMiddleware";
|
|
21
15
|
import Request from "./Request";
|
|
22
16
|
import Response from "./Response";
|
|
23
17
|
import SecuritySchemes from "./SecuritySchemes";
|
|
24
|
-
import { createStoreWithState } from "./store";
|
|
25
18
|
import styles from "./styles.module.css";
|
|
26
19
|
|
|
27
20
|
function ApiDemoPanel({
|
|
@@ -31,76 +24,20 @@ function ApiDemoPanel({
|
|
|
31
24
|
item: NonNullable<ApiItem>;
|
|
32
25
|
infoPath: string;
|
|
33
26
|
}) {
|
|
34
|
-
const { siteConfig } = useDocusaurusContext();
|
|
35
|
-
const themeConfig = siteConfig.themeConfig as ThemeConfig;
|
|
36
|
-
const options = themeConfig.api;
|
|
37
27
|
const postman = new sdk.Request(item.postman);
|
|
38
|
-
|
|
39
|
-
const acceptArray = Array.from(
|
|
40
|
-
new Set(
|
|
41
|
-
Object.values(item.responses ?? {})
|
|
42
|
-
.map((response: any) => Object.keys(response.content ?? {}))
|
|
43
|
-
.flat()
|
|
44
|
-
)
|
|
45
|
-
);
|
|
46
|
-
|
|
47
|
-
const content = item.requestBody?.content ?? {};
|
|
48
|
-
|
|
49
|
-
const contentTypeArray = Object.keys(content);
|
|
50
|
-
|
|
51
|
-
const servers = item.servers ?? [];
|
|
52
|
-
|
|
53
|
-
const params = {
|
|
54
|
-
path: [] as ParameterObject[],
|
|
55
|
-
query: [] as ParameterObject[],
|
|
56
|
-
header: [] as ParameterObject[],
|
|
57
|
-
cookie: [] as ParameterObject[],
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
item.parameters?.forEach(
|
|
61
|
-
(param: { in: "path" | "query" | "header" | "cookie" }) => {
|
|
62
|
-
const paramType = param.in;
|
|
63
|
-
const paramsArray: ParameterObject[] = params[paramType];
|
|
64
|
-
paramsArray.push(param as ParameterObject);
|
|
65
|
-
}
|
|
66
|
-
);
|
|
67
|
-
|
|
68
|
-
const auth = createAuth({
|
|
69
|
-
security: item.security,
|
|
70
|
-
securitySchemes: item.securitySchemes,
|
|
71
|
-
options,
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
const persistanceMiddleware = createPersistanceMiddleware(options);
|
|
75
|
-
|
|
76
|
-
const store2 = createStoreWithState(
|
|
77
|
-
{
|
|
78
|
-
accept: { value: acceptArray[0], options: acceptArray },
|
|
79
|
-
contentType: { value: contentTypeArray[0], options: contentTypeArray },
|
|
80
|
-
server: { value: servers[0], options: servers },
|
|
81
|
-
response: { value: undefined },
|
|
82
|
-
body: { type: "empty" },
|
|
83
|
-
params,
|
|
84
|
-
auth,
|
|
85
|
-
},
|
|
86
|
-
[persistanceMiddleware]
|
|
87
|
-
);
|
|
88
|
-
|
|
89
28
|
const { path, method } = item;
|
|
90
29
|
|
|
91
30
|
return (
|
|
92
|
-
<
|
|
93
|
-
<
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
</div>
|
|
103
|
-
</Provider>
|
|
31
|
+
<div className={styles.apiDemoPanelContainer}>
|
|
32
|
+
<MethodEndpoint method={method} path={path} />
|
|
33
|
+
<SecuritySchemes infoPath={infoPath} />
|
|
34
|
+
<Request item={item} />
|
|
35
|
+
<Response />
|
|
36
|
+
<Curl
|
|
37
|
+
postman={postman}
|
|
38
|
+
codeSamples={(item as any)["x-code-samples"] ?? []}
|
|
39
|
+
/>
|
|
40
|
+
</div>
|
|
104
41
|
);
|
|
105
42
|
}
|
|
106
43
|
|
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
import { Middleware } from "@reduxjs/toolkit";
|
|
9
9
|
|
|
10
10
|
import { ThemeConfig } from "../../types";
|
|
11
|
+
import { AppDispatch, RootState } from "../ApiItem/store";
|
|
11
12
|
import { setAuthData, setSelectedAuth } from "./Authorization/slice";
|
|
12
13
|
import { createStorage, hashArray } from "./storage-utils";
|
|
13
|
-
import { AppDispatch, RootState } from "./store";
|
|
14
14
|
|
|
15
15
|
export function createPersistanceMiddleware(options: ThemeConfig["api"]) {
|
|
16
16
|
const persistanceMiddleware: Middleware<{}, RootState, AppDispatch> =
|
|
@@ -40,6 +40,26 @@ export function createPersistanceMiddleware(options: ThemeConfig["api"]) {
|
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
+
if (action.type === "contentType/setContentType") {
|
|
44
|
+
storage.setItem("contentType", action.payload);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (action.type === "accept/setAccept") {
|
|
48
|
+
storage.setItem("accept", action.payload);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (action.type === "server/setServer") {
|
|
52
|
+
storage.setItem("server", action.payload);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (action.type === "server/setServerVariable") {
|
|
56
|
+
const server = storage.getItem("server") ?? "{}";
|
|
57
|
+
const variables = JSON.parse(action.payload);
|
|
58
|
+
let serverObject = JSON.parse(server);
|
|
59
|
+
serverObject.variables[variables.key].default = variables.value;
|
|
60
|
+
storage.setItem("server", JSON.stringify(serverObject));
|
|
61
|
+
}
|
|
62
|
+
|
|
43
63
|
return result;
|
|
44
64
|
};
|
|
45
65
|
return persistanceMiddleware;
|
|
@@ -154,12 +154,15 @@
|
|
|
154
154
|
margin-bottom: 0;
|
|
155
155
|
}
|
|
156
156
|
|
|
157
|
-
:global(
|
|
157
|
+
:global([class^="paramsItem"]::before),
|
|
158
|
+
:global([class^="schemaItem"]::before) {
|
|
158
159
|
position: absolute;
|
|
159
160
|
top: 10px;
|
|
160
161
|
left: 0;
|
|
161
|
-
width: 0.7rem;
|
|
162
|
-
|
|
162
|
+
width: 0.7rem;
|
|
163
|
+
/* width of horizontal line */
|
|
164
|
+
height: 0.5rem;
|
|
165
|
+
/* vertical position of line */
|
|
163
166
|
vertical-align: top;
|
|
164
167
|
border-bottom: thin solid var(--ifm-color-gray-500);
|
|
165
168
|
content: "";
|
|
@@ -410,3 +413,8 @@
|
|
|
410
413
|
max-height: 500px;
|
|
411
414
|
overflow: auto;
|
|
412
415
|
}
|
|
416
|
+
|
|
417
|
+
/* Prism code styles */
|
|
418
|
+
:global(.prism-code.language-json) {
|
|
419
|
+
white-space: pre !important;
|
|
420
|
+
}
|
|
File without changes
|