docusaurus-theme-openapi-docs 0.0.0-beta.646 → 0.0.0-beta.651
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/ApiCodeBlock/Content/_Content.scss +1 -0
- package/lib/theme/ApiDemoPanel/Body/index.d.ts +3 -1
- package/lib/theme/ApiDemoPanel/Body/index.js +30 -32
- package/lib/theme/ApiDemoPanel/CodeTabs/_CodeTabs.scss +95 -39
- package/lib/theme/ApiDemoPanel/CodeTabs/index.js +24 -6
- package/lib/theme/ApiDemoPanel/Curl/index.d.ts +5 -4
- package/lib/theme/ApiDemoPanel/Curl/index.js +79 -11
- package/lib/theme/ApiDemoPanel/FormItem/_FormItem.scss +11 -2
- package/lib/theme/ApiDemoPanel/FormItem/index.d.ts +2 -1
- package/lib/theme/ApiDemoPanel/FormItem/index.js +9 -3
- package/lib/theme/ApiDemoPanel/FormMultiSelect/_FormMultiSelect.scss +8 -4
- package/lib/theme/ApiDemoPanel/FormMultiSelect/index.d.ts +2 -1
- package/lib/theme/ApiDemoPanel/FormMultiSelect/index.js +5 -2
- package/lib/theme/ApiDemoPanel/FormSelect/_FormSelect.scss +3 -3
- package/lib/theme/ApiDemoPanel/FormTextInput/_FormTextInput.scss +24 -5
- package/lib/theme/ApiDemoPanel/FormTextInput/index.d.ts +1 -1
- package/lib/theme/ApiDemoPanel/FormTextInput/index.js +56 -10
- package/lib/theme/ApiDemoPanel/LiveEditor/index.d.ts +5 -2
- package/lib/theme/ApiDemoPanel/LiveEditor/index.js +59 -14
- package/lib/theme/ApiDemoPanel/ParamOptions/ParamFormItems/ParamArrayFormItem.d.ts +6 -0
- package/lib/theme/ApiDemoPanel/ParamOptions/ParamFormItems/ParamArrayFormItem.js +194 -0
- package/lib/theme/ApiDemoPanel/ParamOptions/ParamFormItems/ParamBooleanFormItem.d.ts +6 -0
- package/lib/theme/ApiDemoPanel/ParamOptions/ParamFormItems/ParamBooleanFormItem.js +63 -0
- package/lib/theme/ApiDemoPanel/ParamOptions/ParamFormItems/ParamMultiSelectFormItem.d.ts +6 -0
- package/lib/theme/ApiDemoPanel/ParamOptions/ParamFormItems/ParamMultiSelectFormItem.js +89 -0
- package/lib/theme/ApiDemoPanel/ParamOptions/ParamFormItems/ParamSelectFormItem.d.ts +6 -0
- package/lib/theme/ApiDemoPanel/ParamOptions/ParamFormItems/ParamSelectFormItem.js +63 -0
- package/lib/theme/ApiDemoPanel/ParamOptions/ParamFormItems/ParamTextFormItem.d.ts +6 -0
- package/lib/theme/ApiDemoPanel/ParamOptions/ParamFormItems/ParamTextFormItem.js +38 -0
- package/lib/theme/ApiDemoPanel/ParamOptions/_ParamOptions.scss +9 -28
- package/lib/theme/ApiDemoPanel/ParamOptions/index.js +24 -176
- package/lib/theme/ApiDemoPanel/Request/_Request.scss +93 -20
- package/lib/theme/ApiDemoPanel/Request/index.d.ts +1 -1
- package/lib/theme/ApiDemoPanel/Request/index.js +316 -37
- package/lib/theme/ApiDemoPanel/Response/_Response.scss +54 -0
- package/lib/theme/ApiDemoPanel/Response/index.d.ts +4 -1
- package/lib/theme/ApiDemoPanel/Response/index.js +56 -31
- package/lib/theme/ApiDemoPanel/Server/_Server.scss +10 -0
- package/lib/theme/ApiDemoPanel/Server/index.js +10 -11
- package/lib/theme/ApiDemoPanel/index.js +1 -1
- package/lib/theme/SchemaTabs/_SchemaTabs.scss +0 -1
- package/lib/theme/styles.scss +27 -0
- package/package.json +7 -4
- package/src/theme/ApiDemoPanel/ApiCodeBlock/Content/_Content.scss +1 -0
- package/src/theme/ApiDemoPanel/Body/index.tsx +38 -29
- package/src/theme/ApiDemoPanel/CodeTabs/_CodeTabs.scss +95 -39
- package/src/theme/ApiDemoPanel/CodeTabs/index.js +24 -6
- package/src/theme/ApiDemoPanel/Curl/index.tsx +85 -22
- package/src/theme/ApiDemoPanel/FormItem/_FormItem.scss +11 -2
- package/src/theme/ApiDemoPanel/FormItem/index.tsx +8 -3
- package/src/theme/ApiDemoPanel/FormMultiSelect/_FormMultiSelect.scss +8 -4
- package/src/theme/ApiDemoPanel/FormMultiSelect/index.tsx +7 -2
- package/src/theme/ApiDemoPanel/FormSelect/_FormSelect.scss +3 -3
- package/src/theme/ApiDemoPanel/FormTextInput/_FormTextInput.scss +24 -5
- package/src/theme/ApiDemoPanel/FormTextInput/index.tsx +58 -10
- package/src/theme/ApiDemoPanel/LiveEditor/index.tsx +53 -14
- package/src/theme/ApiDemoPanel/ParamOptions/ParamFormItems/ParamArrayFormItem.tsx +153 -0
- package/src/theme/ApiDemoPanel/ParamOptions/ParamFormItems/ParamBooleanFormItem.tsx +64 -0
- package/src/theme/ApiDemoPanel/ParamOptions/ParamFormItems/ParamMultiSelectFormItem.tsx +86 -0
- package/src/theme/ApiDemoPanel/ParamOptions/ParamFormItems/ParamSelectFormItem.tsx +65 -0
- package/src/theme/ApiDemoPanel/ParamOptions/ParamFormItems/ParamTextFormItem.tsx +38 -0
- package/src/theme/ApiDemoPanel/ParamOptions/_ParamOptions.scss +9 -28
- package/src/theme/ApiDemoPanel/ParamOptions/index.tsx +8 -196
- package/src/theme/ApiDemoPanel/Request/_Request.scss +93 -20
- package/src/theme/ApiDemoPanel/Request/index.tsx +250 -28
- package/src/theme/ApiDemoPanel/Response/_Response.scss +54 -0
- package/src/theme/ApiDemoPanel/Response/index.tsx +44 -26
- package/src/theme/ApiDemoPanel/Server/_Server.scss +10 -0
- package/src/theme/ApiDemoPanel/Server/index.tsx +8 -11
- package/src/theme/ApiDemoPanel/index.tsx +1 -1
- package/src/theme/SchemaTabs/_SchemaTabs.scss +0 -1
- package/src/theme/styles.scss +27 -0
- package/src/theme-openapi.d.ts +40 -1
- package/lib/theme/ApiDemoPanel/Execute/index.d.ts +0 -8
- package/lib/theme/ApiDemoPanel/Execute/index.js +0 -213
- package/src/theme/ApiDemoPanel/Execute/index.tsx +0 -200
- /package/lib/theme/ApiDemoPanel/{Execute → Request}/makeRequest.d.ts +0 -0
- /package/lib/theme/ApiDemoPanel/{Execute → Request}/makeRequest.js +0 -0
- /package/src/theme/ApiDemoPanel/{Execute → Request}/makeRequest.ts +0 -0
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
.openapi-
|
|
2
|
-
background: var(--
|
|
1
|
+
.openapi-demo__request-form {
|
|
2
|
+
background-color: var(--ifm-pre-background);
|
|
3
3
|
border-radius: var(--openapi-card-border-radius);
|
|
4
|
+
border: 1px solid var(--openapi-demo-border-color);
|
|
5
|
+
box-shadow: 0 2px 3px hsla(222, 8%, 43%, 0.1),
|
|
6
|
+
0 8px 16px -10px hsla(222, 8%, 43%, 0.2);
|
|
4
7
|
color: var(--ifm-pre-color);
|
|
5
8
|
line-height: var(--ifm-pre-line-height);
|
|
6
9
|
margin-bottom: var(--ifm-spacing-vertical);
|
|
7
10
|
margin-top: 0;
|
|
8
11
|
overflow: auto;
|
|
9
|
-
|
|
10
|
-
padding: var(--ifm-pre-padding);
|
|
12
|
+
transition: 300ms;
|
|
11
13
|
|
|
12
14
|
/* hack for view calculation when monaco is hidden */
|
|
13
15
|
position: relative;
|
|
@@ -15,34 +17,105 @@
|
|
|
15
17
|
&:empty {
|
|
16
18
|
display: none;
|
|
17
19
|
}
|
|
18
|
-
}
|
|
19
20
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
&:hover {
|
|
22
|
+
box-shadow: 0 0 0 2px rgba(38, 53, 61, 0.15),
|
|
23
|
+
0 2px 3px hsla(222, 8%, 43%, 0.15),
|
|
24
|
+
0 16px 16px -10px hsla(222, 8%, 43%, 0.2);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.required {
|
|
28
|
+
font-size: var(--ifm-code-font-size);
|
|
29
|
+
color: var(--openapi-required);
|
|
30
|
+
|
|
31
|
+
&.request-body {
|
|
32
|
+
padding-left: 0.25rem;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
24
35
|
}
|
|
25
36
|
|
|
26
|
-
.openapi-
|
|
27
|
-
|
|
28
|
-
|
|
37
|
+
.openapi-demo__request-header-container {
|
|
38
|
+
display: flex;
|
|
39
|
+
justify-content: space-between;
|
|
40
|
+
border-bottom: 1px solid var(--openapi-demo-border-color);
|
|
41
|
+
margin: 0;
|
|
42
|
+
padding: 0.75rem var(--ifm-pre-padding);
|
|
43
|
+
text-transform: uppercase;
|
|
44
|
+
font-size: 12px;
|
|
45
|
+
font-weight: bold;
|
|
46
|
+
}
|
|
29
47
|
|
|
48
|
+
.openapi-demo__expand-details-btn {
|
|
30
49
|
&:hover {
|
|
31
50
|
cursor: pointer;
|
|
32
51
|
}
|
|
33
52
|
}
|
|
34
53
|
|
|
35
|
-
.openapi-
|
|
36
|
-
|
|
37
|
-
|
|
54
|
+
.openapi-demo__details-outer-container {
|
|
55
|
+
padding: 1rem;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.openapi-demo__details-container[open] {
|
|
59
|
+
.openapi-demo__details-summary::before {
|
|
60
|
+
transform: rotate(180deg);
|
|
61
|
+
margin-top: 0.25rem;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.openapi-demo__details-summary {
|
|
66
|
+
display: inline-flex;
|
|
38
67
|
align-items: center;
|
|
68
|
+
padding: 0.35rem 0;
|
|
69
|
+
font-size: 14px;
|
|
70
|
+
list-style: none;
|
|
71
|
+
|
|
72
|
+
&:hover {
|
|
73
|
+
cursor: pointer;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
&::-webkit-details-marker {
|
|
77
|
+
display: none;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
&::before {
|
|
81
|
+
margin-right: 0.25rem;
|
|
82
|
+
margin-bottom: 0.25rem;
|
|
83
|
+
background-image: var(--openapi-demo-caret-bg);
|
|
84
|
+
border: none !important;
|
|
85
|
+
transform: rotate(90deg);
|
|
86
|
+
content: "";
|
|
87
|
+
height: 0.75rem;
|
|
88
|
+
width: 0.75rem;
|
|
89
|
+
}
|
|
39
90
|
}
|
|
40
91
|
|
|
41
|
-
.openapi-
|
|
42
|
-
|
|
92
|
+
.openapi-demo__request-btn {
|
|
93
|
+
border: none;
|
|
94
|
+
border-radius: var(--ifm-global-radius);
|
|
95
|
+
padding: 0.5rem 1rem;
|
|
96
|
+
margin-top: 1rem;
|
|
97
|
+
background-color: var(--ifm-color-primary-light);
|
|
98
|
+
text-transform: uppercase;
|
|
99
|
+
font-weight: bold;
|
|
100
|
+
font-size: 12px;
|
|
101
|
+
color: white;
|
|
102
|
+
cursor: pointer;
|
|
103
|
+
transition: 300ms;
|
|
104
|
+
|
|
105
|
+
&:hover {
|
|
106
|
+
background-color: var(--ifm-color-primary-lightest);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
&:active {
|
|
110
|
+
background-color: var(--ifm-color-primary-light);
|
|
111
|
+
}
|
|
43
112
|
}
|
|
44
113
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
114
|
+
// Prevent auto zoom on mobile iOS devices when focusing on input elmenents
|
|
115
|
+
@media screen and (-webkit-min-device-pixel-ratio: 0) and (max-device-width: 1024px) {
|
|
116
|
+
.prism-code,
|
|
117
|
+
select,
|
|
118
|
+
input {
|
|
119
|
+
font-size: 1rem;
|
|
120
|
+
}
|
|
48
121
|
}
|
|
@@ -5,27 +5,80 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
* ========================================================================== */
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
// @ts-nocheck
|
|
9
|
+
import React, { useState } from "react";
|
|
9
10
|
|
|
10
11
|
import { useDoc } from "@docusaurus/theme-common/internal";
|
|
11
12
|
import sdk from "@paloaltonetworks/postman-collection";
|
|
12
13
|
import Accept from "@theme/ApiDemoPanel/Accept";
|
|
13
14
|
import Authorization from "@theme/ApiDemoPanel/Authorization";
|
|
14
15
|
import Body from "@theme/ApiDemoPanel/Body";
|
|
15
|
-
import
|
|
16
|
+
import buildPostmanRequest from "@theme/ApiDemoPanel/buildPostmanRequest";
|
|
17
|
+
import ContentType from "@theme/ApiDemoPanel/ContentType";
|
|
16
18
|
import ParamOptions from "@theme/ApiDemoPanel/ParamOptions";
|
|
19
|
+
import {
|
|
20
|
+
setResponse,
|
|
21
|
+
setCode,
|
|
22
|
+
clearCode,
|
|
23
|
+
setHeaders,
|
|
24
|
+
clearHeaders,
|
|
25
|
+
} from "@theme/ApiDemoPanel/Response/slice";
|
|
17
26
|
import Server from "@theme/ApiDemoPanel/Server";
|
|
18
|
-
import { useTypedSelector } from "@theme/ApiItem/hooks";
|
|
27
|
+
import { useTypedDispatch, useTypedSelector } from "@theme/ApiItem/hooks";
|
|
19
28
|
import { ParameterObject } from "docusaurus-plugin-openapi-docs/src/openapi/types";
|
|
20
29
|
import { ApiItem } from "docusaurus-plugin-openapi-docs/src/types";
|
|
30
|
+
import { FormProvider, useForm } from "react-hook-form";
|
|
31
|
+
|
|
32
|
+
import makeRequest from "./makeRequest";
|
|
21
33
|
|
|
22
34
|
function Request({ item }: { item: NonNullable<ApiItem> }) {
|
|
23
|
-
const response = useTypedSelector((state: any) => state.response.value);
|
|
24
35
|
const postman = new sdk.Request(item.postman);
|
|
25
36
|
const metadata = useDoc();
|
|
26
|
-
const { proxy, hide_send_button } = metadata.frontMatter;
|
|
37
|
+
const { proxy, hide_send_button: hideSendButton } = metadata.frontMatter;
|
|
38
|
+
|
|
39
|
+
const pathParams = useTypedSelector((state: any) => state.params.path);
|
|
40
|
+
const queryParams = useTypedSelector((state: any) => state.params.query);
|
|
41
|
+
const cookieParams = useTypedSelector((state: any) => state.params.cookie);
|
|
42
|
+
const contentType = useTypedSelector((state: any) => state.contentType.value);
|
|
43
|
+
const headerParams = useTypedSelector((state: any) => state.params.header);
|
|
44
|
+
const body = useTypedSelector((state: any) => state.body);
|
|
45
|
+
const accept = useTypedSelector((state: any) => state.accept.value);
|
|
46
|
+
const acceptOptions = useTypedDispatch((state: any) => state.accept.options);
|
|
47
|
+
const authSelected = useTypedSelector((state: any) => state.auth.selected);
|
|
48
|
+
const server = useTypedSelector((state: any) => state.server.value);
|
|
49
|
+
const serverOptions = useTypedSelector((state: any) => state.server.options);
|
|
50
|
+
const auth = useTypedSelector((state: any) => state.auth);
|
|
51
|
+
const dispatch = useTypedDispatch();
|
|
52
|
+
|
|
53
|
+
const [expandAccept, setExpandAccept] = useState(true);
|
|
54
|
+
const [expandAuth, setExpandAuth] = useState(true);
|
|
55
|
+
const [expandBody, setExpandBody] = useState(true);
|
|
56
|
+
const [expandParams, setExpandParams] = useState(true);
|
|
57
|
+
const [expandServer, setExpandServer] = useState(true);
|
|
58
|
+
|
|
59
|
+
const allParams = [
|
|
60
|
+
...pathParams,
|
|
61
|
+
...queryParams,
|
|
62
|
+
...cookieParams,
|
|
63
|
+
...headerParams,
|
|
64
|
+
];
|
|
65
|
+
|
|
66
|
+
const postmanRequest = buildPostmanRequest(postman, {
|
|
67
|
+
queryParams,
|
|
68
|
+
pathParams,
|
|
69
|
+
cookieParams,
|
|
70
|
+
contentType,
|
|
71
|
+
accept,
|
|
72
|
+
headerParams,
|
|
73
|
+
body,
|
|
74
|
+
server,
|
|
75
|
+
auth,
|
|
76
|
+
});
|
|
27
77
|
|
|
28
|
-
const
|
|
78
|
+
const delay = (ms: number) =>
|
|
79
|
+
new Promise((resolve) => setTimeout(resolve, ms));
|
|
80
|
+
|
|
81
|
+
const paramsObject = {
|
|
29
82
|
path: [] as ParameterObject[],
|
|
30
83
|
query: [] as ParameterObject[],
|
|
31
84
|
header: [] as ParameterObject[],
|
|
@@ -35,34 +88,203 @@ function Request({ item }: { item: NonNullable<ApiItem> }) {
|
|
|
35
88
|
item.parameters?.forEach(
|
|
36
89
|
(param: { in: "path" | "query" | "header" | "cookie" }) => {
|
|
37
90
|
const paramType = param.in;
|
|
38
|
-
const paramsArray: ParameterObject[] =
|
|
91
|
+
const paramsArray: ParameterObject[] = paramsObject[paramType];
|
|
39
92
|
paramsArray.push(param as ParameterObject);
|
|
40
93
|
}
|
|
41
94
|
);
|
|
42
95
|
|
|
96
|
+
const methods = useForm({ shouldFocusError: false });
|
|
97
|
+
|
|
98
|
+
const onSubmit = async (data) => {
|
|
99
|
+
dispatch(setResponse("Fetching..."));
|
|
100
|
+
try {
|
|
101
|
+
await delay(1200);
|
|
102
|
+
const res = await makeRequest(postmanRequest, proxy, body);
|
|
103
|
+
dispatch(setResponse(await res.text()));
|
|
104
|
+
dispatch(setCode(res.status));
|
|
105
|
+
res.headers && dispatch(setHeaders(Object.fromEntries(res.headers)));
|
|
106
|
+
} catch (e: any) {
|
|
107
|
+
console.log(e);
|
|
108
|
+
dispatch(setResponse("Connection failed"));
|
|
109
|
+
dispatch(clearCode());
|
|
110
|
+
dispatch(clearHeaders());
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const showServerOptions = serverOptions.length > 0;
|
|
115
|
+
const showAcceptOptions = acceptOptions.length > 1;
|
|
116
|
+
const showRequestBody = contentType !== undefined;
|
|
117
|
+
const showRequestButton = item.servers && !hideSendButton;
|
|
118
|
+
const showAuth = authSelected !== undefined;
|
|
119
|
+
const showParams = allParams.length > 0;
|
|
120
|
+
const requestBodyRequired = item.requestBody?.required;
|
|
121
|
+
|
|
122
|
+
if (
|
|
123
|
+
!showAcceptOptions &&
|
|
124
|
+
!showAuth &&
|
|
125
|
+
!showParams &&
|
|
126
|
+
!showRequestBody &&
|
|
127
|
+
!showServerOptions
|
|
128
|
+
) {
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const expandAllDetails = () => {
|
|
133
|
+
setExpandAccept(true);
|
|
134
|
+
setExpandAuth(true);
|
|
135
|
+
setExpandBody(true);
|
|
136
|
+
setExpandParams(true);
|
|
137
|
+
setExpandServer(true);
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
const collapseAllDetails = () => {
|
|
141
|
+
setExpandAccept(false);
|
|
142
|
+
setExpandAuth(false);
|
|
143
|
+
setExpandBody(false);
|
|
144
|
+
setExpandParams(false);
|
|
145
|
+
setExpandServer(false);
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
const allDetailsExpanded =
|
|
149
|
+
expandParams && expandBody && expandServer && expandAuth && expandAccept;
|
|
150
|
+
|
|
43
151
|
return (
|
|
44
|
-
|
|
45
|
-
<
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
152
|
+
<FormProvider {...methods}>
|
|
153
|
+
<form
|
|
154
|
+
className="openapi-demo__request-form"
|
|
155
|
+
onSubmit={methods.handleSubmit(onSubmit)}
|
|
156
|
+
>
|
|
157
|
+
<div className="openapi-demo__request-header-container">
|
|
158
|
+
<span className="openapi-demo__request-title">Request </span>
|
|
159
|
+
{allDetailsExpanded ? (
|
|
160
|
+
<span
|
|
161
|
+
className="openapi-demo__expand-details-btn"
|
|
162
|
+
onClick={collapseAllDetails}
|
|
163
|
+
>
|
|
164
|
+
Collapse all
|
|
165
|
+
</span>
|
|
166
|
+
) : (
|
|
167
|
+
<span
|
|
168
|
+
className="openapi-demo__expand-details-btn"
|
|
169
|
+
onClick={expandAllDetails}
|
|
170
|
+
>
|
|
171
|
+
Expand all
|
|
172
|
+
</span>
|
|
173
|
+
)}
|
|
174
|
+
</div>
|
|
175
|
+
<div className="openapi-demo__details-outer-container">
|
|
176
|
+
{showServerOptions && (
|
|
177
|
+
<details
|
|
178
|
+
open={expandServer}
|
|
179
|
+
className="openapi-demo__details-container"
|
|
180
|
+
>
|
|
181
|
+
<summary
|
|
182
|
+
className="openapi-demo__details-summary"
|
|
183
|
+
onClick={(e) => {
|
|
184
|
+
e.preventDefault();
|
|
185
|
+
setExpandServer(!expandServer);
|
|
186
|
+
}}
|
|
187
|
+
>
|
|
188
|
+
Base URL
|
|
189
|
+
</summary>
|
|
190
|
+
<Server />
|
|
191
|
+
</details>
|
|
192
|
+
)}
|
|
193
|
+
{showAuth && (
|
|
194
|
+
<details
|
|
195
|
+
open={expandAuth}
|
|
196
|
+
className="openapi-demo__details-container"
|
|
197
|
+
>
|
|
198
|
+
<summary
|
|
199
|
+
className="openapi-demo__details-summary"
|
|
200
|
+
onClick={(e) => {
|
|
201
|
+
e.preventDefault();
|
|
202
|
+
setExpandAuth(!expandAuth);
|
|
203
|
+
}}
|
|
204
|
+
>
|
|
205
|
+
Auth
|
|
206
|
+
</summary>
|
|
207
|
+
<Authorization />
|
|
208
|
+
</details>
|
|
209
|
+
)}
|
|
210
|
+
{showParams && (
|
|
211
|
+
<details
|
|
212
|
+
open={
|
|
213
|
+
expandParams || Object.keys(methods.formState.errors).length
|
|
214
|
+
}
|
|
215
|
+
className="openapi-demo__details-container"
|
|
216
|
+
>
|
|
217
|
+
<summary
|
|
218
|
+
className="openapi-demo__details-summary"
|
|
219
|
+
onClick={(e) => {
|
|
220
|
+
e.preventDefault();
|
|
221
|
+
setExpandParams(!expandParams);
|
|
222
|
+
}}
|
|
223
|
+
>
|
|
224
|
+
Parameters
|
|
225
|
+
</summary>
|
|
226
|
+
<ParamOptions />
|
|
227
|
+
</details>
|
|
228
|
+
)}
|
|
229
|
+
{showRequestBody && (
|
|
230
|
+
<details
|
|
231
|
+
open={expandBody}
|
|
232
|
+
className="openapi-demo__details-container"
|
|
233
|
+
>
|
|
234
|
+
<summary
|
|
235
|
+
className="openapi-demo__details-summary"
|
|
236
|
+
onClick={(e) => {
|
|
237
|
+
e.preventDefault();
|
|
238
|
+
setExpandBody(!expandBody);
|
|
239
|
+
}}
|
|
240
|
+
>
|
|
241
|
+
Body{" "}
|
|
242
|
+
{requestBodyRequired && (
|
|
243
|
+
<span>
|
|
244
|
+
<small>
|
|
245
|
+
<strong className="request-body required">
|
|
246
|
+
{" "}
|
|
247
|
+
required
|
|
248
|
+
</strong>
|
|
249
|
+
</small>
|
|
250
|
+
</span>
|
|
251
|
+
)}
|
|
252
|
+
</summary>
|
|
253
|
+
<>
|
|
254
|
+
<ContentType />
|
|
255
|
+
<Body
|
|
256
|
+
jsonRequestBodyExample={item.jsonRequestBodyExample}
|
|
257
|
+
requestBodyMetadata={item.requestBody}
|
|
258
|
+
required={requestBodyRequired}
|
|
259
|
+
/>
|
|
260
|
+
</>
|
|
261
|
+
</details>
|
|
262
|
+
)}
|
|
263
|
+
{showAcceptOptions && (
|
|
264
|
+
<details
|
|
265
|
+
open={expandAccept}
|
|
266
|
+
className="openapi-demo__details-container"
|
|
267
|
+
>
|
|
268
|
+
<summary
|
|
269
|
+
className="openapi-demo__details-summary"
|
|
270
|
+
onClick={(e) => {
|
|
271
|
+
e.preventDefault();
|
|
272
|
+
setExpandAccept(!expandAccept);
|
|
273
|
+
}}
|
|
274
|
+
>
|
|
275
|
+
Accept
|
|
276
|
+
</summary>
|
|
277
|
+
<Accept />
|
|
278
|
+
</details>
|
|
279
|
+
)}
|
|
280
|
+
{showRequestButton && (
|
|
281
|
+
<button className="openapi-demo__request-btn" type="submit">
|
|
282
|
+
Send API Request
|
|
283
|
+
</button>
|
|
284
|
+
)}
|
|
63
285
|
</div>
|
|
64
|
-
</
|
|
65
|
-
|
|
286
|
+
</form>
|
|
287
|
+
</FormProvider>
|
|
66
288
|
);
|
|
67
289
|
}
|
|
68
290
|
|
|
@@ -1,3 +1,57 @@
|
|
|
1
|
+
.openapi-demo__response-container {
|
|
2
|
+
background-color: var(--ifm-pre-background);
|
|
3
|
+
border-radius: var(--openapi-card-border-radius);
|
|
4
|
+
border: 1px solid var(--openapi-demo-border-color);
|
|
5
|
+
box-shadow: 0 2px 3px hsla(222, 8%, 43%, 0.1),
|
|
6
|
+
0 8px 16px -10px hsla(222, 8%, 43%, 0.2);
|
|
7
|
+
color: var(--ifm-pre-color);
|
|
8
|
+
line-height: var(--ifm-pre-line-height);
|
|
9
|
+
margin-bottom: var(--ifm-spacing-vertical);
|
|
10
|
+
margin-top: 0;
|
|
11
|
+
overflow: auto;
|
|
12
|
+
transition: 300ms;
|
|
13
|
+
|
|
14
|
+
&:hover {
|
|
15
|
+
box-shadow: 0 0 0 2px rgba(38, 53, 61, 0.15),
|
|
16
|
+
0 2px 3px hsla(222, 8%, 43%, 0.15),
|
|
17
|
+
0 16px 16px -10px hsla(222, 8%, 43%, 0.2);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.openapi-demo__code-block code {
|
|
21
|
+
padding-top: 0;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.openapi-demo__response-title-container {
|
|
26
|
+
display: flex;
|
|
27
|
+
justify-content: space-between;
|
|
28
|
+
border-bottom: 1px solid var(--openapi-demo-border-color);
|
|
29
|
+
margin: 0;
|
|
30
|
+
padding: 0.75rem var(--ifm-pre-padding);
|
|
31
|
+
text-transform: uppercase;
|
|
32
|
+
font-size: 12px;
|
|
33
|
+
font-weight: bold;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.openapi-demo__response-placeholder-message {
|
|
37
|
+
font-size: 12px;
|
|
38
|
+
padding: 1.25rem;
|
|
39
|
+
margin-bottom: 0;
|
|
40
|
+
text-align: center;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.openapi-demo__response-clear-btn {
|
|
44
|
+
&:hover {
|
|
45
|
+
cursor: pointer;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.openapi-demo__loading-container {
|
|
50
|
+
width: 100%;
|
|
51
|
+
display: flex;
|
|
52
|
+
justify-content: center;
|
|
53
|
+
}
|
|
54
|
+
|
|
1
55
|
.openapi-response__dot::before {
|
|
2
56
|
margin-right: 0.2rem;
|
|
3
57
|
margin-bottom: 0.15rem;
|
|
@@ -8,11 +8,14 @@
|
|
|
8
8
|
import React from "react";
|
|
9
9
|
|
|
10
10
|
import { usePrismTheme } from "@docusaurus/theme-common";
|
|
11
|
+
import { useDoc } from "@docusaurus/theme-common/internal";
|
|
12
|
+
import { Loading } from "@nextui-org/react";
|
|
11
13
|
import { useTypedDispatch, useTypedSelector } from "@theme/ApiItem/hooks";
|
|
12
14
|
import CodeBlock from "@theme/CodeBlock";
|
|
13
15
|
import SchemaTabs from "@theme/SchemaTabs";
|
|
14
16
|
import TabItem from "@theme/TabItem";
|
|
15
17
|
import clsx from "clsx";
|
|
18
|
+
import { ApiItem } from "docusaurus-plugin-openapi-docs/src/types";
|
|
16
19
|
|
|
17
20
|
import { clearResponse, clearCode, clearHeaders } from "./slice";
|
|
18
21
|
|
|
@@ -36,7 +39,9 @@ function formatXml(xml: string) {
|
|
|
36
39
|
return formatted.substring(1, formatted.length - 3);
|
|
37
40
|
}
|
|
38
41
|
|
|
39
|
-
function Response() {
|
|
42
|
+
function Response({ item }: { item: NonNullable<ApiItem> }) {
|
|
43
|
+
const metadata = useDoc();
|
|
44
|
+
const hideSendButton = metadata.frontMatter.hide_send_button;
|
|
40
45
|
const prismTheme = usePrismTheme();
|
|
41
46
|
const code = useTypedSelector((state: any) => state.response.code);
|
|
42
47
|
const headers = useTypedSelector((state: any) => state.response.headers);
|
|
@@ -51,36 +56,37 @@ function Response() {
|
|
|
51
56
|
? "openapi-response__dot--success"
|
|
52
57
|
: "openapi-response__dot--info");
|
|
53
58
|
|
|
54
|
-
if (
|
|
59
|
+
if (!item.servers || hideSendButton) {
|
|
55
60
|
return null;
|
|
56
61
|
}
|
|
57
62
|
|
|
58
63
|
let prettyResponse: string = response;
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
+
|
|
65
|
+
if (prettyResponse) {
|
|
66
|
+
try {
|
|
67
|
+
prettyResponse = JSON.stringify(JSON.parse(response), null, 2);
|
|
68
|
+
} catch {
|
|
69
|
+
if (response.startsWith("<")) {
|
|
70
|
+
prettyResponse = formatXml(response);
|
|
71
|
+
}
|
|
64
72
|
}
|
|
65
73
|
}
|
|
66
74
|
|
|
67
75
|
return (
|
|
68
|
-
<
|
|
69
|
-
<
|
|
70
|
-
<
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
</div>
|
|
83
|
-
</summary>
|
|
76
|
+
<div className="openapi-demo__response-container">
|
|
77
|
+
<div className="openapi-demo__response-title-container">
|
|
78
|
+
<span className="openapi-demo__response-title">Response</span>
|
|
79
|
+
<span
|
|
80
|
+
className="openapi-demo__response-clear-btn"
|
|
81
|
+
onClick={() => {
|
|
82
|
+
dispatch(clearResponse());
|
|
83
|
+
dispatch(clearCode());
|
|
84
|
+
dispatch(clearHeaders());
|
|
85
|
+
}}
|
|
86
|
+
>
|
|
87
|
+
Clear
|
|
88
|
+
</span>
|
|
89
|
+
</div>
|
|
84
90
|
<div
|
|
85
91
|
style={{
|
|
86
92
|
backgroundColor: prismTheme.plain.backgroundColor,
|
|
@@ -106,7 +112,12 @@ function Response() {
|
|
|
106
112
|
className="openapi-demo__code-block openapi-response__status-code"
|
|
107
113
|
language={response.startsWith("<") ? `xml` : `json`}
|
|
108
114
|
>
|
|
109
|
-
{prettyResponse ||
|
|
115
|
+
{prettyResponse || (
|
|
116
|
+
<p className="openapi-demo__response-placeholder-message">
|
|
117
|
+
Click the <code>Send API Request</code> button above and see
|
|
118
|
+
the response here!
|
|
119
|
+
</p>
|
|
120
|
+
)}
|
|
110
121
|
</CodeBlock>
|
|
111
122
|
</TabItem>
|
|
112
123
|
{/* @ts-ignore */}
|
|
@@ -119,11 +130,18 @@ function Response() {
|
|
|
119
130
|
</CodeBlock>
|
|
120
131
|
</TabItem>
|
|
121
132
|
</SchemaTabs>
|
|
133
|
+
) : prettyResponse === "Fetching..." ? (
|
|
134
|
+
<div className="openapi-demo__loading-container">
|
|
135
|
+
<Loading color="success" />
|
|
136
|
+
</div>
|
|
122
137
|
) : (
|
|
123
|
-
|
|
138
|
+
<p className="openapi-demo__response-placeholder-message">
|
|
139
|
+
Click the <code>Send API Request</code> button above and see the
|
|
140
|
+
response here!
|
|
141
|
+
</p>
|
|
124
142
|
)}
|
|
125
143
|
</div>
|
|
126
|
-
</
|
|
144
|
+
</div>
|
|
127
145
|
);
|
|
128
146
|
}
|
|
129
147
|
|
|
@@ -14,3 +14,13 @@
|
|
|
14
14
|
display: none;
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
|
+
|
|
18
|
+
.openapi-demo__server-url {
|
|
19
|
+
font-size: var(--openapi-demo-font-size-input);
|
|
20
|
+
font-family: var(--ifm-font-family-monospace);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.openapi-demo__server-description {
|
|
24
|
+
padding-left: 0.5rem;
|
|
25
|
+
font-weight: var(--ifm-font-weight-bold);
|
|
26
|
+
}
|
|
@@ -58,15 +58,10 @@ function Server() {
|
|
|
58
58
|
}
|
|
59
59
|
return (
|
|
60
60
|
<FloatingButton onClick={() => setIsEditing(true)} label="Edit">
|
|
61
|
-
<FormItem
|
|
62
|
-
<
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
paddingLeft: "0px",
|
|
66
|
-
}}
|
|
67
|
-
>
|
|
68
|
-
<code title={url}>{url}</code>
|
|
69
|
-
</pre>
|
|
61
|
+
<FormItem>
|
|
62
|
+
<span className="openapi-demo__server-url" title={url}>
|
|
63
|
+
{url}
|
|
64
|
+
</span>
|
|
70
65
|
</FormItem>
|
|
71
66
|
</FloatingButton>
|
|
72
67
|
);
|
|
@@ -74,7 +69,7 @@ function Server() {
|
|
|
74
69
|
return (
|
|
75
70
|
<div className="openapi-demo__server-container">
|
|
76
71
|
<FloatingButton onClick={() => setIsEditing(false)} label="Hide">
|
|
77
|
-
<FormItem
|
|
72
|
+
<FormItem>
|
|
78
73
|
<FormSelect
|
|
79
74
|
options={options.map((s: any) => s.url)}
|
|
80
75
|
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
|
|
@@ -88,7 +83,9 @@ function Server() {
|
|
|
88
83
|
}}
|
|
89
84
|
value={value?.url}
|
|
90
85
|
/>
|
|
91
|
-
<small
|
|
86
|
+
<small className="openapi-demo__server-description">
|
|
87
|
+
{value?.description}
|
|
88
|
+
</small>
|
|
92
89
|
</FormItem>
|
|
93
90
|
{value?.variables &&
|
|
94
91
|
Object.keys(value.variables).map((key) => {
|