docusaurus-theme-openapi-docs 1.1.12 → 1.2.0
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/ParamsItem/index.js +5 -1
- 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/ParamsItem/index.js +5 -1
- 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/ParamsItem/index.js +5 -1
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
|
|
10
|
+
var _useDocusaurusContext = _interopRequireDefault(require("@docusaurus/useDocusaurusContext"));
|
|
11
|
+
|
|
12
|
+
var _postmanCollection = _interopRequireDefault(require("@paloaltonetworks/postman-collection"));
|
|
13
|
+
|
|
14
|
+
var _Accept = _interopRequireDefault(require("../Accept"));
|
|
15
|
+
|
|
16
|
+
var _Authorization = _interopRequireDefault(require("../Authorization"));
|
|
17
|
+
|
|
18
|
+
var _Body = _interopRequireDefault(require("../Body"));
|
|
19
|
+
|
|
20
|
+
var _Execute = _interopRequireDefault(require("../Execute"));
|
|
21
|
+
|
|
22
|
+
var _hooks = require("../hooks");
|
|
23
|
+
|
|
24
|
+
var _ParamOptions = _interopRequireDefault(require("../ParamOptions"));
|
|
25
|
+
|
|
26
|
+
var _stylesModule = _interopRequireDefault(require("./styles.module.css"));
|
|
27
|
+
|
|
28
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
29
|
+
|
|
30
|
+
/* ============================================================================
|
|
31
|
+
* Copyright (c) Palo Alto Networks
|
|
32
|
+
*
|
|
33
|
+
* This source code is licensed under the MIT license found in the
|
|
34
|
+
* LICENSE file in the root directory of this source tree.
|
|
35
|
+
* ========================================================================== */
|
|
36
|
+
function Request({
|
|
37
|
+
item
|
|
38
|
+
}) {
|
|
39
|
+
var _item$parameters;
|
|
40
|
+
|
|
41
|
+
const response = (0, _hooks.useTypedSelector)(state => state.response.value);
|
|
42
|
+
const {
|
|
43
|
+
siteConfig
|
|
44
|
+
} = (0, _useDocusaurusContext.default)();
|
|
45
|
+
const themeConfig = siteConfig.themeConfig;
|
|
46
|
+
const options = themeConfig.api;
|
|
47
|
+
const postman = new _postmanCollection.default.Request(item.postman);
|
|
48
|
+
const params = {
|
|
49
|
+
path: [],
|
|
50
|
+
query: [],
|
|
51
|
+
header: [],
|
|
52
|
+
cookie: []
|
|
53
|
+
};
|
|
54
|
+
(_item$parameters = item.parameters) === null || _item$parameters === void 0 ? void 0 : _item$parameters.forEach(param => {
|
|
55
|
+
const paramType = param.in;
|
|
56
|
+
const paramsArray = params[paramType];
|
|
57
|
+
paramsArray.push(param);
|
|
58
|
+
});
|
|
59
|
+
return <div>
|
|
60
|
+
<details className={`details__demo-panel`} open={response ? false : true}>
|
|
61
|
+
<summary>
|
|
62
|
+
<div className={`details__request-summary`}>
|
|
63
|
+
<h4>Request</h4>
|
|
64
|
+
{item.servers && <_Execute.default postman={postman} proxy={options === null || options === void 0 ? void 0 : options.proxy} />}
|
|
65
|
+
</div>
|
|
66
|
+
</summary>
|
|
67
|
+
<div className={_stylesModule.default.optionsPanel}>
|
|
68
|
+
<_Authorization.default />
|
|
69
|
+
<_ParamOptions.default />
|
|
70
|
+
<_Body.default jsonRequestBodyExample={item.jsonRequestBodyExample} requestBodyMetadata={item.requestBody} />
|
|
71
|
+
<_Accept.default />
|
|
72
|
+
</div>
|
|
73
|
+
</details>
|
|
74
|
+
</div>;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
var _default = Request;
|
|
78
|
+
exports.default = _default;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
.optionsPanel:empty {
|
|
2
|
+
display: none;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
.optionsPanel {
|
|
6
|
+
background: var(--openapi-card-background-color);
|
|
7
|
+
border-radius: var(--openapi-card-border-radius);
|
|
8
|
+
color: var(--ifm-pre-color);
|
|
9
|
+
line-height: var(--ifm-pre-line-height);
|
|
10
|
+
margin-bottom: var(--ifm-spacing-vertical);
|
|
11
|
+
margin-top: 0;
|
|
12
|
+
overflow: auto;
|
|
13
|
+
padding: var(--ifm-pre-padding);
|
|
14
|
+
|
|
15
|
+
/* hack for view calculation when monaco is hidden */
|
|
16
|
+
position: relative;
|
|
17
|
+
}
|
|
@@ -7,9 +7,9 @@ exports.default = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _react = _interopRequireDefault(require("react"));
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _CodeBlock = _interopRequireDefault(require("@theme/CodeBlock"));
|
|
11
11
|
|
|
12
|
-
var
|
|
12
|
+
var _hooks = require("../hooks");
|
|
13
13
|
|
|
14
14
|
var _slice = require("./slice");
|
|
15
15
|
|
|
@@ -55,20 +55,24 @@ function Response() {
|
|
|
55
55
|
try {
|
|
56
56
|
prettyResponse = JSON.stringify(JSON.parse(response), null, 2);
|
|
57
57
|
} catch {
|
|
58
|
-
if (response.startsWith("
|
|
58
|
+
if (response.startsWith("<")) {
|
|
59
59
|
prettyResponse = formatXml(response);
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
return <
|
|
64
|
-
<
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
63
|
+
return <details className={`details__demo-panel`} open={true}>
|
|
64
|
+
<summary>
|
|
65
|
+
<div className={`details__response-summary`}>
|
|
66
|
+
<h4>Response</h4>
|
|
67
|
+
<button className="button button--sm button--secondary" onClick={() => dispatch((0, _slice.clearResponse)())}>
|
|
68
|
+
Clear
|
|
69
|
+
</button>
|
|
70
|
+
</div>
|
|
71
|
+
</summary>
|
|
72
|
+
<_CodeBlock.default language={response.startsWith("<") ? `xml` : `json`}>
|
|
73
|
+
{prettyResponse || "No Response"}
|
|
74
|
+
</_CodeBlock.default>
|
|
75
|
+
</details>;
|
|
72
76
|
}
|
|
73
77
|
|
|
74
78
|
var _default = Response;
|
|
@@ -25,49 +25,54 @@ function SecuritySchemes(props) {
|
|
|
25
25
|
const infoAuthPath = `/${props.infoPath}#authentication`;
|
|
26
26
|
if (selected === undefined) return null;
|
|
27
27
|
const selectedAuth = options[selected];
|
|
28
|
-
return <
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
return <details className={`details__demo-panel`} open={false}>
|
|
29
|
+
<summary className={`details__request-summary`}>
|
|
30
|
+
<h4>Authorization</h4>
|
|
31
|
+
</summary>
|
|
31
32
|
{selectedAuth.map(auth => {
|
|
32
33
|
const isApiKey = auth.type === "apiKey";
|
|
33
34
|
const isBearer = auth.type === "http" && auth.key === "Bearer";
|
|
34
|
-
const
|
|
35
|
+
const isOauth2 = auth.type === "oauth2";
|
|
35
36
|
|
|
36
37
|
if (isApiKey || isBearer) {
|
|
37
|
-
return <_react.default.Fragment key={
|
|
38
|
-
<b>
|
|
39
|
-
Authorization: <_Link.default to={infoAuthPath}>{auth.key}</_Link.default>
|
|
40
|
-
</b>
|
|
38
|
+
return <_react.default.Fragment key={auth.key}>
|
|
41
39
|
<pre style={{
|
|
42
40
|
display: "flex",
|
|
43
41
|
flexDirection: "column",
|
|
44
|
-
background: "var(--openapi-card-background-color)"
|
|
45
|
-
borderRadius: "var(--openapi-card-border-radius)"
|
|
42
|
+
background: "var(--openapi-card-background-color)"
|
|
46
43
|
}}>
|
|
47
|
-
<span>name: {auth.name}</span>
|
|
48
|
-
<span>in: {auth.in}</span>
|
|
49
44
|
<span>type: {auth.type}</span>
|
|
45
|
+
<span>
|
|
46
|
+
name: <_Link.default to={infoAuthPath}>{auth.name}</_Link.default>
|
|
47
|
+
</span>
|
|
48
|
+
<span>in: {auth.in}</span>
|
|
50
49
|
</pre>
|
|
51
50
|
</_react.default.Fragment>;
|
|
52
51
|
}
|
|
53
52
|
|
|
54
|
-
if (
|
|
53
|
+
if (isOauth2) {
|
|
55
54
|
return <_react.default.Fragment key={selected}>
|
|
56
|
-
<b>Authorization: {auth.key}</b>
|
|
57
55
|
<pre style={{
|
|
58
56
|
display: "flex",
|
|
59
57
|
flexDirection: "column",
|
|
60
|
-
background: "var(--openapi-card-background-color)"
|
|
61
|
-
borderRadius: "var(--openapi-card-border-radius)"
|
|
58
|
+
background: "var(--openapi-card-background-color)"
|
|
62
59
|
}}>
|
|
63
|
-
<span>
|
|
60
|
+
<span>
|
|
61
|
+
type: <_Link.default to={infoAuthPath}>{auth.type}</_Link.default>
|
|
62
|
+
</span>
|
|
63
|
+
{Object.keys(auth.flows).map(flow => {
|
|
64
|
+
return <span key={flow}>flow: {flow}</span>;
|
|
65
|
+
})}
|
|
66
|
+
<span>
|
|
67
|
+
scopes: <code>{auth.scopes.toString()}</code>
|
|
68
|
+
</span>
|
|
64
69
|
</pre>
|
|
65
70
|
</_react.default.Fragment>;
|
|
66
71
|
}
|
|
67
72
|
|
|
68
|
-
return
|
|
73
|
+
return undefined;
|
|
69
74
|
})}
|
|
70
|
-
</
|
|
75
|
+
</details>;
|
|
71
76
|
}
|
|
72
77
|
|
|
73
78
|
var _default = SecuritySchemes;
|
|
@@ -78,6 +78,7 @@ function Server() {
|
|
|
78
78
|
</button>
|
|
79
79
|
<_FormItem.default label="Base URL">
|
|
80
80
|
<_FormSelect.default options={options.map(s => s.url)} onChange={e => dispatch((0, _slice.setServer)(e.target.value))} />
|
|
81
|
+
<small>{value === null || value === void 0 ? void 0 : value.description}</small>
|
|
81
82
|
</_FormItem.default>
|
|
82
83
|
{(value === null || value === void 0 ? void 0 : value.variables) && Object.keys(value.variables).map(key => {
|
|
83
84
|
var _value$variables2, _value$variables3;
|
|
@@ -276,6 +276,28 @@ function buildPostmanRequest(postman, {
|
|
|
276
276
|
continue;
|
|
277
277
|
}
|
|
278
278
|
|
|
279
|
+
otherHeaders.push({
|
|
280
|
+
key: "Authorization",
|
|
281
|
+
value: `Bearer ${token}`
|
|
282
|
+
});
|
|
283
|
+
continue;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
if (a.type === "oauth2") {
|
|
287
|
+
let token;
|
|
288
|
+
|
|
289
|
+
if (auth.data[a.key]) {
|
|
290
|
+
token = auth.data[a.key].token;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
if (token === undefined) {
|
|
294
|
+
otherHeaders.push({
|
|
295
|
+
key: "Authorization",
|
|
296
|
+
value: "Bearer <TOKEN>"
|
|
297
|
+
});
|
|
298
|
+
continue;
|
|
299
|
+
}
|
|
300
|
+
|
|
279
301
|
otherHeaders.push({
|
|
280
302
|
key: "Authorization",
|
|
281
303
|
value: `Bearer ${token}`
|
|
@@ -304,10 +326,10 @@ function buildPostmanRequest(postman, {
|
|
|
304
326
|
|
|
305
327
|
if (a.type === "apiKey" && a.in === "header") {
|
|
306
328
|
const {
|
|
307
|
-
|
|
329
|
+
apiKey
|
|
308
330
|
} = auth.data[a.key];
|
|
309
331
|
|
|
310
|
-
if (
|
|
332
|
+
if (apiKey === undefined) {
|
|
311
333
|
otherHeaders.push({
|
|
312
334
|
key: a.name,
|
|
313
335
|
value: "<API_KEY_VALUE>"
|
|
@@ -317,7 +339,7 @@ function buildPostmanRequest(postman, {
|
|
|
317
339
|
|
|
318
340
|
otherHeaders.push({
|
|
319
341
|
key: a.name,
|
|
320
|
-
value:
|
|
342
|
+
value: apiKey
|
|
321
343
|
});
|
|
322
344
|
continue;
|
|
323
345
|
}
|
|
@@ -13,20 +13,16 @@ var _postmanCollection = _interopRequireDefault(require("@paloaltonetworks/postm
|
|
|
13
13
|
|
|
14
14
|
var _reactRedux = require("react-redux");
|
|
15
15
|
|
|
16
|
-
var _Accept = _interopRequireDefault(require("./Accept"));
|
|
17
|
-
|
|
18
16
|
var _slice = require("./Authorization/slice");
|
|
19
17
|
|
|
20
|
-
var _Body = _interopRequireDefault(require("./Body"));
|
|
21
|
-
|
|
22
18
|
var _Curl = _interopRequireDefault(require("./Curl"));
|
|
23
19
|
|
|
24
20
|
var _MethodEndpoint = _interopRequireDefault(require("./MethodEndpoint"));
|
|
25
21
|
|
|
26
|
-
var _ParamOptions = _interopRequireDefault(require("./ParamOptions"));
|
|
27
|
-
|
|
28
22
|
var _persistanceMiddleware = require("./persistanceMiddleware");
|
|
29
23
|
|
|
24
|
+
var _Request = _interopRequireDefault(require("./Request"));
|
|
25
|
+
|
|
30
26
|
var _Response = _interopRequireDefault(require("./Response"));
|
|
31
27
|
|
|
32
28
|
var _SecuritySchemes = _interopRequireDefault(require("./SecuritySchemes"));
|
|
@@ -111,15 +107,11 @@ function ApiDemoPanel({
|
|
|
111
107
|
return <_reactRedux.Provider store={store2}>
|
|
112
108
|
<div className={_stylesModule.default.apiDemoPanelContainer}>
|
|
113
109
|
<_MethodEndpoint.default method={method} path={path} />
|
|
114
|
-
<_SecuritySchemes.default infoPath={infoPath} />
|
|
115
|
-
<div className={_stylesModule.default.optionsPanel}>
|
|
116
|
-
<_ParamOptions.default />
|
|
117
|
-
<_Body.default jsonRequestBodyExample={item.jsonRequestBodyExample} requestBodyMetadata={item.requestBody} />
|
|
118
|
-
<_Accept.default />
|
|
119
|
-
</div>
|
|
120
110
|
<_Server.default />
|
|
121
|
-
<
|
|
111
|
+
<_SecuritySchemes.default infoPath={infoPath} />
|
|
112
|
+
<_Request.default item={item} />
|
|
122
113
|
<_Response.default />
|
|
114
|
+
<_Curl.default postman={postman} codeSamples={(_xCodeSamples = item["x-code-samples"]) !== null && _xCodeSamples !== void 0 ? _xCodeSamples : []} />
|
|
123
115
|
</div>
|
|
124
116
|
</_reactRedux.Provider>;
|
|
125
117
|
}
|
|
@@ -19,7 +19,7 @@ function createPersistanceMiddleware(options) {
|
|
|
19
19
|
const persistanceMiddleware = storeAPI => next => action => {
|
|
20
20
|
const result = next(action);
|
|
21
21
|
const state = storeAPI.getState();
|
|
22
|
-
const storage = (0, _storageUtils.createStorage)(
|
|
22
|
+
const storage = (0, _storageUtils.createStorage)("sessionStorage");
|
|
23
23
|
|
|
24
24
|
if (action.type === _slice.setAuthData.type) {
|
|
25
25
|
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;
|
|
@@ -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}\``} />
|
|
@@ -8,6 +8,10 @@ export function getAuthDataKeys(security) {
|
|
|
8
8
|
// Bearer Auth
|
|
9
9
|
if (security.type === "http" && security.scheme === "bearer") {
|
|
10
10
|
return ["token"];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
if (security.type === "oauth2") {
|
|
14
|
+
return ["token"];
|
|
11
15
|
} // Basic Auth
|
|
12
16
|
|
|
13
17
|
if (security.type === "http" && security.scheme === "basic") {
|
|
@@ -0,0 +1,149 @@
|
|
|
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
|
+
import React from "react";
|
|
8
|
+
import FormItem from "../FormItem";
|
|
9
|
+
import FormSelect from "../FormSelect";
|
|
10
|
+
import FormTextInput from "../FormTextInput";
|
|
11
|
+
import { useTypedDispatch, useTypedSelector } from "../hooks";
|
|
12
|
+
import { setAuthData, setSelectedAuth } from "./slice";
|
|
13
|
+
|
|
14
|
+
function Authorization() {
|
|
15
|
+
const data = useTypedSelector((state) => state.auth.data);
|
|
16
|
+
const options = useTypedSelector((state) => state.auth.options);
|
|
17
|
+
const selected = useTypedSelector((state) => state.auth.selected);
|
|
18
|
+
const dispatch = useTypedDispatch();
|
|
19
|
+
|
|
20
|
+
if (selected === undefined) {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const selectedAuth = options[selected];
|
|
25
|
+
const optionKeys = Object.keys(options);
|
|
26
|
+
return (
|
|
27
|
+
<div>
|
|
28
|
+
{optionKeys.length > 1 && (
|
|
29
|
+
<FormItem label="Security Scheme">
|
|
30
|
+
<FormSelect
|
|
31
|
+
options={optionKeys}
|
|
32
|
+
value={selected}
|
|
33
|
+
onChange={(e) => {
|
|
34
|
+
dispatch(setSelectedAuth(e.target.value));
|
|
35
|
+
}}
|
|
36
|
+
/>
|
|
37
|
+
</FormItem>
|
|
38
|
+
)}
|
|
39
|
+
{selectedAuth.map((a) => {
|
|
40
|
+
if (a.type === "http" && a.scheme === "bearer") {
|
|
41
|
+
return (
|
|
42
|
+
<FormItem label="Bearer Token" key={a.key + "-bearer"}>
|
|
43
|
+
<FormTextInput
|
|
44
|
+
placeholder="Bearer Token"
|
|
45
|
+
value={data[a.key].token ?? ""}
|
|
46
|
+
onChange={(e) => {
|
|
47
|
+
const value = e.target.value.trim();
|
|
48
|
+
dispatch(
|
|
49
|
+
setAuthData({
|
|
50
|
+
scheme: a.key,
|
|
51
|
+
key: "token",
|
|
52
|
+
value: value ? value : undefined,
|
|
53
|
+
})
|
|
54
|
+
);
|
|
55
|
+
}}
|
|
56
|
+
/>
|
|
57
|
+
</FormItem>
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (a.type === "oauth2") {
|
|
62
|
+
return (
|
|
63
|
+
<FormItem label="Bearer Token" key={a.key + "-oauth2"}>
|
|
64
|
+
<FormTextInput
|
|
65
|
+
placeholder="Bearer Token"
|
|
66
|
+
value={data[a.key].token ?? ""}
|
|
67
|
+
onChange={(e) => {
|
|
68
|
+
const value = e.target.value.trim();
|
|
69
|
+
dispatch(
|
|
70
|
+
setAuthData({
|
|
71
|
+
scheme: a.key,
|
|
72
|
+
key: "token",
|
|
73
|
+
value: value ? value : undefined,
|
|
74
|
+
})
|
|
75
|
+
);
|
|
76
|
+
}}
|
|
77
|
+
/>
|
|
78
|
+
</FormItem>
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (a.type === "http" && a.scheme === "basic") {
|
|
83
|
+
return (
|
|
84
|
+
<React.Fragment key={a.key + "-basic"}>
|
|
85
|
+
<FormItem label="Username">
|
|
86
|
+
<FormTextInput
|
|
87
|
+
placeholder="Username"
|
|
88
|
+
value={data[a.key].username ?? ""}
|
|
89
|
+
onChange={(e) => {
|
|
90
|
+
const value = e.target.value.trim();
|
|
91
|
+
dispatch(
|
|
92
|
+
setAuthData({
|
|
93
|
+
scheme: a.key,
|
|
94
|
+
key: "username",
|
|
95
|
+
value: value ? value : undefined,
|
|
96
|
+
})
|
|
97
|
+
);
|
|
98
|
+
}}
|
|
99
|
+
/>
|
|
100
|
+
</FormItem>
|
|
101
|
+
<FormItem label="Password">
|
|
102
|
+
<FormTextInput
|
|
103
|
+
placeholder="Password"
|
|
104
|
+
password
|
|
105
|
+
value={data[a.key].password ?? ""}
|
|
106
|
+
onChange={(e) => {
|
|
107
|
+
const value = e.target.value.trim();
|
|
108
|
+
dispatch(
|
|
109
|
+
setAuthData({
|
|
110
|
+
scheme: a.key,
|
|
111
|
+
key: "password",
|
|
112
|
+
value: value ? value : undefined,
|
|
113
|
+
})
|
|
114
|
+
);
|
|
115
|
+
}}
|
|
116
|
+
/>
|
|
117
|
+
</FormItem>
|
|
118
|
+
</React.Fragment>
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (a.type === "apiKey") {
|
|
123
|
+
return (
|
|
124
|
+
<FormItem label={`${a.key}`} key={a.key + "-apikey"}>
|
|
125
|
+
<FormTextInput
|
|
126
|
+
placeholder={`${a.key}`}
|
|
127
|
+
value={data[a.key].apiKey ?? ""}
|
|
128
|
+
onChange={(e) => {
|
|
129
|
+
const value = e.target.value.trim();
|
|
130
|
+
dispatch(
|
|
131
|
+
setAuthData({
|
|
132
|
+
scheme: a.key,
|
|
133
|
+
key: "apiKey",
|
|
134
|
+
value: value ? value : undefined,
|
|
135
|
+
})
|
|
136
|
+
);
|
|
137
|
+
}}
|
|
138
|
+
/>
|
|
139
|
+
</FormItem>
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return null;
|
|
144
|
+
})}
|
|
145
|
+
</div>
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export default Authorization;
|
|
@@ -35,7 +35,7 @@ import { getAuthDataKeys } from "./auth-types"; // The global definitions
|
|
|
35
35
|
// BasicAuth -> { username: xxx, password: xxx }
|
|
36
36
|
|
|
37
37
|
export function createAuth({ security, securitySchemes, options: opts }) {
|
|
38
|
-
const storage = createStorage(
|
|
38
|
+
const storage = createStorage("sessionStorage");
|
|
39
39
|
let data = {};
|
|
40
40
|
let options = {};
|
|
41
41
|
|
|
@@ -45,6 +45,7 @@ function BodyWrap({ requestBodyMetadata, jsonRequestBodyExample }) {
|
|
|
45
45
|
|
|
46
46
|
function Body({ requestBodyMetadata, jsonRequestBodyExample }) {
|
|
47
47
|
const contentType = useTypedSelector((state) => state.contentType.value);
|
|
48
|
+
const required = requestBodyMetadata?.required;
|
|
48
49
|
const dispatch = useTypedDispatch(); // Lot's of possible content-types:
|
|
49
50
|
// - application/json
|
|
50
51
|
// - application/xml
|
|
@@ -68,7 +69,7 @@ function Body({ requestBodyMetadata, jsonRequestBodyExample }) {
|
|
|
68
69
|
|
|
69
70
|
if (schema?.format === "binary") {
|
|
70
71
|
return (
|
|
71
|
-
<FormItem label="Body">
|
|
72
|
+
<FormItem label="Body" required={required}>
|
|
72
73
|
<FormFileUpload
|
|
73
74
|
placeholder={schema.description || "Body"}
|
|
74
75
|
onChange={(file) => {
|
|
@@ -95,7 +96,7 @@ function Body({ requestBodyMetadata, jsonRequestBodyExample }) {
|
|
|
95
96
|
schema?.type === "object"
|
|
96
97
|
) {
|
|
97
98
|
return (
|
|
98
|
-
<FormItem label="Body">
|
|
99
|
+
<FormItem label="Body" required={required}>
|
|
99
100
|
<div
|
|
100
101
|
style={{
|
|
101
102
|
marginTop: "calc(var(--ifm-pre-padding) / 2)",
|
|
@@ -107,7 +108,14 @@ function Body({ requestBodyMetadata, jsonRequestBodyExample }) {
|
|
|
107
108
|
{Object.entries(schema.properties ?? {}).map(([key, val]) => {
|
|
108
109
|
if (val.format === "binary") {
|
|
109
110
|
return (
|
|
110
|
-
<FormItem
|
|
111
|
+
<FormItem
|
|
112
|
+
key={key}
|
|
113
|
+
label={key}
|
|
114
|
+
required={
|
|
115
|
+
Array.isArray(schema.required) &&
|
|
116
|
+
schema.required.includes(key)
|
|
117
|
+
}
|
|
118
|
+
>
|
|
111
119
|
<FormFileUpload
|
|
112
120
|
placeholder={val.description || key}
|
|
113
121
|
onChange={(file) => {
|
|
@@ -133,7 +141,14 @@ function Body({ requestBodyMetadata, jsonRequestBodyExample }) {
|
|
|
133
141
|
|
|
134
142
|
if (val.enum) {
|
|
135
143
|
return (
|
|
136
|
-
<FormItem
|
|
144
|
+
<FormItem
|
|
145
|
+
key={key}
|
|
146
|
+
label={key}
|
|
147
|
+
required={
|
|
148
|
+
Array.isArray(schema.required) &&
|
|
149
|
+
schema.required.includes(key)
|
|
150
|
+
}
|
|
151
|
+
>
|
|
137
152
|
<FormSelect
|
|
138
153
|
options={["---", ...val.enum]}
|
|
139
154
|
onChange={(e) => {
|
|
@@ -156,7 +171,14 @@ function Body({ requestBodyMetadata, jsonRequestBodyExample }) {
|
|
|
156
171
|
} // TODO: support all the other types.
|
|
157
172
|
|
|
158
173
|
return (
|
|
159
|
-
<FormItem
|
|
174
|
+
<FormItem
|
|
175
|
+
key={key}
|
|
176
|
+
label={key}
|
|
177
|
+
required={
|
|
178
|
+
Array.isArray(schema.required) &&
|
|
179
|
+
schema.required.includes(key)
|
|
180
|
+
}
|
|
181
|
+
>
|
|
160
182
|
<FormTextInput
|
|
161
183
|
placeholder={val.description || key}
|
|
162
184
|
onChange={(e) => {
|
|
@@ -204,7 +226,7 @@ function Body({ requestBodyMetadata, jsonRequestBodyExample }) {
|
|
|
204
226
|
}
|
|
205
227
|
|
|
206
228
|
return (
|
|
207
|
-
<FormItem label="Body">
|
|
229
|
+
<FormItem label="Body" required={required}>
|
|
208
230
|
<LiveApp action={dispatch} language={language}>
|
|
209
231
|
{exampleBodyString}
|
|
210
232
|
</LiveApp>
|