docusaurus-theme-openapi-docs 0.0.0-472 → 0.0.0-476
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/Body/index.js +102 -7
- package/lib/theme/ApiItem/Layout/styles.module.css +11 -3
- package/lib/theme/MimeTabs/styles.module.css +1 -0
- package/lib/theme/SchemaTabs/index.js +4 -1
- package/lib-next/theme/ApiDemoPanel/Body/index.js +114 -7
- package/lib-next/theme/ApiItem/Layout/styles.module.css +11 -3
- 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/Body/index.tsx +106 -6
- package/src/theme/ApiItem/Layout/styles.module.css +11 -3
- package/src/theme/MimeTabs/styles.module.css +1 -0
- package/src/theme/SchemaTabs/index.js +4 -1
|
@@ -7,8 +7,12 @@ exports.default = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _react = _interopRequireDefault(require("react"));
|
|
9
9
|
|
|
10
|
+
var _TabItem = _interopRequireDefault(require("@theme/TabItem"));
|
|
11
|
+
|
|
10
12
|
var _xmlFormatter = _interopRequireDefault(require("xml-formatter"));
|
|
11
13
|
|
|
14
|
+
var _SchemaTabs = _interopRequireDefault(require("../../SchemaTabs"));
|
|
15
|
+
|
|
12
16
|
var _ContentType = _interopRequireDefault(require("../ContentType"));
|
|
13
17
|
|
|
14
18
|
var _FormSelect = _interopRequireDefault(require("../FormSelect"));
|
|
@@ -36,6 +40,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
36
40
|
* LICENSE file in the root directory of this source tree.
|
|
37
41
|
* ========================================================================== */
|
|
38
42
|
// @ts-ignore
|
|
43
|
+
// @ts-ignore
|
|
39
44
|
function BodyWrap({
|
|
40
45
|
requestBodyMetadata,
|
|
41
46
|
jsonRequestBodyExample
|
|
@@ -58,7 +63,7 @@ function Body({
|
|
|
58
63
|
requestBodyMetadata,
|
|
59
64
|
jsonRequestBodyExample
|
|
60
65
|
}) {
|
|
61
|
-
var _requestBodyMetadata$, _requestBodyMetadata$2;
|
|
66
|
+
var _requestBodyMetadata$, _requestBodyMetadata$2, _requestBodyMetadata$3, _requestBodyMetadata$4, _requestBodyMetadata$5, _requestBodyMetadata$6;
|
|
62
67
|
|
|
63
68
|
const contentType = (0, _hooks.useTypedSelector)(state => state.contentType.value);
|
|
64
69
|
const required = requestBodyMetadata === null || requestBodyMetadata === void 0 ? void 0 : requestBodyMetadata.required;
|
|
@@ -82,6 +87,8 @@ function Body({
|
|
|
82
87
|
// - application/x-www-form-urlencoded
|
|
83
88
|
|
|
84
89
|
const schema = requestBodyMetadata === null || requestBodyMetadata === void 0 ? void 0 : (_requestBodyMetadata$ = requestBodyMetadata.content) === null || _requestBodyMetadata$ === void 0 ? void 0 : (_requestBodyMetadata$2 = _requestBodyMetadata$[contentType]) === null || _requestBodyMetadata$2 === void 0 ? void 0 : _requestBodyMetadata$2.schema;
|
|
90
|
+
const example = requestBodyMetadata === null || requestBodyMetadata === void 0 ? void 0 : (_requestBodyMetadata$3 = requestBodyMetadata.content) === null || _requestBodyMetadata$3 === void 0 ? void 0 : (_requestBodyMetadata$4 = _requestBodyMetadata$3[contentType]) === null || _requestBodyMetadata$4 === void 0 ? void 0 : _requestBodyMetadata$4.example;
|
|
91
|
+
const examples = requestBodyMetadata === null || requestBodyMetadata === void 0 ? void 0 : (_requestBodyMetadata$5 = requestBodyMetadata.content) === null || _requestBodyMetadata$5 === void 0 ? void 0 : (_requestBodyMetadata$6 = _requestBodyMetadata$5[contentType]) === null || _requestBodyMetadata$6 === void 0 ? void 0 : _requestBodyMetadata$6.examples;
|
|
85
92
|
|
|
86
93
|
if ((schema === null || schema === void 0 ? void 0 : schema.format) === "binary") {
|
|
87
94
|
return <_FormItem.default label="Body" required={required}>
|
|
@@ -161,35 +168,123 @@ function Body({
|
|
|
161
168
|
}
|
|
162
169
|
|
|
163
170
|
let language = "plaintext";
|
|
164
|
-
let
|
|
171
|
+
let defaultBody = ""; //"body content";
|
|
172
|
+
|
|
173
|
+
let exampleBody;
|
|
174
|
+
let examplesBodies = [];
|
|
165
175
|
|
|
166
176
|
if (contentType === "application/json" || contentType.endsWith("+json")) {
|
|
167
177
|
if (jsonRequestBodyExample) {
|
|
168
|
-
|
|
178
|
+
defaultBody = JSON.stringify(jsonRequestBodyExample, null, 2);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
if (example) {
|
|
182
|
+
exampleBody = JSON.stringify(example, null, 2);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
if (examples) {
|
|
186
|
+
for (const [key, example] of Object.entries(examples)) {
|
|
187
|
+
examplesBodies.push({
|
|
188
|
+
label: key,
|
|
189
|
+
body: JSON.stringify(example.value, null, 2),
|
|
190
|
+
summary: example.summary
|
|
191
|
+
});
|
|
192
|
+
}
|
|
169
193
|
}
|
|
170
194
|
|
|
171
195
|
language = "json";
|
|
172
196
|
}
|
|
173
197
|
|
|
174
|
-
if (contentType === "application/xml") {
|
|
198
|
+
if (contentType === "application/xml" || contentType.endsWith("+xml")) {
|
|
175
199
|
if (jsonRequestBodyExample) {
|
|
176
200
|
try {
|
|
177
|
-
|
|
201
|
+
defaultBody = (0, _xmlFormatter.default)((0, _json2xml.default)(jsonRequestBodyExample, ""), {
|
|
202
|
+
indentation: " ",
|
|
203
|
+
lineSeparator: "\n",
|
|
204
|
+
collapseContent: true
|
|
205
|
+
});
|
|
206
|
+
} catch {
|
|
207
|
+
defaultBody = (0, _json2xml.default)(jsonRequestBodyExample);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
if (example) {
|
|
212
|
+
try {
|
|
213
|
+
exampleBody = (0, _xmlFormatter.default)((0, _json2xml.default)(example, ""), {
|
|
178
214
|
indentation: " ",
|
|
179
215
|
lineSeparator: "\n",
|
|
180
216
|
collapseContent: true
|
|
181
217
|
});
|
|
182
218
|
} catch {
|
|
183
|
-
|
|
219
|
+
exampleBody = (0, _json2xml.default)(example);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if (examples) {
|
|
224
|
+
for (const [key, example] of Object.entries(examples)) {
|
|
225
|
+
let formattedXmlBody;
|
|
226
|
+
|
|
227
|
+
try {
|
|
228
|
+
formattedXmlBody = (0, _xmlFormatter.default)(example.value, {
|
|
229
|
+
indentation: " ",
|
|
230
|
+
lineSeparator: "\n",
|
|
231
|
+
collapseContent: true
|
|
232
|
+
});
|
|
233
|
+
} catch {
|
|
234
|
+
formattedXmlBody = example.value;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
examplesBodies.push({
|
|
238
|
+
label: key,
|
|
239
|
+
body: formattedXmlBody,
|
|
240
|
+
summary: example.summary
|
|
241
|
+
});
|
|
184
242
|
}
|
|
185
243
|
}
|
|
186
244
|
|
|
187
245
|
language = "xml";
|
|
188
246
|
}
|
|
189
247
|
|
|
248
|
+
if (exampleBody) {
|
|
249
|
+
return <_FormItem.default label="Body" required={required}>
|
|
250
|
+
<_SchemaTabs.default lazy>
|
|
251
|
+
<_TabItem.default label="Default" value="default" default>
|
|
252
|
+
<_LiveEditor.default action={dispatch} language={language}>
|
|
253
|
+
{defaultBody}
|
|
254
|
+
</_LiveEditor.default>
|
|
255
|
+
</_TabItem.default>
|
|
256
|
+
<_TabItem.default label="Example" value="example">
|
|
257
|
+
{exampleBody && <_LiveEditor.default action={dispatch} language={language}>
|
|
258
|
+
{exampleBody}
|
|
259
|
+
</_LiveEditor.default>}
|
|
260
|
+
</_TabItem.default>
|
|
261
|
+
</_SchemaTabs.default>
|
|
262
|
+
</_FormItem.default>;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
if (examplesBodies && examplesBodies.length > 0) {
|
|
266
|
+
return <_FormItem.default label="Body" required={required}>
|
|
267
|
+
<_SchemaTabs.default lazy>
|
|
268
|
+
<_TabItem.default label="Default" value="default" default>
|
|
269
|
+
<_LiveEditor.default action={dispatch} language={language}>
|
|
270
|
+
{defaultBody}
|
|
271
|
+
</_LiveEditor.default>
|
|
272
|
+
</_TabItem.default>
|
|
273
|
+
{examplesBodies.map(example => {
|
|
274
|
+
return <_TabItem.default label={example.label} value={example.label} key={example.label}>
|
|
275
|
+
{example.summary && <p>{example.summary}</p>}
|
|
276
|
+
{example.body && <_LiveEditor.default action={dispatch} language={language}>
|
|
277
|
+
{example.body}
|
|
278
|
+
</_LiveEditor.default>}
|
|
279
|
+
</_TabItem.default>;
|
|
280
|
+
})}
|
|
281
|
+
</_SchemaTabs.default>
|
|
282
|
+
</_FormItem.default>;
|
|
283
|
+
}
|
|
284
|
+
|
|
190
285
|
return <_FormItem.default label="Body" required={required}>
|
|
191
286
|
<_LiveEditor.default action={dispatch} language={language}>
|
|
192
|
-
{
|
|
287
|
+
{defaultBody}
|
|
193
288
|
</_LiveEditor.default>
|
|
194
289
|
</_FormItem.default>;
|
|
195
290
|
}
|
|
@@ -154,12 +154,15 @@
|
|
|
154
154
|
margin-bottom: 0;
|
|
155
155
|
}
|
|
156
156
|
|
|
157
|
-
:global(
|
|
157
|
+
:global([class^="paramsItem"]::before),
|
|
158
|
+
:global([class^="schemaItem"]::before) {
|
|
158
159
|
position: absolute;
|
|
159
160
|
top: 10px;
|
|
160
161
|
left: 0;
|
|
161
|
-
width: 0.7rem;
|
|
162
|
-
|
|
162
|
+
width: 0.7rem;
|
|
163
|
+
/* width of horizontal line */
|
|
164
|
+
height: 0.5rem;
|
|
165
|
+
/* vertical position of line */
|
|
163
166
|
vertical-align: top;
|
|
164
167
|
border-bottom: thin solid var(--ifm-color-gray-500);
|
|
165
168
|
content: "";
|
|
@@ -410,3 +413,8 @@
|
|
|
410
413
|
max-height: 500px;
|
|
411
414
|
overflow: auto;
|
|
412
415
|
}
|
|
416
|
+
|
|
417
|
+
/* Prism code styles */
|
|
418
|
+
:global(.prism-code.language-json) {
|
|
419
|
+
white-space: nowrap !important;
|
|
420
|
+
}
|
|
@@ -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,10 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
* ========================================================================== */
|
|
7
7
|
import React from "react";
|
|
8
|
-
import
|
|
8
|
+
import TabItem from "@theme/TabItem";
|
|
9
|
+
import format from "xml-formatter"; // @ts-ignore
|
|
10
|
+
|
|
11
|
+
import SchemaTabs from "../../SchemaTabs";
|
|
9
12
|
import ContentType from "../ContentType";
|
|
10
13
|
import FormSelect from "../FormSelect";
|
|
11
14
|
import { useTypedDispatch, useTypedSelector } from "../hooks";
|
|
@@ -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
|
);
|
|
@@ -154,12 +154,15 @@
|
|
|
154
154
|
margin-bottom: 0;
|
|
155
155
|
}
|
|
156
156
|
|
|
157
|
-
:global(
|
|
157
|
+
:global([class^="paramsItem"]::before),
|
|
158
|
+
:global([class^="schemaItem"]::before) {
|
|
158
159
|
position: absolute;
|
|
159
160
|
top: 10px;
|
|
160
161
|
left: 0;
|
|
161
|
-
width: 0.7rem;
|
|
162
|
-
|
|
162
|
+
width: 0.7rem;
|
|
163
|
+
/* width of horizontal line */
|
|
164
|
+
height: 0.5rem;
|
|
165
|
+
/* vertical position of line */
|
|
163
166
|
vertical-align: top;
|
|
164
167
|
border-bottom: thin solid var(--ifm-color-gray-500);
|
|
165
168
|
content: "";
|
|
@@ -410,3 +413,8 @@
|
|
|
410
413
|
max-height: 500px;
|
|
411
414
|
overflow: auto;
|
|
412
415
|
}
|
|
416
|
+
|
|
417
|
+
/* Prism code styles */
|
|
418
|
+
:global(.prism-code.language-json) {
|
|
419
|
+
white-space: nowrap !important;
|
|
420
|
+
}
|
|
@@ -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
|
}
|
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-476",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"openapi",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"buffer": "^6.0.3",
|
|
51
51
|
"clsx": "^1.1.1",
|
|
52
52
|
"crypto-js": "^4.1.1",
|
|
53
|
-
"docusaurus-plugin-openapi-docs": "0.0.0-
|
|
53
|
+
"docusaurus-plugin-openapi-docs": "0.0.0-476",
|
|
54
54
|
"immer": "^9.0.7",
|
|
55
55
|
"lodash": "^4.17.20",
|
|
56
56
|
"process": "^0.11.10",
|
|
@@ -70,5 +70,5 @@
|
|
|
70
70
|
"engines": {
|
|
71
71
|
"node": ">=14"
|
|
72
72
|
},
|
|
73
|
-
"gitHead": "
|
|
73
|
+
"gitHead": "f9884501f80f81eaeed207cc0064aa43826214d0"
|
|
74
74
|
}
|
|
@@ -7,9 +7,12 @@
|
|
|
7
7
|
|
|
8
8
|
import React from "react";
|
|
9
9
|
|
|
10
|
+
import TabItem from "@theme/TabItem";
|
|
10
11
|
import { RequestBodyObject } from "docusaurus-plugin-openapi-docs/src/openapi/types";
|
|
11
12
|
import format from "xml-formatter";
|
|
12
13
|
|
|
14
|
+
// @ts-ignore
|
|
15
|
+
import SchemaTabs from "../../SchemaTabs";
|
|
13
16
|
import ContentType from "../ContentType";
|
|
14
17
|
import FormSelect from "../FormSelect";
|
|
15
18
|
import { useTypedDispatch, useTypedSelector } from "../hooks";
|
|
@@ -82,6 +85,8 @@ function Body({ requestBodyMetadata, jsonRequestBodyExample }: Props) {
|
|
|
82
85
|
// - application/x-www-form-urlencoded
|
|
83
86
|
|
|
84
87
|
const schema = requestBodyMetadata?.content?.[contentType]?.schema;
|
|
88
|
+
const example = requestBodyMetadata?.content?.[contentType]?.example;
|
|
89
|
+
const examples = requestBodyMetadata?.content?.[contentType]?.examples;
|
|
85
90
|
|
|
86
91
|
if (schema?.format === "binary") {
|
|
87
92
|
return (
|
|
@@ -209,34 +214,129 @@ function Body({ requestBodyMetadata, jsonRequestBodyExample }: Props) {
|
|
|
209
214
|
}
|
|
210
215
|
|
|
211
216
|
let language = "plaintext";
|
|
212
|
-
let
|
|
217
|
+
let defaultBody = ""; //"body content";
|
|
218
|
+
let exampleBody;
|
|
219
|
+
let examplesBodies = [] as any;
|
|
213
220
|
|
|
214
221
|
if (contentType === "application/json" || contentType.endsWith("+json")) {
|
|
215
222
|
if (jsonRequestBodyExample) {
|
|
216
|
-
|
|
223
|
+
defaultBody = JSON.stringify(jsonRequestBodyExample, null, 2);
|
|
224
|
+
}
|
|
225
|
+
if (example) {
|
|
226
|
+
exampleBody = JSON.stringify(example, null, 2);
|
|
227
|
+
}
|
|
228
|
+
if (examples) {
|
|
229
|
+
for (const [key, example] of Object.entries(examples)) {
|
|
230
|
+
examplesBodies.push({
|
|
231
|
+
label: key,
|
|
232
|
+
body: JSON.stringify(example.value, null, 2),
|
|
233
|
+
summary: example.summary,
|
|
234
|
+
});
|
|
235
|
+
}
|
|
217
236
|
}
|
|
218
237
|
language = "json";
|
|
219
238
|
}
|
|
220
239
|
|
|
221
|
-
if (contentType === "application/xml") {
|
|
240
|
+
if (contentType === "application/xml" || contentType.endsWith("+xml")) {
|
|
222
241
|
if (jsonRequestBodyExample) {
|
|
223
242
|
try {
|
|
224
|
-
|
|
243
|
+
defaultBody = format(json2xml(jsonRequestBodyExample, ""), {
|
|
244
|
+
indentation: " ",
|
|
245
|
+
lineSeparator: "\n",
|
|
246
|
+
collapseContent: true,
|
|
247
|
+
});
|
|
248
|
+
} catch {
|
|
249
|
+
defaultBody = json2xml(jsonRequestBodyExample);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
if (example) {
|
|
253
|
+
try {
|
|
254
|
+
exampleBody = format(json2xml(example, ""), {
|
|
225
255
|
indentation: " ",
|
|
226
256
|
lineSeparator: "\n",
|
|
227
257
|
collapseContent: true,
|
|
228
258
|
});
|
|
229
259
|
} catch {
|
|
230
|
-
|
|
260
|
+
exampleBody = json2xml(example);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
if (examples) {
|
|
264
|
+
for (const [key, example] of Object.entries(examples)) {
|
|
265
|
+
let formattedXmlBody;
|
|
266
|
+
try {
|
|
267
|
+
formattedXmlBody = format(example.value, {
|
|
268
|
+
indentation: " ",
|
|
269
|
+
lineSeparator: "\n",
|
|
270
|
+
collapseContent: true,
|
|
271
|
+
});
|
|
272
|
+
} catch {
|
|
273
|
+
formattedXmlBody = example.value;
|
|
274
|
+
}
|
|
275
|
+
examplesBodies.push({
|
|
276
|
+
label: key,
|
|
277
|
+
body: formattedXmlBody,
|
|
278
|
+
summary: example.summary,
|
|
279
|
+
});
|
|
231
280
|
}
|
|
232
281
|
}
|
|
233
282
|
language = "xml";
|
|
234
283
|
}
|
|
235
284
|
|
|
285
|
+
if (exampleBody) {
|
|
286
|
+
return (
|
|
287
|
+
<FormItem label="Body" required={required}>
|
|
288
|
+
<SchemaTabs lazy>
|
|
289
|
+
<TabItem label="Default" value="default" default>
|
|
290
|
+
<LiveApp action={dispatch} language={language}>
|
|
291
|
+
{defaultBody}
|
|
292
|
+
</LiveApp>
|
|
293
|
+
</TabItem>
|
|
294
|
+
<TabItem label="Example" value="example">
|
|
295
|
+
{exampleBody && (
|
|
296
|
+
<LiveApp action={dispatch} language={language}>
|
|
297
|
+
{exampleBody}
|
|
298
|
+
</LiveApp>
|
|
299
|
+
)}
|
|
300
|
+
</TabItem>
|
|
301
|
+
</SchemaTabs>
|
|
302
|
+
</FormItem>
|
|
303
|
+
);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
if (examplesBodies && examplesBodies.length > 0) {
|
|
307
|
+
return (
|
|
308
|
+
<FormItem label="Body" required={required}>
|
|
309
|
+
<SchemaTabs lazy>
|
|
310
|
+
<TabItem label="Default" value="default" default>
|
|
311
|
+
<LiveApp action={dispatch} language={language}>
|
|
312
|
+
{defaultBody}
|
|
313
|
+
</LiveApp>
|
|
314
|
+
</TabItem>
|
|
315
|
+
{examplesBodies.map((example: any) => {
|
|
316
|
+
return (
|
|
317
|
+
<TabItem
|
|
318
|
+
label={example.label}
|
|
319
|
+
value={example.label}
|
|
320
|
+
key={example.label}
|
|
321
|
+
>
|
|
322
|
+
{example.summary && <p>{example.summary}</p>}
|
|
323
|
+
{example.body && (
|
|
324
|
+
<LiveApp action={dispatch} language={language}>
|
|
325
|
+
{example.body}
|
|
326
|
+
</LiveApp>
|
|
327
|
+
)}
|
|
328
|
+
</TabItem>
|
|
329
|
+
);
|
|
330
|
+
})}
|
|
331
|
+
</SchemaTabs>
|
|
332
|
+
</FormItem>
|
|
333
|
+
);
|
|
334
|
+
}
|
|
335
|
+
|
|
236
336
|
return (
|
|
237
337
|
<FormItem label="Body" required={required}>
|
|
238
338
|
<LiveApp action={dispatch} language={language}>
|
|
239
|
-
{
|
|
339
|
+
{defaultBody}
|
|
240
340
|
</LiveApp>
|
|
241
341
|
</FormItem>
|
|
242
342
|
);
|
|
@@ -154,12 +154,15 @@
|
|
|
154
154
|
margin-bottom: 0;
|
|
155
155
|
}
|
|
156
156
|
|
|
157
|
-
:global(
|
|
157
|
+
:global([class^="paramsItem"]::before),
|
|
158
|
+
:global([class^="schemaItem"]::before) {
|
|
158
159
|
position: absolute;
|
|
159
160
|
top: 10px;
|
|
160
161
|
left: 0;
|
|
161
|
-
width: 0.7rem;
|
|
162
|
-
|
|
162
|
+
width: 0.7rem;
|
|
163
|
+
/* width of horizontal line */
|
|
164
|
+
height: 0.5rem;
|
|
165
|
+
/* vertical position of line */
|
|
163
166
|
vertical-align: top;
|
|
164
167
|
border-bottom: thin solid var(--ifm-color-gray-500);
|
|
165
168
|
content: "";
|
|
@@ -410,3 +413,8 @@
|
|
|
410
413
|
max-height: 500px;
|
|
411
414
|
overflow: auto;
|
|
412
415
|
}
|
|
416
|
+
|
|
417
|
+
/* Prism code styles */
|
|
418
|
+
:global(.prism-code.language-json) {
|
|
419
|
+
white-space: nowrap !important;
|
|
420
|
+
}
|
|
@@ -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
|
}
|