docusaurus-theme-openapi-docs 0.0.0-1151 → 0.0.0-1154

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.
@@ -92,10 +92,6 @@ function FileArrayFormBodyItem({ id, description }) {
92
92
  );
93
93
  return;
94
94
  }
95
- let maxIndex = 0;
96
- newItems.keys().forEach((item) => {
97
- maxIndex = item > maxIndex ? item : maxIndex;
98
- });
99
95
  newItems.set(index, {
100
96
  src: `/path/to/${file.name}`,
101
97
  content: file,
@@ -6,6 +6,7 @@ interface FormBodyItemProps {
6
6
  schema: SchemaObject;
7
7
  label?: string;
8
8
  required?: boolean;
9
+ exampleValue?: SchemaObject["example"];
9
10
  }
10
- export default function FormBodyItem({ schemaObject, id, schema, label, required, }: FormBodyItemProps): React.JSX.Element;
11
+ export default function FormBodyItem({ schemaObject, id, schema, label, required, exampleValue, }: FormBodyItemProps): React.JSX.Element;
11
12
  export {};
@@ -5,6 +5,62 @@
5
5
  * This source code is licensed under the MIT license found in the
6
6
  * LICENSE file in the root directory of this source tree.
7
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
+ })();
8
64
  var __importDefault =
9
65
  (this && this.__importDefault) ||
10
66
  function (mod) {
@@ -12,7 +68,7 @@ var __importDefault =
12
68
  };
13
69
  Object.defineProperty(exports, "__esModule", { value: true });
14
70
  exports.default = FormBodyItem;
15
- const react_1 = __importDefault(require("react"));
71
+ const react_1 = __importStar(require("react"));
16
72
  const FormFileUpload_1 = __importDefault(
17
73
  require("@theme/ApiExplorer/FormFileUpload")
18
74
  );
@@ -27,8 +83,30 @@ const FileArrayFormBodyItem_1 = __importDefault(
27
83
  require("../FileArrayFormBodyItem")
28
84
  );
29
85
  const slice_1 = require("../slice");
30
- function FormBodyItem({ schemaObject, id, schema, label, required }) {
86
+ function FormBodyItem({
87
+ schemaObject,
88
+ id,
89
+ schema,
90
+ label,
91
+ required,
92
+ exampleValue,
93
+ }) {
31
94
  const dispatch = (0, hooks_1.useTypedDispatch)();
95
+ const [value, setValue] = (0, react_1.useState)(() => {
96
+ let initialValue = exampleValue ?? "";
97
+ if (schemaObject.type === "object" && exampleValue) {
98
+ initialValue = JSON.stringify(exampleValue, null, 2);
99
+ }
100
+ return initialValue;
101
+ });
102
+ (0, react_1.useEffect)(() => {
103
+ if (value) {
104
+ dispatch((0, slice_1.setStringFormBody)({ key: id, value }));
105
+ } else {
106
+ dispatch((0, slice_1.clearFormBodyKey)(id));
107
+ }
108
+ // eslint-disable-next-line react-hooks/exhaustive-deps
109
+ }, []);
32
110
  if (
33
111
  schemaObject.type === "array" &&
34
112
  schemaObject.items?.format === "binary"
@@ -76,15 +154,7 @@ function FormBodyItem({ schemaObject, id, schema, label, required }) {
76
154
  })
77
155
  );
78
156
  }
79
- if (
80
- schemaObject.type === "object" &&
81
- (schemaObject.example || schemaObject.examples)
82
- ) {
83
- const objectExample = JSON.stringify(
84
- schemaObject.example ?? schemaObject.examples[0],
85
- null,
86
- 2
87
- );
157
+ if (schemaObject.type === "object") {
88
158
  return react_1.default.createElement(
89
159
  react_1.default.Fragment,
90
160
  null,
@@ -99,7 +169,7 @@ function FormBodyItem({ schemaObject, id, schema, label, required }) {
99
169
  action: (code) =>
100
170
  dispatch((0, slice_1.setStringFormBody)({ key: id, value: code })),
101
171
  },
102
- objectExample
172
+ value
103
173
  )
104
174
  );
105
175
  }
