docusaurus-theme-openapi-docs 1.1.12 → 1.2.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/Authorization/auth-types.js +4 -0
- package/lib/theme/ApiDemoPanel/Authorization/index.js +125 -0
- package/lib/theme/ApiDemoPanel/Authorization/slice.js +1 -1
- package/lib/theme/ApiDemoPanel/Body/index.js +7 -6
- package/lib/theme/ApiDemoPanel/Execute/index.js +168 -0
- package/lib/theme/ApiDemoPanel/Execute/makeRequest.js +204 -0
- package/lib/theme/ApiDemoPanel/FormItem/index.js +7 -0
- package/lib/theme/ApiDemoPanel/FormItem/styles.module.css +5 -0
- package/lib/theme/ApiDemoPanel/ParamOptions/index.js +1 -1
- package/lib/theme/ApiDemoPanel/Request/index.js +78 -0
- package/lib/theme/ApiDemoPanel/Request/styles.module.css +17 -0
- package/lib/theme/ApiDemoPanel/Response/index.js +16 -12
- package/lib/theme/ApiDemoPanel/SecuritySchemes/index.js +24 -19
- package/lib/theme/ApiDemoPanel/Server/index.js +1 -0
- package/lib/theme/ApiDemoPanel/buildPostmanRequest.js +25 -3
- package/lib/theme/ApiDemoPanel/index.js +5 -13
- package/lib/theme/ApiDemoPanel/persistanceMiddleware.js +1 -1
- package/lib/theme/ApiDemoPanel/react-modal.d.ts +8 -0
- package/lib/theme/ApiItem/Layout/styles.module.css +56 -0
- package/lib/theme/ApiTabs/styles.module.css +9 -5
- package/lib/theme/ParamsItem/index.js +5 -1
- package/lib/theme/SchemaTabs/styles.module.css +10 -6
- package/lib-next/theme/ApiDemoPanel/Authorization/auth-types.js +4 -0
- package/lib-next/theme/ApiDemoPanel/Authorization/index.js +149 -0
- package/lib-next/theme/ApiDemoPanel/Authorization/slice.js +1 -1
- package/lib-next/theme/ApiDemoPanel/Body/index.js +28 -6
- package/lib-next/theme/ApiDemoPanel/Execute/index.js +170 -0
- package/lib-next/theme/ApiDemoPanel/Execute/makeRequest.js +190 -0
- package/lib-next/theme/ApiDemoPanel/FormItem/index.js +9 -1
- package/lib-next/theme/ApiDemoPanel/FormItem/styles.module.css +5 -0
- package/lib-next/theme/ApiDemoPanel/ParamOptions/index.js +1 -1
- package/lib-next/theme/ApiDemoPanel/Request/index.js +60 -0
- package/lib-next/theme/ApiDemoPanel/Request/styles.module.css +17 -0
- package/lib-next/theme/ApiDemoPanel/Response/index.js +18 -13
- package/lib-next/theme/ApiDemoPanel/SecuritySchemes/index.js +22 -20
- package/lib-next/theme/ApiDemoPanel/Server/index.js +1 -0
- package/lib-next/theme/ApiDemoPanel/buildPostmanRequest.js +25 -3
- package/lib-next/theme/ApiDemoPanel/index.js +4 -13
- package/lib-next/theme/ApiDemoPanel/persistanceMiddleware.js +1 -1
- package/lib-next/theme/ApiDemoPanel/react-modal.d.ts +8 -0
- package/lib-next/theme/ApiItem/Layout/styles.module.css +56 -0
- package/lib-next/theme/ApiTabs/styles.module.css +9 -5
- package/lib-next/theme/ParamsItem/index.js +5 -1
- package/lib-next/theme/SchemaTabs/styles.module.css +10 -6
- package/package.json +5 -4
- package/src/theme/ApiDemoPanel/Authorization/auth-types.ts +4 -0
- package/src/theme/ApiDemoPanel/Authorization/index.tsx +154 -0
- package/src/theme/ApiDemoPanel/Authorization/slice.ts +1 -1
- package/src/theme/ApiDemoPanel/Body/index.tsx +28 -6
- package/src/theme/ApiDemoPanel/Execute/index.tsx +188 -0
- package/src/theme/ApiDemoPanel/Execute/makeRequest.ts +197 -0
- package/src/theme/ApiDemoPanel/FormItem/index.tsx +11 -2
- package/src/theme/ApiDemoPanel/FormItem/styles.module.css +5 -0
- package/src/theme/ApiDemoPanel/ParamOptions/index.tsx +1 -1
- package/src/theme/ApiDemoPanel/Request/index.tsx +71 -0
- package/src/theme/ApiDemoPanel/Request/styles.module.css +17 -0
- package/src/theme/ApiDemoPanel/Response/index.tsx +19 -13
- package/src/theme/ApiDemoPanel/SecuritySchemes/index.tsx +22 -17
- package/src/theme/ApiDemoPanel/Server/index.tsx +1 -0
- package/src/theme/ApiDemoPanel/buildPostmanRequest.ts +22 -3
- package/src/theme/ApiDemoPanel/index.tsx +4 -13
- package/src/theme/ApiDemoPanel/persistanceMiddleware.ts +1 -1
- package/src/theme/ApiDemoPanel/react-modal.d.ts +8 -0
- package/src/theme/ApiItem/Layout/styles.module.css +56 -0
- package/src/theme/ApiTabs/styles.module.css +9 -5
- package/src/theme/ParamsItem/index.js +5 -1
- package/src/theme/SchemaTabs/styles.module.css +10 -6
|
@@ -15,60 +15,62 @@ function SecuritySchemes(props) {
|
|
|
15
15
|
if (selected === undefined) return null;
|
|
16
16
|
const selectedAuth = options[selected];
|
|
17
17
|
return (
|
|
18
|
-
<
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
>
|
|
18
|
+
<details className={`details__demo-panel`} open={false}>
|
|
19
|
+
<summary className={`details__request-summary`}>
|
|
20
|
+
<h4>Authorization</h4>
|
|
21
|
+
</summary>
|
|
23
22
|
{selectedAuth.map((auth) => {
|
|
24
23
|
const isApiKey = auth.type === "apiKey";
|
|
25
24
|
const isBearer = auth.type === "http" && auth.key === "Bearer";
|
|
26
|
-
const
|
|
27
|
-
auth.type === "oauth2" && auth.key === "ClientCredentials";
|
|
25
|
+
const isOauth2 = auth.type === "oauth2";
|
|
28
26
|
|
|
29
27
|
if (isApiKey || isBearer) {
|
|
30
28
|
return (
|
|
31
|
-
<React.Fragment key={
|
|
32
|
-
<b>
|
|
33
|
-
Authorization: <Link to={infoAuthPath}>{auth.key}</Link>
|
|
34
|
-
</b>
|
|
29
|
+
<React.Fragment key={auth.key}>
|
|
35
30
|
<pre
|
|
36
31
|
style={{
|
|
37
32
|
display: "flex",
|
|
38
33
|
flexDirection: "column",
|
|
39
34
|
background: "var(--openapi-card-background-color)",
|
|
40
|
-
borderRadius: "var(--openapi-card-border-radius)",
|
|
41
35
|
}}
|
|
42
36
|
>
|
|
43
|
-
<span>name: {auth.name}</span>
|
|
44
|
-
<span>in: {auth.in}</span>
|
|
45
37
|
<span>type: {auth.type}</span>
|
|
38
|
+
<span>
|
|
39
|
+
name: <Link to={infoAuthPath}>{auth.name}</Link>
|
|
40
|
+
</span>
|
|
41
|
+
<span>in: {auth.in}</span>
|
|
46
42
|
</pre>
|
|
47
43
|
</React.Fragment>
|
|
48
44
|
);
|
|
49
45
|
}
|
|
50
46
|
|
|
51
|
-
if (
|
|
47
|
+
if (isOauth2) {
|
|
52
48
|
return (
|
|
53
49
|
<React.Fragment key={selected}>
|
|
54
|
-
<b>Authorization: {auth.key}</b>
|
|
55
50
|
<pre
|
|
56
51
|
style={{
|
|
57
52
|
display: "flex",
|
|
58
53
|
flexDirection: "column",
|
|
59
54
|
background: "var(--openapi-card-background-color)",
|
|
60
|
-
borderRadius: "var(--openapi-card-border-radius)",
|
|
61
55
|
}}
|
|
62
56
|
>
|
|
63
|
-
<span>
|
|
57
|
+
<span>
|
|
58
|
+
type: <Link to={infoAuthPath}>{auth.type}</Link>
|
|
59
|
+
</span>
|
|
60
|
+
{Object.keys(auth.flows).map((flow) => {
|
|
61
|
+
return <span key={flow}>flow: {flow}</span>;
|
|
62
|
+
})}
|
|
63
|
+
<span>
|
|
64
|
+
scopes: <code>{auth.scopes.toString()}</code>
|
|
65
|
+
</span>
|
|
64
66
|
</pre>
|
|
65
67
|
</React.Fragment>
|
|
66
68
|
);
|
|
67
69
|
}
|
|
68
70
|
|
|
69
|
-
return
|
|
71
|
+
return undefined;
|
|
70
72
|
})}
|
|
71
|
-
</
|
|
73
|
+
</details>
|
|
72
74
|
);
|
|
73
75
|
}
|
|
74
76
|
|
|
@@ -258,6 +258,28 @@ function buildPostmanRequest(
|
|
|
258
258
|
continue;
|
|
259
259
|
}
|
|
260
260
|
|
|
261
|
+
otherHeaders.push({
|
|
262
|
+
key: "Authorization",
|
|
263
|
+
value: `Bearer ${token}`,
|
|
264
|
+
});
|
|
265
|
+
continue;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
if (a.type === "oauth2") {
|
|
269
|
+
let token;
|
|
270
|
+
|
|
271
|
+
if (auth.data[a.key]) {
|
|
272
|
+
token = auth.data[a.key].token;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
if (token === undefined) {
|
|
276
|
+
otherHeaders.push({
|
|
277
|
+
key: "Authorization",
|
|
278
|
+
value: "Bearer <TOKEN>",
|
|
279
|
+
});
|
|
280
|
+
continue;
|
|
281
|
+
}
|
|
282
|
+
|
|
261
283
|
otherHeaders.push({
|
|
262
284
|
key: "Authorization",
|
|
263
285
|
value: `Bearer ${token}`,
|
|
@@ -280,9 +302,9 @@ function buildPostmanRequest(
|
|
|
280
302
|
} // API Key
|
|
281
303
|
|
|
282
304
|
if (a.type === "apiKey" && a.in === "header") {
|
|
283
|
-
const {
|
|
305
|
+
const { apiKey } = auth.data[a.key];
|
|
284
306
|
|
|
285
|
-
if (
|
|
307
|
+
if (apiKey === undefined) {
|
|
286
308
|
otherHeaders.push({
|
|
287
309
|
key: a.name,
|
|
288
310
|
value: "<API_KEY_VALUE>",
|
|
@@ -292,7 +314,7 @@ function buildPostmanRequest(
|
|
|
292
314
|
|
|
293
315
|
otherHeaders.push({
|
|
294
316
|
key: a.name,
|
|
295
|
-
value:
|
|
317
|
+
value: apiKey,
|
|
296
318
|
});
|
|
297
319
|
continue;
|
|
298
320
|
}
|
|
@@ -8,13 +8,11 @@ import React from "react";
|
|
|
8
8
|
import useDocusaurusContext from "@docusaurus/useDocusaurusContext";
|
|
9
9
|
import sdk from "@paloaltonetworks/postman-collection";
|
|
10
10
|
import { Provider } from "react-redux";
|
|
11
|
-
import Accept from "./Accept";
|
|
12
11
|
import { createAuth } from "./Authorization/slice";
|
|
13
|
-
import Body from "./Body";
|
|
14
12
|
import Curl from "./Curl";
|
|
15
13
|
import MethodEndpoint from "./MethodEndpoint";
|
|
16
|
-
import ParamOptions from "./ParamOptions";
|
|
17
14
|
import { createPersistanceMiddleware } from "./persistanceMiddleware";
|
|
15
|
+
import Request from "./Request";
|
|
18
16
|
import Response from "./Response";
|
|
19
17
|
import SecuritySchemes from "./SecuritySchemes";
|
|
20
18
|
import Server from "./Server";
|
|
@@ -83,18 +81,11 @@ function ApiDemoPanel({ item, infoPath }) {
|
|
|
83
81
|
<Provider store={store2}>
|
|
84
82
|
<div className={styles.apiDemoPanelContainer}>
|
|
85
83
|
<MethodEndpoint method={method} path={path} />
|
|
86
|
-
<SecuritySchemes infoPath={infoPath} />
|
|
87
|
-
<div className={styles.optionsPanel}>
|
|
88
|
-
<ParamOptions />
|
|
89
|
-
<Body
|
|
90
|
-
jsonRequestBodyExample={item.jsonRequestBodyExample}
|
|
91
|
-
requestBodyMetadata={item.requestBody}
|
|
92
|
-
/>
|
|
93
|
-
<Accept />
|
|
94
|
-
</div>
|
|
95
84
|
<Server />
|
|
96
|
-
<
|
|
85
|
+
<SecuritySchemes infoPath={infoPath} />
|
|
86
|
+
<Request item={item} />
|
|
97
87
|
<Response />
|
|
88
|
+
<Curl postman={postman} codeSamples={item["x-code-samples"] ?? []} />
|
|
98
89
|
</div>
|
|
99
90
|
</Provider>
|
|
100
91
|
);
|
|
@@ -10,7 +10,7 @@ export function createPersistanceMiddleware(options) {
|
|
|
10
10
|
const persistanceMiddleware = (storeAPI) => (next) => (action) => {
|
|
11
11
|
const result = next(action);
|
|
12
12
|
const state = storeAPI.getState();
|
|
13
|
-
const storage = createStorage(
|
|
13
|
+
const storage = createStorage("sessionStorage");
|
|
14
14
|
|
|
15
15
|
if (action.type === setAuthData.type) {
|
|
16
16
|
for (const [key, value] of Object.entries(state.auth.data)) {
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/* ============================================================================
|
|
2
|
+
* Copyright (c) Palo Alto Networks
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
* ========================================================================== */
|
|
7
|
+
|
|
8
|
+
declare module "react-modal";
|
|
@@ -71,6 +71,62 @@
|
|
|
71
71
|
border-top: unset !important;
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
+
:global(.theme-api-markdown .details__demo-panel) {
|
|
75
|
+
margin-bottom: 1rem;
|
|
76
|
+
background: var(--openapi-card-background-color);
|
|
77
|
+
border-radius: var(--openapi-card-border-radius);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
:global(.theme-api-markdown .details__demo-panel > summary) {
|
|
81
|
+
padding-left: 1rem;
|
|
82
|
+
padding-top: 1rem;
|
|
83
|
+
cursor: pointer;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
:global(.theme-api-markdown .details__demo-panel > div > div > pre) {
|
|
87
|
+
border-top-left-radius: 0;
|
|
88
|
+
border-top-right-radius: 0;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
:global(.theme-api-markdown .details__demo-panel > summary::marker) {
|
|
92
|
+
display: none;
|
|
93
|
+
content: "";
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
:global(.theme-api-markdown
|
|
97
|
+
.details__demo-panel
|
|
98
|
+
> summary::-webkit-details-marker) {
|
|
99
|
+
display: none;
|
|
100
|
+
content: "";
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
:global(.theme-api-markdown .details__demo-panel > pre) {
|
|
104
|
+
margin-bottom: 0;
|
|
105
|
+
padding-top: 0;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
:global(.theme-api-markdown .details__request-summary) {
|
|
109
|
+
display: flex;
|
|
110
|
+
justify-content: space-between;
|
|
111
|
+
align-items: center;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
:global(.theme-api-markdown .details__request-summary > button) {
|
|
115
|
+
margin-bottom: 1rem;
|
|
116
|
+
margin-right: 1rem;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
:global(.theme-api-markdown .details__response-summary) {
|
|
120
|
+
display: flex;
|
|
121
|
+
justify-content: space-between;
|
|
122
|
+
align-items: center;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
:global(.theme-api-markdown .details__response-summary > button) {
|
|
126
|
+
margin-bottom: 1rem;
|
|
127
|
+
margin-right: 1rem;
|
|
128
|
+
}
|
|
129
|
+
|
|
74
130
|
:global(.theme-api-markdown code) {
|
|
75
131
|
max-width: 600px;
|
|
76
132
|
max-height: 500px;
|
|
@@ -12,14 +12,19 @@
|
|
|
12
12
|
height: 2.5rem;
|
|
13
13
|
margin-top: 0 !important;
|
|
14
14
|
margin-right: 0.5rem;
|
|
15
|
-
border: 1px solid var(--
|
|
15
|
+
border: 1px solid var(--ifm-color-primary);
|
|
16
16
|
border-radius: var(--ifm-global-radius);
|
|
17
|
+
color: var(--ifm-color-primary);
|
|
17
18
|
font-weight: var(--ifm-font-weight-normal);
|
|
18
|
-
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.tabItem:not(.responseTabActive) {
|
|
22
|
+
opacity: 0.65;
|
|
19
23
|
}
|
|
20
24
|
|
|
21
25
|
.tabItem:hover {
|
|
22
|
-
|
|
26
|
+
opacity: 1;
|
|
27
|
+
background-color: var(--ifm-color-emphasis-100);
|
|
23
28
|
}
|
|
24
29
|
|
|
25
30
|
.tabItem:last-child {
|
|
@@ -74,8 +79,7 @@
|
|
|
74
79
|
}
|
|
75
80
|
|
|
76
81
|
.responseTabActive {
|
|
77
|
-
|
|
78
|
-
color: var(--ifm-color-primary);
|
|
82
|
+
background-color: var(--ifm-color-emphasis-100);
|
|
79
83
|
}
|
|
80
84
|
|
|
81
85
|
.responseSchemaContainer {
|
|
@@ -53,7 +53,11 @@ function ParamsItem({
|
|
|
53
53
|
));
|
|
54
54
|
|
|
55
55
|
const renderDefaultValue = guard(
|
|
56
|
-
schema
|
|
56
|
+
schema && schema.items
|
|
57
|
+
? schema.items.default
|
|
58
|
+
: schema
|
|
59
|
+
? schema.default
|
|
60
|
+
: undefined,
|
|
57
61
|
(value) => (
|
|
58
62
|
<div>
|
|
59
63
|
<ReactMarkdown children={`**Default value:** \`${value}\``} />
|
|
@@ -12,14 +12,19 @@
|
|
|
12
12
|
height: 1.8rem;
|
|
13
13
|
margin-top: 0 !important;
|
|
14
14
|
margin-right: 0.5rem;
|
|
15
|
-
border: 1px solid var(--
|
|
15
|
+
border: 1px solid var(--ifm-color-primary);
|
|
16
16
|
border-radius: var(--ifm-global-radius);
|
|
17
|
-
color: var(--
|
|
17
|
+
color: var(--ifm-color-primary);
|
|
18
18
|
font-size: 12px;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
.tabItem:not(.schemaTabActive) {
|
|
22
|
+
opacity: 0.65;
|
|
23
|
+
}
|
|
24
|
+
|
|
21
25
|
.tabItem:hover {
|
|
22
|
-
|
|
26
|
+
opacity: 1;
|
|
27
|
+
background-color: var(--ifm-color-emphasis-100);
|
|
23
28
|
}
|
|
24
29
|
|
|
25
30
|
.tabItem:last-child {
|
|
@@ -49,9 +54,8 @@
|
|
|
49
54
|
display: none;
|
|
50
55
|
}
|
|
51
56
|
|
|
52
|
-
.
|
|
53
|
-
|
|
54
|
-
color: var(--ifm-color-primary);
|
|
57
|
+
.schemaTabActive {
|
|
58
|
+
background-color: var(--ifm-color-emphasis-100);
|
|
55
59
|
}
|
|
56
60
|
|
|
57
61
|
.schemaTabLabel {
|
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.1
|
|
4
|
+
"version": "1.2.1",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"openapi",
|
|
@@ -44,19 +44,20 @@
|
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@docusaurus/theme-common": "^2.0.1",
|
|
46
46
|
"@mdx-js/react": "^1.6.21",
|
|
47
|
-
"@paloaltonetworks/postman-code-generators": "^1.1.
|
|
47
|
+
"@paloaltonetworks/postman-code-generators": "^1.1.12",
|
|
48
48
|
"@paloaltonetworks/postman-collection": "^4.1.0",
|
|
49
49
|
"@reduxjs/toolkit": "^1.7.1",
|
|
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.2.0",
|
|
54
54
|
"immer": "^9.0.7",
|
|
55
55
|
"lodash": "^4.17.20",
|
|
56
56
|
"process": "^0.11.10",
|
|
57
57
|
"react-live": "^3.1.1",
|
|
58
58
|
"react-magic-dropzone": "^1.0.1",
|
|
59
59
|
"react-markdown": "^8.0.1",
|
|
60
|
+
"react-modal": "^3.15.1",
|
|
60
61
|
"react-redux": "^7.2.0",
|
|
61
62
|
"redux-devtools-extension": "^2.13.8",
|
|
62
63
|
"webpack": "^5.61.0",
|
|
@@ -69,5 +70,5 @@
|
|
|
69
70
|
"engines": {
|
|
70
71
|
"node": ">=14"
|
|
71
72
|
},
|
|
72
|
-
"gitHead": "
|
|
73
|
+
"gitHead": "1d2b03eae750d2092994620b4695699910f40841"
|
|
73
74
|
}
|
|
@@ -11,6 +11,10 @@ export function getAuthDataKeys(security: { [key: string]: any }) {
|
|
|
11
11
|
return ["token"];
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
if (security.type === "oauth2") {
|
|
15
|
+
return ["token"];
|
|
16
|
+
}
|
|
17
|
+
|
|
14
18
|
// Basic Auth
|
|
15
19
|
if (security.type === "http" && security.scheme === "basic") {
|
|
16
20
|
return ["username", "password"];
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/* ============================================================================
|
|
2
|
+
* Copyright (c) Palo Alto Networks
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
* ========================================================================== */
|
|
7
|
+
|
|
8
|
+
import React from "react";
|
|
9
|
+
|
|
10
|
+
import FormItem from "../FormItem";
|
|
11
|
+
import FormSelect from "../FormSelect";
|
|
12
|
+
import FormTextInput from "../FormTextInput";
|
|
13
|
+
import { useTypedDispatch, useTypedSelector } from "../hooks";
|
|
14
|
+
import { setAuthData, setSelectedAuth } from "./slice";
|
|
15
|
+
|
|
16
|
+
function Authorization() {
|
|
17
|
+
const data = useTypedSelector((state) => state.auth.data);
|
|
18
|
+
const options = useTypedSelector((state) => state.auth.options);
|
|
19
|
+
const selected = useTypedSelector((state) => state.auth.selected);
|
|
20
|
+
|
|
21
|
+
const dispatch = useTypedDispatch();
|
|
22
|
+
|
|
23
|
+
if (selected === undefined) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const selectedAuth = options[selected];
|
|
28
|
+
|
|
29
|
+
const optionKeys = Object.keys(options);
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<div>
|
|
33
|
+
{optionKeys.length > 1 && (
|
|
34
|
+
<FormItem label="Security Scheme">
|
|
35
|
+
<FormSelect
|
|
36
|
+
options={optionKeys}
|
|
37
|
+
value={selected}
|
|
38
|
+
onChange={(e) => {
|
|
39
|
+
dispatch(setSelectedAuth(e.target.value));
|
|
40
|
+
}}
|
|
41
|
+
/>
|
|
42
|
+
</FormItem>
|
|
43
|
+
)}
|
|
44
|
+
{selectedAuth.map((a) => {
|
|
45
|
+
if (a.type === "http" && a.scheme === "bearer") {
|
|
46
|
+
return (
|
|
47
|
+
<FormItem label="Bearer Token" key={a.key + "-bearer"}>
|
|
48
|
+
<FormTextInput
|
|
49
|
+
placeholder="Bearer Token"
|
|
50
|
+
value={data[a.key].token ?? ""}
|
|
51
|
+
onChange={(e) => {
|
|
52
|
+
const value = e.target.value.trim();
|
|
53
|
+
dispatch(
|
|
54
|
+
setAuthData({
|
|
55
|
+
scheme: a.key,
|
|
56
|
+
key: "token",
|
|
57
|
+
value: value ? value : undefined,
|
|
58
|
+
})
|
|
59
|
+
);
|
|
60
|
+
}}
|
|
61
|
+
/>
|
|
62
|
+
</FormItem>
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (a.type === "oauth2") {
|
|
67
|
+
return (
|
|
68
|
+
<FormItem label="Bearer Token" key={a.key + "-oauth2"}>
|
|
69
|
+
<FormTextInput
|
|
70
|
+
placeholder="Bearer Token"
|
|
71
|
+
value={data[a.key].token ?? ""}
|
|
72
|
+
onChange={(e) => {
|
|
73
|
+
const value = e.target.value.trim();
|
|
74
|
+
dispatch(
|
|
75
|
+
setAuthData({
|
|
76
|
+
scheme: a.key,
|
|
77
|
+
key: "token",
|
|
78
|
+
value: value ? value : undefined,
|
|
79
|
+
})
|
|
80
|
+
);
|
|
81
|
+
}}
|
|
82
|
+
/>
|
|
83
|
+
</FormItem>
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (a.type === "http" && a.scheme === "basic") {
|
|
88
|
+
return (
|
|
89
|
+
<React.Fragment key={a.key + "-basic"}>
|
|
90
|
+
<FormItem label="Username">
|
|
91
|
+
<FormTextInput
|
|
92
|
+
placeholder="Username"
|
|
93
|
+
value={data[a.key].username ?? ""}
|
|
94
|
+
onChange={(e) => {
|
|
95
|
+
const value = e.target.value.trim();
|
|
96
|
+
dispatch(
|
|
97
|
+
setAuthData({
|
|
98
|
+
scheme: a.key,
|
|
99
|
+
key: "username",
|
|
100
|
+
value: value ? value : undefined,
|
|
101
|
+
})
|
|
102
|
+
);
|
|
103
|
+
}}
|
|
104
|
+
/>
|
|
105
|
+
</FormItem>
|
|
106
|
+
<FormItem label="Password">
|
|
107
|
+
<FormTextInput
|
|
108
|
+
placeholder="Password"
|
|
109
|
+
password
|
|
110
|
+
value={data[a.key].password ?? ""}
|
|
111
|
+
onChange={(e) => {
|
|
112
|
+
const value = e.target.value.trim();
|
|
113
|
+
dispatch(
|
|
114
|
+
setAuthData({
|
|
115
|
+
scheme: a.key,
|
|
116
|
+
key: "password",
|
|
117
|
+
value: value ? value : undefined,
|
|
118
|
+
})
|
|
119
|
+
);
|
|
120
|
+
}}
|
|
121
|
+
/>
|
|
122
|
+
</FormItem>
|
|
123
|
+
</React.Fragment>
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (a.type === "apiKey") {
|
|
128
|
+
return (
|
|
129
|
+
<FormItem label={`${a.key}`} key={a.key + "-apikey"}>
|
|
130
|
+
<FormTextInput
|
|
131
|
+
placeholder={`${a.key}`}
|
|
132
|
+
value={data[a.key].apiKey ?? ""}
|
|
133
|
+
onChange={(e) => {
|
|
134
|
+
const value = e.target.value.trim();
|
|
135
|
+
dispatch(
|
|
136
|
+
setAuthData({
|
|
137
|
+
scheme: a.key,
|
|
138
|
+
key: "apiKey",
|
|
139
|
+
value: value ? value : undefined,
|
|
140
|
+
})
|
|
141
|
+
);
|
|
142
|
+
}}
|
|
143
|
+
/>
|
|
144
|
+
</FormItem>
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return null;
|
|
149
|
+
})}
|
|
150
|
+
</div>
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export default Authorization;
|
|
@@ -57,7 +57,7 @@ export function createAuth({
|
|
|
57
57
|
};
|
|
58
58
|
options?: ThemeConfig["api"];
|
|
59
59
|
}): AuthState {
|
|
60
|
-
const storage = createStorage(
|
|
60
|
+
const storage = createStorage("sessionStorage");
|
|
61
61
|
|
|
62
62
|
let data: AuthState["data"] = {};
|
|
63
63
|
let options: AuthState["options"] = {};
|
|
@@ -56,6 +56,7 @@ function BodyWrap({ requestBodyMetadata, jsonRequestBodyExample }: Props) {
|
|
|
56
56
|
|
|
57
57
|
function Body({ requestBodyMetadata, jsonRequestBodyExample }: Props) {
|
|
58
58
|
const contentType = useTypedSelector((state) => state.contentType.value);
|
|
59
|
+
const required = requestBodyMetadata?.required;
|
|
59
60
|
|
|
60
61
|
const dispatch = useTypedDispatch();
|
|
61
62
|
|
|
@@ -84,7 +85,7 @@ function Body({ requestBodyMetadata, jsonRequestBodyExample }: Props) {
|
|
|
84
85
|
|
|
85
86
|
if (schema?.format === "binary") {
|
|
86
87
|
return (
|
|
87
|
-
<FormItem label="Body">
|
|
88
|
+
<FormItem label="Body" required={required}>
|
|
88
89
|
<FormFileUpload
|
|
89
90
|
placeholder={schema.description || "Body"}
|
|
90
91
|
onChange={(file) => {
|
|
@@ -110,7 +111,7 @@ function Body({ requestBodyMetadata, jsonRequestBodyExample }: Props) {
|
|
|
110
111
|
schema?.type === "object"
|
|
111
112
|
) {
|
|
112
113
|
return (
|
|
113
|
-
<FormItem label="Body">
|
|
114
|
+
<FormItem label="Body" required={required}>
|
|
114
115
|
<div
|
|
115
116
|
style={{
|
|
116
117
|
marginTop: "calc(var(--ifm-pre-padding) / 2)",
|
|
@@ -122,7 +123,14 @@ function Body({ requestBodyMetadata, jsonRequestBodyExample }: Props) {
|
|
|
122
123
|
{Object.entries(schema.properties ?? {}).map(([key, val]: any) => {
|
|
123
124
|
if (val.format === "binary") {
|
|
124
125
|
return (
|
|
125
|
-
<FormItem
|
|
126
|
+
<FormItem
|
|
127
|
+
key={key}
|
|
128
|
+
label={key}
|
|
129
|
+
required={
|
|
130
|
+
Array.isArray(schema.required) &&
|
|
131
|
+
schema.required.includes(key)
|
|
132
|
+
}
|
|
133
|
+
>
|
|
126
134
|
<FormFileUpload
|
|
127
135
|
placeholder={val.description || key}
|
|
128
136
|
onChange={(file) => {
|
|
@@ -147,7 +155,14 @@ function Body({ requestBodyMetadata, jsonRequestBodyExample }: Props) {
|
|
|
147
155
|
|
|
148
156
|
if (val.enum) {
|
|
149
157
|
return (
|
|
150
|
-
<FormItem
|
|
158
|
+
<FormItem
|
|
159
|
+
key={key}
|
|
160
|
+
label={key}
|
|
161
|
+
required={
|
|
162
|
+
Array.isArray(schema.required) &&
|
|
163
|
+
schema.required.includes(key)
|
|
164
|
+
}
|
|
165
|
+
>
|
|
151
166
|
<FormSelect
|
|
152
167
|
options={["---", ...val.enum]}
|
|
153
168
|
onChange={(e) => {
|
|
@@ -169,7 +184,14 @@ function Body({ requestBodyMetadata, jsonRequestBodyExample }: Props) {
|
|
|
169
184
|
}
|
|
170
185
|
// TODO: support all the other types.
|
|
171
186
|
return (
|
|
172
|
-
<FormItem
|
|
187
|
+
<FormItem
|
|
188
|
+
key={key}
|
|
189
|
+
label={key}
|
|
190
|
+
required={
|
|
191
|
+
Array.isArray(schema.required) &&
|
|
192
|
+
schema.required.includes(key)
|
|
193
|
+
}
|
|
194
|
+
>
|
|
173
195
|
<FormTextInput
|
|
174
196
|
placeholder={val.description || key}
|
|
175
197
|
onChange={(e) => {
|
|
@@ -212,7 +234,7 @@ function Body({ requestBodyMetadata, jsonRequestBodyExample }: Props) {
|
|
|
212
234
|
}
|
|
213
235
|
|
|
214
236
|
return (
|
|
215
|
-
<FormItem label="Body">
|
|
237
|
+
<FormItem label="Body" required={required}>
|
|
216
238
|
<LiveApp action={dispatch} language={language}>
|
|
217
239
|
{exampleBodyString}
|
|
218
240
|
</LiveApp>
|