docusaurus-plugin-openapi-docs 4.0.0 → 4.1.0

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/README.md CHANGED
@@ -41,9 +41,9 @@ Key Features:
41
41
 
42
42
  | Docusaurus OpenAPI Docs | Docusaurus |
43
43
  | ----------------------- | --------------- |
44
- | 4.0.0 (current) | `3.5.0 - 3.5.2` |
45
- | 3.0.2 (legacy) | `3.0.1 - 3.4.0` |
46
- | 2.2.1 (legacy) | `2.4.1 - 2.4.3` |
44
+ | 4.0.x (current) | `3.5.0 - 3.5.2` |
45
+ | 3.0.x (end-of-support) | `3.0.1 - 3.4.0` |
46
+ | 2.2.3 (legacy) | `2.4.1 - 2.4.3` |
47
47
  | 1.7.3 (end-of-support) | `2.0.1 - 2.2.0` |
48
48
 
49
49
  ## Bootstrapping from Template (new Docusaurus site)
@@ -172,6 +172,8 @@ The `docusaurus-plugin-openapi-docs` plugin can be configured with the following
172
172
  | `markdownGenerators` | `object` | `null` | _Optional:_ Customize MDX content with a set of options for specifying markdown generator functions. See below for a list of supported options. |
173
173
  | `showSchemas` | `boolean` | `null` | _Optional:_ If set to `true`, generates schema pages and adds them to the sidebar. |
174
174
 
175
+ ### sidebarOptions
176
+
175
177
  `sidebarOptions` can be configured with the following options:
176
178
 
177
179
  | Name | Type | Default | Description |
@@ -181,6 +183,7 @@ The `docusaurus-plugin-openapi-docs` plugin can be configured with the following
181
183
  | `sidebarCollapsible` | `boolean` | `true` | Whether sidebar categories are collapsible by default. |
182
184
  | `sidebarCollapsed` | `boolean` | `true` | Whether sidebar categories are collapsed by default. |
183
185
  | `customProps` | `object` | `null` | Additional props for customizing a sidebar item. |
186
+ | `sidebarGenerators` | `object` | `null` | Optional: Customize sidebar rendering with callback functions. |
184
187
 
185
188
  > You may optionally configure a `sidebarOptions`. In doing so, an individual `sidebar.js` slice with the configured options will be generated within the respective `outputDir`.
186
189
 
@@ -206,6 +209,14 @@ The `docusaurus-plugin-openapi-docs` plugin can be configured with the following
206
209
  | `createTagPageMD` | `function` | `null` | _Optional:_ Returns a string of the raw markdown body for tag pages.<br/><br/>**Function type:** `(pageData: TagPageMetadata) => string` |
207
210
  | `createSchemaPageMD` | `function` | `null` | _Optional:_ Returns a string of the raw markdown body for schema pages.<br/><br/>**Function type:** `(pageData: SchemaPageMetadata) => string` |
208
211
 
212
+ ### sidebarGenerators
213
+
214
+ `sidebarGenerators` can be configured with the following options:
215
+
216
+ | Name | Type | Default | Description |
217
+ | --------------- | ---------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
218
+ | `createDocItem` | `function` | `null` | Optional: Returns a `SidebarItemDoc` object containing metadata for a sidebar item.<br/><br/>**Function type:** `(item: ApiPageMetadata \| SchemaPageMetadata, context: { sidebarOptions: SidebarOptions; basePath: string }) => SidebarItemDoc` |
219
+
209
220
  ## CLI Usage
210
221
 