@@ -110,9 +180,11 @@ function FormBodyItem({ schemaObject, id, schema, label, required }) {
110
180
  return react_1.default.createElement(FormSelect_1.default, {
111
181
  label: label,
112
182
  required: required,
183
+ value: value,
113
184
  options: ["---", ...schemaObject.enum],
114
185
  onChange: (e) => {
115
186
  const val = e.target.value;
187
+ setValue(val);
116
188
  if (val === "---") {
117
189
  dispatch((0, slice_1.clearFormBodyKey)(id));
118
190
  } else {
@@ -130,10 +202,12 @@ function FormBodyItem({ schemaObject, id, schema, label, required }) {
130
202
  return react_1.default.createElement(FormTextInput_1.default, {
131
203
  label: label,
132
204
  required: required,
205
+ value: value,
133
206
  paramName: id,
134
207
  isRequired: Array.isArray(schema.required) && schema.required.includes(id),
135
208
  placeholder: schemaObject.description || id,
136
209
  onChange: (e) => {
210
+ setValue(e.target.value);
137
211
  dispatch(
138
212
  (0, slice_1.setStringFormBody)({ key: id, value: e.target.value })
139
213
  );
@@ -365,20 +365,89 @@ function Body({
365
365
  return react_1.default.createElement(
366
366
  FormItem_1.default,
367
367
  { className: "openapi-explorer__form-item-body-container" },
368
- Object.entries(schema.properties ?? {}).map(([key, val]) => {
369
- return react_1.default.createElement(
370
- FormItem_1.default,
371
- { key: key },
372
- react_1.default.createElement(FormBodyItem_1.default, {
373
- schemaObject: val,
374
- id: key,
375
- schema: schema,
376
- label: key,
377
- required:
378
- Array.isArray(schema.required) && schema.required.includes(key),
368
+ react_1.default.createElement(
369
+ SchemaTabs_1.default,
370
+ { className: "openapi-tabs__schema", lazy: true },
371
+ react_1.default.createElement(
372
+ TabItem_1.default,
373
+ {
374
+ label: (0, Translate_1.translate)({
375
+ id: translationIds_1.OPENAPI_BODY.EXAMPLE_FROM_SCHEMA,
376
+ message: "Example (from schema)",
377
+ }),
378
+ value: "Example (from schema)",
379
+ default: true,
380
+ },
381
+ Object.entries(schema.properties ?? {}).map(([key, val]) => {
382
+ return react_1.default.createElement(
383
+ FormItem_1.default,
384
+ { key: key },
385
+ react_1.default.createElement(FormBodyItem_1.default, {
386
+ schemaObject: val,
387
+ id: key,
388
+ schema: schema,
389
+ exampleValue: val.example,
390
+ label: key,
391
+ required:
392
+ Array.isArray(schema.required) &&
393
+ schema.required.includes(key),
394
+ })
395
+ );
379
396
  })
380
- );
381
- })
397
+ ),
398
+ example &&
399
+ // @ts-ignore
400
+ react_1.default.createElement(
401
+ TabItem_1.default,
402
+ { label: "Example", value: "example" },
403
+ Object.entries(schema.properties ?? {}).map(
404
+ ([schemaKey, schemaVal]) => {
405
+ return react_1.default.createElement(
406
+ FormItem_1.default,
407
+ { key: schemaKey },
408
+ react_1.default.createElement(FormBodyItem_1.default, {
409
+ schemaObject: schemaVal,
410
+ id: schemaKey,
411
+ schema: schema,
412
+ exampleValue: example[schemaKey],
413
+ label: schemaKey,
414
+ required:
415
+ Array.isArray(schema.required) &&
416
+ schema.required.includes(schemaKey),
417
+ })
418
+ );
419
+ }
420
+ )
421
+ ),
422
+ examples &&
423
+ Object.entries(examples).map(([key, value]) => {
424
+ return (
425
+ // @ts-ignore
426
+ react_1.default.createElement(
427
+ TabItem_1.default,
428
+ { label: key, value: key, key: key },
429
+ Object.entries(schema.properties ?? {}).map(
430
+ ([schemaKey, schemaVal]) => {
431
+ return react_1.default.createElement(
432
+ FormItem_1.default,
433
+ { key: schemaKey },
434
+ react_1.default.createElement(FormBodyItem_1.default, {
435
+ schemaObject: schemaVal,
436
+ id: schemaKey,
437
+ schema: schema,
438
+ exampleValue: value.value?.[schemaKey],
439
+ label: schemaKey,
440
+ required:
441
+ Array.isArray(schema.required) &&
442
+ schema.required.includes(schemaKey),
443
+ })
444
+ );
445
+ }
446
+ )
447
+ )
448
+ );
449
+ })
450
+ )
382
451
  );
383
452
  }
384
453
  if (exampleBody) {
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-1151",
4
+ "version": "0.0.0-1154",
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-1151",
41
+ "docusaurus-plugin-openapi-docs": "0.0.0-1154",
42
42
  "docusaurus-plugin-sass": "^0.2.6",
43
43
  "eslint-plugin-prettier": "^5.5.1"
44
44
  },
@@ -82,5 +82,5 @@
82
82
  "engines": {
83
83
  "node": ">=14"
84
84
  },
85
- "gitHead": "ce9f21391974edb2ad7a1a7c2e39700a27bc5123"
85
+ "gitHead": "0debbc67d743f553056175f125d0df187f4e4939"
86
86
  }
@@ -43,11 +43,6 @@ export default function FileArrayFormBodyItem({
43
43
  return;
44
44
  }
45
45
 
46
- let maxIndex = 0;
47
-
48
- newItems.keys().forEach((item) => {
49
- maxIndex = item > maxIndex ? item : maxIndex;
50
- });
51
46
  newItems.set(index, {
52
47
  src: `/path/to/${file.name}`,
53
48
  content: file,
@@ -5,7 +5,7 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  * ========================================================================== */
7
7
 
8
- import React from "react";
8
+ import React, { useEffect, useState } from "react";
9
9
 
10
10
  import FormFileUpload from "@theme/ApiExplorer/FormFileUpload";
11
11
  import FormLabel from "@theme/ApiExplorer/FormLabel";
@@ -24,6 +24,7 @@ interface FormBodyItemProps {
24
24
  schema: SchemaObject;
25
25
  label?: string;
26
26
  required?: boolean;
27
+ exampleValue?: SchemaObject["example"];
27
28
  }
28
29
 
29
30
  export default function FormBodyItem({
@@ -32,8 +33,27 @@ export default function FormBodyItem({
32
33
  schema,
33
34
  label,
34
35
  required,
36
+ exampleValue,
35
37
  }: FormBodyItemProps): React.JSX.Element {
36
38
  const dispatch = useTypedDispatch();
39
+ const [value, setValue] = useState(() => {
40
+ let initialValue = exampleValue ?? "";
41
+
42
+ if (schemaObject.type === "object" && exampleValue) {
43
+ initialValue = JSON.stringify(exampleValue, null, 2);
44
+ }
45
+
46
+ return initialValue;
47
+ });
48
+
49
+ useEffect(() => {
50
+ if (value) {
51
+ dispatch(setStringFormBody({ key: id, value }));
52
+ } else {
53
+ dispatch(clearFormBodyKey(id));
54
+ }
55
+ // eslint-disable-next-line react-hooks/exhaustive-deps
56
+ }, []);
37
57
 
38
58
  if (
39
59
  schemaObject.type === "array" &&
@@ -73,27 +93,18 @@ export default function FormBodyItem({
73
93
  );
74
94
  }
75
95
 
76
- if (
77
- schemaObject.type === "object" &&
78
- (schemaObject.example || schemaObject.examples)
79
- ) {
80
- const objectExample = JSON.stringify(
81
- schemaObject.example ?? schemaObject.examples[0],
82
- null,
83
- 2
84
- );
85
-
96
+ if (schemaObject.type === "object") {
86
97
  return (
87
- <>
88
- {label && <FormLabel label={label} required={required} />}
89
- <LiveApp
90
- action={(code: string) =>
91
- dispatch(setStringFormBody({ key: id, value: code }))
92
- }
93
- >
94
- {objectExample}
95
- </LiveApp>
96
- </>
98
+ <>
99
+ {label && <FormLabel label={label} required={required} />}
100
+ <LiveApp
101
+ action={(code: string) =>
102
+ dispatch(setStringFormBody({ key: id, value: code }))
103
+ }
104
+ >
105
+ {value}
106
+ </LiveApp>
107
+ </>
97
108
  );
98
109
  }
99
110
 
@@ -105,9 +116,11 @@ export default function FormBodyItem({
105
116
  <FormSelect
106
117
  label={label}
107
118
  required={required}
119
+ value={value}
108
120
  options={["---", ...schemaObject.enum]}
109
121
  onChange={(e: React.ChangeEvent<HTMLSelectElement>) => {
110
122
  const val = e.target.value;
123
+ setValue(val);
111
124
  if (val === "---") {
112
125
  dispatch(clearFormBodyKey(id));
113
126
  } else {
@@ -127,12 +140,14 @@ export default function FormBodyItem({
127
140
  <FormTextInput
128
141
  label={label}
129
142
  required={required}
143
+ value={value}
130
144
  paramName={id}
131
145
  isRequired={
132
146
  Array.isArray(schema.required) && schema.required.includes(id)
133
147
  }
134
148
  placeholder={schemaObject.description || id}
135
149
  onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
150
+ setValue(e.target.value);
136
151
  dispatch(setStringFormBody({ key: id, value: e.target.value }));
137
152
  }}
138
153
  />
@@ -316,22 +316,86 @@ function Body({
316
316
  ) {
317
317
  return (
318
318
  <FormItem className="openapi-explorer__form-item-body-container">
319
- {Object.entries(schema.properties ?? {}).map(([key, val]: any) => {
320
- return (
321
- <FormItem key={key}>
322
- <FormBodyItem
323
- schemaObject={val}
324
- id={key}
325
- schema={schema}
326
- label={key}
327
- required={
328
- Array.isArray(schema.required) &&
329
- schema.required.includes(key)
319
+ <SchemaTabs className="openapi-tabs__schema" lazy>
320
+ {/* @ts-ignore */}
321
+ <TabItem
322
+ label={translate({
323
+ id: OPENAPI_BODY.EXAMPLE_FROM_SCHEMA,
324
+ message: "Example (from schema)",
325
+ })}
326
+ value="Example (from schema)"
327
+ default
328
+ >
329
+ {Object.entries(schema.properties ?? {}).map(([key, val]: any) => {
330
+ return (
331
+ <FormItem key={key}>
332
+ <FormBodyItem
333
+ schemaObject={val}
334
+ id={key}
335
+ schema={schema}
336
+ exampleValue={val.example}
337
+ label={key}
338
+ required={
339
+ Array.isArray(schema.required) &&
340
+ schema.required.includes(key)
341
+ }
342
+ ></FormBodyItem>
343
+ </FormItem>
344
+ );
345
+ })}
346
+ </TabItem>
347
+ {example && (
348
+ // @ts-ignore
349
+ <TabItem label="Example" value="example">
350
+ {Object.entries(schema.properties ?? {}).map(
351
+ ([schemaKey, schemaVal]: any) => {
352
+ return (
353
+ <FormItem key={schemaKey}>
354
+ <FormBodyItem
355
+ schemaObject={schemaVal}
356
+ id={schemaKey}
357
+ schema={schema}
358
+ exampleValue={example[schemaKey]}
359
+ label={schemaKey}
360
+ required={
361
+ Array.isArray(schema.required) &&
362
+ schema.required.includes(schemaKey)
363
+ }
364
+ ></FormBodyItem>
365
+ </FormItem>
366
+ );
330
367
  }
331
- />
332
- </FormItem>
333
- );
334
- })}
368
+ )}
369
+ </TabItem>
370
+ )}
371
+ {examples &&
372
+ Object.entries(examples).map(([key, value]) => {
373
+ return (
374
+ // @ts-ignore
375
+ <TabItem label={key} value={key} key={key}>
376
+ {Object.entries(schema.properties ?? {}).map(
377
+ ([schemaKey, schemaVal]: any) => {
378
+ return (
379
+ <FormItem key={schemaKey}>
380
+ <FormBodyItem
381
+ schemaObject={schemaVal}
382
+ id={schemaKey}
383
+ schema={schema}
384
+ exampleValue={value.value?.[schemaKey]}
385
+ label={schemaKey}
386
+ required={
387
+ Array.isArray(schema.required) &&
388
+ schema.required.includes(schemaKey)
389
+ }
390
+ ></FormBodyItem>
391
+ </FormItem>
392
+ );
393
+ }
394
+ )}
395
+ </TabItem>
396
+ );
397
+ })}
398
+ </SchemaTabs>
335
399
  </FormItem>
336
400
  );
337
401
  }