docusaurus-plugin-openapi-docs 0.0.0-beta.668 → 0.0.0-beta.670

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.
@@ -356,8 +356,6 @@ function createDetailsNode(name, schemaName, schema, required, nullable) {
356
356
  * For handling anyOf/oneOf properties.
357
357
  */
358
358
  function createAnyOneOfProperty(name, schemaName, schema, required, nullable) {
359
- const type = schema.oneOf ? "oneOf" : "anyOf";
360
- const children = schema[type] || [];
361
359
  return (0, utils_1.create)("SchemaItem", {
362
360
  collapsible: true,
363
361
  className: "schemaItem",
@@ -408,38 +406,7 @@ function createAnyOneOfProperty(name, schemaName, schema, required, nullable) {
408
406
  })),
409
407
  ],
410
408
  }),
411
- (0, utils_1.create)("div", {
412
- children: [
413
- (0, utils_1.create)("span", {
414
- className: "badge badge--info",
415
- children: type,
416
- }),
417
- (0, utils_1.create)("SchemaTabs", {
418
- children: children.map((property, index) => {
419
- var _a;
420
- const label = (_a = property.title) !== null && _a !== void 0 ? _a : `MOD${index + 1}`;
421
- if (property.properties) {
422
- return (0, utils_1.create)("TabItem", {
423
- label: label,
424
- value: `${index}-property`,
425
- children: [createNodes(property)],
426
- });
427
- }
428
- return (0, utils_1.create)("TabItem", {
429
- label: label,
430
- value: `${index}-property`,
431
- children: [
432
- (0, utils_1.create)("p", { children: label }),
433
- (0, utils_1.guard)(schema.description, (description) => (0, utils_1.create)("div", {
434
- style: { marginTop: ".5rem", marginBottom: ".5rem" },
435
- children: (0, createDescription_1.createDescription)(description),
436
- })),
437
- ],
438
- });
439
- }),
440
- }),
441
- ],
442
- }),
409
+ createAnyOneOf(schema),
443
410
  ],
444
411
  }),
445
412
  ],
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,73 @@
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 = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9
+ if (k2 === undefined) k2 = k;
10
+ var desc = Object.getOwnPropertyDescriptor(m, k);
11
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
12
+ desc = { enumerable: true, get: function() { return m[k]; } };
13
+ }
14
+ Object.defineProperty(o, k2, desc);
15
+ }) : (function(o, m, k, k2) {
16
+ if (k2 === undefined) k2 = k;
17
+ o[k2] = m[k];
18
+ }));
19
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
20
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
21
+ }) : function(o, v) {
22
+ o["default"] = v;
23
+ });
24
+ var __importStar = (this && this.__importStar) || function (mod) {
25
+ if (mod && mod.__esModule) return mod;
26
+ var result = {};
27
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
28
+ __setModuleDefault(result, mod);
29
+ return result;
30
+ };
31
+ Object.defineProperty(exports, "__esModule", { value: true });
32
+ const prettier = __importStar(require("prettier"));
33
+ const createSchema_1 = require("./createSchema");
34
+ describe("createNodes", () => {
35
+ it("should create readable MODs for oneOf primitive properties", () => {
36
+ const schema = {
37
+ type: "object",
38
+ properties: {
39
+ oneOfProperty: {
40
+ oneOf: [
41
+ {
42
+ type: "object",
43
+ properties: {
44
+ noseLength: {
45
+ type: "number",
46
+ },
47
+ },
48
+ required: ["noseLength"],
49
+ description: "Clown's nose length",
50
+ },
51
+ {
52
+ type: "array",
53
+ items: {
54
+ type: "string",
55
+ },
56
+ description: "Array of strings",
57
+ },
58
+ {
59
+ type: "boolean",
60
+ },
61
+ {
62
+ type: "number",
63
+ },
64
+ {
65
+ type: "string",
66
+ },
67
+ ],
68
+ },
69
+ },
70
+ };
71
+ expect((0, createSchema_1.createNodes)(schema).map((md) => prettier.format(md, { parser: "babel" }))).toMatchSnapshot();
72
+ });
73
+ });
@@ -10,6 +10,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  const path_1 = __importDefault(require("path"));
13
+ // eslint-disable-next-line import/no-extraneous-dependencies
13
14
  const utils_1 = require("@docusaurus/utils");
