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
|
@@ -9,58 +9,134 @@ import React from "react";
|
|
|
9
9
|
|
|
10
10
|
import ExecutionEnvironment from "@docusaurus/ExecutionEnvironment";
|
|
11
11
|
import { HtmlClassNameProvider } from "@docusaurus/theme-common";
|
|
12
|
+
import useDocusaurusContext from "@docusaurus/useDocusaurusContext";
|
|
12
13
|
import type { Props } from "@theme/DocItem";
|
|
13
14
|
import clsx from "clsx";
|
|
15
|
+
import { ServerObject } from "docusaurus-plugin-openapi-docs/lib/openapi/types";
|
|
14
16
|
import type { ApiItem as ApiItemType } from "docusaurus-plugin-openapi-docs/lib/types";
|
|
17
|
+
import { ParameterObject } from "docusaurus-plugin-openapi-docs/src/openapi/types";
|
|
18
|
+
import { Provider } from "react-redux";
|
|
15
19
|
|
|
16
20
|
import { DocFrontMatter } from "../../types";
|
|
21
|
+
import { ThemeConfig } from "../../types";
|
|
22
|
+
import { createAuth } from "../ApiDemoPanel/Authorization/slice";
|
|
23
|
+
import { createPersistanceMiddleware } from "../ApiDemoPanel/persistanceMiddleware";
|
|
17
24
|
import DocItemLayout from "./Layout";
|
|
18
25
|
import DocItemMetadata from "./Metadata";
|
|
26
|
+
import { createStoreWithState } from "./store";
|
|
19
27
|
|
|
20
28
|
const { DocProvider } = require("@docusaurus/theme-common/internal");
|
|
21
29
|
|
|
22
30
|
let ApiDemoPanel = (_: { item: any; infoPath: any }) => (
|
|
23
31
|
<div style={{ marginTop: "3.5em" }} />
|
|
24
32
|
);
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
33
|
+
|
|
34
|
+
let DocItem = (props: Props) => {
|
|
35
|
+
return <div style={{ marginTop: "3.5em" }} />;
|
|
36
|
+
};
|
|
28
37
|
|
|
29
38
|
interface ApiFrontMatter extends DocFrontMatter {
|
|
30
39
|
readonly api?: ApiItemType;
|
|
31
40
|
}
|
|
32
41
|
|
|
33
|
-
|
|
34
|
-
|
|
42
|
+
if (ExecutionEnvironment.canUseDOM) {
|
|
43
|
+
ApiDemoPanel = require("@theme/ApiDemoPanel").default;
|
|
35
44
|
|
|
36
|
-
|
|
45
|
+
DocItem = function DocItem(props: Props): JSX.Element {
|
|
46
|
+
const docHtmlClassName = `docs-doc-id-${props.content.metadata.unversionedId}`;
|
|
37
47
|
const MDXComponent = props.content;
|
|
38
48
|
const { frontMatter } = MDXComponent;
|
|
39
49
|
const { info_path: infoPath } = frontMatter as DocFrontMatter;
|
|
40
50
|
const { api } = frontMatter as ApiFrontMatter;
|
|
51
|
+
const { siteConfig } = useDocusaurusContext();
|
|
52
|
+
const themeConfig = siteConfig.themeConfig as ThemeConfig;
|
|
53
|
+
const options = themeConfig.api;
|
|
41
54
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
55
|
+
const acceptArray = Array.from(
|
|
56
|
+
new Set(
|
|
57
|
+
Object.values(api?.responses ?? {})
|
|
58
|
+
.map((response: any) => Object.keys(response.content ?? {}))
|
|
59
|
+
.flat()
|
|
60
|
+
)
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
const content = api?.requestBody?.content ?? {};
|
|
64
|
+
const contentTypeArray = Object.keys(content);
|
|
65
|
+
const servers = api?.servers ?? [];
|
|
66
|
+
|
|
67
|
+
const params = {
|
|
68
|
+
path: [] as ParameterObject[],
|
|
69
|
+
query: [] as ParameterObject[],
|
|
70
|
+
header: [] as ParameterObject[],
|
|
71
|
+
cookie: [] as ParameterObject[],
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
api?.parameters?.forEach(
|
|
75
|
+
(param: { in: "path" | "query" | "header" | "cookie" }) => {
|
|
76
|
+
const paramType = param.in;
|
|
77
|
+
const paramsArray: ParameterObject[] = params[paramType];
|
|
78
|
+
paramsArray.push(param as ParameterObject);
|
|
79
|
+
}
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
const auth = createAuth({
|
|
83
|
+
security: api?.security,
|
|
84
|
+
securitySchemes: api?.securitySchemes,
|
|
85
|
+
options,
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
const persistanceMiddleware = createPersistanceMiddleware(options);
|
|
89
|
+
const acceptValue = window?.sessionStorage.getItem("accept");
|
|
90
|
+
const contentTypeValue = window?.sessionStorage.getItem("contentType");
|
|
91
|
+
const server = window?.sessionStorage.getItem("server");
|
|
92
|
+
const serverObject = (JSON.parse(server!) as ServerObject) ?? {};
|
|
93
|
+
const store2 = createStoreWithState(
|
|
94
|
+
{
|
|
95
|
+
accept: { value: acceptValue || acceptArray[0], options: acceptArray },
|
|
96
|
+
contentType: {
|
|
97
|
+
value: contentTypeValue || contentTypeArray[0],
|
|
98
|
+
options: contentTypeArray,
|
|
99
|
+
},
|
|
100
|
+
server: {
|
|
101
|
+
value: serverObject.url ? serverObject : undefined,
|
|
102
|
+
options: servers,
|
|
103
|
+
},
|
|
104
|
+
response: { value: undefined },
|
|
105
|
+
body: { type: "empty" },
|
|
106
|
+
params,
|
|
107
|
+
auth,
|
|
108
|
+
},
|
|
109
|
+
[persistanceMiddleware]
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
const DocContent = () => {
|
|
113
|
+
return (
|
|
114
|
+
<div className="row">
|
|
115
|
+
<div className={clsx("col", api ? "col--7" : "col--12")}>
|
|
116
|
+
<MDXComponent />
|
|
50
117
|
</div>
|
|
51
|
-
|
|
52
|
-
|
|
118
|
+
{api && (
|
|
119
|
+
<div className="col col--5">
|
|
120
|
+
<ApiDemoPanel item={api} infoPath={infoPath} />
|
|
121
|
+
</div>
|
|
122
|
+
)}
|
|
123
|
+
</div>
|
|
124
|
+
);
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
return (
|
|
128
|
+
<Provider store={store2}>
|
|
129
|
+
<DocProvider content={props.content}>
|
|
130
|
+
<HtmlClassNameProvider className={docHtmlClassName}>
|
|
131
|
+
<DocItemMetadata />
|
|
132
|
+
<DocItemLayout>
|
|
133
|
+
<DocContent />
|
|
134
|
+
</DocItemLayout>
|
|
135
|
+
</HtmlClassNameProvider>
|
|
136
|
+
</DocProvider>
|
|
137
|
+
</Provider>
|
|
53
138
|
);
|
|
54
139
|
};
|
|
55
|
-
|
|
56
|
-
return (
|
|
57
|
-
<DocProvider content={props.content}>
|
|
58
|
-
<HtmlClassNameProvider className={docHtmlClassName}>
|
|
59
|
-
<DocItemMetadata />
|
|
60
|
-
<DocItemLayout>
|
|
61
|
-
<DocContent />
|
|
62
|
-
</DocItemLayout>
|
|
63
|
-
</HtmlClassNameProvider>
|
|
64
|
-
</DocProvider>
|
|
65
|
-
);
|
|
66
140
|
}
|
|
141
|
+
|
|
142
|
+
export default DocItem;
|
|
@@ -7,13 +7,13 @@
|
|
|
7
7
|
|
|
8
8
|
import { configureStore, combineReducers } from "@reduxjs/toolkit";
|
|
9
9
|
|
|
10
|
-
import accept from "
|
|
11
|
-
import auth from "
|
|
12
|
-
import body from "
|
|
13
|
-
import contentType from "
|
|
14
|
-
import params from "
|
|
15
|
-
import response from "
|
|
16
|
-
import server from "
|
|
10
|
+
import accept from "../ApiDemoPanel/Accept/slice";
|
|
11
|
+
import auth from "../ApiDemoPanel/Authorization/slice";
|
|
12
|
+
import body from "../ApiDemoPanel/Body/slice";
|
|
13
|
+
import contentType from "../ApiDemoPanel/ContentType/slice";
|
|
14
|
+
import params from "../ApiDemoPanel/ParamOptions/slice";
|
|
15
|
+
import response from "../ApiDemoPanel/Response/slice";
|
|
16
|
+
import server from "../ApiDemoPanel/Server/slice";
|
|
17
17
|
|
|
18
18
|
const rootReducer = combineReducers({
|
|
19
19
|
accept,
|
|
@@ -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
|
}
|