docusaurus-theme-openapi-docs 1.4.2 → 1.4.4
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/index.js +5 -8
- package/lib/markdown/createDescription.js +1 -2
- package/lib/markdown/schema.js +7 -42
- package/lib/markdown/utils.js +1 -7
- package/lib/theme/ApiDemoPanel/Accept/index.js +1 -10
- package/lib/theme/ApiDemoPanel/Accept/slice.js +1 -2
- package/lib/theme/ApiDemoPanel/Authorization/auth-types.js +7 -8
- package/lib/theme/ApiDemoPanel/Authorization/index.js +1 -19
- package/lib/theme/ApiDemoPanel/Authorization/slice.js +7 -21
- package/lib/theme/ApiDemoPanel/Body/index.js +14 -47
- package/lib/theme/ApiDemoPanel/Body/slice.js +1 -4
- package/lib/theme/ApiDemoPanel/CodeTabs/index.js +14 -46
- package/lib/theme/ApiDemoPanel/ContentType/index.js +1 -10
- package/lib/theme/ApiDemoPanel/ContentType/slice.js +1 -2
- package/lib/theme/ApiDemoPanel/Curl/index.js +9 -29
- package/lib/theme/ApiDemoPanel/Execute/index.js +6 -23
- package/lib/theme/ApiDemoPanel/Execute/makeRequest.js +4 -27
- package/lib/theme/ApiDemoPanel/Export/index.js +1 -8
- package/lib/theme/ApiDemoPanel/FloatingButton/index.js +1 -5
- package/lib/theme/ApiDemoPanel/FormFileUpload/index.js +1 -14
- package/lib/theme/ApiDemoPanel/FormItem/index.js +1 -5
- package/lib/theme/ApiDemoPanel/FormMultiSelect/index.js +1 -8
- package/lib/theme/ApiDemoPanel/FormSelect/index.js +1 -6
- package/lib/theme/ApiDemoPanel/FormTextInput/index.js +1 -6
- package/lib/theme/ApiDemoPanel/LiveEditor/index.js +3 -17
- package/lib/theme/ApiDemoPanel/MethodEndpoint/index.js +1 -12
- package/lib/theme/ApiDemoPanel/ParamOptions/index.js +20 -52
- package/lib/theme/ApiDemoPanel/ParamOptions/slice.js +1 -2
- package/lib/theme/ApiDemoPanel/Request/index.js +1 -15
- package/lib/theme/ApiDemoPanel/Response/index.js +1 -14
- package/lib/theme/ApiDemoPanel/Response/slice.js +1 -2
- package/lib/theme/ApiDemoPanel/SecuritySchemes/index.js +1 -9
- package/lib/theme/ApiDemoPanel/Server/index.js +3 -27
- package/lib/theme/ApiDemoPanel/Server/slice.js +1 -3
- package/lib/theme/ApiDemoPanel/buildPostmanRequest.js +11 -62
- package/lib/theme/ApiDemoPanel/index.js +2 -14
- package/lib/theme/ApiDemoPanel/persistanceMiddleware.js +5 -11
- package/lib/theme/ApiDemoPanel/storage-utils.js +1 -7
- package/lib/theme/ApiItem/Layout/index.js +5 -22
- package/lib/theme/ApiItem/Layout/styles.module.css +0 -403
- package/lib/theme/ApiItem/hooks.js +1 -3
- package/lib/theme/ApiItem/index.js +14 -30
- package/lib/theme/ApiItem/store.js +1 -14
- package/lib/theme/ApiLogo/index.js +1 -4
- package/lib/theme/styles.css +428 -0
- package/lib/theme-classic.d.ts +5 -0
- package/lib-next/index.js +5 -3
- package/lib-next/markdown/createDescription.js +1 -1
- package/lib-next/markdown/schema.js +7 -35
- package/lib-next/markdown/utils.js +1 -4
- package/lib-next/theme/ApiDemoPanel/Accept/index.js +1 -4
- package/lib-next/theme/ApiDemoPanel/Accept/slice.js +1 -0
- package/lib-next/theme/ApiDemoPanel/Authorization/auth-types.js +7 -4
- package/lib-next/theme/ApiDemoPanel/Authorization/index.js +1 -8
- package/lib-next/theme/ApiDemoPanel/Authorization/slice.js +12 -14
- package/lib-next/theme/ApiDemoPanel/Body/index.js +16 -34
- package/lib-next/theme/ApiDemoPanel/Body/slice.js +1 -2
- package/lib-next/theme/ApiDemoPanel/CodeTabs/index.js +12 -26
- package/lib-next/theme/ApiDemoPanel/ContentType/index.js +1 -4
- package/lib-next/theme/ApiDemoPanel/ContentType/slice.js +1 -0
- package/lib-next/theme/ApiDemoPanel/Curl/index.js +11 -12
- package/lib-next/theme/ApiDemoPanel/Execute/index.js +10 -13
- package/lib-next/theme/ApiDemoPanel/Execute/makeRequest.js +4 -22
- package/lib-next/theme/ApiDemoPanel/Export/index.js +1 -5
- package/lib-next/theme/ApiDemoPanel/FloatingButton/index.js +1 -2
- package/lib-next/theme/ApiDemoPanel/FormFileUpload/index.js +1 -7
- package/lib-next/theme/ApiDemoPanel/FormItem/index.js +1 -2
- package/lib-next/theme/ApiDemoPanel/FormMultiSelect/index.js +1 -5
- package/lib-next/theme/ApiDemoPanel/FormSelect/index.js +1 -3
- package/lib-next/theme/ApiDemoPanel/FormTextInput/index.js +1 -2
- package/lib-next/theme/ApiDemoPanel/LiveEditor/index.js +3 -6
- package/lib-next/theme/ApiDemoPanel/MethodEndpoint/index.js +1 -9
- package/lib-next/theme/ApiDemoPanel/ParamOptions/index.js +34 -29
- package/lib-next/theme/ApiDemoPanel/ParamOptions/slice.js +1 -0
- package/lib-next/theme/ApiDemoPanel/Request/index.js +1 -2
- package/lib-next/theme/ApiDemoPanel/Response/index.js +3 -9
- package/lib-next/theme/ApiDemoPanel/Response/slice.js +1 -0
- package/lib-next/theme/ApiDemoPanel/SecuritySchemes/index.js +1 -5
- package/lib-next/theme/ApiDemoPanel/Server/index.js +3 -13
- package/lib-next/theme/ApiDemoPanel/Server/slice.js +1 -0
- package/lib-next/theme/ApiDemoPanel/buildPostmanRequest.js +12 -49
- package/lib-next/theme/ApiDemoPanel/index.js +2 -4
- package/lib-next/theme/ApiDemoPanel/persistanceMiddleware.js +5 -6
- package/lib-next/theme/ApiDemoPanel/storage-utils.js +1 -3
- package/lib-next/theme/ApiItem/Layout/index.js +8 -9
- package/lib-next/theme/ApiItem/Layout/styles.module.css +0 -403
- package/lib-next/theme/ApiItem/hooks.js +1 -0
- package/lib-next/theme/ApiItem/index.js +14 -13
- package/lib-next/theme/ApiItem/store.js +1 -0
- package/lib-next/theme/ApiLogo/index.js +1 -0
- package/lib-next/theme/styles.css +428 -0
- package/lib-next/theme-classic.d.ts +5 -0
- package/package.json +5 -5
- package/src/index.ts +5 -0
- package/src/theme/ApiDemoPanel/Execute/index.tsx +1 -0
- package/src/theme/ApiDemoPanel/index.tsx +1 -2
- package/src/theme/ApiItem/Layout/index.tsx +5 -6
- package/src/theme/ApiItem/Layout/styles.module.css +0 -403
- package/src/theme/ApiItem/index.tsx +5 -4
- package/src/theme/styles.css +428 -0
- package/src/theme-classic.d.ts +5 -0
- package/lib/theme/ApiDemoPanel/styles.module.css +0 -44
- package/lib/theme/ApiItem/Content/index.js +0 -65
- package/lib/theme/ApiItem/Footer/index.js +0 -78
- package/lib/theme/ApiItem/Footer/styles.module.css +0 -18
- package/lib/theme/ApiItem/Metadata/index.js +0 -32
- package/lib/theme/ApiItem/Paginator/index.js +0 -33
- package/lib/theme/ApiItem/TOC/Desktop/index.js +0 -31
- package/lib/theme/ApiItem/TOC/Mobile/index.js +0 -35
- package/lib/theme/ApiItem/TOC/Mobile/styles.module.css +0 -19
- package/lib-next/theme/ApiDemoPanel/styles.module.css +0 -44
- package/lib-next/theme/ApiItem/Content/index.js +0 -55
- package/lib-next/theme/ApiItem/Footer/index.js +0 -88
- package/lib-next/theme/ApiItem/Footer/styles.module.css +0 -18
- package/lib-next/theme/ApiItem/Metadata/index.js +0 -21
- package/lib-next/theme/ApiItem/Paginator/index.js +0 -19
- package/lib-next/theme/ApiItem/TOC/Desktop/index.js +0 -22
- package/lib-next/theme/ApiItem/TOC/Mobile/index.js +0 -24
- package/lib-next/theme/ApiItem/TOC/Mobile/styles.module.css +0 -19
- package/src/theme/ApiDemoPanel/styles.module.css +0 -44
- package/src/theme/ApiItem/Content/index.tsx +0 -57
- package/src/theme/ApiItem/Footer/index.tsx +0 -101
- package/src/theme/ApiItem/Footer/styles.module.css +0 -18
- package/src/theme/ApiItem/Metadata/index.tsx +0 -24
- package/src/theme/ApiItem/Paginator/index.tsx +0 -21
- package/src/theme/ApiItem/TOC/Desktop/index.tsx +0 -25
- package/src/theme/ApiItem/TOC/Mobile/index.tsx +0 -28
- package/src/theme/ApiItem/TOC/Mobile/styles.module.css +0 -19
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
* ========================================================================== */
|
|
7
|
+
|
|
7
8
|
import { createSlice } from "@reduxjs/toolkit";
|
|
8
9
|
const initialState = {};
|
|
9
10
|
export const slice = createSlice({
|
|
@@ -4,23 +4,26 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
* ========================================================================== */
|
|
7
|
+
|
|
7
8
|
export function getAuthDataKeys(security) {
|
|
8
9
|
// Bearer Auth
|
|
9
10
|
if (security.type === "http" && security.scheme === "bearer") {
|
|
10
11
|
return ["token"];
|
|
11
12
|
}
|
|
12
|
-
|
|
13
13
|
if (security.type === "oauth2") {
|
|
14
14
|
return ["token"];
|
|
15
|
-
}
|
|
15
|
+
}
|
|
16
16
|
|
|
17
|
+
// Basic Auth
|
|
17
18
|
if (security.type === "http" && security.scheme === "basic") {
|
|
18
19
|
return ["username", "password"];
|
|
19
|
-
}
|
|
20
|
+
}
|
|
20
21
|
|
|
22
|
+
// API Auth
|
|
21
23
|
if (security.type === "apiKey") {
|
|
22
24
|
return ["apiKey"];
|
|
23
|
-
}
|
|
25
|
+
}
|
|
24
26
|
|
|
27
|
+
// none
|
|
25
28
|
return [];
|
|
26
29
|
}
|
|
@@ -4,23 +4,21 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
* ========================================================================== */
|
|
7
|
+
|
|
7
8
|
import React from "react";
|
|
8
9
|
import { useTypedDispatch, useTypedSelector } from "../../ApiItem/hooks";
|
|
9
10
|
import FormItem from "../FormItem";
|
|
10
11
|
import FormSelect from "../FormSelect";
|
|
11
12
|
import FormTextInput from "../FormTextInput";
|
|
12
13
|
import { setAuthData, setSelectedAuth } from "./slice";
|
|
13
|
-
|
|
14
14
|
function Authorization() {
|
|
15
15
|
const data = useTypedSelector((state) => state.auth.data);
|
|
16
16
|
const options = useTypedSelector((state) => state.auth.options);
|
|
17
17
|
const selected = useTypedSelector((state) => state.auth.selected);
|
|
18
18
|
const dispatch = useTypedDispatch();
|
|
19
|
-
|
|
20
19
|
if (selected === undefined) {
|
|
21
20
|
return null;
|
|
22
21
|
}
|
|
23
|
-
|
|
24
22
|
const selectedAuth = options[selected];
|
|
25
23
|
const optionKeys = Object.keys(options);
|
|
26
24
|
return (
|
|
@@ -57,7 +55,6 @@ function Authorization() {
|
|
|
57
55
|
</FormItem>
|
|
58
56
|
);
|
|
59
57
|
}
|
|
60
|
-
|
|
61
58
|
if (a.type === "oauth2") {
|
|
62
59
|
return (
|
|
63
60
|
<FormItem label="Bearer Token" key={a.key + "-oauth2"}>
|
|
@@ -78,7 +75,6 @@ function Authorization() {
|
|
|
78
75
|
</FormItem>
|
|
79
76
|
);
|
|
80
77
|
}
|
|
81
|
-
|
|
82
78
|
if (a.type === "http" && a.scheme === "basic") {
|
|
83
79
|
return (
|
|
84
80
|
<React.Fragment key={a.key + "-basic"}>
|
|
@@ -118,7 +114,6 @@ function Authorization() {
|
|
|
118
114
|
</React.Fragment>
|
|
119
115
|
);
|
|
120
116
|
}
|
|
121
|
-
|
|
122
117
|
if (a.type === "apiKey") {
|
|
123
118
|
return (
|
|
124
119
|
<FormItem label={`${a.key}`} key={a.key + "-apikey"}>
|
|
@@ -139,11 +134,9 @@ function Authorization() {
|
|
|
139
134
|
</FormItem>
|
|
140
135
|
);
|
|
141
136
|
}
|
|
142
|
-
|
|
143
137
|
return null;
|
|
144
138
|
})}
|
|
145
139
|
</div>
|
|
146
140
|
);
|
|
147
141
|
}
|
|
148
|
-
|
|
149
142
|
export default Authorization;
|
|
@@ -4,18 +4,23 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
* ========================================================================== */
|
|
7
|
+
|
|
7
8
|
import { createSlice } from "@reduxjs/toolkit";
|
|
8
9
|
import { createStorage, hashArray } from "../storage-utils";
|
|
9
|
-
import { getAuthDataKeys } from "./auth-types";
|
|
10
|
+
import { getAuthDataKeys } from "./auth-types";
|
|
11
|
+
|
|
12
|
+
// The global definitions
|
|
10
13
|
// "securitySchemes": {
|
|
11
14
|
// "BearerAuth": { "type": "http", "scheme": "BeAreR" },
|
|
12
15
|
// "BasicAuth": { "type": "http", "scheme": "basic" }
|
|
13
16
|
// },
|
|
17
|
+
|
|
14
18
|
// The operation level requirements
|
|
15
19
|
// "security": [
|
|
16
20
|
// { "BearerAuth": [] },
|
|
17
21
|
// { "BearerAuth": [], "BasicAuth": [] }
|
|
18
22
|
// ],
|
|
23
|
+
|
|
19
24
|
// SLICE_STATE
|
|
20
25
|
// data:
|
|
21
26
|
// BearerAuth:
|
|
@@ -29,6 +34,7 @@ import { getAuthDataKeys } from "./auth-types"; // The global definitions
|
|
|
29
34
|
// "BearerAuth and BasicAuth": [{ key: "BearerAuth", scopes: [], ...rest }, { key: "BasicAuth", scopes: [], ...rest }]
|
|
30
35
|
//
|
|
31
36
|
// selected: "BearerAuth and BasicAuth"
|
|
37
|
+
|
|
32
38
|
// LOCAL_STORAGE
|
|
33
39
|
// hash(SLICE_STATE.options) -> "BearerAuth and BasicAuth"
|
|
34
40
|
// BearerAuth -> { token: xxx }
|
|
@@ -38,45 +44,37 @@ export function createAuth({ security, securitySchemes, options: opts }) {
|
|
|
38
44
|
const storage = createStorage("sessionStorage");
|
|
39
45
|
let data = {};
|
|
40
46
|
let options = {};
|
|
41
|
-
|
|
42
47
|
for (const option of security ?? []) {
|
|
43
48
|
const id = Object.keys(option).join(" and ");
|
|
44
|
-
|
|
45
49
|
for (const [schemeID, scopes] of Object.entries(option)) {
|
|
46
50
|
const scheme = securitySchemes?.[schemeID];
|
|
47
|
-
|
|
48
51
|
if (scheme) {
|
|
49
52
|
if (options[id] === undefined) {
|
|
50
53
|
options[id] = [];
|
|
51
54
|
}
|
|
52
|
-
|
|
53
55
|
const dataKeys = getAuthDataKeys(scheme);
|
|
54
|
-
|
|
55
56
|
for (const key of dataKeys) {
|
|
56
57
|
if (data[schemeID] === undefined) {
|
|
57
58
|
data[schemeID] = {};
|
|
58
59
|
}
|
|
59
|
-
|
|
60
60
|
let persisted = undefined;
|
|
61
|
-
|
|
62
61
|
try {
|
|
63
62
|
persisted = JSON.parse(storage.getItem(schemeID) ?? "")[key];
|
|
64
63
|
} catch {}
|
|
65
|
-
|
|
66
64
|
data[schemeID][key] = persisted;
|
|
67
65
|
}
|
|
68
|
-
|
|
69
|
-
|
|
66
|
+
options[id].push({
|
|
67
|
+
...scheme,
|
|
68
|
+
key: schemeID,
|
|
69
|
+
scopes,
|
|
70
|
+
});
|
|
70
71
|
}
|
|
71
72
|
}
|
|
72
73
|
}
|
|
73
|
-
|
|
74
74
|
let persisted = undefined;
|
|
75
|
-
|
|
76
75
|
try {
|
|
77
76
|
persisted = storage.getItem(hashArray(Object.keys(options))) ?? undefined;
|
|
78
77
|
} catch {}
|
|
79
|
-
|
|
80
78
|
return {
|
|
81
79
|
data,
|
|
82
80
|
options,
|
|
@@ -4,19 +4,20 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
* ========================================================================== */
|
|
7
|
+
|
|
7
8
|
import React from "react";
|
|
8
9
|
import TabItem from "@theme/TabItem";
|
|
9
10
|
import format from "xml-formatter";
|
|
10
|
-
import { useTypedDispatch, useTypedSelector } from "../../ApiItem/hooks";
|
|
11
|
-
|
|
11
|
+
import { useTypedDispatch, useTypedSelector } from "../../ApiItem/hooks";
|
|
12
|
+
// @ts-ignore
|
|
12
13
|
import SchemaTabs from "../../SchemaTabs";
|
|
13
14
|
import ContentType from "../ContentType";
|
|
14
15
|
import FormSelect from "../FormSelect";
|
|
15
16
|
import LiveApp from "../LiveEditor";
|
|
16
17
|
import FormFileUpload from "./../FormFileUpload";
|
|
17
18
|
import FormItem from "./../FormItem";
|
|
18
|
-
import FormTextInput from "./../FormTextInput";
|
|
19
|
-
|
|
19
|
+
import FormTextInput from "./../FormTextInput";
|
|
20
|
+
// @ts-ignore
|
|
20
21
|
import json2xml from "./json2xml";
|
|
21
22
|
import {
|
|
22
23
|
clearFormBodyKey,
|
|
@@ -25,16 +26,16 @@ import {
|
|
|
25
26
|
setFileRawBody,
|
|
26
27
|
setStringFormBody,
|
|
27
28
|
} from "./slice";
|
|
28
|
-
|
|
29
29
|
function BodyWrap({ requestBodyMetadata, jsonRequestBodyExample }) {
|
|
30
|
-
const contentType = useTypedSelector((state) => state.contentType.value);
|
|
30
|
+
const contentType = useTypedSelector((state) => state.contentType.value);
|
|
31
|
+
|
|
32
|
+
// NOTE: We used to check if body was required, but opted to always show the request body
|
|
31
33
|
// to reduce confusion, see: https://github.com/cloud-annotations/docusaurus-openapi/issues/145
|
|
32
|
-
// No body
|
|
33
34
|
|
|
35
|
+
// No body
|
|
34
36
|
if (contentType === undefined) {
|
|
35
37
|
return null;
|
|
36
38
|
}
|
|
37
|
-
|
|
38
39
|
return (
|
|
39
40
|
<>
|
|
40
41
|
<ContentType />
|
|
@@ -45,11 +46,12 @@ function BodyWrap({ requestBodyMetadata, jsonRequestBodyExample }) {
|
|
|
45
46
|
</>
|
|
46
47
|
);
|
|
47
48
|
}
|
|
48
|
-
|
|
49
49
|
function Body({ requestBodyMetadata, jsonRequestBodyExample }) {
|
|
50
50
|
const contentType = useTypedSelector((state) => state.contentType.value);
|
|
51
51
|
const required = requestBodyMetadata?.required;
|
|
52
|
-
const dispatch = useTypedDispatch();
|
|
52
|
+
const dispatch = useTypedDispatch();
|
|
53
|
+
|
|
54
|
+
// Lot's of possible content-types:
|
|
53
55
|
// - application/json
|
|
54
56
|
// - application/xml
|
|
55
57
|
// - text/plain
|
|
@@ -60,10 +62,12 @@ function Body({ requestBodyMetadata, jsonRequestBodyExample }) {
|
|
|
60
62
|
// - multipart/form-data
|
|
61
63
|
// - application/x-www-form-urlencoded
|
|
62
64
|
// - image/svg+xml;charset=US-ASCII
|
|
65
|
+
|
|
63
66
|
// Show editor:
|
|
64
67
|
// - application/json
|
|
65
68
|
// - application/xml
|
|
66
69
|
// - */*
|
|
70
|
+
|
|
67
71
|
// Show form:
|
|
68
72
|
// - multipart/form-data
|
|
69
73
|
// - application/x-www-form-urlencoded
|
|
@@ -71,7 +75,6 @@ function Body({ requestBodyMetadata, jsonRequestBodyExample }) {
|
|
|
71
75
|
const schema = requestBodyMetadata?.content?.[contentType]?.schema;
|
|
72
76
|
const example = requestBodyMetadata?.content?.[contentType]?.example;
|
|
73
77
|
const examples = requestBodyMetadata?.content?.[contentType]?.examples;
|
|
74
|
-
|
|
75
78
|
if (schema?.format === "binary") {
|
|
76
79
|
return (
|
|
77
80
|
<FormItem label="Body" required={required}>
|
|
@@ -82,7 +85,6 @@ function Body({ requestBodyMetadata, jsonRequestBodyExample }) {
|
|
|
82
85
|
dispatch(clearRawBody());
|
|
83
86
|
return;
|
|
84
87
|
}
|
|
85
|
-
|
|
86
88
|
dispatch(
|
|
87
89
|
setFileRawBody({
|
|
88
90
|
src: `/path/to/${file.name}`,
|
|
@@ -94,7 +96,6 @@ function Body({ requestBodyMetadata, jsonRequestBodyExample }) {
|
|
|
94
96
|
</FormItem>
|
|
95
97
|
);
|
|
96
98
|
}
|
|
97
|
-
|
|
98
99
|
if (
|
|
99
100
|
(contentType === "multipart/form-data" ||
|
|
100
101
|
contentType === "application/x-www-form-urlencoded") &&
|
|
@@ -128,7 +129,6 @@ function Body({ requestBodyMetadata, jsonRequestBodyExample }) {
|
|
|
128
129
|
dispatch(clearFormBodyKey(key));
|
|
129
130
|
return;
|
|
130
131
|
}
|
|
131
|
-
|
|
132
132
|
dispatch(
|
|
133
133
|
setFileFormBody({
|
|
134
134
|
key: key,
|
|
@@ -143,7 +143,6 @@ function Body({ requestBodyMetadata, jsonRequestBodyExample }) {
|
|
|
143
143
|
</FormItem>
|
|
144
144
|
);
|
|
145
145
|
}
|
|
146
|
-
|
|
147
146
|
if (val.enum) {
|
|
148
147
|
return (
|
|
149
148
|
<FormItem
|
|
@@ -158,7 +157,6 @@ function Body({ requestBodyMetadata, jsonRequestBodyExample }) {
|
|
|
158
157
|
options={["---", ...val.enum]}
|
|
159
158
|
onChange={(e) => {
|
|
160
159
|
const val = e.target.value;
|
|
161
|
-
|
|
162
160
|
if (val === "---") {
|
|
163
161
|
dispatch(clearFormBodyKey(key));
|
|
164
162
|
} else {
|
|
@@ -173,8 +171,8 @@ function Body({ requestBodyMetadata, jsonRequestBodyExample }) {
|
|
|
173
171
|
/>
|
|
174
172
|
</FormItem>
|
|
175
173
|
);
|
|
176
|
-
}
|
|
177
|
-
|
|
174
|
+
}
|
|
175
|
+
// TODO: support all the other types.
|
|
178
176
|
return (
|
|
179
177
|
<FormItem
|
|
180
178
|
key={key}
|
|
@@ -202,22 +200,17 @@ function Body({ requestBodyMetadata, jsonRequestBodyExample }) {
|
|
|
202
200
|
</FormItem>
|
|
203
201
|
);
|
|
204
202
|
}
|
|
205
|
-
|
|
206
203
|
let language = "plaintext";
|
|
207
204
|
let defaultBody = ""; //"body content";
|
|
208
|
-
|
|
209
205
|
let exampleBody;
|
|
210
206
|
let examplesBodies = [];
|
|
211
|
-
|
|
212
207
|
if (contentType === "application/json" || contentType.endsWith("+json")) {
|
|
213
208
|
if (jsonRequestBodyExample) {
|
|
214
209
|
defaultBody = JSON.stringify(jsonRequestBodyExample, null, 2);
|
|
215
210
|
}
|
|
216
|
-
|
|
217
211
|
if (example) {
|
|
218
212
|
exampleBody = JSON.stringify(example, null, 2);
|
|
219
213
|
}
|
|
220
|
-
|
|
221
214
|
if (examples) {
|
|
222
215
|
for (const [key, example] of Object.entries(examples)) {
|
|
223
216
|
examplesBodies.push({
|
|
@@ -227,10 +220,8 @@ function Body({ requestBodyMetadata, jsonRequestBodyExample }) {
|
|
|
227
220
|
});
|
|
228
221
|
}
|
|
229
222
|
}
|
|
230
|
-
|
|
231
223
|
language = "json";
|
|
232
224
|
}
|
|
233
|
-
|
|
234
225
|
if (contentType === "application/xml" || contentType.endsWith("+xml")) {
|
|
235
226
|
if (jsonRequestBodyExample) {
|
|
236
227
|
try {
|
|
@@ -243,7 +234,6 @@ function Body({ requestBodyMetadata, jsonRequestBodyExample }) {
|
|
|
243
234
|
defaultBody = json2xml(jsonRequestBodyExample);
|
|
244
235
|
}
|
|
245
236
|
}
|
|
246
|
-
|
|
247
237
|
if (example) {
|
|
248
238
|
try {
|
|
249
239
|
exampleBody = format(json2xml(example, ""), {
|
|
@@ -255,11 +245,9 @@ function Body({ requestBodyMetadata, jsonRequestBodyExample }) {
|
|
|
255
245
|
exampleBody = json2xml(example);
|
|
256
246
|
}
|
|
257
247
|
}
|
|
258
|
-
|
|
259
248
|
if (examples) {
|
|
260
249
|
for (const [key, example] of Object.entries(examples)) {
|
|
261
250
|
let formattedXmlBody;
|
|
262
|
-
|
|
263
251
|
try {
|
|
264
252
|
formattedXmlBody = format(example.value, {
|
|
265
253
|
indentation: " ",
|
|
@@ -269,7 +257,6 @@ function Body({ requestBodyMetadata, jsonRequestBodyExample }) {
|
|
|
269
257
|
} catch {
|
|
270
258
|
formattedXmlBody = example.value;
|
|
271
259
|
}
|
|
272
|
-
|
|
273
260
|
examplesBodies.push({
|
|
274
261
|
label: key,
|
|
275
262
|
body: formattedXmlBody,
|
|
@@ -277,10 +264,8 @@ function Body({ requestBodyMetadata, jsonRequestBodyExample }) {
|
|
|
277
264
|
});
|
|
278
265
|
}
|
|
279
266
|
}
|
|
280
|
-
|
|
281
267
|
language = "xml";
|
|
282
268
|
}
|
|
283
|
-
|
|
284
269
|
if (exampleBody) {
|
|
285
270
|
return (
|
|
286
271
|
<FormItem label="Body" required={required}>
|
|
@@ -301,7 +286,6 @@ function Body({ requestBodyMetadata, jsonRequestBodyExample }) {
|
|
|
301
286
|
</FormItem>
|
|
302
287
|
);
|
|
303
288
|
}
|
|
304
|
-
|
|
305
289
|
if (examplesBodies && examplesBodies.length > 0) {
|
|
306
290
|
return (
|
|
307
291
|
<FormItem label="Body" required={required}>
|
|
@@ -331,7 +315,6 @@ function Body({ requestBodyMetadata, jsonRequestBodyExample }) {
|
|
|
331
315
|
</FormItem>
|
|
332
316
|
);
|
|
333
317
|
}
|
|
334
|
-
|
|
335
318
|
return (
|
|
336
319
|
<FormItem label="Body" required={required}>
|
|
337
320
|
<LiveApp action={dispatch} language={language}>
|
|
@@ -340,5 +323,4 @@ function Body({ requestBodyMetadata, jsonRequestBodyExample }) {
|
|
|
340
323
|
</FormItem>
|
|
341
324
|
);
|
|
342
325
|
}
|
|
343
|
-
|
|
344
326
|
export default BodyWrap;
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
* ========================================================================== */
|
|
7
|
+
|
|
7
8
|
import { createSlice } from "@reduxjs/toolkit";
|
|
8
9
|
const initialState = {};
|
|
9
10
|
export const slice = createSlice({
|
|
@@ -50,7 +51,6 @@ export const slice = createSlice({
|
|
|
50
51
|
},
|
|
51
52
|
};
|
|
52
53
|
}
|
|
53
|
-
|
|
54
54
|
state.content[action.payload.key] = {
|
|
55
55
|
type: "string",
|
|
56
56
|
value: action.payload.value,
|
|
@@ -69,7 +69,6 @@ export const slice = createSlice({
|
|
|
69
69
|
},
|
|
70
70
|
};
|
|
71
71
|
}
|
|
72
|
-
|
|
73
72
|
state.content[action.payload.key] = {
|
|
74
73
|
type: "file",
|
|
75
74
|
value: action.payload.value,
|
|
@@ -4,23 +4,23 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
* ========================================================================== */
|
|
7
|
+
|
|
7
8
|
import React, { useState, cloneElement, isValidElement } from "react";
|
|
8
9
|
import { duplicates } from "@docusaurus/theme-common";
|
|
9
10
|
import useIsBrowser from "@docusaurus/useIsBrowser";
|
|
10
11
|
import clsx from "clsx";
|
|
11
12
|
import { languageSet } from "../Curl";
|
|
12
13
|
import styles from "./styles.module.css";
|
|
13
|
-
|
|
14
14
|
const {
|
|
15
15
|
useScrollPositionBlocker,
|
|
16
16
|
useTabGroupChoice,
|
|
17
|
-
} = require("@docusaurus/theme-common/internal");
|
|
18
|
-
// allowing customization
|
|
17
|
+
} = require("@docusaurus/theme-common/internal");
|
|
19
18
|
|
|
19
|
+
// A very rough duck type, but good enough to guard against mistakes while
|
|
20
|
+
// allowing customization
|
|
20
21
|
function isTabItem(comp) {
|
|
21
22
|
return "value" in comp.props;
|
|
22
23
|
}
|
|
23
|
-
|
|
24
24
|
function TabsComponent(props) {
|
|
25
25
|
const {
|
|
26
26
|
lazy,
|
|
@@ -34,9 +34,9 @@ function TabsComponent(props) {
|
|
|
34
34
|
const children = React.Children.map(props.children, (child) => {
|
|
35
35
|
if (isValidElement(child) && isTabItem(child)) {
|
|
36
36
|
return child;
|
|
37
|
-
}
|
|
37
|
+
}
|
|
38
|
+
// child.type.name will give non-sensical values in prod because of
|
|
38
39
|
// minification, but we assume it won't throw in prod.
|
|
39
|
-
|
|
40
40
|
throw new Error(
|
|
41
41
|
`Docusaurus error: Bad <Tabs> child <${
|
|
42
42
|
// @ts-expect-error: guarding against unexpected cases
|
|
@@ -45,29 +45,28 @@ function TabsComponent(props) {
|
|
|
45
45
|
);
|
|
46
46
|
});
|
|
47
47
|
const values =
|
|
48
|
-
valuesProp ??
|
|
48
|
+
valuesProp ??
|
|
49
|
+
// Only pick keys that we recognize. MDX would inject some keys by default
|
|
49
50
|
children.map(({ props: { value, label, attributes } }) => ({
|
|
50
51
|
value,
|
|
51
52
|
label,
|
|
52
53
|
attributes,
|
|
53
54
|
}));
|
|
54
55
|
const dup = duplicates(values, (a, b) => a.value === b.value);
|
|
55
|
-
|
|
56
56
|
if (dup.length > 0) {
|
|
57
57
|
throw new Error(
|
|
58
58
|
`Docusaurus error: Duplicate values "${dup
|
|
59
59
|
.map((a) => a.value)
|
|
60
60
|
.join(", ")}" found in <Tabs>. Every value needs to be unique.`
|
|
61
61
|
);
|
|
62
|
-
}
|
|
63
|
-
|
|
62
|
+
}
|
|
63
|
+
// When defaultValueProp is null, don't show a default tab
|
|
64
64
|
const defaultValue =
|
|
65
65
|
defaultValueProp === null
|
|
66
66
|
? defaultValueProp
|
|
67
67
|
: defaultValueProp ??
|
|
68
68
|
children.find((child) => child.props.default)?.props.value ??
|
|
69
69
|
children[0].props.value;
|
|
70
|
-
|
|
71
70
|
if (defaultValue !== null && !values.some((a) => a.value === defaultValue)) {
|
|
72
71
|
throw new Error(
|
|
73
72
|
`Docusaurus error: The <Tabs> has a defaultValue "${defaultValue}" but none of its children has the corresponding value. Available values are: ${values
|
|
@@ -77,16 +76,13 @@ function TabsComponent(props) {
|
|
|
77
76
|
)}. If you intend to show no default tab, use defaultValue={null} instead.`
|
|
78
77
|
);
|
|
79
78
|
}
|
|
80
|
-
|
|
81
79
|
const { tabGroupChoices, setTabGroupChoices } = useTabGroupChoice();
|
|
82
80
|
const [selectedValue, setSelectedValue] = useState(defaultValue);
|
|
83
81
|
const tabRefs = [];
|
|
84
82
|
const { blockElementScrollPositionUntilNextRender } =
|
|
85
83
|
useScrollPositionBlocker();
|
|
86
|
-
|
|
87
84
|
if (groupId != null) {
|
|
88
85
|
const relevantTabGroupChoice = tabGroupChoices[groupId];
|
|
89
|
-
|
|
90
86
|
if (
|
|
91
87
|
relevantTabGroupChoice != null &&
|
|
92
88
|
relevantTabGroupChoice !== selectedValue &&
|
|
@@ -95,52 +91,42 @@ function TabsComponent(props) {
|
|
|
95
91
|
setSelectedValue(relevantTabGroupChoice);
|
|
96
92
|
}
|
|
97
93
|
}
|
|
98
|
-
|
|
99
94
|
const handleTabChange = (event) => {
|
|
100
95
|
const newTab = event.currentTarget;
|
|
101
96
|
const newTabIndex = tabRefs.indexOf(newTab);
|
|
102
97
|
const newTabValue = values[newTabIndex].value;
|
|
103
|
-
|
|
104
98
|
if (newTabValue !== selectedValue) {
|
|
105
99
|
blockElementScrollPositionUntilNextRender(newTab);
|
|
106
100
|
setSelectedValue(newTabValue);
|
|
107
|
-
|
|
108
101
|
if (action) {
|
|
109
102
|
const newLanguage = languageSet.filter(
|
|
110
103
|
(lang) => lang.language === newTabValue
|
|
111
104
|
);
|
|
112
105
|
action(newLanguage[0]);
|
|
113
106
|
}
|
|
114
|
-
|
|
115
107
|
if (groupId != null) {
|
|
116
108
|
setTabGroupChoices(groupId, String(newTabValue));
|
|
117
109
|
}
|
|
118
110
|
}
|
|
119
111
|
};
|
|
120
|
-
|
|
121
112
|
const handleKeydown = (event) => {
|
|
122
113
|
let focusElement = null;
|
|
123
|
-
|
|
124
114
|
switch (event.key) {
|
|
125
115
|
case "ArrowRight": {
|
|
126
116
|
const nextTab = tabRefs.indexOf(event.currentTarget) + 1;
|
|
127
117
|
focusElement = tabRefs[nextTab] ?? tabRefs[0];
|
|
128
118
|
break;
|
|
129
119
|
}
|
|
130
|
-
|
|
131
120
|
case "ArrowLeft": {
|
|
132
121
|
const prevTab = tabRefs.indexOf(event.currentTarget) - 1;
|
|
133
122
|
focusElement = tabRefs[prevTab] ?? tabRefs[tabRefs.length - 1];
|
|
134
123
|
break;
|
|
135
124
|
}
|
|
136
|
-
|
|
137
125
|
default:
|
|
138
126
|
break;
|
|
139
127
|
}
|
|
140
|
-
|
|
141
128
|
focusElement?.focus();
|
|
142
129
|
};
|
|
143
|
-
|
|
144
130
|
return (
|
|
145
131
|
<div className={clsx("tabs-container", styles.tabList)}>
|
|
146
132
|
<ul
|
|
@@ -202,11 +188,11 @@ function TabsComponent(props) {
|
|
|
202
188
|
</div>
|
|
203
189
|
);
|
|
204
190
|
}
|
|
205
|
-
|
|
206
191
|
export default function CodeTabs(props) {
|
|
207
192
|
const isBrowser = useIsBrowser();
|
|
208
193
|
return (
|
|
209
|
-
<TabsComponent
|
|
194
|
+
<TabsComponent
|
|
195
|
+
// Remount tabs after hydration
|
|
210
196
|
// Temporary fix for https://github.com/facebook/docusaurus/issues/5653
|
|
211
197
|
key={String(isBrowser)}
|
|
212
198
|
{...props}
|
|
@@ -4,21 +4,19 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
* ========================================================================== */
|
|
7
|
+
|
|
7
8
|
import React from "react";
|
|
8
9
|
import { useTypedDispatch, useTypedSelector } from "../../ApiItem/hooks";
|
|
9
10
|
import FormItem from "./../FormItem";
|
|
10
11
|
import FormSelect from "./../FormSelect";
|
|
11
12
|
import { setContentType } from "./slice";
|
|
12
|
-
|
|
13
13
|
function ContentType() {
|
|
14
14
|
const value = useTypedSelector((state) => state.contentType.value);
|
|
15
15
|
const options = useTypedSelector((state) => state.contentType.options);
|
|
16
16
|
const dispatch = useTypedDispatch();
|
|
17
|
-
|
|
18
17
|
if (options.length <= 1) {
|
|
19
18
|
return null;
|
|
20
19
|
}
|
|
21
|
-
|
|
22
20
|
return (
|
|
23
21
|
<FormItem label="Content-Type">
|
|
24
22
|
<FormSelect
|
|
@@ -29,5 +27,4 @@ function ContentType() {
|
|
|
29
27
|
</FormItem>
|
|
30
28
|
);
|
|
31
29
|
}
|
|
32
|
-
|
|
33
30
|
export default ContentType;
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
* ========================================================================== */
|
|
7
|
+
|
|
7
8
|
import { createSlice } from "@reduxjs/toolkit";
|
|
8
9
|
const initialState = {};
|
|
9
10
|
export const slice = createSlice({
|