docusaurus-theme-openapi-docs 0.0.0-1084 → 0.0.0-1085
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/ApiExplorer/Body/FileArrayFormBodyItem/index.d.ts +7 -0
- package/lib/theme/ApiExplorer/Body/FileArrayFormBodyItem/index.js +126 -0
- package/lib/theme/ApiExplorer/Body/FormBodyItem/index.d.ts +9 -0
- package/lib/theme/ApiExplorer/Body/FormBodyItem/index.js +110 -0
- package/lib/theme/ApiExplorer/Body/index.js +42 -97
- package/lib/theme/ApiExplorer/Body/slice.d.ts +27 -2
- package/lib/theme/ApiExplorer/Body/slice.js +22 -2
- package/lib/theme/ApiExplorer/LiveEditor/index.js +2 -3
- package/lib/theme/ApiExplorer/buildPostmanRequest.js +23 -7
- package/package.json +3 -3
- package/src/theme/ApiExplorer/Body/FileArrayFormBodyItem/index.tsx +77 -0
- package/src/theme/ApiExplorer/Body/FormBodyItem/index.tsx +120 -0
- package/src/theme/ApiExplorer/Body/index.tsx +39 -104
- package/src/theme/ApiExplorer/Body/slice.ts +40 -1
- package/src/theme/ApiExplorer/LiveEditor/index.tsx +2 -3
- package/src/theme/ApiExplorer/buildPostmanRequest.ts +23 -7
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* ============================================================================
|
|
3
|
+
* Copyright (c) Palo Alto Networks
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
* ========================================================================== */
|
|
8
|
+
var __createBinding =
|
|
9
|
+
(this && this.__createBinding) ||
|
|
10
|
+
(Object.create
|
|
11
|
+
? function (o, m, k, k2) {
|
|
12
|
+
if (k2 === undefined) k2 = k;
|
|
13
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
14
|
+
if (
|
|
15
|
+
!desc ||
|
|
16
|
+
("get" in desc ? !m.__esModule : desc.writable || desc.configurable)
|
|
17
|
+
) {
|
|
18
|
+
desc = {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return m[k];
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
Object.defineProperty(o, k2, desc);
|
|
26
|
+
}
|
|
27
|
+
: function (o, m, k, k2) {
|
|
28
|
+
if (k2 === undefined) k2 = k;
|
|
29
|
+
o[k2] = m[k];
|
|
30
|
+
});
|
|
31
|
+
var __setModuleDefault =
|
|
32
|
+
(this && this.__setModuleDefault) ||
|
|
33
|
+
(Object.create
|
|
34
|
+
? function (o, v) {
|
|
35
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
36
|
+
}
|
|
37
|
+
: function (o, v) {
|
|
38
|
+
o["default"] = v;
|
|
39
|
+
});
|
|
40
|
+
var __importStar =
|
|
41
|
+
(this && this.__importStar) ||
|
|
42
|
+
(function () {
|
|
43
|
+
var ownKeys = function (o) {
|
|
44
|
+
ownKeys =
|
|
45
|
+
Object.getOwnPropertyNames ||
|
|
46
|
+
function (o) {
|
|
47
|
+
var ar = [];
|
|
48
|
+
for (var k in o)
|
|
49
|
+
if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
50
|
+
return ar;
|
|
51
|
+
};
|
|
52
|
+
return ownKeys(o);
|
|
53
|
+
};
|
|
54
|
+
return function (mod) {
|
|
55
|
+
if (mod && mod.__esModule) return mod;
|
|
56
|
+
var result = {};
|
|
57
|
+
if (mod != null)
|
|
58
|
+
for (var k = ownKeys(mod), i = 0; i < k.length; i++)
|
|
59
|
+
if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
60
|
+
__setModuleDefault(result, mod);
|
|
61
|
+
return result;
|
|
62
|
+
};
|
|
63
|
+
})();
|
|
64
|
+
var __importDefault =
|
|
65
|
+
(this && this.__importDefault) ||
|
|
66
|
+
function (mod) {
|
|
67
|
+
return mod && mod.__esModule ? mod : { default: mod };
|
|
68
|
+
};
|
|
69
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
70
|
+
exports.default = FileArrayFormBodyItem;
|
|
71
|
+
const react_1 = __importStar(require("react"));
|
|
72
|
+
const FormFileUpload_1 = __importDefault(
|
|
73
|
+
require("@theme/ApiExplorer/FormFileUpload")
|
|
74
|
+
);
|
|
75
|
+
const hooks_1 = require("@theme/ApiItem/hooks");
|
|
76
|
+
const slice_1 = require("../slice");
|
|
77
|
+
function FileArrayFormBodyItem({ id, description }) {
|
|
78
|
+
const dispatch = (0, hooks_1.useTypedDispatch)();
|
|
79
|
+
const [fileItems, setFileItems] = (0, react_1.useState)(
|
|
80
|
+
new Map([[0, undefined]])
|
|
81
|
+
);
|
|
82
|
+
const handleFileChange = (index, file) => {
|
|
83
|
+
const newItems = new Map(fileItems);
|
|
84
|
+
if (file === undefined) {
|
|
85
|
+
newItems.delete(index);
|
|
86
|
+
setFileItems(newItems);
|
|
87
|
+
dispatch(
|
|
88
|
+
(0, slice_1.setFileArrayFormBody)({
|
|
89
|
+
key: id,
|
|
90
|
+
value: [...newItems.values()].filter((item) => item !== undefined),
|
|
91
|
+
})
|
|
92
|
+
);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
let maxIndex = 0;
|
|
96
|
+
newItems.keys().forEach((item) => {
|
|
97
|
+
maxIndex = item > maxIndex ? item : maxIndex;
|
|
98
|
+
});
|
|
99
|
+
newItems.set(index, {
|
|
100
|
+
src: `/path/to/${file.name}`,
|
|
101
|
+
content: file,
|
|
102
|
+
});
|
|
103
|
+
newItems.set(index + 1, undefined);
|
|
104
|
+
setFileItems(newItems);
|
|
105
|
+
dispatch(
|
|
106
|
+
(0, slice_1.setFileArrayFormBody)({
|
|
107
|
+
key: id,
|
|
108
|
+
value: [...newItems.values()].filter((item) => item !== undefined),
|
|
109
|
+
})
|
|
110
|
+
);
|
|
111
|
+
};
|
|
112
|
+
return react_1.default.createElement(
|
|
113
|
+
"div",
|
|
114
|
+
null,
|
|
115
|
+
[...fileItems.keys()].map((index) =>
|
|
116
|
+
react_1.default.createElement(
|
|
117
|
+
"div",
|
|
118
|
+
{ key: index },
|
|
119
|
+
react_1.default.createElement(FormFileUpload_1.default, {
|
|
120
|
+
placeholder: description || id,
|
|
121
|
+
onChange: (file) => handleFileChange(index, file),
|
|
122
|
+
})
|
|
123
|
+
)
|
|
124
|
+
)
|
|
125
|
+
);
|
|
126
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { SchemaObject } from "docusaurus-plugin-openapi-docs/src/openapi/types";
|
|
3
|
+
interface FormBodyItemProps {
|
|
4
|
+
schemaObject: SchemaObject;
|
|
5
|
+
id: string;
|
|
6
|
+
schema: SchemaObject;
|
|
7
|
+
}
|
|
8
|
+
export default function FormBodyItem({ schemaObject, id, schema, }: FormBodyItemProps): React.JSX.Element;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* ============================================================================
|
|
3
|
+
* Copyright (c) Palo Alto Networks
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
* ========================================================================== */
|
|
8
|
+
var __importDefault =
|
|
9
|
+
(this && this.__importDefault) ||
|
|
10
|
+
function (mod) {
|
|
11
|
+
return mod && mod.__esModule ? mod : { default: mod };
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.default = FormBodyItem;
|
|
15
|
+
const react_1 = __importDefault(require("react"));
|
|
16
|
+
const FormFileUpload_1 = __importDefault(
|
|
17
|
+
require("@theme/ApiExplorer/FormFileUpload")
|
|
18
|
+
);
|
|
19
|
+
const FormSelect_1 = __importDefault(require("@theme/ApiExplorer/FormSelect"));
|
|
20
|
+
const FormTextInput_1 = __importDefault(
|
|
21
|
+
require("@theme/ApiExplorer/FormTextInput")
|
|
22
|
+
);
|
|
23
|
+
const LiveEditor_1 = __importDefault(require("@theme/ApiExplorer/LiveEditor"));
|
|
24
|
+
const hooks_1 = require("@theme/ApiItem/hooks");
|
|
25
|
+
const slice_1 = require("../slice");
|
|
26
|
+
const FileArrayFormBodyItem_1 = __importDefault(
|
|
27
|
+
require("../FileArrayFormBodyItem")
|
|
28
|
+
);
|
|
29
|
+
function FormBodyItem({ schemaObject, id, schema }) {
|
|
30
|
+
const dispatch = (0, hooks_1.useTypedDispatch)();
|
|
31
|
+
if (
|
|
32
|
+
schemaObject.type === "array" &&
|
|
33
|
+
schemaObject.items?.format === "binary"
|
|
34
|
+
) {
|
|
35
|
+
return react_1.default.createElement(FileArrayFormBodyItem_1.default, {
|
|
36
|
+
id: id,
|
|
37
|
+
description: schemaObject.description,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
if (schemaObject.format === "binary") {
|
|
41
|
+
return react_1.default.createElement(FormFileUpload_1.default, {
|
|
42
|
+
placeholder: schemaObject.description || id,
|
|
43
|
+
onChange: (file) => {
|
|
44
|
+
if (file === undefined) {
|
|
45
|
+
dispatch((0, slice_1.clearFormBodyKey)(id));
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
dispatch(
|
|
49
|
+
(0, slice_1.setFileFormBody)({
|
|
50
|
+
key: id,
|
|
51
|
+
value: {
|
|
52
|
+
src: `/path/to/${file.name}`,
|
|
53
|
+
content: file,
|
|
54
|
+
},
|
|
55
|
+
})
|
|
56
|
+
);
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
if (
|
|
61
|
+
schemaObject.type === "object" &&
|
|
62
|
+
(schemaObject.example || schemaObject.examples)
|
|
63
|
+
) {
|
|
64
|
+
const objectExample = JSON.stringify(
|
|
65
|
+
schemaObject.example ?? schemaObject.examples[0],
|
|
66
|
+
null,
|
|
67
|
+
2
|
|
68
|
+
);
|
|
69
|
+
return react_1.default.createElement(
|
|
70
|
+
LiveEditor_1.default,
|
|
71
|
+
{
|
|
72
|
+
action: (code) =>
|
|
73
|
+
dispatch((0, slice_1.setStringFormBody)({ key: id, value: code })),
|
|
74
|
+
},
|
|
75
|
+
objectExample
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
if (
|
|
79
|
+
schemaObject.enum &&
|
|
80
|
+
schemaObject.enum.every((value) => typeof value === "string")
|
|
81
|
+
) {
|
|
82
|
+
return react_1.default.createElement(FormSelect_1.default, {
|
|
83
|
+
options: ["---", ...schemaObject.enum],
|
|
84
|
+
onChange: (e) => {
|
|
85
|
+
const val = e.target.value;
|
|
86
|
+
if (val === "---") {
|
|
87
|
+
dispatch((0, slice_1.clearFormBodyKey)(id));
|
|
88
|
+
} else {
|
|
89
|
+
dispatch(
|
|
90
|
+
(0, slice_1.setStringFormBody)({
|
|
91
|
+
key: id,
|
|
92
|
+
value: val,
|
|
93
|
+
})
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
// TODO: support all the other types.
|
|
100
|
+
return react_1.default.createElement(FormTextInput_1.default, {
|
|
101
|
+
paramName: id,
|
|
102
|
+
isRequired: Array.isArray(schema.required) && schema.required.includes(id),
|
|
103
|
+
placeholder: schemaObject.description || id,
|
|
104
|
+
onChange: (e) => {
|
|
105
|
+
dispatch(
|
|
106
|
+
(0, slice_1.setStringFormBody)({ key: id, value: e.target.value })
|
|
107
|
+
);
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
}
|
|
@@ -18,10 +18,6 @@ const FormFileUpload_1 = __importDefault(
|
|
|
18
18
|
require("@theme/ApiExplorer/FormFileUpload")
|
|
19
19
|
);
|
|
20
20
|
const FormItem_1 = __importDefault(require("@theme/ApiExplorer/FormItem"));
|
|
21
|
-
const FormSelect_1 = __importDefault(require("@theme/ApiExplorer/FormSelect"));
|
|
22
|
-
const FormTextInput_1 = __importDefault(
|
|
23
|
-
require("@theme/ApiExplorer/FormTextInput")
|
|
24
|
-
);
|
|
25
21
|
const LiveEditor_1 = __importDefault(require("@theme/ApiExplorer/LiveEditor"));
|
|
26
22
|
const hooks_1 = require("@theme/ApiItem/hooks");
|
|
27
23
|
const Markdown_1 = __importDefault(require("@theme/Markdown"));
|
|
@@ -30,6 +26,7 @@ const TabItem_1 = __importDefault(require("@theme/TabItem"));
|
|
|
30
26
|
const translationIds_1 = require("@theme/translationIds");
|
|
31
27
|
const xml_formatter_1 = __importDefault(require("xml-formatter"));
|
|
32
28
|
const slice_1 = require("./slice");
|
|
29
|
+
const FormBodyItem_1 = __importDefault(require("./FormBodyItem"));
|
|
33
30
|
function BodyWrap({
|
|
34
31
|
requestBodyMetadata,
|
|
35
32
|
jsonRequestBodyExample,
|
|
@@ -118,94 +115,22 @@ function Body({
|
|
|
118
115
|
return react_1.default.createElement(
|
|
119
116
|
FormItem_1.default,
|
|
120
117
|
{ className: "openapi-explorer__form-item-body-container" },
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
onChange: (file) => {
|
|
138
|
-
if (file === undefined) {
|
|
139
|
-
dispatch((0, slice_1.clearFormBodyKey)(key));
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
dispatch(
|
|
143
|
-
(0, slice_1.setFileFormBody)({
|
|
144
|
-
key: key,
|
|
145
|
-
value: {
|
|
146
|
-
src: `/path/to/${file.name}`,
|
|
147
|
-
content: file,
|
|
148
|
-
},
|
|
149
|
-
})
|
|
150
|
-
);
|
|
151
|
-
},
|
|
152
|
-
})
|
|
153
|
-
);
|
|
154
|
-
}
|
|
155
|
-
if (val.enum) {
|
|
156
|
-
return react_1.default.createElement(
|
|
157
|
-
FormItem_1.default,
|
|
158
|
-
{
|
|
159
|
-
key: key,
|
|
160
|
-
label: key,
|
|
161
|
-
required:
|
|
162
|
-
Array.isArray(schema.required) &&
|
|
163
|
-
schema.required.includes(key),
|
|
164
|
-
},
|
|
165
|
-
react_1.default.createElement(FormSelect_1.default, {
|
|
166
|
-
options: ["---", ...val.enum],
|
|
167
|
-
onChange: (e) => {
|
|
168
|
-
const val = e.target.value;
|
|
169
|
-
if (val === "---") {
|
|
170
|
-
dispatch((0, slice_1.clearFormBodyKey)(key));
|
|
171
|
-
} else {
|
|
172
|
-
dispatch(
|
|
173
|
-
(0, slice_1.setStringFormBody)({
|
|
174
|
-
key: key,
|
|
175
|
-
value: val,
|
|
176
|
-
})
|
|
177
|
-
);
|
|
178
|
-
}
|
|
179
|
-
},
|
|
180
|
-
})
|
|
181
|
-
);
|
|
182
|
-
}
|
|
183
|
-
// TODO: support all the other types.
|
|
184
|
-
return react_1.default.createElement(
|
|
185
|
-
FormItem_1.default,
|
|
186
|
-
{
|
|
187
|
-
key: key,
|
|
188
|
-
label: key,
|
|
189
|
-
required:
|
|
190
|
-
Array.isArray(schema.required) && schema.required.includes(key),
|
|
191
|
-
},
|
|
192
|
-
react_1.default.createElement(FormTextInput_1.default, {
|
|
193
|
-
paramName: key,
|
|
194
|
-
isRequired:
|
|
195
|
-
Array.isArray(schema.required) && schema.required.includes(key),
|
|
196
|
-
placeholder: val.description || key,
|
|
197
|
-
onChange: (e) => {
|
|
198
|
-
dispatch(
|
|
199
|
-
(0, slice_1.setStringFormBody)({
|
|
200
|
-
key: key,
|
|
201
|
-
value: e.target.value,
|
|
202
|
-
})
|
|
203
|
-
);
|
|
204
|
-
},
|
|
205
|
-
})
|
|
206
|
-
);
|
|
207
|
-
})
|
|
208
|
-
)
|
|
118
|
+
Object.entries(schema.properties ?? {}).map(([key, val]) => {
|
|
119
|
+
return react_1.default.createElement(
|
|
120
|
+
FormItem_1.default,
|
|
121
|
+
{
|
|
122
|
+
key: key,
|
|
123
|
+
label: key,
|
|
124
|
+
required:
|
|
125
|
+
Array.isArray(schema.required) && schema.required.includes(key),
|
|
126
|
+
},
|
|
127
|
+
react_1.default.createElement(FormBodyItem_1.default, {
|
|
128
|
+
schemaObject: val,
|
|
129
|
+
id: key,
|
|
130
|
+
schema: schema,
|
|
131
|
+
})
|
|
132
|
+
);
|
|
133
|
+
})
|
|
209
134
|
);
|
|
210
135
|
}
|
|
211
136
|
let language = "plaintext";
|
|
@@ -343,7 +268,11 @@ function Body({
|
|
|
343
268
|
},
|
|
344
269
|
react_1.default.createElement(
|
|
345
270
|
LiveEditor_1.default,
|
|
346
|
-
{
|
|
271
|
+
{
|
|
272
|
+
action: (code) => dispatch((0, slice_1.setStringRawBody)(code)),
|
|
273
|
+
language: language,
|
|
274
|
+
required: required,
|
|
275
|
+
},
|
|
347
276
|
defaultBody
|
|
348
277
|
)
|
|
349
278
|
),
|
|
@@ -359,7 +288,11 @@ function Body({
|
|
|
359
288
|
exampleBody &&
|
|
360
289
|
react_1.default.createElement(
|
|
361
290
|
LiveEditor_1.default,
|
|
362
|
-
{
|
|
291
|
+
{
|
|
292
|
+
action: (code) => dispatch((0, slice_1.setStringRawBody)(code)),
|
|
293
|
+
language: language,
|
|
294
|
+
required: required,
|
|
295
|
+
},
|
|
363
296
|
exampleBody
|
|
364
297
|
)
|
|
365
298
|
)
|
|
@@ -385,7 +318,11 @@ function Body({
|
|
|
385
318
|
},
|
|
386
319
|
react_1.default.createElement(
|
|
387
320
|
LiveEditor_1.default,
|
|
388
|
-
{
|
|
321
|
+
{
|
|
322
|
+
action: (code) => dispatch((0, slice_1.setStringRawBody)(code)),
|
|
323
|
+
language: language,
|
|
324
|
+
required: required,
|
|
325
|
+
},
|
|
389
326
|
defaultBody
|
|
390
327
|
)
|
|
391
328
|
),
|
|
@@ -408,7 +345,11 @@ function Body({
|
|
|
408
345
|
example.body &&
|
|
409
346
|
react_1.default.createElement(
|
|
410
347
|
LiveEditor_1.default,
|
|
411
|
-
{
|
|
348
|
+
{
|
|
349
|
+
action: (code) =>
|
|
350
|
+
dispatch((0, slice_1.setStringRawBody)(code)),
|
|
351
|
+
language: language,
|
|
352
|
+
},
|
|
412
353
|
example.body
|
|
413
354
|
)
|
|
414
355
|
)
|
|
@@ -422,7 +363,11 @@ function Body({
|
|
|
422
363
|
null,
|
|
423
364
|
react_1.default.createElement(
|
|
424
365
|
LiveEditor_1.default,
|
|
425
|
-
{
|
|
366
|
+
{
|
|
367
|
+
action: (code) => dispatch((0, slice_1.setStringRawBody)(code)),
|
|
368
|
+
language: language,
|
|
369
|
+
required: required,
|
|
370
|
+
},
|
|
426
371
|
defaultBody
|
|
427
372
|
)
|
|
428
373
|
);
|
|
@@ -6,11 +6,18 @@ export interface FileContent {
|
|
|
6
6
|
content: Blob;
|
|
7
7
|
};
|
|
8
8
|
}
|
|
9
|
+
export interface FileArrayContent {
|
|
10
|
+
type: "file[]";
|
|
11
|
+
value: {
|
|
12
|
+
src: string;
|
|
13
|
+
content: Blob;
|
|
14
|
+
}[];
|
|
15
|
+
}
|
|
9
16
|
export interface StringContent {
|
|
10
17
|
type: "string";
|
|
11
18
|
value?: string;
|
|
12
19
|
}
|
|
13
|
-
export type Content = FileContent | StringContent | undefined;
|
|
20
|
+
export type Content = FileContent | FileArrayContent | StringContent | undefined;
|
|
14
21
|
export interface FormBody {
|
|
15
22
|
type: "form";
|
|
16
23
|
content: {
|
|
@@ -67,6 +74,21 @@ export declare const slice: import("@reduxjs/toolkit").Slice<FormBody | RawBody
|
|
|
67
74
|
};
|
|
68
75
|
};
|
|
69
76
|
};
|
|
77
|
+
setFileArrayFormBody: (state: import("immer").WritableDraft<FormBody> | import("immer").WritableDraft<RawBody> | import("immer").WritableDraft<EmptyBody>, action: PayloadAction<{
|
|
78
|
+
key: string;
|
|
79
|
+
value: FileArrayContent["value"];
|
|
80
|
+
}>) => import("immer").WritableDraft<FormBody> | {
|
|
81
|
+
type: "form";
|
|
82
|
+
content: {
|
|
83
|
+
[x: string]: {
|
|
84
|
+
type: "file[]";
|
|
85
|
+
value: {
|
|
86
|
+
src: string;
|
|
87
|
+
content: Blob;
|
|
88
|
+
}[];
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
};
|
|
70
92
|
}, "body", "body", import("@reduxjs/toolkit").SliceSelectors<FormBody | RawBody | EmptyBody>>;
|
|
71
93
|
export declare const clearRawBody: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<"body/clearRawBody">, setStringRawBody: import("@reduxjs/toolkit").ActionCreatorWithPayload<string, "body/setStringRawBody">, setFileRawBody: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
|
|
72
94
|
src: string;
|
|
@@ -77,6 +99,9 @@ export declare const clearRawBody: import("@reduxjs/toolkit").ActionCreatorWitho
|
|
|
77
99
|
}, "body/setStringFormBody">, setFileFormBody: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
|
|
78
100
|
key: string;
|
|
79
101
|
value: FileContent["value"];
|
|
80
|
-
}, "body/setFileFormBody"
|
|
102
|
+
}, "body/setFileFormBody">, setFileArrayFormBody: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
|
|
103
|
+
key: string;
|
|
104
|
+
value: FileArrayContent["value"];
|
|
105
|
+
}, "body/setFileArrayFormBody">;
|
|
81
106
|
declare const _default: import("redux").Reducer<FormBody | RawBody | EmptyBody>;
|
|
82
107
|
export default _default;
|
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
* ========================================================================== */
|
|
8
8
|
var _a;
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.
|
|
10
|
+
exports.setFileArrayFormBody =
|
|
11
|
+
exports.setFileFormBody =
|
|
11
12
|
exports.setStringFormBody =
|
|
12
13
|
exports.clearFormBodyKey =
|
|
13
14
|
exports.setFileRawBody =
|
|
@@ -85,6 +86,24 @@ exports.slice = (0, toolkit_1.createSlice)({
|
|
|
85
86
|
};
|
|
86
87
|
return state;
|
|
87
88
|
},
|
|
89
|
+
setFileArrayFormBody: (state, action) => {
|
|
90
|
+
if (state?.type !== "form") {
|
|
91
|
+
return {
|
|
92
|
+
type: "form",
|
|
93
|
+
content: {
|
|
94
|
+
[action.payload.key]: {
|
|
95
|
+
type: "file[]",
|
|
96
|
+
value: action.payload.value,
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
state.content[action.payload.key] = {
|
|
102
|
+
type: "file[]",
|
|
103
|
+
value: action.payload.value,
|
|
104
|
+
};
|
|
105
|
+
return state;
|
|
106
|
+
},
|
|
88
107
|
},
|
|
89
108
|
});
|
|
90
109
|
((_a = exports.slice.actions),
|
|
@@ -93,5 +112,6 @@ exports.slice = (0, toolkit_1.createSlice)({
|
|
|
93
112
|
(exports.setFileRawBody = _a.setFileRawBody),
|
|
94
113
|
(exports.clearFormBodyKey = _a.clearFormBodyKey),
|
|
95
114
|
(exports.setStringFormBody = _a.setStringFormBody),
|
|
96
|
-
(exports.setFileFormBody = _a.setFileFormBody)
|
|
115
|
+
(exports.setFileFormBody = _a.setFileFormBody),
|
|
116
|
+
(exports.setFileArrayFormBody = _a.setFileArrayFormBody));
|
|
97
117
|
exports.default = exports.slice.reducer;
|
|
@@ -72,7 +72,6 @@ const theme_common_1 = require("@docusaurus/theme-common");
|
|
|
72
72
|
const Translate_1 = require("@docusaurus/Translate");
|
|
73
73
|
const useIsBrowser_1 = __importDefault(require("@docusaurus/useIsBrowser"));
|
|
74
74
|
const error_message_1 = require("@hookform/error-message");
|
|
75
|
-
const slice_1 = require("@theme/ApiExplorer/Body/slice");
|
|
76
75
|
const translationIds_1 = require("@theme/translationIds");
|
|
77
76
|
const clsx_1 = __importDefault(require("clsx"));
|
|
78
77
|
const react_hook_form_1 = require("react-hook-form");
|
|
@@ -112,8 +111,8 @@ function App({
|
|
|
112
111
|
const prismTheme = (0, theme_common_1.usePrismTheme)();
|
|
113
112
|
const [code, setCode] = react_1.default.useState(children.replace(/\n$/, ""));
|
|
114
113
|
(0, react_1.useEffect)(() => {
|
|
115
|
-
action(
|
|
116
|
-
}, [
|
|
114
|
+
action(code);
|
|
115
|
+
}, [code]);
|
|
117
116
|
const {
|
|
118
117
|
control,
|
|
119
118
|
formState: { errors },
|
|
@@ -331,7 +331,11 @@ function setBody(clonedPostman, body) {
|
|
|
331
331
|
switch (clonedPostman.body.mode) {
|
|
332
332
|
case "raw": {
|
|
333
333
|
// check file even though it should already be set from above
|
|
334
|
-
if (
|
|
334
|
+
if (
|
|
335
|
+
body.type !== "raw" ||
|
|
336
|
+
body.content?.type === "file" ||
|
|
337
|
+
body.content?.type === "file[]"
|
|
338
|
+
) {
|
|
335
339
|
clonedPostman.body = undefined;
|
|
336
340
|
return;
|
|
337
341
|
}
|
|
@@ -346,15 +350,23 @@ function setBody(clonedPostman, body) {
|
|
|
346
350
|
clonedPostman.body.raw = `${body.content?.value}`;
|
|
347
351
|
return;
|
|
348
352
|
}
|
|
349
|
-
const params =
|
|
353
|
+
const params = [];
|
|
354
|
+
Object.entries(body.content)
|
|
350
355
|
.filter((entry) => !!entry[1])
|
|
351
|
-
.
|
|
356
|
+
.forEach(([key, content]) => {
|
|
352
357
|
if (content.type === "file") {
|
|
353
|
-
|
|
358
|
+
params.push(new sdk.FormParam({ key: key, ...content }));
|
|
359
|
+
} else if (content.type === "file[]") {
|
|
360
|
+
content.value.forEach((file) =>
|
|
361
|
+
params.push(new sdk.FormParam({ key, value: file }))
|
|
362
|
+
);
|
|
363
|
+
} else {
|
|
364
|
+
params.push(new sdk.FormParam({ key: key, value: content.value }));
|
|
354
365
|
}
|
|
355
|
-
return new sdk.FormParam({ key: key, value: content.value });
|
|
356
366
|
});
|
|
357
|
-
|
|
367
|
+
params.forEach((param) => {
|
|
368
|
+
clonedPostman.body?.formdata?.add(param);
|
|
369
|
+
});
|
|
358
370
|
return;
|
|
359
371
|
}
|
|
360
372
|
case "urlencoded": {
|
|
@@ -368,7 +380,11 @@ function setBody(clonedPostman, body) {
|
|
|
368
380
|
const params = Object.entries(body.content)
|
|
369
381
|
.filter((entry) => !!entry[1])
|
|
370
382
|
.map(([key, content]) => {
|
|
371
|
-
if (
|
|
383
|
+
if (
|
|
384
|
+
content.type !== "file" &&
|
|
385
|
+
content.type !== "file[]" &&
|
|
386
|
+
content.value
|
|
387
|
+
) {
|
|
372
388
|
return new sdk.QueryParam({ key: key, value: content.value });
|
|
373
389
|
}
|
|
374
390
|
return undefined;
|
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": "0.0.0-
|
|
4
|
+
"version": "0.0.0-1085",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"openapi",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"@types/postman-collection": "^3.5.11",
|
|
39
39
|
"@types/react-modal": "^3.16.3",
|
|
40
40
|
"concurrently": "^9.2.0",
|
|
41
|
-
"docusaurus-plugin-openapi-docs": "0.0.0-
|
|
41
|
+
"docusaurus-plugin-openapi-docs": "0.0.0-1085",
|
|
42
42
|
"docusaurus-plugin-sass": "^0.2.6",
|
|
43
43
|
"eslint-plugin-prettier": "^5.5.1"
|
|
44
44
|
},
|
|
@@ -81,5 +81,5 @@
|
|
|
81
81
|
"engines": {
|
|
82
82
|
"node": ">=14"
|
|
83
83
|
},
|
|
84
|
-
"gitHead": "
|
|
84
|
+
"gitHead": "26311f52652bf29d0ca59389d5f39707320f1baf"
|
|
85
85
|
}
|
|
@@ -0,0 +1,77 @@
|
|
|
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, { useState } from "react";
|
|
9
|
+
import FormFileUpload from "@theme/ApiExplorer/FormFileUpload";
|
|
10
|
+
import { useTypedDispatch } from "@theme/ApiItem/hooks";
|
|
11
|
+
import { FileContent, setFileArrayFormBody } from "../slice";
|
|
12
|
+
|
|
13
|
+
interface FileArrayFormItemProps {
|
|
14
|
+
id: string;
|
|
15
|
+
description: string | undefined;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export default function FileArrayFormBodyItem({
|
|
19
|
+
id,
|
|
20
|
+
description,
|
|
21
|
+
}: FileArrayFormItemProps): React.JSX.Element {
|
|
22
|
+
const dispatch = useTypedDispatch();
|
|
23
|
+
const [fileItems, setFileItems] = useState<
|
|
24
|
+
Map<number, FileContent["value"] | undefined>
|
|
25
|
+
>(new Map([[0, undefined]]));
|
|
26
|
+
|
|
27
|
+
const handleFileChange = (index: number, file: any) => {
|
|
28
|
+
const newItems = new Map(fileItems);
|
|
29
|
+
|
|
30
|
+
if (file === undefined) {
|
|
31
|
+
newItems.delete(index);
|
|
32
|
+
|
|
33
|
+
setFileItems(newItems);
|
|
34
|
+
|
|
35
|
+
dispatch(
|
|
36
|
+
setFileArrayFormBody({
|
|
37
|
+
key: id,
|
|
38
|
+
value: [...newItems.values()].filter((item) => item !== undefined),
|
|
39
|
+
})
|
|
40
|
+
);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
let maxIndex = 0;
|
|
45
|
+
|
|
46
|
+
newItems.keys().forEach((item) => {
|
|
47
|
+
maxIndex = item > maxIndex ? item : maxIndex;
|
|
48
|
+
});
|
|
49
|
+
newItems.set(index, {
|
|
50
|
+
src: `/path/to/${file.name}`,
|
|
51
|
+
content: file,
|
|
52
|
+
});
|
|
53
|
+
newItems.set(index + 1, undefined);
|
|
54
|
+
|
|
55
|
+
setFileItems(newItems);
|
|
56
|
+
|
|
57
|
+
dispatch(
|
|
58
|
+
setFileArrayFormBody({
|
|
59
|
+
key: id,
|
|
60
|
+
value: [...newItems.values()].filter((item) => item !== undefined),
|
|
61
|
+
})
|
|
62
|
+
);
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
return (
|
|
66
|
+
<div>
|
|
67
|
+
{[...fileItems.keys()].map((index) => (
|
|
68
|
+
<div key={index}>
|
|
69
|
+
<FormFileUpload
|
|
70
|
+
placeholder={description || id}
|
|
71
|
+
onChange={(file: any) => handleFileChange(index, file)}
|
|
72
|
+
/>
|
|
73
|
+
</div>
|
|
74
|
+
))}
|
|
75
|
+
</div>
|
|
76
|
+
);
|
|
77
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
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
|
+
import FormFileUpload from "@theme/ApiExplorer/FormFileUpload";
|
|
10
|
+
import FormSelect from "@theme/ApiExplorer/FormSelect";
|
|
11
|
+
import FormTextInput from "@theme/ApiExplorer/FormTextInput";
|
|
12
|
+
import LiveApp from "@theme/ApiExplorer/LiveEditor";
|
|
13
|
+
import { useTypedDispatch } from "@theme/ApiItem/hooks";
|
|
14
|
+
import { SchemaObject } from "docusaurus-plugin-openapi-docs/src/openapi/types";
|
|
15
|
+
import { clearFormBodyKey, setFileFormBody, setStringFormBody } from "../slice";
|
|
16
|
+
import FileArrayFormBodyItem from "../FileArrayFormBodyItem";
|
|
17
|
+
|
|
18
|
+
interface FormBodyItemProps {
|
|
19
|
+
schemaObject: SchemaObject;
|
|
20
|
+
id: string;
|
|
21
|
+
schema: SchemaObject;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export default function FormBodyItem({
|
|
25
|
+
schemaObject,
|
|
26
|
+
id,
|
|
27
|
+
schema,
|
|
28
|
+
}: FormBodyItemProps): React.JSX.Element {
|
|
29
|
+
const dispatch = useTypedDispatch();
|
|
30
|
+
|
|
31
|
+
if (
|
|
32
|
+
schemaObject.type === "array" &&
|
|
33
|
+
schemaObject.items?.format === "binary"
|
|
34
|
+
) {
|
|
35
|
+
return (
|
|
36
|
+
<FileArrayFormBodyItem id={id} description={schemaObject.description} />
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (schemaObject.format === "binary") {
|
|
41
|
+
return (
|
|
42
|
+
<FormFileUpload
|
|
43
|
+
placeholder={schemaObject.description || id}
|
|
44
|
+
onChange={(file: any) => {
|
|
45
|
+
if (file === undefined) {
|
|
46
|
+
dispatch(clearFormBodyKey(id));
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
dispatch(
|
|
50
|
+
setFileFormBody({
|
|
51
|
+
key: id,
|
|
52
|
+
value: {
|
|
53
|
+
src: `/path/to/${file.name}`,
|
|
54
|
+
content: file,
|
|
55
|
+
},
|
|
56
|
+
})
|
|
57
|
+
);
|
|
58
|
+
}}
|
|
59
|
+
/>
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (
|
|
64
|
+
schemaObject.type === "object" &&
|
|
65
|
+
(schemaObject.example || schemaObject.examples)
|
|
66
|
+
) {
|
|
67
|
+
const objectExample = JSON.stringify(
|
|
68
|
+
schemaObject.example ?? schemaObject.examples[0],
|
|
69
|
+
null,
|
|
70
|
+
2
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
return (
|
|
74
|
+
<LiveApp
|
|
75
|
+
action={(code: string) =>
|
|
76
|
+
dispatch(setStringFormBody({ key: id, value: code }))
|
|
77
|
+
}
|
|
78
|
+
>
|
|
79
|
+
{objectExample}
|
|
80
|
+
</LiveApp>
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (
|
|
85
|
+
schemaObject.enum &&
|
|
86
|
+
schemaObject.enum.every((value) => typeof value === "string")
|
|
87
|
+
) {
|
|
88
|
+
return (
|
|
89
|
+
<FormSelect
|
|
90
|
+
options={["---", ...schemaObject.enum]}
|
|
91
|
+
onChange={(e: React.ChangeEvent<HTMLSelectElement>) => {
|
|
92
|
+
const val = e.target.value;
|
|
93
|
+
if (val === "---") {
|
|
94
|
+
dispatch(clearFormBodyKey(id));
|
|
95
|
+
} else {
|
|
96
|
+
dispatch(
|
|
97
|
+
setStringFormBody({
|
|
98
|
+
key: id,
|
|
99
|
+
value: val,
|
|
100
|
+
})
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
}}
|
|
104
|
+
/>
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
// TODO: support all the other types.
|
|
108
|
+
return (
|
|
109
|
+
<FormTextInput
|
|
110
|
+
paramName={id}
|
|
111
|
+
isRequired={
|
|
112
|
+
Array.isArray(schema.required) && schema.required.includes(id)
|
|
113
|
+
}
|
|
114
|
+
placeholder={schemaObject.description || id}
|
|
115
|
+
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
|
|
116
|
+
dispatch(setStringFormBody({ key: id, value: e.target.value }));
|
|
117
|
+
}}
|
|
118
|
+
/>
|
|
119
|
+
);
|
|
120
|
+
}
|
|
@@ -12,8 +12,6 @@ import { translate } from "@docusaurus/Translate";
|
|
|
12
12
|
import json2xml from "@theme/ApiExplorer/Body/json2xml";
|
|
13
13
|
import FormFileUpload from "@theme/ApiExplorer/FormFileUpload";
|
|
14
14
|
import FormItem from "@theme/ApiExplorer/FormItem";
|
|
15
|
-
import FormSelect from "@theme/ApiExplorer/FormSelect";
|
|
16
|
-
import FormTextInput from "@theme/ApiExplorer/FormTextInput";
|
|
17
15
|
import LiveApp from "@theme/ApiExplorer/LiveEditor";
|
|
18
16
|
import { useTypedDispatch, useTypedSelector } from "@theme/ApiItem/hooks";
|
|
19
17
|
import Markdown from "@theme/Markdown";
|
|
@@ -23,13 +21,8 @@ import { OPENAPI_BODY, OPENAPI_REQUEST } from "@theme/translationIds";
|
|
|
23
21
|
import { RequestBodyObject } from "docusaurus-plugin-openapi-docs/src/openapi/types";
|
|
24
22
|
import format from "xml-formatter";
|
|
25
23
|
|
|
26
|
-
import {
|
|
27
|
-
|
|
28
|
-
clearRawBody,
|
|
29
|
-
setFileFormBody,
|
|
30
|
-
setFileRawBody,
|
|
31
|
-
setStringFormBody,
|
|
32
|
-
} from "./slice";
|
|
24
|
+
import { clearRawBody, setFileRawBody, setStringRawBody } from "./slice";
|
|
25
|
+
import FormBodyItem from "./FormBodyItem";
|
|
33
26
|
|
|
34
27
|
export interface Props {
|
|
35
28
|
jsonRequestBodyExample: string;
|
|
@@ -130,96 +123,23 @@ function Body({
|
|
|
130
123
|
) {
|
|
131
124
|
return (
|
|
132
125
|
<FormItem className="openapi-explorer__form-item-body-container">
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
return;
|
|
151
|
-
}
|
|
152
|
-
dispatch(
|
|
153
|
-
setFileFormBody({
|
|
154
|
-
key: key,
|
|
155
|
-
value: {
|
|
156
|
-
src: `/path/to/${file.name}`,
|
|
157
|
-
content: file,
|
|
158
|
-
},
|
|
159
|
-
})
|
|
160
|
-
);
|
|
161
|
-
}}
|
|
162
|
-
/>
|
|
163
|
-
</FormItem>
|
|
164
|
-
);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
if (val.enum) {
|
|
168
|
-
return (
|
|
169
|
-
<FormItem
|
|
170
|
-
key={key}
|
|
171
|
-
label={key}
|
|
172
|
-
required={
|
|
173
|
-
Array.isArray(schema.required) &&
|
|
174
|
-
schema.required.includes(key)
|
|
175
|
-
}
|
|
176
|
-
>
|
|
177
|
-
<FormSelect
|
|
178
|
-
options={["---", ...val.enum]}
|
|
179
|
-
onChange={(e: React.ChangeEvent<HTMLSelectElement>) => {
|
|
180
|
-
const val = e.target.value;
|
|
181
|
-
if (val === "---") {
|
|
182
|
-
dispatch(clearFormBodyKey(key));
|
|
183
|
-
} else {
|
|
184
|
-
dispatch(
|
|
185
|
-
setStringFormBody({
|
|
186
|
-
key: key,
|
|
187
|
-
value: val,
|
|
188
|
-
})
|
|
189
|
-
);
|
|
190
|
-
}
|
|
191
|
-
}}
|
|
192
|
-
/>
|
|
193
|
-
</FormItem>
|
|
194
|
-
);
|
|
195
|
-
}
|
|
196
|
-
// TODO: support all the other types.
|
|
197
|
-
return (
|
|
198
|
-
<FormItem
|
|
199
|
-
key={key}
|
|
200
|
-
label={key}
|
|
201
|
-
required={
|
|
202
|
-
Array.isArray(schema.required) &&
|
|
203
|
-
schema.required.includes(key)
|
|
204
|
-
}
|
|
205
|
-
>
|
|
206
|
-
<FormTextInput
|
|
207
|
-
paramName={key}
|
|
208
|
-
isRequired={
|
|
209
|
-
Array.isArray(schema.required) &&
|
|
210
|
-
schema.required.includes(key)
|
|
211
|
-
}
|
|
212
|
-
placeholder={val.description || key}
|
|
213
|
-
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
|
|
214
|
-
dispatch(
|
|
215
|
-
setStringFormBody({ key: key, value: e.target.value })
|
|
216
|
-
);
|
|
217
|
-
}}
|
|
218
|
-
/>
|
|
219
|
-
</FormItem>
|
|
220
|
-
);
|
|
221
|
-
})}
|
|
222
|
-
</div>
|
|
126
|
+
{Object.entries(schema.properties ?? {}).map(([key, val]: any) => {
|
|
127
|
+
return (
|
|
128
|
+
<FormItem
|
|
129
|
+
key={key}
|
|
130
|
+
label={key}
|
|
131
|
+
required={
|
|
132
|
+
Array.isArray(schema.required) && schema.required.includes(key)
|
|
133
|
+
}
|
|
134
|
+
>
|
|
135
|
+
<FormBodyItem
|
|
136
|
+
schemaObject={val}
|
|
137
|
+
id={key}
|
|
138
|
+
schema={schema}
|
|
139
|
+
></FormBodyItem>
|
|
140
|
+
</FormItem>
|
|
141
|
+
);
|
|
142
|
+
})}
|
|
223
143
|
</FormItem>
|
|
224
144
|
);
|
|
225
145
|
}
|
|
@@ -348,7 +268,11 @@ function Body({
|
|
|
348
268
|
value="Example (from schema)"
|
|
349
269
|
default
|
|
350
270
|
>
|
|
351
|
-
<LiveApp
|
|
271
|
+
<LiveApp
|
|
272
|
+
action={(code: string) => dispatch(setStringRawBody(code))}
|
|
273
|
+
language={language}
|
|
274
|
+
required={required}
|
|
275
|
+
>
|
|
352
276
|
{defaultBody}
|
|
353
277
|
</LiveApp>
|
|
354
278
|
</TabItem>
|
|
@@ -357,7 +281,7 @@ function Body({
|
|
|
357
281
|
{example.summary && <Markdown>{example.summary}</Markdown>}
|
|
358
282
|
{exampleBody && (
|
|
359
283
|
<LiveApp
|
|
360
|
-
action={dispatch}
|
|
284
|
+
action={(code: string) => dispatch(setStringRawBody(code))}
|
|
361
285
|
language={language}
|
|
362
286
|
required={required}
|
|
363
287
|
>
|
|
@@ -383,7 +307,11 @@ function Body({
|
|
|
383
307
|
value="Example (from schema)"
|
|
384
308
|
default
|
|
385
309
|
>
|
|
386
|
-
<LiveApp
|
|
310
|
+
<LiveApp
|
|
311
|
+
action={(code: string) => dispatch(setStringRawBody(code))}
|
|
312
|
+
language={language}
|
|
313
|
+
required={required}
|
|
314
|
+
>
|
|
387
315
|
{defaultBody}
|
|
388
316
|
</LiveApp>
|
|
389
317
|
</TabItem>
|
|
@@ -397,7 +325,10 @@ function Body({
|
|
|
397
325
|
>
|
|
398
326
|
{example.summary && <Markdown>{example.summary}</Markdown>}
|
|
399
327
|
{example.body && (
|
|
400
|
-
<LiveApp
|
|
328
|
+
<LiveApp
|
|
329
|
+
action={(code: string) => dispatch(setStringRawBody(code))}
|
|
330
|
+
language={language}
|
|
331
|
+
>
|
|
401
332
|
{example.body}
|
|
402
333
|
</LiveApp>
|
|
403
334
|
)}
|
|
@@ -411,7 +342,11 @@ function Body({
|
|
|
411
342
|
|
|
412
343
|
return (
|
|
413
344
|
<FormItem>
|
|
414
|
-
<LiveApp
|
|
345
|
+
<LiveApp
|
|
346
|
+
action={(code: string) => dispatch(setStringRawBody(code))}
|
|
347
|
+
language={language}
|
|
348
|
+
required={required}
|
|
349
|
+
>
|
|
415
350
|
{defaultBody}
|
|
416
351
|
</LiveApp>
|
|
417
352
|
</FormItem>
|
|
@@ -15,12 +15,24 @@ export interface FileContent {
|
|
|
15
15
|
};
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
export interface FileArrayContent {
|
|
19
|
+
type: "file[]";
|
|
20
|
+
value: {
|
|
21
|
+
src: string;
|
|
22
|
+
content: Blob;
|
|
23
|
+
}[];
|
|
24
|
+
}
|
|
25
|
+
|
|
18
26
|
export interface StringContent {
|
|
19
27
|
type: "string";
|
|
20
28
|
value?: string;
|
|
21
29
|
}
|
|
22
30
|
|
|
23
|
-
export type Content =
|
|
31
|
+
export type Content =
|
|
32
|
+
| FileContent
|
|
33
|
+
| FileArrayContent
|
|
34
|
+
| StringContent
|
|
35
|
+
| undefined;
|
|
24
36
|
|
|
25
37
|
export interface FormBody {
|
|
26
38
|
type: "form";
|
|
@@ -118,6 +130,32 @@ export const slice = createSlice({
|
|
|
118
130
|
};
|
|
119
131
|
return state;
|
|
120
132
|
},
|
|
133
|
+
setFileArrayFormBody: (
|
|
134
|
+
state,
|
|
135
|
+
action: PayloadAction<{
|
|
136
|
+
key: string;
|
|
137
|
+
value: FileArrayContent["value"];
|
|
138
|
+
}>
|
|
139
|
+
) => {
|
|
140
|
+
if (state?.type !== "form") {
|
|
141
|
+
return {
|
|
142
|
+
type: "form",
|
|
143
|
+
content: {
|
|
144
|
+
[action.payload.key]: {
|
|
145
|
+
type: "file[]",
|
|
146
|
+
value: action.payload.value,
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
state.content[action.payload.key] = {
|
|
153
|
+
type: "file[]",
|
|
154
|
+
value: action.payload.value,
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
return state;
|
|
158
|
+
},
|
|
121
159
|
},
|
|
122
160
|
});
|
|
123
161
|
|
|
@@ -128,6 +166,7 @@ export const {
|
|
|
128
166
|
clearFormBodyKey,
|
|
129
167
|
setStringFormBody,
|
|
130
168
|
setFileFormBody,
|
|
169
|
+
setFileArrayFormBody,
|
|
131
170
|
} = slice.actions;
|
|
132
171
|
|
|
133
172
|
export default slice.reducer;
|
|
@@ -11,7 +11,6 @@ import { usePrismTheme } from "@docusaurus/theme-common";
|
|
|
11
11
|
import { translate } from "@docusaurus/Translate";
|
|
12
12
|
import useIsBrowser from "@docusaurus/useIsBrowser";
|
|
13
13
|
import { ErrorMessage } from "@hookform/error-message";
|
|
14
|
-
import { setStringRawBody } from "@theme/ApiExplorer/Body/slice";
|
|
15
14
|
import { OPENAPI_FORM } from "@theme/translationIds";
|
|
16
15
|
import clsx from "clsx";
|
|
17
16
|
import { Controller, useFormContext } from "react-hook-form";
|
|
@@ -56,8 +55,8 @@ function App({
|
|
|
56
55
|
const [code, setCode] = React.useState(children.replace(/\n$/, ""));
|
|
57
56
|
|
|
58
57
|
useEffect(() => {
|
|
59
|
-
action(
|
|
60
|
-
}, [
|
|
58
|
+
action(code);
|
|
59
|
+
}, [code]);
|
|
61
60
|
|
|
62
61
|
const {
|
|
63
62
|
control,
|
|
@@ -313,7 +313,11 @@ function setBody(clonedPostman: sdk.Request, body: Body) {
|
|
|
313
313
|
switch (clonedPostman.body.mode) {
|
|
314
314
|
case "raw": {
|
|
315
315
|
// check file even though it should already be set from above
|
|
316
|
-
if (
|
|
316
|
+
if (
|
|
317
|
+
body.type !== "raw" ||
|
|
318
|
+
body.content?.type === "file" ||
|
|
319
|
+
body.content?.type === "file[]"
|
|
320
|
+
) {
|
|
317
321
|
clonedPostman.body = undefined;
|
|
318
322
|
return;
|
|
319
323
|
}
|
|
@@ -328,15 +332,23 @@ function setBody(clonedPostman: sdk.Request, body: Body) {
|
|
|
328
332
|
clonedPostman.body.raw = `${body.content?.value}`;
|
|
329
333
|
return;
|
|
330
334
|
}
|
|
331
|
-
const params =
|
|
335
|
+
const params: sdk.FormParam[] = [];
|
|
336
|
+
Object.entries(body.content)
|
|
332
337
|
.filter((entry): entry is [string, NonNullable<Content>] => !!entry[1])
|
|
333
|
-
.
|
|
338
|
+
.forEach(([key, content]) => {
|
|
334
339
|
if (content.type === "file") {
|
|
335
|
-
|
|
340
|
+
params.push(new sdk.FormParam({ key: key, ...content }));
|
|
341
|
+
} else if (content.type === "file[]") {
|
|
342
|
+
content.value.forEach((file) =>
|
|
343
|
+
params.push(new sdk.FormParam({ key, value: file }))
|
|
344
|
+
);
|
|
345
|
+
} else {
|
|
346
|
+
params.push(new sdk.FormParam({ key: key, value: content.value }));
|
|
336
347
|
}
|
|
337
|
-
return new sdk.FormParam({ key: key, value: content.value });
|
|
338
348
|
});
|
|
339
|
-
|
|
349
|
+
params.forEach((param) => {
|
|
350
|
+
clonedPostman.body?.formdata?.add(param);
|
|
351
|
+
});
|
|
340
352
|
return;
|
|
341
353
|
}
|
|
342
354
|
case "urlencoded": {
|
|
@@ -350,7 +362,11 @@ function setBody(clonedPostman: sdk.Request, body: Body) {
|
|
|
350
362
|
const params = Object.entries(body.content)
|
|
351
363
|
.filter((entry): entry is [string, NonNullable<Content>] => !!entry[1])
|
|
352
364
|
.map(([key, content]) => {
|
|
353
|
-
if (
|
|
365
|
+
if (
|
|
366
|
+
content.type !== "file" &&
|
|
367
|
+
content.type !== "file[]" &&
|
|
368
|
+
content.value
|
|
369
|
+
) {
|
|
354
370
|
return new sdk.QueryParam({ key: key, value: content.value });
|
|
355
371
|
}
|
|
356
372
|
return undefined;
|
package/tsconfig.tsbuildinfo
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"root":["./src/index.ts","./src/plugin-content-docs.d.ts","./src/postman-code-generators.d.ts","./src/react-magic-dropzone.d.ts","./src/theme-classic.d.ts","./src/theme-openapi.d.ts","./src/types.ts","./src/markdown/createDescription.ts","./src/markdown/schema.ts","./src/markdown/utils.test.ts","./src/markdown/utils.ts","./src/theme/translationIds.ts","./src/theme/ApiExplorer/buildPostmanRequest.ts","./src/theme/ApiExplorer/index.tsx","./src/theme/ApiExplorer/persistenceMiddleware.ts","./src/theme/ApiExplorer/storage-utils.ts","./src/theme/ApiExplorer/Accept/index.tsx","./src/theme/ApiExplorer/Accept/slice.ts","./src/theme/ApiExplorer/ApiCodeBlock/index.tsx","./src/theme/ApiExplorer/ApiCodeBlock/Container/index.tsx","./src/theme/ApiExplorer/ApiCodeBlock/Content/Element.tsx","./src/theme/ApiExplorer/ApiCodeBlock/Content/String.tsx","./src/theme/ApiExplorer/ApiCodeBlock/CopyButton/index.tsx","./src/theme/ApiExplorer/ApiCodeBlock/ExitButton/index.tsx","./src/theme/ApiExplorer/ApiCodeBlock/ExpandButton/index.tsx","./src/theme/ApiExplorer/ApiCodeBlock/Line/index.tsx","./src/theme/ApiExplorer/ApiCodeBlock/WordWrapButton/index.tsx","./src/theme/ApiExplorer/Authorization/auth-types.ts","./src/theme/ApiExplorer/Authorization/index.tsx","./src/theme/ApiExplorer/Authorization/slice.ts","./src/theme/ApiExplorer/Body/index.tsx","./src/theme/ApiExplorer/Body/json2xml.d.ts","./src/theme/ApiExplorer/Body/slice.ts","./src/theme/ApiExplorer/CodeSnippets/code-snippets-types.ts","./src/theme/ApiExplorer/CodeSnippets/index.tsx","./src/theme/ApiExplorer/CodeSnippets/languages.ts","./src/theme/ApiExplorer/CodeTabs/index.tsx","./src/theme/ApiExplorer/ContentType/index.tsx","./src/theme/ApiExplorer/ContentType/slice.ts","./src/theme/ApiExplorer/Export/index.tsx","./src/theme/ApiExplorer/FloatingButton/index.tsx","./src/theme/ApiExplorer/FormFileUpload/index.tsx","./src/theme/ApiExplorer/FormItem/index.tsx","./src/theme/ApiExplorer/FormMultiSelect/index.tsx","./src/theme/ApiExplorer/FormSelect/index.tsx","./src/theme/ApiExplorer/FormTextInput/index.tsx","./src/theme/ApiExplorer/LiveEditor/index.tsx","./src/theme/ApiExplorer/MethodEndpoint/index.tsx","./src/theme/ApiExplorer/ParamOptions/index.tsx","./src/theme/ApiExplorer/ParamOptions/slice.ts","./src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamArrayFormItem.tsx","./src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamBooleanFormItem.tsx","./src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamMultiSelectFormItem.tsx","./src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamSelectFormItem.tsx","./src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamTextFormItem.tsx","./src/theme/ApiExplorer/Request/index.tsx","./src/theme/ApiExplorer/Request/makeRequest.ts","./src/theme/ApiExplorer/Response/index.tsx","./src/theme/ApiExplorer/Response/slice.ts","./src/theme/ApiExplorer/SecuritySchemes/index.tsx","./src/theme/ApiExplorer/Server/index.tsx","./src/theme/ApiExplorer/Server/slice.ts","./src/theme/ApiItem/hooks.ts","./src/theme/ApiItem/index.tsx","./src/theme/ApiItem/store.ts","./src/theme/ApiItem/Layout/index.tsx","./src/theme/ApiLogo/index.tsx","./src/theme/ApiTabs/index.tsx","./src/theme/ArrayBrackets/index.tsx","./src/theme/CodeSamples/index.tsx","./src/theme/DiscriminatorTabs/index.tsx","./src/theme/Example/index.tsx","./src/theme/Markdown/index.d.ts","./src/theme/MimeTabs/index.tsx","./src/theme/OperationTabs/index.tsx","./src/theme/ParamsDetails/index.tsx","./src/theme/ParamsItem/index.tsx","./src/theme/RequestSchema/index.tsx","./src/theme/ResponseExamples/index.tsx","./src/theme/ResponseHeaders/index.tsx","./src/theme/ResponseSchema/index.tsx","./src/theme/Schema/index.tsx","./src/theme/SchemaItem/index.tsx","./src/theme/SchemaTabs/index.tsx","./src/theme/SkeletonLoader/index.tsx","./src/theme/StatusCodes/index.tsx"],"version":"5.8.3"}
|
|
1
|
+
{"root":["./src/index.ts","./src/plugin-content-docs.d.ts","./src/postman-code-generators.d.ts","./src/react-magic-dropzone.d.ts","./src/theme-classic.d.ts","./src/theme-openapi.d.ts","./src/types.ts","./src/markdown/createDescription.ts","./src/markdown/schema.ts","./src/markdown/utils.test.ts","./src/markdown/utils.ts","./src/theme/translationIds.ts","./src/theme/ApiExplorer/buildPostmanRequest.ts","./src/theme/ApiExplorer/index.tsx","./src/theme/ApiExplorer/persistenceMiddleware.ts","./src/theme/ApiExplorer/storage-utils.ts","./src/theme/ApiExplorer/Accept/index.tsx","./src/theme/ApiExplorer/Accept/slice.ts","./src/theme/ApiExplorer/ApiCodeBlock/index.tsx","./src/theme/ApiExplorer/ApiCodeBlock/Container/index.tsx","./src/theme/ApiExplorer/ApiCodeBlock/Content/Element.tsx","./src/theme/ApiExplorer/ApiCodeBlock/Content/String.tsx","./src/theme/ApiExplorer/ApiCodeBlock/CopyButton/index.tsx","./src/theme/ApiExplorer/ApiCodeBlock/ExitButton/index.tsx","./src/theme/ApiExplorer/ApiCodeBlock/ExpandButton/index.tsx","./src/theme/ApiExplorer/ApiCodeBlock/Line/index.tsx","./src/theme/ApiExplorer/ApiCodeBlock/WordWrapButton/index.tsx","./src/theme/ApiExplorer/Authorization/auth-types.ts","./src/theme/ApiExplorer/Authorization/index.tsx","./src/theme/ApiExplorer/Authorization/slice.ts","./src/theme/ApiExplorer/Body/index.tsx","./src/theme/ApiExplorer/Body/json2xml.d.ts","./src/theme/ApiExplorer/Body/slice.ts","./src/theme/ApiExplorer/Body/FileArrayFormBodyItem/index.tsx","./src/theme/ApiExplorer/Body/FormBodyItem/index.tsx","./src/theme/ApiExplorer/CodeSnippets/code-snippets-types.ts","./src/theme/ApiExplorer/CodeSnippets/index.tsx","./src/theme/ApiExplorer/CodeSnippets/languages.ts","./src/theme/ApiExplorer/CodeTabs/index.tsx","./src/theme/ApiExplorer/ContentType/index.tsx","./src/theme/ApiExplorer/ContentType/slice.ts","./src/theme/ApiExplorer/Export/index.tsx","./src/theme/ApiExplorer/FloatingButton/index.tsx","./src/theme/ApiExplorer/FormFileUpload/index.tsx","./src/theme/ApiExplorer/FormItem/index.tsx","./src/theme/ApiExplorer/FormMultiSelect/index.tsx","./src/theme/ApiExplorer/FormSelect/index.tsx","./src/theme/ApiExplorer/FormTextInput/index.tsx","./src/theme/ApiExplorer/LiveEditor/index.tsx","./src/theme/ApiExplorer/MethodEndpoint/index.tsx","./src/theme/ApiExplorer/ParamOptions/index.tsx","./src/theme/ApiExplorer/ParamOptions/slice.ts","./src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamArrayFormItem.tsx","./src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamBooleanFormItem.tsx","./src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamMultiSelectFormItem.tsx","./src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamSelectFormItem.tsx","./src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamTextFormItem.tsx","./src/theme/ApiExplorer/Request/index.tsx","./src/theme/ApiExplorer/Request/makeRequest.ts","./src/theme/ApiExplorer/Response/index.tsx","./src/theme/ApiExplorer/Response/slice.ts","./src/theme/ApiExplorer/SecuritySchemes/index.tsx","./src/theme/ApiExplorer/Server/index.tsx","./src/theme/ApiExplorer/Server/slice.ts","./src/theme/ApiItem/hooks.ts","./src/theme/ApiItem/index.tsx","./src/theme/ApiItem/store.ts","./src/theme/ApiItem/Layout/index.tsx","./src/theme/ApiLogo/index.tsx","./src/theme/ApiTabs/index.tsx","./src/theme/ArrayBrackets/index.tsx","./src/theme/CodeSamples/index.tsx","./src/theme/DiscriminatorTabs/index.tsx","./src/theme/Example/index.tsx","./src/theme/Markdown/index.d.ts","./src/theme/MimeTabs/index.tsx","./src/theme/OperationTabs/index.tsx","./src/theme/ParamsDetails/index.tsx","./src/theme/ParamsItem/index.tsx","./src/theme/RequestSchema/index.tsx","./src/theme/ResponseExamples/index.tsx","./src/theme/ResponseHeaders/index.tsx","./src/theme/ResponseSchema/index.tsx","./src/theme/Schema/index.tsx","./src/theme/SchemaItem/index.tsx","./src/theme/SchemaTabs/index.tsx","./src/theme/SkeletonLoader/index.tsx","./src/theme/StatusCodes/index.tsx"],"version":"5.8.3"}
|