docusaurus-theme-openapi-docs 1.2.2 → 1.3.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/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/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/SchemaTabs/index.js +4 -1
- package/package.json +3 -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/SchemaTabs/index.js +4 -1
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.default =
|
|
6
|
+
exports.default = void 0;
|
|
7
7
|
|
|
8
8
|
var _react = _interopRequireDefault(require("react"));
|
|
9
9
|
|
|
@@ -11,12 +11,22 @@ var _ExecutionEnvironment = _interopRequireDefault(require("@docusaurus/Executio
|
|
|
11
11
|
|
|
12
12
|
var _themeCommon = require("@docusaurus/theme-common");
|
|
13
13
|
|
|
14
|
+
var _useDocusaurusContext = _interopRequireDefault(require("@docusaurus/useDocusaurusContext"));
|
|
15
|
+
|
|
14
16
|
var _clsx = _interopRequireDefault(require("clsx"));
|
|
15
17
|
|
|
18
|
+
var _reactRedux = require("react-redux");
|
|
19
|
+
|
|
20
|
+
var _slice = require("../ApiDemoPanel/Authorization/slice");
|
|
21
|
+
|
|
22
|
+
var _persistanceMiddleware = require("../ApiDemoPanel/persistanceMiddleware");
|
|
23
|
+
|
|
16
24
|
var _Layout = _interopRequireDefault(require("./Layout"));
|
|
17
25
|
|
|
18
26
|
var _Metadata = _interopRequireDefault(require("./Metadata"));
|
|
19
27
|
|
|
28
|
+
var _store = require("./store");
|
|
29
|
+
|
|
20
30
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
31
|
|
|
22
32
|
/* ============================================================================
|
|
@@ -33,14 +43,19 @@ let ApiDemoPanel = _ => <div style={{
|
|
|
33
43
|
marginTop: "3.5em"
|
|
34
44
|
}} />;
|
|
35
45
|
|
|
46
|
+
let DocItem = props => {
|
|
47
|
+
return <div style={{
|
|
48
|
+
marginTop: "3.5em"
|
|
49
|
+
}} />;
|
|
50
|
+
};
|
|
51
|
+
|
|
36
52
|
if (_ExecutionEnvironment.default.canUseDOM) {
|
|
37
53
|
ApiDemoPanel = require("@theme/ApiDemoPanel").default;
|
|
38
|
-
}
|
|
39
54
|
|
|
40
|
-
function DocItem(props) {
|
|
41
|
-
|
|
55
|
+
DocItem = function DocItem(props) {
|
|
56
|
+
var _api$responses, _api$requestBody$cont, _api$requestBody, _api$servers, _api$parameters, _window, _window2, _window3, _ref;
|
|
42
57
|
|
|
43
|
-
|
|
58
|
+
const docHtmlClassName = `docs-doc-id-${props.content.metadata.unversionedId}`;
|
|
44
59
|
const MDXComponent = props.content;
|
|
45
60
|
const {
|
|
46
61
|
frontMatter
|
|
@@ -51,22 +66,86 @@ function DocItem(props) {
|
|
|
51
66
|
const {
|
|
52
67
|
api
|
|
53
68
|
} = frontMatter;
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
69
|
+
const {
|
|
70
|
+
siteConfig
|
|
71
|
+
} = (0, _useDocusaurusContext.default)();
|
|
72
|
+
const themeConfig = siteConfig.themeConfig;
|
|
73
|
+
const options = themeConfig.api;
|
|
74
|
+
const acceptArray = Array.from(new Set(Object.values((_api$responses = api === null || api === void 0 ? void 0 : api.responses) !== null && _api$responses !== void 0 ? _api$responses : {}).map(response => {
|
|
75
|
+
var _response$content;
|
|
76
|
+
|
|
77
|
+
return Object.keys((_response$content = response.content) !== null && _response$content !== void 0 ? _response$content : {});
|
|
78
|
+
}).flat()));
|
|
79
|
+
const content = (_api$requestBody$cont = api === null || api === void 0 ? void 0 : (_api$requestBody = api.requestBody) === null || _api$requestBody === void 0 ? void 0 : _api$requestBody.content) !== null && _api$requestBody$cont !== void 0 ? _api$requestBody$cont : {};
|
|
80
|
+
const contentTypeArray = Object.keys(content);
|
|
81
|
+
const servers = (_api$servers = api === null || api === void 0 ? void 0 : api.servers) !== null && _api$servers !== void 0 ? _api$servers : [];
|
|
82
|
+
const params = {
|
|
83
|
+
path: [],
|
|
84
|
+
query: [],
|
|
85
|
+
header: [],
|
|
86
|
+
cookie: []
|
|
87
|
+
};
|
|
88
|
+
api === null || api === void 0 ? void 0 : (_api$parameters = api.parameters) === null || _api$parameters === void 0 ? void 0 : _api$parameters.forEach(param => {
|
|
89
|
+
const paramType = param.in;
|
|
90
|
+
const paramsArray = params[paramType];
|
|
91
|
+
paramsArray.push(param);
|
|
92
|
+
});
|
|
93
|
+
const auth = (0, _slice.createAuth)({
|
|
94
|
+
security: api === null || api === void 0 ? void 0 : api.security,
|
|
95
|
+
securitySchemes: api === null || api === void 0 ? void 0 : api.securitySchemes,
|
|
96
|
+
options
|
|
97
|
+
});
|
|
98
|
+
const persistanceMiddleware = (0, _persistanceMiddleware.createPersistanceMiddleware)(options);
|
|
99
|
+
const acceptValue = (_window = window) === null || _window === void 0 ? void 0 : _window.sessionStorage.getItem("accept");
|
|
100
|
+
const contentTypeValue = (_window2 = window) === null || _window2 === void 0 ? void 0 : _window2.sessionStorage.getItem("contentType");
|
|
101
|
+
const server = (_window3 = window) === null || _window3 === void 0 ? void 0 : _window3.sessionStorage.getItem("server");
|
|
102
|
+
const serverObject = (_ref = JSON.parse(server)) !== null && _ref !== void 0 ? _ref : {};
|
|
103
|
+
const store2 = (0, _store.createStoreWithState)({
|
|
104
|
+
accept: {
|
|
105
|
+
value: acceptValue || acceptArray[0],
|
|
106
|
+
options: acceptArray
|
|
107
|
+
},
|
|
108
|
+
contentType: {
|
|
109
|
+
value: contentTypeValue || contentTypeArray[0],
|
|
110
|
+
options: contentTypeArray
|
|
111
|
+
},
|
|
112
|
+
server: {
|
|
113
|
+
value: serverObject.url ? serverObject : undefined,
|
|
114
|
+
options: servers
|
|
115
|
+
},
|
|
116
|
+
response: {
|
|
117
|
+
value: undefined
|
|
118
|
+
},
|
|
119
|
+
body: {
|
|
120
|
+
type: "empty"
|
|
121
|
+
},
|
|
122
|
+
params,
|
|
123
|
+
auth
|
|
124
|
+
}, [persistanceMiddleware]);
|
|
125
|
+
|
|
126
|
+
const DocContent = () => {
|
|
127
|
+
return <div className="row">
|
|
128
|
+
<div className={(0, _clsx.default)("col", api ? "col--7" : "col--12")}>
|
|
129
|
+
<MDXComponent />
|
|
130
|
+
</div>
|
|
131
|
+
{api && <div className="col col--5">
|
|
132
|
+
<ApiDemoPanel item={api} infoPath={infoPath} />
|
|
133
|
+
</div>}
|
|
134
|
+
</div>;
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
return <_reactRedux.Provider store={store2}>
|
|
138
|
+
<DocProvider content={props.content}>
|
|
139
|
+
<_themeCommon.HtmlClassNameProvider className={docHtmlClassName}>
|
|
140
|
+
<_Metadata.default />
|
|
141
|
+
<_Layout.default>
|
|
142
|
+
<DocContent />
|
|
143
|
+
</_Layout.default>
|
|
144
|
+
</_themeCommon.HtmlClassNameProvider>
|
|
145
|
+
</DocProvider>
|
|
146
|
+
</_reactRedux.Provider>;
|
|
62
147
|
};
|
|
148
|
+
}
|
|
63
149
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
<_Metadata.default />
|
|
67
|
-
<_Layout.default>
|
|
68
|
-
<DocContent />
|
|
69
|
-
</_Layout.default>
|
|
70
|
-
</_themeCommon.HtmlClassNameProvider>
|
|
71
|
-
</DocProvider>;
|
|
72
|
-
}
|
|
150
|
+
var _default = DocItem;
|
|
151
|
+
exports.default = _default;
|
|
@@ -7,19 +7,19 @@ exports.createStoreWithState = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _toolkit = require("@reduxjs/toolkit");
|
|
9
9
|
|
|
10
|
-
var _slice = _interopRequireDefault(require("
|
|
10
|
+
var _slice = _interopRequireDefault(require("../ApiDemoPanel/Accept/slice"));
|
|
11
11
|
|
|
12
|
-
var _slice2 = _interopRequireDefault(require("
|
|
12
|
+
var _slice2 = _interopRequireDefault(require("../ApiDemoPanel/Authorization/slice"));
|
|
13
13
|
|
|
14
|
-
var _slice3 = _interopRequireDefault(require("
|
|
14
|
+
var _slice3 = _interopRequireDefault(require("../ApiDemoPanel/Body/slice"));
|
|
15
15
|
|
|
16
|
-
var _slice4 = _interopRequireDefault(require("
|
|
16
|
+
var _slice4 = _interopRequireDefault(require("../ApiDemoPanel/ContentType/slice"));
|
|
17
17
|
|
|
18
|
-
var _slice5 = _interopRequireDefault(require("
|
|
18
|
+
var _slice5 = _interopRequireDefault(require("../ApiDemoPanel/ParamOptions/slice"));
|
|
19
19
|
|
|
20
|
-
var _slice6 = _interopRequireDefault(require("
|
|
20
|
+
var _slice6 = _interopRequireDefault(require("../ApiDemoPanel/Response/slice"));
|
|
21
21
|
|
|
22
|
-
var _slice7 = _interopRequireDefault(require("
|
|
22
|
+
var _slice7 = _interopRequireDefault(require("../ApiDemoPanel/Server/slice"));
|
|
23
23
|
|
|
24
24
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
25
25
|
|
|
@@ -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",
|
|
@@ -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
|
}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
* ========================================================================== */
|
|
7
7
|
import React from "react";
|
|
8
|
-
import { useTypedDispatch, useTypedSelector } from "
|
|
8
|
+
import { useTypedDispatch, useTypedSelector } from "../../ApiItem/hooks";
|
|
9
9
|
import FormItem from "./../FormItem";
|
|
10
10
|
import FormSelect from "./../FormSelect";
|
|
11
11
|
import { setAccept } from "./slice";
|
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
* ========================================================================== */
|
|
7
7
|
import React from "react";
|
|
8
|
+
import { useTypedDispatch, useTypedSelector } from "../../ApiItem/hooks";
|
|
8
9
|
import FormItem from "../FormItem";
|
|
9
10
|
import FormSelect from "../FormSelect";
|
|
10
11
|
import FormTextInput from "../FormTextInput";
|
|
11
|
-
import { useTypedDispatch, useTypedSelector } from "../hooks";
|
|
12
12
|
import { setAuthData, setSelectedAuth } from "./slice";
|
|
13
13
|
|
|
14
14
|
function Authorization() {
|
|
@@ -5,10 +5,13 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
* ========================================================================== */
|
|
7
7
|
import React from "react";
|
|
8
|
+
import TabItem from "@theme/TabItem";
|
|
8
9
|
import format from "xml-formatter";
|
|
10
|
+
import { useTypedDispatch, useTypedSelector } from "../../ApiItem/hooks"; // @ts-ignore
|
|
11
|
+
|
|
12
|
+
import SchemaTabs from "../../SchemaTabs";
|
|
9
13
|
import ContentType from "../ContentType";
|
|
10
14
|
import FormSelect from "../FormSelect";
|
|
11
|
-
import { useTypedDispatch, useTypedSelector } from "../hooks";
|
|
12
15
|
import LiveApp from "../LiveEditor";
|
|
13
16
|
import FormFileUpload from "./../FormFileUpload";
|
|
14
17
|
import FormItem from "./../FormItem";
|
|
@@ -66,6 +69,8 @@ function Body({ requestBodyMetadata, jsonRequestBodyExample }) {
|
|
|
66
69
|
// - application/x-www-form-urlencoded
|
|
67
70
|
|
|
68
71
|
const schema = requestBodyMetadata?.content?.[contentType]?.schema;
|
|
72
|
+
const example = requestBodyMetadata?.content?.[contentType]?.example;
|
|
73
|
+
const examples = requestBodyMetadata?.content?.[contentType]?.examples;
|
|
69
74
|
|
|
70
75
|
if (schema?.format === "binary") {
|
|
71
76
|
return (
|
|
@@ -199,36 +204,138 @@ function Body({ requestBodyMetadata, jsonRequestBodyExample }) {
|
|
|
199
204
|
}
|
|
200
205
|
|
|
201
206
|
let language = "plaintext";
|
|
202
|
-
let
|
|
207
|
+
let defaultBody = ""; //"body content";
|
|
208
|
+
|
|
209
|
+
let exampleBody;
|
|
210
|
+
let examplesBodies = [];
|
|
203
211
|
|
|
204
212
|
if (contentType === "application/json" || contentType.endsWith("+json")) {
|
|
205
213
|
if (jsonRequestBodyExample) {
|
|
206
|
-
|
|
214
|
+
defaultBody = JSON.stringify(jsonRequestBodyExample, null, 2);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if (example) {
|
|
218
|
+
exampleBody = JSON.stringify(example, null, 2);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
if (examples) {
|
|
222
|
+
for (const [key, example] of Object.entries(examples)) {
|
|
223
|
+
examplesBodies.push({
|
|
224
|
+
label: key,
|
|
225
|
+
body: JSON.stringify(example.value, null, 2),
|
|
226
|
+
summary: example.summary,
|
|
227
|
+
});
|
|
228
|
+
}
|
|
207
229
|
}
|
|
208
230
|
|
|
209
231
|
language = "json";
|
|
210
232
|
}
|
|
211
233
|
|
|
212
|
-
if (contentType === "application/xml") {
|
|
234
|
+
if (contentType === "application/xml" || contentType.endsWith("+xml")) {
|
|
213
235
|
if (jsonRequestBodyExample) {
|
|
214
236
|
try {
|
|
215
|
-
|
|
237
|
+
defaultBody = format(json2xml(jsonRequestBodyExample, ""), {
|
|
238
|
+
indentation: " ",
|
|
239
|
+
lineSeparator: "\n",
|
|
240
|
+
collapseContent: true,
|
|
241
|
+
});
|
|
242
|
+
} catch {
|
|
243
|
+
defaultBody = json2xml(jsonRequestBodyExample);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
if (example) {
|
|
248
|
+
try {
|
|
249
|
+
exampleBody = format(json2xml(example, ""), {
|
|
216
250
|
indentation: " ",
|
|
217
251
|
lineSeparator: "\n",
|
|
218
252
|
collapseContent: true,
|
|
219
253
|
});
|
|
220
254
|
} catch {
|
|
221
|
-
|
|
255
|
+
exampleBody = json2xml(example);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
if (examples) {
|
|
260
|
+
for (const [key, example] of Object.entries(examples)) {
|
|
261
|
+
let formattedXmlBody;
|
|
262
|
+
|
|
263
|
+
try {
|
|
264
|
+
formattedXmlBody = format(example.value, {
|
|
265
|
+
indentation: " ",
|
|
266
|
+
lineSeparator: "\n",
|
|
267
|
+
collapseContent: true,
|
|
268
|
+
});
|
|
269
|
+
} catch {
|
|
270
|
+
formattedXmlBody = example.value;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
examplesBodies.push({
|
|
274
|
+
label: key,
|
|
275
|
+
body: formattedXmlBody,
|
|
276
|
+
summary: example.summary,
|
|
277
|
+
});
|
|
222
278
|
}
|
|
223
279
|
}
|
|
224
280
|
|
|
225
281
|
language = "xml";
|
|
226
282
|
}
|
|
227
283
|
|
|
284
|
+
if (exampleBody) {
|
|
285
|
+
return (
|
|
286
|
+
<FormItem label="Body" required={required}>
|
|
287
|
+
<SchemaTabs lazy>
|
|
288
|
+
<TabItem label="Default" value="default" default>
|
|
289
|
+
<LiveApp action={dispatch} language={language}>
|
|
290
|
+
{defaultBody}
|
|
291
|
+
</LiveApp>
|
|
292
|
+
</TabItem>
|
|
293
|
+
<TabItem label="Example" value="example">
|
|
294
|
+
{exampleBody && (
|
|
295
|
+
<LiveApp action={dispatch} language={language}>
|
|
296
|
+
{exampleBody}
|
|
297
|
+
</LiveApp>
|
|
298
|
+
)}
|
|
299
|
+
</TabItem>
|
|
300
|
+
</SchemaTabs>
|
|
301
|
+
</FormItem>
|
|
302
|
+
);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
if (examplesBodies && examplesBodies.length > 0) {
|
|
306
|
+
return (
|
|
307
|
+
<FormItem label="Body" required={required}>
|
|
308
|
+
<SchemaTabs lazy>
|
|
309
|
+
<TabItem label="Default" value="default" default>
|
|
310
|
+
<LiveApp action={dispatch} language={language}>
|
|
311
|
+
{defaultBody}
|
|
312
|
+
</LiveApp>
|
|
313
|
+
</TabItem>
|
|
314
|
+
{examplesBodies.map((example) => {
|
|
315
|
+
return (
|
|
316
|
+
<TabItem
|
|
317
|
+
label={example.label}
|
|
318
|
+
value={example.label}
|
|
319
|
+
key={example.label}
|
|
320
|
+
>
|
|
321
|
+
{example.summary && <p>{example.summary}</p>}
|
|
322
|
+
{example.body && (
|
|
323
|
+
<LiveApp action={dispatch} language={language}>
|
|
324
|
+
{example.body}
|
|
325
|
+
</LiveApp>
|
|
326
|
+
)}
|
|
327
|
+
</TabItem>
|
|
328
|
+
);
|
|
329
|
+
})}
|
|
330
|
+
</SchemaTabs>
|
|
331
|
+
</FormItem>
|
|
332
|
+
);
|
|
333
|
+
}
|
|
334
|
+
|
|
228
335
|
return (
|
|
229
336
|
<FormItem label="Body" required={required}>
|
|
230
337
|
<LiveApp action={dispatch} language={language}>
|
|
231
|
-
{
|
|
338
|
+
{defaultBody}
|
|
232
339
|
</LiveApp>
|
|
233
340
|
</FormItem>
|
|
234
341
|
);
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
* ========================================================================== */
|
|
7
7
|
import React from "react";
|
|
8
|
-
import { useTypedDispatch, useTypedSelector } from "
|
|
8
|
+
import { useTypedDispatch, useTypedSelector } from "../../ApiItem/hooks";
|
|
9
9
|
import FormItem from "./../FormItem";
|
|
10
10
|
import FormSelect from "./../FormSelect";
|
|
11
11
|
import { setContentType } from "./slice";
|
|
@@ -9,8 +9,8 @@ import useDocusaurusContext from "@docusaurus/useDocusaurusContext";
|
|
|
9
9
|
import codegen from "@paloaltonetworks/postman-code-generators";
|
|
10
10
|
import CodeBlock from "@theme/CodeBlock";
|
|
11
11
|
import clsx from "clsx";
|
|
12
|
+
import { useTypedSelector } from "../../ApiItem/hooks";
|
|
12
13
|
import CodeTabs from "../CodeTabs";
|
|
13
|
-
import { useTypedSelector } from "../hooks";
|
|
14
14
|
import buildPostmanRequest from "./../buildPostmanRequest";
|
|
15
15
|
import styles from "./styles.module.css";
|
|
16
16
|
export const languageSet = [
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* ========================================================================== */
|
|
7
7
|
import React from "react";
|
|
8
8
|
import Modal from "react-modal";
|
|
9
|
-
import { useTypedDispatch, useTypedSelector } from "
|
|
9
|
+
import { useTypedDispatch, useTypedSelector } from "../../ApiItem/hooks";
|
|
10
10
|
import { setResponse } from "../Response/slice";
|
|
11
11
|
import buildPostmanRequest from "./../buildPostmanRequest";
|
|
12
12
|
import makeRequest from "./makeRequest";
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* ========================================================================== */
|
|
7
7
|
import React, { useState, useEffect } from "react";
|
|
8
8
|
import { nanoid } from "@reduxjs/toolkit";
|
|
9
|
-
import { useTypedDispatch, useTypedSelector } from "
|
|
9
|
+
import { useTypedDispatch, useTypedSelector } from "../../ApiItem/hooks";
|
|
10
10
|
import FormItem from "./../FormItem";
|
|
11
11
|
import FormMultiSelect from "./../FormMultiSelect";
|
|
12
12
|
import FormSelect from "./../FormSelect";
|
|
@@ -7,11 +7,11 @@
|
|
|
7
7
|
import React from "react";
|
|
8
8
|
import useDocusaurusContext from "@docusaurus/useDocusaurusContext";
|
|
9
9
|
import sdk from "@paloaltonetworks/postman-collection";
|
|
10
|
+
import { useTypedSelector } from "../../ApiItem/hooks";
|
|
10
11
|
import Accept from "../Accept";
|
|
11
12
|
import Authorization from "../Authorization";
|
|
12
13
|
import Body from "../Body";
|
|
13
14
|
import Execute from "../Execute";
|
|
14
|
-
import { useTypedSelector } from "../hooks";
|
|
15
15
|
import ParamOptions from "../ParamOptions";
|
|
16
16
|
import Server from "../Server";
|
|
17
17
|
import styles from "./styles.module.css";
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* ========================================================================== */
|
|
7
7
|
import React from "react";
|
|
8
8
|
import CodeBlock from "@theme/CodeBlock";
|
|
9
|
-
import { useTypedDispatch, useTypedSelector } from "
|
|
9
|
+
import { useTypedDispatch, useTypedSelector } from "../../ApiItem/hooks";
|
|
10
10
|
import { clearResponse } from "./slice"; // TODO: We probably shouldn't attempt to format XML...
|
|
11
11
|
|
|
12
12
|
function formatXml(xml) {
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* ========================================================================== */
|
|
7
7
|
import React from "react";
|
|
8
8
|
import Link from "@docusaurus/Link";
|
|
9
|
-
import { useTypedSelector } from "
|
|
9
|
+
import { useTypedSelector } from "../../ApiItem/hooks";
|
|
10
10
|
|
|
11
11
|
function SecuritySchemes(props) {
|
|
12
12
|
const options = useTypedSelector((state) => state.auth.options);
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
* ========================================================================== */
|
|
7
7
|
import React, { useState } from "react";
|
|
8
|
+
import { useTypedDispatch, useTypedSelector } from "../../ApiItem/hooks";
|
|
8
9
|
import FloatingButton from "../FloatingButton";
|
|
9
|
-
import { useTypedDispatch, useTypedSelector } from "../hooks";
|
|
10
10
|
import FormItem from "./../FormItem";
|
|
11
11
|
import FormSelect from "./../FormSelect";
|
|
12
12
|
import FormTextInput from "./../FormTextInput";
|
|
@@ -27,6 +27,20 @@ function Server() {
|
|
|
27
27
|
return null;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
+
if (!value) {
|
|
31
|
+
const defaultOption = options[0];
|
|
32
|
+
dispatch(setServer(JSON.stringify(defaultOption)));
|
|
33
|
+
} // Default to first option when existing server state is mismatched
|
|
34
|
+
|
|
35
|
+
if (value) {
|
|
36
|
+
const urlExists = options.find((s) => s.url === value.url);
|
|
37
|
+
|
|
38
|
+
if (!urlExists) {
|
|
39
|
+
const defaultOption = options[0];
|
|
40
|
+
dispatch(setServer(JSON.stringify(defaultOption)));
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
30
44
|
if (!isEditing) {
|
|
31
45
|
let url = "";
|
|
32
46
|
|
|
@@ -65,7 +79,15 @@ function Server() {
|
|
|
65
79
|
<FormItem label="Base URL">
|
|
66
80
|
<FormSelect
|
|
67
81
|
options={options.map((s) => s.url)}
|
|
68
|
-
onChange={(e) =>
|
|
82
|
+
onChange={(e) => {
|
|
83
|
+
dispatch(
|
|
84
|
+
setServer(
|
|
85
|
+
JSON.stringify(
|
|
86
|
+
options.filter((s) => s.url === e.target.value)[0]
|
|
87
|
+
)
|
|
88
|
+
)
|
|
89
|
+
);
|
|
90
|
+
}}
|
|
69
91
|
value={value?.url}
|
|
70
92
|
/>
|
|
71
93
|
<small>{value?.description}</small>
|
|
@@ -79,12 +101,15 @@ function Server() {
|
|
|
79
101
|
options={value.variables[key].enum}
|
|
80
102
|
onChange={(e) => {
|
|
81
103
|
dispatch(
|
|
82
|
-
setServerVariable(
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
104
|
+
setServerVariable(
|
|
105
|
+
JSON.stringify({
|
|
106
|
+
key,
|
|
107
|
+
value: e.target.value,
|
|
108
|
+
})
|
|
109
|
+
)
|
|
86
110
|
);
|
|
87
111
|
}}
|
|
112
|
+
value={value?.variables[key].default}
|
|
88
113
|
/>
|
|
89
114
|
</FormItem>
|
|
90
115
|
);
|
|
@@ -96,12 +121,15 @@ function Server() {
|
|
|
96
121
|
placeholder={value.variables?.[key].default}
|
|
97
122
|
onChange={(e) => {
|
|
98
123
|
dispatch(
|
|
99
|
-
setServerVariable(
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
124
|
+
setServerVariable(
|
|
125
|
+
JSON.stringify({
|
|
126
|
+
key,
|
|
127
|
+
value: e.target.value,
|
|
128
|
+
})
|
|
129
|
+
)
|
|
103
130
|
);
|
|
104
131
|
}}
|
|
132
|
+
value={value?.variables?.[key].default}
|
|
105
133
|
/>
|
|
106
134
|
</FormItem>
|
|
107
135
|
);
|
|
@@ -11,12 +11,14 @@ export const slice = createSlice({
|
|
|
11
11
|
initialState,
|
|
12
12
|
reducers: {
|
|
13
13
|
setServer: (state, action) => {
|
|
14
|
-
state.value = state.options.find(
|
|
14
|
+
state.value = state.options.find(
|
|
15
|
+
(s) => s.url === JSON.parse(action.payload).url
|
|
16
|
+
);
|
|
15
17
|
},
|
|
16
18
|
setServerVariable: (state, action) => {
|
|
17
19
|
if (state.value?.variables) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
+
const parsedPayload = JSON.parse(action.payload);
|
|
21
|
+
state.value.variables[parsedPayload.key].default = parsedPayload.value;
|
|
20
22
|
}
|
|
21
23
|
},
|
|
22
24
|
},
|