14
15
  const _1 = require(".");
15
16
  // npx jest packages/docusaurus-plugin-openapi/src/openapi/openapi.test.ts --watch
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "docusaurus-plugin-openapi-docs",
3
3
  "description": "OpenAPI plugin for Docusaurus.",
4
- "version": "0.0.0-beta.668",
4
+ "version": "0.0.0-beta.670",
5
5
  "license": "MIT",
6
6
  "keywords": [
7
7
  "openapi",
@@ -60,5 +60,5 @@
60
60
  "engines": {
61
61
  "node": ">=14"
62
62
  },
63
- "gitHead": "6cc9b3278fa74422cdec235464488059b8458806"
63
+ "gitHead": "027a734f68092976b1e49ba8475b4f9a0909db67"
64
64
  }
@@ -0,0 +1,98 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`createNodes should create readable MODs for oneOf primitive properties 1`] = `
4
+ Array [
5
+ "<SchemaItem collapsible={true} className={\\"schemaItem\\"}>
6
+ <details style={{}} className={\\"openapi-markdown__details\\"}>
7
+ <summary style={{}}>
8
+ <strong>oneOfProperty</strong>
9
+ <span style={{ opacity: \\"0.6\\" }}> object</span>
10
+ </summary>
11
+ <div style={{ marginLeft: \\"1rem\\" }}></div>
12
+ <div>
13
+ <span className={\\"badge badge--info\\"}>oneOf</span>
14
+ <SchemaTabs>
15
+ <TabItem label={\\"MOD1\\"} value={\\"0-item-properties\\"}>
16
+ <SchemaItem
17
+ collapsible={false}
18
+ name={\\"noseLength\\"}
19
+ required={true}
20
+ schemaName={\\"number\\"}
21
+ qualifierMessage={undefined}
22
+ schema={{ type: \\"number\\" }}
23
+ ></SchemaItem>
24
+ </TabItem>
25
+ <TabItem label={\\"MOD2\\"} value={\\"1-item-properties\\"}>
26
+ <li>
27
+ <div
28
+ style={{
29
+ fontSize: \\"var(--ifm-code-font-size)\\",
30
+ opacity: \\"0.6\\",
31
+ marginLeft: \\"-.5rem\\",
32
+ paddingBottom: \\".5rem\\",
33
+ }}
34
+ >
35
+ Array [
36
+ </div>
37
+ </li>
38
+ <div
39
+ style={{
40
+ marginTop: \\".5rem\\",
41
+ marginBottom: \\".5rem\\",
42
+ marginLeft: \\"1rem\\",
43
+ }}
44
+ >
45
+ string
46
+ </div>
47
+ <li>
48
+ <div
49
+ style={{
50
+ fontSize: \\"var(--ifm-code-font-size)\\",
51
+ opacity: \\"0.6\\",
52
+ marginLeft: \\"-.5rem\\",
53
+ }}
54
+ >
55
+ ]
56
+ </div>
57
+ </li>
58
+ </TabItem>
59
+ <TabItem label={\\"MOD3\\"} value={\\"2-item-properties\\"}>
60
+ <div
61
+ style={{
62
+ marginTop: \\".5rem\\",
63
+ marginBottom: \\".5rem\\",
64
+ marginLeft: \\"1rem\\",
65
+ }}
66
+ >
67
+ boolean
68
+ </div>
69
+ </TabItem>
70
+ <TabItem label={\\"MOD4\\"} value={\\"3-item-properties\\"}>
71
+ <div
72
+ style={{
73
+ marginTop: \\".5rem\\",
74
+ marginBottom: \\".5rem\\",
75
+ marginLeft: \\"1rem\\",
76
+ }}
77
+ >
78
+ number
79
+ </div>
80
+ </TabItem>
81
+ <TabItem label={\\"MOD5\\"} value={\\"4-item-properties\\"}>
82
+ <div
83
+ style={{
84
+ marginTop: \\".5rem\\",
85
+ marginBottom: \\".5rem\\",
86
+ marginLeft: \\"1rem\\",
87
+ }}
88
+ >
89
+ string
90
+ </div>
91
+ </TabItem>
92
+ </SchemaTabs>
93
+ </div>
94
+ </details>
95
+ </SchemaItem>;
96
+ ",
97
+ ]
98
+ `;
@@ -0,0 +1,56 @@
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 * as prettier from "prettier";
9
+
10
+ import { SchemaObject } from "../openapi/types";
11
+ import { createNodes } from "./createSchema";
12
+
13
+ describe("createNodes", () => {
14
+ it("should create readable MODs for oneOf primitive properties", () => {
15
+ const schema: SchemaObject = {
16
+ type: "object",
17
+ properties: {
18
+ oneOfProperty: {
19
+ oneOf: [
20
+ {
21
+ type: "object",
22
+ properties: {
23
+ noseLength: {
24
+ type: "number",
25
+ },
26
+ },
27
+ required: ["noseLength"],
28
+ description: "Clown's nose length",
29
+ },
30
+ {
31
+ type: "array",
32
+ items: {
33
+ type: "string",
34
+ },
35
+ description: "Array of strings",
36
+ },
37
+ {
38
+ type: "boolean",
39
+ },
40
+ {
41
+ type: "number",
42
+ },
43
+ {
44
+ type: "string",
45
+ },
46
+ ],
47
+ },
48
+ },
49
+ };
50
+ expect(
51
+ createNodes(schema).map((md: any) =>
52
+ prettier.format(md, { parser: "babel" })
53
+ )
54
+ ).toMatchSnapshot();
55
+ });
56
+ });
@@ -430,8 +430,6 @@ function createAnyOneOfProperty(
430
430
  required: string[] | boolean,
431
431
  nullable: boolean | unknown
432
432
  ): any {
433
- const type = schema.oneOf ? "oneOf" : "anyOf";
434
- const children = schema[type] || [];
435
433
  return create("SchemaItem", {
436
434
  collapsible: true,
437
435
  className: "schemaItem",
@@ -492,39 +490,7 @@ function createAnyOneOfProperty(
492
490
  ),
493
491
  ],
494
492
  }),