211
222
  ```bash
@@ -0,0 +1 @@
1
+ export declare function createCallbackMethodEndpoint(method: String, path: String): string[];
@@ -0,0 +1,21 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.createCallbackMethodEndpoint = void 0;
10
+ const utils_1 = require("./utils");
11
+ function createCallbackMethodEndpoint(method, path) {
12
+ return [
13
+ (0, utils_1.create)("MethodEndpoint", {
14
+ method: method,
15
+ path: path,
16
+ context: "callback",
17
+ }),
18
+ "\n\n",
19
+ ];
20
+ }
21
+ exports.createCallbackMethodEndpoint = createCallbackMethodEndpoint;
@@ -7,8 +7,8 @@
7
7
  * ========================================================================== */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.createCallbacks = void 0;
10
+ const createCallbackMethodEndpoint_1 = require("./createCallbackMethodEndpoint");
10
11
  const createDescription_1 = require("./createDescription");
11
- const createMethodEndpoint_1 = require("./createMethodEndpoint");
12
12
  const createRequestBodyDetails_1 = require("./createRequestBodyDetails");
13
13
  const createStatusCodes_1 = require("./createStatusCodes");
14
14
  const utils_1 = require("./utils");
@@ -54,7 +54,7 @@ function createCallbacks({ callbacks }) {
54
54
  label: `${method.toUpperCase()} ${name}`,
55
55
  value: `${method}-${name}`,
56
56
  children: [
57
- (0, createMethodEndpoint_1.createMethodEndpoint)(method, path),
57
+ (0, createCallbackMethodEndpoint_1.createCallbackMethodEndpoint)(method, path),
58
58
  // TODO: add `deprecation notice` when markdown support is added
59
59
  (0, createDescription_1.createDescription)(description),
60
60
  (0, createRequestBodyDetails_1.createRequestBodyDetails)({
@@ -12,11 +12,10 @@ function createAdmonition({ children }) {
12
12
  return `:::caution deprecated\n\n${(0, utils_1.render)(children)}\n\n:::`;
13
13
  }
14
14
  function createDeprecationNotice({ deprecated, description, }) {
15
- return (0, utils_1.guard)(deprecated, () => {
16
- var _a;
17
- return createAdmonition({
18
- children: (_a = (0, utils_1.clean)(description)) !== null && _a !== void 0 ? _a : "This endpoint has been deprecated and may be replaced or removed in future versions of the API.",
19
- });
20
- });
15
+ return (0, utils_1.guard)(deprecated, () => createAdmonition({
16
+ children: description && description.length > 0
17
+ ? (0, utils_1.clean)(description)
18
+ : "This endpoint has been deprecated and may be replaced or removed in future versions of the API.",
19
+ }));
21
20
  }
22
21
  exports.createDeprecationNotice = createDeprecationNotice;
@@ -9,6 +9,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.createMethodEndpoint = void 0;
10
10
  const utils_1 = require("./utils");
11
11
  function createMethodEndpoint(method, path) {
12
- return [(0, utils_1.create)("MethodEndpoint", { method: method, path: path }), "\n\n"];
12
+ return [
13
+ (0, utils_1.create)("MethodEndpoint", {
14
+ method: method,
15
+ path: path,
16
+ context: "endpoint",
17
+ }),
18
+ "\n\n",
19
+ ];
13
20
  }
14
21
  exports.createMethodEndpoint = createMethodEndpoint;
@@ -35,10 +35,16 @@ function createParamsDetails({ parameters, type }) {
35
35
  (0, utils_1.create)("div", {
36
36
  children: [
37
37
  (0, utils_1.create)("ul", {
38
- children: params.map((param) => (0, utils_1.create)("ParamsItem", {
39
- className: "paramsItem",
40
- param: param,
41
- })),
38
+ children: params.map((param) => {
39
+ var _a, _b, _c, _d, _e;
40
+ return (0, utils_1.create)("ParamsItem", {
41
+ className: "paramsItem",
42
+ param: {
43
+ ...param,
44
+ enumDescriptions: Object.entries((_e = (_b = (_a = param === null || param === void 0 ? void 0 : param.schema) === null || _a === void 0 ? void 0 : _a["x-enumDescriptions"]) !== null && _b !== void 0 ? _b : (_d = (_c = param === null || param === void 0 ? void 0 : param.schema) === null || _c === void 0 ? void 0 : _c.items) === null || _d === void 0 ? void 0 : _d["x-enumDescriptions"]) !== null && _e !== void 0 ? _e : {}),
45
+ },
46
+ });
47
+ }),
42
48
  }),
43
49
  ],
44
50
  }),
@@ -90,6 +90,10 @@ function createAnyOneOf(schema) {
90
90
  anyOneChildren.push(createNodes(anyOneSchema, SCHEMA_TYPE));
91
91
  delete anyOneSchema.allOf;
92
92
  }
93
+ if (anyOneSchema.oneOf !== undefined) {
94
+ anyOneChildren.push(createNodes(anyOneSchema, SCHEMA_TYPE));
95
+ delete anyOneSchema.oneOf;
96
+ }
93
97
  if (anyOneSchema.items !== undefined) {
94
98
  anyOneChildren.push(createItems(anyOneSchema));
95
99
  delete anyOneSchema.items;
@@ -347,14 +351,14 @@ function createDetailsNode(name, schemaName, schema, required, nullable) {
347
351
  (0, utils_1.create)("div", {
348
352
  style: { marginLeft: "1rem" },
349
353
  children: [
350
- (0, utils_1.guard)((0, schema_1.getQualifierMessage)(schema), (message) => (0, utils_1.create)("div", {
351
- style: { marginTop: ".5rem", marginBottom: ".5rem" },
352
- children: (0, createDescription_1.createDescription)(message),
353
- })),
354
354
  (0, utils_1.guard)(schema.description, (description) => (0, utils_1.create)("div", {
355
355
  style: { marginTop: ".5rem", marginBottom: ".5rem" },
356
356
  children: (0, createDescription_1.createDescription)(description),
357
357
  })),
358
+ (0, utils_1.guard)((0, schema_1.getQualifierMessage)(schema), (message) => (0, utils_1.create)("div", {
359
+ style: { marginTop: ".5rem", marginBottom: ".5rem" },
360
+ children: (0, createDescription_1.createDescription)(message),
361
+ })),
358
362
  createNodes(schema, SCHEMA_TYPE),
359
363
  ],
360
364
  }),
@@ -447,8 +451,9 @@ function createPropertyDiscriminator(name, schemaName, schema, discriminator, re
447
451
  if (schema === undefined) {
448
452
  return undefined;
449
453
  }
454
+ // render as a simple property if there's no mapping
450
455
  if (discriminator.mapping === undefined) {
451
- return undefined;
456
+ return createEdges({ name, schema, required });
452
457
  }
453
458
  return (0, utils_1.create)("div", {
454
459
  className: "openapi-discriminator__item openapi-schema__list-item",
@@ -473,17 +478,17 @@ function createPropertyDiscriminator(name, schemaName, schema, discriminator, re
473
478
  ]),
474
479
  ],
475
480
  }),
476
- (0, utils_1.guard)((0, schema_1.getQualifierMessage)(discriminator), (message) => (0, utils_1.create)("div", {
481
+ (0, utils_1.guard)(schema.description, (description) => (0, utils_1.create)("div", {
477
482
  style: {
478
483
  paddingLeft: "1rem",
479
484
  },
480
- children: (0, createDescription_1.createDescription)(message),
485
+ children: (0, createDescription_1.createDescription)(description),
481
486
  })),
482
- (0, utils_1.guard)(schema.description, (description) => (0, utils_1.create)("div", {
487
+ (0, utils_1.guard)((0, schema_1.getQualifierMessage)(discriminator), (message) => (0, utils_1.create)("div", {
483
488
  style: {
484
489
  paddingLeft: "1rem",
485
490
  },
486
- children: (0, createDescription_1.createDescription)(description),
491
+ children: (0, createDescription_1.createDescription)(message),
487
492
  })),
488
493
  (0, utils_1.create)("DiscriminatorTabs", {
489
494
  className: "openapi-tabs__discriminator",
@@ -538,38 +543,43 @@ function createEdges({ name, schema, required, discriminator, }) {
538
543
  }
539
544
  if (schema.allOf !== undefined) {
540
545
  const { mergedSchemas } = mergeAllOf(schema.allOf);
546
+ delete schema.allOf;
547
+ const combinedSchemas = { ...schema, ...mergedSchemas };
541
548
  if (SCHEMA_TYPE === "request") {
542
- if (mergedSchemas.readOnly && mergedSchemas.readOnly === true) {
549
+ if (combinedSchemas.readOnly && combinedSchemas.readOnly === true) {
543
550
  return undefined;
544
551
  }
545
552
  }
546
553
  if (SCHEMA_TYPE === "response") {
547
- if (mergedSchemas.writeOnly && mergedSchemas.writeOnly === true) {
554
+ if (combinedSchemas.writeOnly && combinedSchemas.writeOnly === true) {
548
555
  return undefined;
549
556
  }
550
557
  }
551
- const mergedSchemaName = (0, schema_1.getSchemaName)(mergedSchemas);
552
- if (mergedSchemas.oneOf !== undefined ||
553
- mergedSchemas.anyOf !== undefined) {
554
- return createDetailsNode(name, mergedSchemaName, mergedSchemas, required, schema.nullable);
558
+ const mergedSchemaName = (0, schema_1.getSchemaName)(combinedSchemas);
559
+ if (name === "eventName") {
560
+ console.log(mergedSchemaName, combinedSchemas);
555
561
  }
556
- if (mergedSchemas.properties !== undefined) {
557
- return createDetailsNode(name, mergedSchemaName, mergedSchemas, required, schema.nullable);
562
+ if (combinedSchemas.oneOf !== undefined ||
563
+ combinedSchemas.anyOf !== undefined) {
564
+ return createDetailsNode(name, mergedSchemaName, combinedSchemas, required, combinedSchemas.nullable);
565
+ }
566
+ if (combinedSchemas.properties !== undefined) {
567
+ return createDetailsNode(name, mergedSchemaName, combinedSchemas, required, combinedSchemas.nullable);
558
568
  }
559
- if (mergedSchemas.additionalProperties !== undefined) {
560
- return createDetailsNode(name, mergedSchemaName, mergedSchemas, required, schema.nullable);
569
+ if (combinedSchemas.additionalProperties !== undefined) {
570
+ return createDetailsNode(name, mergedSchemaName, combinedSchemas, required, combinedSchemas.nullable);
561
571
  }
562
572
  // array of objects
563
573
  if (((_d = mergedSchemas.items) === null || _d === void 0 ? void 0 : _d.properties) !== undefined) {
564
- return createDetailsNode(name, mergedSchemaName, mergedSchemas, required, schema.nullable);
574
+ return createDetailsNode(name, mergedSchemaName, combinedSchemas, required, combinedSchemas.nullable);
565
575
  }
566
576
  return (0, utils_1.create)("SchemaItem", {
567
577
  collapsible: false,
568
578
  name,
569
579
  required: Array.isArray(required) ? required.includes(name) : required,
570
580
  schemaName: mergedSchemaName,
571
- qualifierMessage: (0, schema_1.getQualifierMessage)(mergedSchemas),
572
- schema: mergedSchemas,
581
+ qualifierMessage: (0, schema_1.getQualifierMessage)(combinedSchemas),
582
+ schema: combinedSchemas,
573
583
  });
574
584
  }
575
585
  // primitives and array of non-objects