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
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
* ========================================================================== */
|
|
7
7
|
import React, { useState } from "react";
|
|
8
|
+
import { useTypedDispatch, useTypedSelector } from "../../ApiItem/hooks";
|
|
8
9
|
import FloatingButton from "../FloatingButton";
|
|
9
|
-
import { useTypedDispatch, useTypedSelector } from "../hooks";
|
|
10
10
|
import FormItem from "./../FormItem";
|
|
11
11
|
import FormSelect from "./../FormSelect";
|
|
12
12
|
import FormTextInput from "./../FormTextInput";
|
|
@@ -27,6 +27,20 @@ function Server() {
|
|
|
27
27
|
return null;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
+
if (!value) {
|
|
31
|
+
const defaultOption = options[0];
|
|
32
|
+
dispatch(setServer(JSON.stringify(defaultOption)));
|
|
33
|
+
} // Default to first option when existing server state is mismatched
|
|
34
|
+
|
|
35
|
+
if (value) {
|
|
36
|
+
const urlExists = options.find((s) => s.url === value.url);
|
|
37
|
+
|
|
38
|
+
if (!urlExists) {
|
|
39
|
+
const defaultOption = options[0];
|
|
40
|
+
dispatch(setServer(JSON.stringify(defaultOption)));
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
30
44
|
if (!isEditing) {
|
|
31
45
|
let url = "";
|
|
32
46
|
|
|
@@ -65,7 +79,15 @@ function Server() {
|
|
|
65
79
|
<FormItem label="Base URL">
|
|
66
80
|
<FormSelect
|
|
67
81
|
options={options.map((s) => s.url)}
|
|
68
|
-
onChange={(e) =>
|
|
82
|
+
onChange={(e) => {
|
|
83
|
+
dispatch(
|
|
84
|
+
setServer(
|
|
85
|
+
JSON.stringify(
|
|
86
|
+
options.filter((s) => s.url === e.target.value)[0]
|
|
87
|
+
)
|
|
88
|
+
)
|
|
89
|
+
);
|
|
90
|
+
}}
|
|
69
91
|
value={value?.url}
|
|
70
92
|
/>
|
|
71
93
|
<small>{value?.description}</small>
|
|
@@ -79,12 +101,15 @@ function Server() {
|
|
|
79
101
|
options={value.variables[key].enum}
|
|
80
102
|
onChange={(e) => {
|
|
81
103
|
dispatch(
|
|
82
|
-
setServerVariable(
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
104
|
+
setServerVariable(
|
|
105
|
+
JSON.stringify({
|
|
106
|
+
key,
|
|
107
|
+
value: e.target.value,
|
|
108
|
+
})
|
|
109
|
+
)
|
|
86
110
|
);
|
|
87
111
|
}}
|
|
112
|
+
value={value?.variables[key].default}
|
|
88
113
|
/>
|
|
89
114
|
</FormItem>
|
|
90
115
|
);
|
|
@@ -96,12 +121,15 @@ function Server() {
|
|
|
96
121
|
placeholder={value.variables?.[key].default}
|
|
97
122
|
onChange={(e) => {
|
|
98
123
|
dispatch(
|
|
99
|
-
setServerVariable(
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
124
|
+
setServerVariable(
|
|
125
|
+
JSON.stringify({
|
|
126
|
+
key,
|
|
127
|
+
value: e.target.value,
|
|
128
|
+
})
|
|
129
|
+
)
|
|
103
130
|
);
|
|
104
131
|
}}
|
|
132
|
+
value={value?.variables?.[key].default}
|
|
105
133
|
/>
|
|
106
134
|
</FormItem>
|
|
107
135
|
);
|
|
@@ -11,12 +11,14 @@ export const slice = createSlice({
|
|
|
11
11
|
initialState,
|
|
12
12
|
reducers: {
|
|
13
13
|
setServer: (state, action) => {
|
|
14
|
-
state.value = state.options.find(
|
|
14
|
+
state.value = state.options.find(
|
|
15
|
+
(s) => s.url === JSON.parse(action.payload).url
|
|
16
|
+
);
|
|
15
17
|
},
|
|
16
18
|
setServerVariable: (state, action) => {
|
|
17
19
|
if (state.value?.variables) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
+
const parsedPayload = JSON.parse(action.payload);
|
|
21
|
+
state.value.variables[parsedPayload.key].default = parsedPayload.value;
|
|
20
22
|
}
|
|
21
23
|
},
|
|
22
24
|
},
|
|
@@ -5,87 +5,25 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
* ========================================================================== */
|
|
7
7
|
import React from "react";
|
|
8
|
-
import useDocusaurusContext from "@docusaurus/useDocusaurusContext";
|
|
9
8
|
import sdk from "@paloaltonetworks/postman-collection";
|
|
10
|
-
import { Provider } from "react-redux";
|
|
11
|
-
import { createAuth } from "./Authorization/slice";
|
|
12
9
|
import Curl from "./Curl";
|
|
13
10
|
import MethodEndpoint from "./MethodEndpoint";
|
|
14
|
-
import { createPersistanceMiddleware } from "./persistanceMiddleware";
|
|
15
11
|
import Request from "./Request";
|
|
16
12
|
import Response from "./Response";
|
|
17
13
|
import SecuritySchemes from "./SecuritySchemes";
|
|
18
|
-
import { createStoreWithState } from "./store";
|
|
19
14
|
import styles from "./styles.module.css";
|
|
20
15
|
|
|
21
16
|
function ApiDemoPanel({ item, infoPath }) {
|
|
22
|
-
const { siteConfig } = useDocusaurusContext();
|
|
23
|
-
const themeConfig = siteConfig.themeConfig;
|
|
24
|
-
const options = themeConfig.api;
|
|
25
17
|
const postman = new sdk.Request(item.postman);
|
|
26
|
-
const acceptArray = Array.from(
|
|
27
|
-
new Set(
|
|
28
|
-
Object.values(item.responses ?? {})
|
|
29
|
-
.map((response) => Object.keys(response.content ?? {}))
|
|
30
|
-
.flat()
|
|
31
|
-
)
|
|
32
|
-
);
|
|
33
|
-
const content = item.requestBody?.content ?? {};
|
|
34
|
-
const contentTypeArray = Object.keys(content);
|
|
35
|
-
const servers = item.servers ?? [];
|
|
36
|
-
const params = {
|
|
37
|
-
path: [],
|
|
38
|
-
query: [],
|
|
39
|
-
header: [],
|
|
40
|
-
cookie: [],
|
|
41
|
-
};
|
|
42
|
-
item.parameters?.forEach((param) => {
|
|
43
|
-
const paramType = param.in;
|
|
44
|
-
const paramsArray = params[paramType];
|
|
45
|
-
paramsArray.push(param);
|
|
46
|
-
});
|
|
47
|
-
const auth = createAuth({
|
|
48
|
-
security: item.security,
|
|
49
|
-
securitySchemes: item.securitySchemes,
|
|
50
|
-
options,
|
|
51
|
-
});
|
|
52
|
-
const persistanceMiddleware = createPersistanceMiddleware(options);
|
|
53
|
-
const store2 = createStoreWithState(
|
|
54
|
-
{
|
|
55
|
-
accept: {
|
|
56
|
-
value: acceptArray[0],
|
|
57
|
-
options: acceptArray,
|
|
58
|
-
},
|
|
59
|
-
contentType: {
|
|
60
|
-
value: contentTypeArray[0],
|
|
61
|
-
options: contentTypeArray,
|
|
62
|
-
},
|
|
63
|
-
server: {
|
|
64
|
-
value: servers[0],
|
|
65
|
-
options: servers,
|
|
66
|
-
},
|
|
67
|
-
response: {
|
|
68
|
-
value: undefined,
|
|
69
|
-
},
|
|
70
|
-
body: {
|
|
71
|
-
type: "empty",
|
|
72
|
-
},
|
|
73
|
-
params,
|
|
74
|
-
auth,
|
|
75
|
-
},
|
|
76
|
-
[persistanceMiddleware]
|
|
77
|
-
);
|
|
78
18
|
const { path, method } = item;
|
|
79
19
|
return (
|
|
80
|
-
<
|
|
81
|
-
<
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
</div>
|
|
88
|
-
</Provider>
|
|
20
|
+
<div className={styles.apiDemoPanelContainer}>
|
|
21
|
+
<MethodEndpoint method={method} path={path} />
|
|
22
|
+
<SecuritySchemes infoPath={infoPath} />
|
|
23
|
+
<Request item={item} />
|
|
24
|
+
<Response />
|
|
25
|
+
<Curl postman={postman} codeSamples={item["x-code-samples"] ?? []} />
|
|
26
|
+
</div>
|
|
89
27
|
);
|
|
90
28
|
}
|
|
91
29
|
|
|
@@ -31,6 +31,26 @@ export function createPersistanceMiddleware(options) {
|
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
+
if (action.type === "contentType/setContentType") {
|
|
35
|
+
storage.setItem("contentType", action.payload);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (action.type === "accept/setAccept") {
|
|
39
|
+
storage.setItem("accept", action.payload);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (action.type === "server/setServer") {
|
|
43
|
+
storage.setItem("server", action.payload);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (action.type === "server/setServerVariable") {
|
|
47
|
+
const server = storage.getItem("server") ?? "{}";
|
|
48
|
+
const variables = JSON.parse(action.payload);
|
|
49
|
+
let serverObject = JSON.parse(server);
|
|
50
|
+
serverObject.variables[variables.key].default = variables.value;
|
|
51
|
+
storage.setItem("server", JSON.stringify(serverObject));
|
|
52
|
+
}
|
|
53
|
+
|
|
34
54
|
return result;
|
|
35
55
|
};
|
|
36
56
|
|
|
@@ -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
|
|
@@ -7,9 +7,14 @@
|
|
|
7
7
|
import React from "react";
|
|
8
8
|
import ExecutionEnvironment from "@docusaurus/ExecutionEnvironment";
|
|
9
9
|
import { HtmlClassNameProvider } from "@docusaurus/theme-common";
|
|
10
|
+
import useDocusaurusContext from "@docusaurus/useDocusaurusContext";
|
|
10
11
|
import clsx from "clsx";
|
|
12
|
+
import { Provider } from "react-redux";
|
|
13
|
+
import { createAuth } from "../ApiDemoPanel/Authorization/slice";
|
|
14
|
+
import { createPersistanceMiddleware } from "../ApiDemoPanel/persistanceMiddleware";
|
|
11
15
|
import DocItemLayout from "./Layout";
|
|
12
16
|
import DocItemMetadata from "./Metadata";
|
|
17
|
+
import { createStoreWithState } from "./store";
|
|
13
18
|
|
|
14
19
|
const { DocProvider } = require("@docusaurus/theme-common/internal");
|
|
15
20
|
|
|
@@ -21,40 +26,113 @@ let ApiDemoPanel = (_) => (
|
|
|
21
26
|
/>
|
|
22
27
|
);
|
|
23
28
|
|
|
29
|
+
let DocItem = (props) => {
|
|
30
|
+
return (
|
|
31
|
+
<div
|
|
32
|
+
style={{
|
|
33
|
+
marginTop: "3.5em",
|
|
34
|
+
}}
|
|
35
|
+
/>
|
|
36
|
+
);
|
|
37
|
+
};
|
|
38
|
+
|
|
24
39
|
if (ExecutionEnvironment.canUseDOM) {
|
|
25
40
|
ApiDemoPanel = require("@theme/ApiDemoPanel").default;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export default function DocItem(props) {
|
|
29
|
-
const docHtmlClassName = `docs-doc-id-${props.content.metadata.unversionedId}`;
|
|
30
41
|
|
|
31
|
-
|
|
42
|
+
DocItem = function DocItem(props) {
|
|
43
|
+
const docHtmlClassName = `docs-doc-id-${props.content.metadata.unversionedId}`;
|
|
32
44
|
const MDXComponent = props.content;
|
|
33
45
|
const { frontMatter } = MDXComponent;
|
|
34
46
|
const { info_path: infoPath } = frontMatter;
|
|
35
47
|
const { api } = frontMatter;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
48
|
+
const { siteConfig } = useDocusaurusContext();
|
|
49
|
+
const themeConfig = siteConfig.themeConfig;
|
|
50
|
+
const options = themeConfig.api;
|
|
51
|
+
const acceptArray = Array.from(
|
|
52
|
+
new Set(
|
|
53
|
+
Object.values(api?.responses ?? {})
|
|
54
|
+
.map((response) => Object.keys(response.content ?? {}))
|
|
55
|
+
.flat()
|
|
56
|
+
)
|
|
57
|
+
);
|
|
58
|
+
const content = api?.requestBody?.content ?? {};
|
|
59
|
+
const contentTypeArray = Object.keys(content);
|
|
60
|
+
const servers = api?.servers ?? [];
|
|
61
|
+
const params = {
|
|
62
|
+
path: [],
|
|
63
|
+
query: [],
|
|
64
|
+
header: [],
|
|
65
|
+
cookie: [],
|
|
66
|
+
};
|
|
67
|
+
api?.parameters?.forEach((param) => {
|
|
68
|
+
const paramType = param.in;
|
|
69
|
+
const paramsArray = params[paramType];
|
|
70
|
+
paramsArray.push(param);
|
|
71
|
+
});
|
|
72
|
+
const auth = createAuth({
|
|
73
|
+
security: api?.security,
|
|
74
|
+
securitySchemes: api?.securitySchemes,
|
|
75
|
+
options,
|
|
76
|
+
});
|
|
77
|
+
const persistanceMiddleware = createPersistanceMiddleware(options);
|
|
78
|
+
const acceptValue = window?.sessionStorage.getItem("accept");
|
|
79
|
+
const contentTypeValue = window?.sessionStorage.getItem("contentType");
|
|
80
|
+
const server = window?.sessionStorage.getItem("server");
|
|
81
|
+
const serverObject = JSON.parse(server) ?? {};
|
|
82
|
+
const store2 = createStoreWithState(
|
|
83
|
+
{
|
|
84
|
+
accept: {
|
|
85
|
+
value: acceptValue || acceptArray[0],
|
|
86
|
+
options: acceptArray,
|
|
87
|
+
},
|
|
88
|
+
contentType: {
|
|
89
|
+
value: contentTypeValue || contentTypeArray[0],
|
|
90
|
+
options: contentTypeArray,
|
|
91
|
+
},
|
|
92
|
+
server: {
|
|
93
|
+
value: serverObject.url ? serverObject : undefined,
|
|
94
|
+
options: servers,
|
|
95
|
+
},
|
|
96
|
+
response: {
|
|
97
|
+
value: undefined,
|
|
98
|
+
},
|
|
99
|
+
body: {
|
|
100
|
+
type: "empty",
|
|
101
|
+
},
|
|
102
|
+
params,
|
|
103
|
+
auth,
|
|
104
|
+
},
|
|
105
|
+
[persistanceMiddleware]
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
const DocContent = () => {
|
|
109
|
+
return (
|
|
110
|
+
<div className="row">
|
|
111
|
+
<div className={clsx("col", api ? "col--7" : "col--12")}>
|
|
112
|
+
<MDXComponent />
|
|
44
113
|
</div>
|
|
45
|
-
|
|
46
|
-
|
|
114
|
+
{api && (
|
|
115
|
+
<div className="col col--5">
|
|
116
|
+
<ApiDemoPanel item={api} infoPath={infoPath} />
|
|
117
|
+
</div>
|
|
118
|
+
)}
|
|
119
|
+
</div>
|
|
120
|
+
);
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
return (
|
|
124
|
+
<Provider store={store2}>
|
|
125
|
+
<DocProvider content={props.content}>
|
|
126
|
+
<HtmlClassNameProvider className={docHtmlClassName}>
|
|
127
|
+
<DocItemMetadata />
|
|
128
|
+
<DocItemLayout>
|
|
129
|
+
<DocContent />
|
|
130
|
+
</DocItemLayout>
|
|
131
|
+
</HtmlClassNameProvider>
|
|
132
|
+
</DocProvider>
|
|
133
|
+
</Provider>
|
|
47
134
|
);
|
|
48
135
|
};
|
|
49
|
-
|
|
50
|
-
return (
|
|
51
|
-
<DocProvider content={props.content}>
|
|
52
|
-
<HtmlClassNameProvider className={docHtmlClassName}>
|
|
53
|
-
<DocItemMetadata />
|
|
54
|
-
<DocItemLayout>
|
|
55
|
-
<DocContent />
|
|
56
|
-
</DocItemLayout>
|
|
57
|
-
</HtmlClassNameProvider>
|
|
58
|
-
</DocProvider>
|
|
59
|
-
);
|
|
60
136
|
}
|
|
137
|
+
|
|
138
|
+
export default DocItem;
|
|
@@ -5,13 +5,13 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
* ========================================================================== */
|
|
7
7
|
import { configureStore, combineReducers } from "@reduxjs/toolkit";
|
|
8
|
-
import accept from "
|
|
9
|
-
import auth from "
|
|
10
|
-
import body from "
|
|
11
|
-
import contentType from "
|
|
12
|
-
import params from "
|
|
13
|
-
import response from "
|
|
14
|
-
import server from "
|
|
8
|
+
import accept from "../ApiDemoPanel/Accept/slice";
|
|
9
|
+
import auth from "../ApiDemoPanel/Authorization/slice";
|
|
10
|
+
import body from "../ApiDemoPanel/Body/slice";
|
|
11
|
+
import contentType from "../ApiDemoPanel/ContentType/slice";
|
|
12
|
+
import params from "../ApiDemoPanel/ParamOptions/slice";
|
|
13
|
+
import response from "../ApiDemoPanel/Response/slice";
|
|
14
|
+
import server from "../ApiDemoPanel/Server/slice";
|
|
15
15
|
const rootReducer = combineReducers({
|
|
16
16
|
accept,
|
|
17
17
|
contentType,
|
|
@@ -18,6 +18,9 @@ import { duplicates } from "@docusaurus/theme-common";
|
|
|
18
18
|
import useIsBrowser from "@docusaurus/useIsBrowser";
|
|
19
19
|
import clsx from "clsx";
|
|
20
20
|
|
|
21
|
+
import { setAccept } from "../ApiDemoPanel/Accept/slice";
|
|
22
|
+
import { setContentType } from "../ApiDemoPanel/ContentType/slice";
|
|
23
|
+
import { useTypedDispatch, useTypedSelector } from "../ApiItem/hooks";
|
|
21
24
|
import styles from "./styles.module.css"; // A very rough duck type, but good enough to guard against mistakes while
|
|
22
25
|
|
|
23
26
|
const {
|
|
@@ -39,6 +42,7 @@ function MimeTabsComponent(props) {
|
|
|
39
42
|
values: valuesProp,
|
|
40
43
|
groupId,
|
|
41
44
|
className,
|
|
45
|
+
schemaType,
|
|
42
46
|
} = props;
|
|
43
47
|
const children = Children.map(props.children, (child) => {
|
|
44
48
|
if (isValidElement(child) && isTabItem(child)) {
|
|
@@ -105,12 +109,22 @@ function MimeTabsComponent(props) {
|
|
|
105
109
|
}
|
|
106
110
|
}
|
|
107
111
|
|
|
112
|
+
const dispatch = useTypedDispatch();
|
|
113
|
+
const isRequestSchema = schemaType?.toLowerCase() === "request";
|
|
114
|
+
|
|
108
115
|
const handleTabChange = (event) => {
|
|
116
|
+
event.preventDefault();
|
|
109
117
|
const newTab = event.currentTarget;
|
|
110
118
|
const newTabIndex = tabRefs.indexOf(newTab);
|
|
111
119
|
const newTabValue = values[newTabIndex].value;
|
|
112
120
|
|
|
113
121
|
if (newTabValue !== selectedValue) {
|
|
122
|
+
if (isRequestSchema) {
|
|
123
|
+
dispatch(setContentType(newTabValue));
|
|
124
|
+
} else {
|
|
125
|
+
dispatch(setAccept(newTabValue));
|
|
126
|
+
}
|
|
127
|
+
|
|
114
128
|
blockElementScrollPositionUntilNextRender(newTab);
|
|
115
129
|
setSelectedValue(newTabValue);
|
|
116
130
|
|
|
@@ -120,6 +134,20 @@ function MimeTabsComponent(props) {
|
|
|
120
134
|
}
|
|
121
135
|
};
|
|
122
136
|
|
|
137
|
+
const contentTypeVal = useTypedSelector((state) => state.contentType.value);
|
|
138
|
+
const acceptTypeVal = useTypedSelector((state) => state.accept.value);
|
|
139
|
+
|
|
140
|
+
useEffect(() => {
|
|
141
|
+
if (tabRefs.length > 1) {
|
|
142
|
+
if (isRequestSchema) {
|
|
143
|
+
setSelectedValue(contentTypeVal);
|
|
144
|
+
} else {
|
|
145
|
+
setSelectedValue(acceptTypeVal);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
149
|
+
}, [contentTypeVal, acceptTypeVal]);
|
|
150
|
+
|
|
123
151
|
const handleKeydown = (event) => {
|
|
124
152
|
let focusElement = null;
|
|
125
153
|
|
|
@@ -197,7 +225,7 @@ function MimeTabsComponent(props) {
|
|
|
197
225
|
ref={(tabControl) => tabRefs.push(tabControl)}
|
|
198
226
|
onKeyDown={handleKeydown}
|
|
199
227
|
onFocus={handleTabChange}
|
|
200
|
-
onClick={handleTabChange}
|
|
228
|
+
onClick={(e) => handleTabChange(e)}
|
|
201
229
|
{...attributes}
|
|
202
230
|
className={clsx(
|
|
203
231
|
"tabs__item",
|
|
@@ -9,6 +9,7 @@ import React from "react";
|
|
|
9
9
|
|
|
10
10
|
import CodeBlock from "@theme/CodeBlock";
|
|
11
11
|
import ReactMarkdown from "react-markdown";
|
|
12
|
+
import rehypeRaw from "rehype-raw";
|
|
12
13
|
|
|
13
14
|
import { createDescription } from "../../markdown/createDescription";
|
|
14
15
|
import { getQualifierMessage, getSchemaName } from "../../markdown/schema";
|
|
@@ -28,7 +29,10 @@ function ParamsItem({
|
|
|
28
29
|
|
|
29
30
|
const renderSchema = guard(getQualifierMessage(schema), (message) => (
|
|
30
31
|
<div>
|
|
31
|
-
<ReactMarkdown
|
|
32
|
+
<ReactMarkdown
|
|
33
|
+
children={createDescription(message)}
|
|
34
|
+
rehypePlugins={[rehypeRaw]}
|
|
35
|
+
/>
|
|
32
36
|
</div>
|
|
33
37
|
));
|
|
34
38
|
|
|
@@ -48,6 +52,7 @@ function ParamsItem({
|
|
|
48
52
|
);
|
|
49
53
|
},
|
|
50
54
|
}}
|
|
55
|
+
rehypePlugins={[rehypeRaw]}
|
|
51
56
|
/>
|
|
52
57
|
</div>
|
|
53
58
|
));
|
|
@@ -9,6 +9,7 @@ import React from "react";
|
|
|
9
9
|
|
|
10
10
|
import CodeBlock from "@theme/CodeBlock";
|
|
11
11
|
import ReactMarkdown from "react-markdown";
|
|
12
|
+
import rehypeRaw from "rehype-raw";
|
|
12
13
|
|
|
13
14
|
import { createDescription } from "../../markdown/createDescription";
|
|
14
15
|
import { guard } from "../../markdown/utils";
|
|
@@ -45,13 +46,17 @@ function SchemaItem({
|
|
|
45
46
|
);
|
|
46
47
|
},
|
|
47
48
|
}}
|
|
49
|
+
rehypePlugins={[rehypeRaw]}
|
|
48
50
|
/>
|
|
49
51
|
</div>
|
|
50
52
|
));
|
|
51
53
|
|
|
52
54
|
const renderQualifierMessage = guard(qualifierMessage, (message) => (
|
|
53
55
|
<div className={styles.schemaQualifierMessage}>
|
|
54
|
-
<ReactMarkdown
|
|
56
|
+
<ReactMarkdown
|
|
57
|
+
children={createDescription(message)}
|
|
58
|
+
rehypePlugins={[rehypeRaw]}
|
|
59
|
+
/>
|
|
55
60
|
</div>
|
|
56
61
|
));
|
|
57
62
|
|
|
@@ -227,7 +227,10 @@ function SchemaTabsComponent(props) {
|
|
|
227
227
|
cloneElement(
|
|
228
228
|
children.filter(
|
|
229
229
|
(tabItem) => tabItem.props.value === selectedValue
|
|
230
|
-
)[0]
|
|
230
|
+
)[0] ?? // TODO: see if there's a better way to handle this
|
|
231
|
+
children.filter(
|
|
232
|
+
(tabItem) => tabItem.props.value === defaultValue
|
|
233
|
+
)[0],
|
|
231
234
|
{
|
|
232
235
|
className: "margin-vert--md",
|
|
233
236
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "docusaurus-theme-openapi-docs",
|
|
3
3
|
"description": "OpenAPI theme for Docusaurus.",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.3.1",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"openapi",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"buffer": "^6.0.3",
|
|
51
51
|
"clsx": "^1.1.1",
|
|
52
52
|
"crypto-js": "^4.1.1",
|
|
53
|
-
"docusaurus-plugin-openapi-docs": "^1.
|
|
53
|
+
"docusaurus-plugin-openapi-docs": "^1.3.1",
|
|
54
54
|
"immer": "^9.0.7",
|
|
55
55
|
"lodash": "^4.17.20",
|
|
56
56
|
"process": "^0.11.10",
|
|
@@ -60,6 +60,7 @@
|
|
|
60
60
|
"react-modal": "^3.15.1",
|
|
61
61
|
"react-redux": "^7.2.0",
|
|
62
62
|
"redux-devtools-extension": "^2.13.8",
|
|
63
|
+
"rehype-raw": "^6.1.1",
|
|
63
64
|
"webpack": "^5.61.0",
|
|
64
65
|
"xml-formatter": "^2.6.1"
|
|
65
66
|
},
|
|
@@ -70,5 +71,5 @@
|
|
|
70
71
|
"engines": {
|
|
71
72
|
"node": ">=14"
|
|
72
73
|
},
|
|
73
|
-
"gitHead": "
|
|
74
|
+
"gitHead": "5f41e8dc4981409902ae96a7d127a2ae7eb9a47d"
|
|
74
75
|
}
|
|
@@ -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 { setAccept } from "./slice";
|
|
@@ -7,10 +7,10 @@
|
|
|
7
7
|
|
|
8
8
|
import React from "react";
|
|
9
9
|
|
|
10
|
+
import { useTypedDispatch, useTypedSelector } from "../../ApiItem/hooks";
|
|
10
11
|
import FormItem from "../FormItem";
|
|
11
12
|
import FormSelect from "../FormSelect";
|
|
12
13
|
import FormTextInput from "../FormTextInput";
|
|
13
|
-
import { useTypedDispatch, useTypedSelector } from "../hooks";
|
|
14
14
|
import { setAuthData, setSelectedAuth } from "./slice";
|
|
15
15
|
|
|
16
16
|
function Authorization() {
|