495
- create("div", {
496
- children: [
497
- create("span", {
498
- className: "badge badge--info",
499
- children: type,
500
- }),
501
- create("SchemaTabs", {
502
- children: children.map((property, index) => {
503
- const label = property.title ?? `MOD${index + 1}`;
504
- if (property.properties) {
505
- return create("TabItem", {
506
- label: label,
507
- value: `${index}-property`,
508
- children: [createNodes(property)],
509
- });
510
- }
511
- return create("TabItem", {
512
- label: label,
513
- value: `${index}-property`,
514
- children: [
515
- create("p", { children: label }),
516
- guard(schema.description, (description) =>
517
- create("div", {
518
- style: { marginTop: ".5rem", marginBottom: ".5rem" },
519
- children: createDescription(description),
520
- })
521
- ),
522
- ],
523
- });
524
- }),
525
- }),
526
- ],
527
- }),
493
+ createAnyOneOf(schema),
528
494
  ],
529
495
  }),
530
496
  ],
@@ -7,6 +7,7 @@
7
7
 
8
8
  import path from "path";
9
9
 
10
+ // eslint-disable-next-line import/no-extraneous-dependencies
10
11
  import { posixPath } from "@docusaurus/utils";
11
12
 
12
13
  import { readOpenapiFiles } from ".";