docusaurus-plugin-openapi-docs 4.0.1 → 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
@@ -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
  }),
@@ -474,17 +478,17 @@ function createPropertyDiscriminator(name, schemaName, schema, discriminator, re
474
478
  ]),
475
479
  ],
476
480
  }),
477
- (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", {
478
482
  style: {
479
483
  paddingLeft: "1rem",
480
484
  },
481
- children: (0, createDescription_1.createDescription)(message),
485
+ children: (0, createDescription_1.createDescription)(description),
482
486
  })),
483
- (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", {
484
488
  style: {
485
489
  paddingLeft: "1rem",
486
490
  },
487
- children: (0, createDescription_1.createDescription)(description),
491
+ children: (0, createDescription_1.createDescription)(message),
488
492
  })),
489
493
  (0, utils_1.create)("DiscriminatorTabs", {
490
494
  className: "openapi-tabs__discriminator",
@@ -539,38 +543,43 @@ function createEdges({ name, schema, required, discriminator, }) {
539
543
  }
540
544
  if (schema.allOf !== undefined) {
541
545
  const { mergedSchemas } = mergeAllOf(schema.allOf);
546
+ delete schema.allOf;
547
+ const combinedSchemas = { ...schema, ...mergedSchemas };
542
548
  if (SCHEMA_TYPE === "request") {
543
- if (mergedSchemas.readOnly && mergedSchemas.readOnly === true) {
549
+ if (combinedSchemas.readOnly && combinedSchemas.readOnly === true) {
544
550
  return undefined;
545
551
  }
546
552
  }
547
553
  if (SCHEMA_TYPE === "response") {
548
- if (mergedSchemas.writeOnly && mergedSchemas.writeOnly === true) {
554
+ if (combinedSchemas.writeOnly && combinedSchemas.writeOnly === true) {
549
555
  return undefined;
550
556
  }
551
557
  }
552
- const mergedSchemaName = (0, schema_1.getSchemaName)(mergedSchemas);
553
- if (mergedSchemas.oneOf !== undefined ||
554
- mergedSchemas.anyOf !== undefined) {
555
- 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);
556
561
  }
557
- if (mergedSchemas.properties !== undefined) {
558
- 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);
559
568
  }
560
- if (mergedSchemas.additionalProperties !== undefined) {
561
- return createDetailsNode(name, mergedSchemaName, mergedSchemas, required, schema.nullable);
569
+ if (combinedSchemas.additionalProperties !== undefined) {
570
+ return createDetailsNode(name, mergedSchemaName, combinedSchemas, required, combinedSchemas.nullable);
562
571
  }
563
572
  // array of objects
564
573
  if (((_d = mergedSchemas.items) === null || _d === void 0 ? void 0 : _d.properties) !== undefined) {
565
- return createDetailsNode(name, mergedSchemaName, mergedSchemas, required, schema.nullable);
574
+ return createDetailsNode(name, mergedSchemaName, combinedSchemas, required, combinedSchemas.nullable);
566
575
  }
567
576
  return (0, utils_1.create)("SchemaItem", {
568
577
  collapsible: false,
569
578
  name,
570
579
  required: Array.isArray(required) ? required.includes(name) : required,
571
580
  schemaName: mergedSchemaName,
572
- qualifierMessage: (0, schema_1.getQualifierMessage)(mergedSchemas),
573
- schema: mergedSchemas,
581
+ qualifierMessage: (0, schema_1.getQualifierMessage)(combinedSchemas),
582
+ schema: combinedSchemas,
574
583
  });
575
584
  }
576
585
  // primitives and array of non-objects
@@ -218,6 +218,54 @@ describe("createNodes", () => {
218
218
  expect(await Promise.all((0, createSchema_1.createNodes)(schema, "response").map(async (md) => await prettier.format(md, { parser: "babel" })))).toMatchSnapshot();
219
219
  });
220
220
  });
221
+ describe("anyOf", () => {
222
+ it("should render primitives within anyOf", async () => {
223
+ const schema = {
224
+ type: "object",
225
+ properties: {
226
+ oneOfProperty: {
227
+ anyOf: [
228
+ {
229
+ type: "integer",
230
+ },
231
+ {
232
+ type: "boolean",
233
+ },
234
+ ],
235
+ title: "One of int or bool",
236
+ },
237
+ },
238
+ };
239
+ expect(await Promise.all((0, createSchema_1.createNodes)(schema, "response").map(async (md) => await prettier.format(md, { parser: "babel" })))).toMatchSnapshot();
240
+ });
241
+ it("should render oneOf within anyOf", async () => {
242
+ const schema = {
243
+ type: "object",
244
+ properties: {
245
+ oneOfProperty: {
246
+ anyOf: [
247
+ {
248
+ oneOf: [
249
+ {
250
+ type: "integer",
251
+ },
252
+ {
253
+ type: "boolean",
254
+ },
255
+ ],
256
+ title: "An int or a bool",
257
+ },
258
+ {
259
+ type: "string",
260
+ },
261
+ ],
262
+ title: "One of int or bool, or a string",
263
+ },
264
+ },
265
+ };
266
+ expect(await Promise.all((0, createSchema_1.createNodes)(schema, "response").map(async (md) => await prettier.format(md, { parser: "babel" })))).toMatchSnapshot();
267
+ });
268
+ });
221
269
  describe("allOf", () => {
222
270
  it("should render same-level properties with allOf", async () => {
223
271
  const schema = {
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Children in the plugin does not accept DOM elements, when compared with Children in the theme.
3
+ * It is designed for rendering HTML a strings.
4
+ */
1
5
  export type Children = string | undefined | (string | string[] | undefined)[];
2
6
  export type Props = Record<string, any> & {
3
7
  children?: Children;
@@ -61,7 +61,7 @@ async function createPostmanCollection(openapiData) {
61
61
  return await jsonToCollection(data);
62
62
  }
63
63
  function createItems(openapiData, options, sidebarOptions) {
64
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6;
64
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7;
65
65
  // TODO: Find a better way to handle this
66
66
  let items = [];
67
67
  const infoIdSpaces = openapiData.info.title.replace(" ", "-").toLowerCase();
@@ -212,15 +212,15 @@ function createItems(openapiData, options, sidebarOptions) {
212
212
  }
213
213
  }
214
214
  // Gather x-webhooks endpoints
215
- for (let [path, pathObject] of Object.entries((_p = openapiData["x-webhooks"]) !== null && _p !== void 0 ? _p : {})) {
215
+ for (let [path, pathObject] of Object.entries((_q = (_p = openapiData["x-webhooks"]) !== null && _p !== void 0 ? _p : openapiData["webhooks"]) !== null && _q !== void 0 ? _q : {})) {
216
216
  path = "webhook";
217
217
  const { $ref, description, parameters, servers, summary, ...rest } = pathObject;
218
218
  for (let [method, operationObject] of Object.entries({ ...rest })) {
219
219
  method = "event";
220
- const title = (_r = (_q = operationObject.summary) !== null && _q !== void 0 ? _q : operationObject.operationId) !== null && _r !== void 0 ? _r : "Missing summary";
220
+ const title = (_s = (_r = operationObject.summary) !== null && _r !== void 0 ? _r : operationObject.operationId) !== null && _s !== void 0 ? _s : "Missing summary";
221
221
  if (operationObject.description === undefined) {
222
222
  operationObject.description =
223
- (_t = (_s = operationObject.summary) !== null && _s !== void 0 ? _s : operationObject.operationId) !== null && _t !== void 0 ? _t : "";
223
+ (_u = (_t = operationObject.summary) !== null && _t !== void 0 ? _t : operationObject.operationId) !== null && _u !== void 0 ? _u : "";
224
224
  }
225
225
  const baseId = operationObject.operationId
226
226
  ? (0, kebabCase_1.default)(operationObject.operationId)
@@ -232,10 +232,10 @@ function createItems(openapiData, options, sidebarOptions) {
232
232
  extensions.push({ key, value });
233
233
  }
234
234
  }
235
- const servers = (_v = (_u = operationObject.servers) !== null && _u !== void 0 ? _u : pathObject.servers) !== null && _v !== void 0 ? _v : openapiData.servers;
236
- const security = (_w = operationObject.security) !== null && _w !== void 0 ? _w : openapiData.security;
235
+ const servers = (_w = (_v = operationObject.servers) !== null && _v !== void 0 ? _v : pathObject.servers) !== null && _w !== void 0 ? _w : openapiData.servers;
236
+ const security = (_x = operationObject.security) !== null && _x !== void 0 ? _x : openapiData.security;
237
237
  // Add security schemes so we know how to handle security.
238
- const securitySchemes = (_x = openapiData.components) === null || _x === void 0 ? void 0 : _x.securitySchemes;
238
+ const securitySchemes = (_y = openapiData.components) === null || _y === void 0 ? void 0 : _y.securitySchemes;
239
239
  // Make sure schemes are lowercase. See: https://github.com/cloud-annotations/docusaurus-plugin-openapi/issues/79
240
240
  if (securitySchemes) {
241
241
  for (let securityScheme of Object.values(securitySchemes)) {
@@ -245,7 +245,7 @@ function createItems(openapiData, options, sidebarOptions) {
245
245
  }
246
246
  }
247
247
  let jsonRequestBodyExample;
248
- const content = (_y = operationObject.requestBody) === null || _y === void 0 ? void 0 : _y.content;
248
+ const content = (_z = operationObject.requestBody) === null || _z === void 0 ? void 0 : _z.content;
249
249
  let body;
250
250
  for (let key in content) {
251
251
  if (key.toLowerCase() === "application/json" ||
@@ -258,7 +258,7 @@ function createItems(openapiData, options, sidebarOptions) {
258
258
  jsonRequestBodyExample = (0, createRequestExample_1.sampleRequestFromSchema)(body.schema);
259
259
  }
260
260
  // Handle vendor JSON media types
261
- const bodyContent = (_z = operationObject.requestBody) === null || _z === void 0 ? void 0 : _z.content;
261
+ const bodyContent = (_0 = operationObject.requestBody) === null || _0 === void 0 ? void 0 : _0.content;
262
262
  if (bodyContent) {
263
263
  const firstBodyContentKey = Object.keys(bodyContent)[0];
264
264
  if (firstBodyContentKey.endsWith("+json")) {
@@ -325,13 +325,13 @@ function createItems(openapiData, options, sidebarOptions) {
325
325
  }
326
326
  }
327
327
  if ((options === null || options === void 0 ? void 0 : options.showSchemas) === true ||
328
- Object.entries((_1 = (_0 = openapiData === null || openapiData === void 0 ? void 0 : openapiData.components) === null || _0 === void 0 ? void 0 : _0.schemas) !== null && _1 !== void 0 ? _1 : {})
328
+ Object.entries((_2 = (_1 = openapiData === null || openapiData === void 0 ? void 0 : openapiData.components) === null || _1 === void 0 ? void 0 : _1.schemas) !== null && _2 !== void 0 ? _2 : {})
329
329
  .flatMap(([_, s]) => s["x-tags"])
330
330
  .filter((item) => !!item).length > 0) {
331
331
  // Gather schemas
332
- for (let [schema, schemaObject] of Object.entries((_3 = (_2 = openapiData === null || openapiData === void 0 ? void 0 : openapiData.components) === null || _2 === void 0 ? void 0 : _2.schemas) !== null && _3 !== void 0 ? _3 : {})) {
332
+ for (let [schema, schemaObject] of Object.entries((_4 = (_3 = openapiData === null || openapiData === void 0 ? void 0 : openapiData.components) === null || _3 === void 0 ? void 0 : _3.schemas) !== null && _4 !== void 0 ? _4 : {})) {
333
333
  if ((options === null || options === void 0 ? void 0 : options.showSchemas) === true || schemaObject["x-tags"]) {
334
- const baseIdSpaces = (_5 = (_4 = schemaObject === null || schemaObject === void 0 ? void 0 : schemaObject.title) === null || _4 === void 0 ? void 0 : _4.replace(" ", "-").toLowerCase()) !== null && _5 !== void 0 ? _5 : "";
334
+ const baseIdSpaces = (_6 = (_5 = schemaObject === null || schemaObject === void 0 ? void 0 : schemaObject.title) === null || _5 === void 0 ? void 0 : _5.replace(" ", "-").toLowerCase()) !== null && _6 !== void 0 ? _6 : "";
335
335
  const baseId = (0, kebabCase_1.default)(baseIdSpaces);
336
336
  const schemaDescription = schemaObject.description;
337
337
  let splitDescription;
@@ -364,7 +364,7 @@ function createItems(openapiData, options, sidebarOptions) {
364
364
  }
365
365
  if ((sidebarOptions === null || sidebarOptions === void 0 ? void 0 : sidebarOptions.categoryLinkSource) === "tag") {
366
366
  // Get global tags
367
- const tags = (_6 = openapiData.tags) !== null && _6 !== void 0 ? _6 : [];
367
+ const tags = (_7 = openapiData.tags) !== null && _7 !== void 0 ? _7 : [];
368
368
  // Get operation tags
369
369
  const apiItems = items.filter((item) => {
370
370
  return item.type === "api";
@@ -12,6 +12,7 @@ export interface OpenApiObject {
12
12
  tags?: TagObject[];
13
13
  externalDocs?: ExternalDocumentationObject;
14
14
  swagger?: string;
15
+ webhooks?: PathsObject;
15
16
  "x-webhooks"?: PathsObject;
16
17
  "x-tagGroups"?: TagGroupObject[];
17
18
  }
@@ -163,6 +164,7 @@ export interface ParameterObject {
163
164
  examples?: Map<ExampleObject>;
164
165
  content?: Map<MediaTypeObject>;
165
166
  param?: Object;
167
+ "x-enumDescriptions"?: Record<string, string>;
166
168
  }
167
169
  export interface ParameterObjectWithRef {
168
170
  name: string;
@@ -279,6 +281,7 @@ export type SchemaObject = Omit<JSONSchema, "type" | "allOf" | "oneOf" | "anyOf"
279
281
  example?: any;
280
282
  deprecated?: boolean;
281
283
  "x-tags"?: string[];
284
+ "x-enumDescriptions"?: Record<string, string>;
282
285
  };
283
286
  export type SchemaObjectWithRef = Omit<JSONSchema, "type" | "allOf" | "oneOf" | "anyOf" | "not" | "items" | "properties" | "additionalProperties"> & {
284
287
  type?: "string" | "number" | "integer" | "boolean" | "object" | "array";
@@ -215,7 +215,7 @@ class OpenAPIParser {
215
215
  })
216
216
  .filter((child) => child !== undefined);
217
217
  for (const { $ref: subSchemaRef, schema: subSchema } of allOfSchemas) {
218
- const { type, enum: enumProperty, properties, items, required, oneOf, anyOf, title, ...otherConstraints } = subSchema;
218
+ const { type, enum: enumProperty, "x-enumDescription": enumDescription, properties, items, required, oneOf, anyOf, title, ...otherConstraints } = subSchema;
219
219
  if (receiver.type !== type &&
220
220
  receiver.type !== undefined &&
221
221
  type !== undefined) {
package/lib/options.js CHANGED
@@ -8,12 +8,16 @@
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.OptionsSchema = void 0;
10
10
  const utils_validation_1 = require("@docusaurus/utils-validation");
11
+ const sidebarGenerators = utils_validation_1.Joi.object({
12
+ createDocItem: utils_validation_1.Joi.function(),
13
+ });
11
14
  const sidebarOptions = utils_validation_1.Joi.object({
12
15
  groupPathsBy: utils_validation_1.Joi.string().valid("tag", "tagGroup"),
13
16
  categoryLinkSource: utils_validation_1.Joi.string().valid("tag", "info", "auto"),
14
17
  customProps: utils_validation_1.Joi.object(),
15
18
  sidebarCollapsible: utils_validation_1.Joi.boolean(),
16
19
  sidebarCollapsed: utils_validation_1.Joi.boolean(),
20
+ sidebarGenerators: sidebarGenerators,
17
21
  });
18
22
  const markdownGenerators = utils_validation_1.Joi.object({
19
23
  createApiPageMD: utils_validation_1.Joi.function(),
@@ -23,11 +23,33 @@ function isInfoItem(item) {
23
23
  function isSchemaItem(item) {
24
24
  return item.type === "schema";
25
25
  }
26
+ const createDocItem = (item, { sidebarOptions: { customProps }, basePath }) => {
27
+ var _a, _b;
28
+ const sidebar_label = item.frontMatter.sidebar_label;
29
+ const title = item.title;
30
+ const id = item.type === "schema" ? `schemas/${item.id}` : item.id;
31
+ const className = item.type === "api"
32
+ ? (0, clsx_1.default)({
33
+ "menu__list-item--deprecated": item.api.deprecated,
34
+ "api-method": !!item.api.method,
35
+ }, item.api.method)
36
+ : (0, clsx_1.default)({
37
+ "menu__list-item--deprecated": item.schema.deprecated,
38
+ }, "schema");
39
+ return {
40
+ type: "doc",
41
+ id: basePath === "" || undefined ? `${id}` : `${basePath}/${id}`,
42
+ label: (_b = (_a = sidebar_label) !== null && _a !== void 0 ? _a : title) !== null && _b !== void 0 ? _b : id,
43
+ customProps: customProps,
44
+ className: className ? className : undefined,
45
+ };
46
+ };
26
47
  function groupByTags(items, sidebarOptions, options, tags, docPath) {
48
+ var _a, _b;
27
49
  let { outputDir, label, showSchemas } = options;
28
50
  // Remove trailing slash before proceeding
29
51
  outputDir = outputDir.replace(/\/$/, "");
30
- const { sidebarCollapsed, sidebarCollapsible, customProps, categoryLinkSource, } = sidebarOptions;
52
+ const { sidebarCollapsed, sidebarCollapsible, categoryLinkSource } = sidebarOptions;
31
53
  const apiItems = items.filter(isApiItem);
32
54
  const infoItems = items.filter(isInfoItem);
33
55
  const schemaItems = items.filter(isSchemaItem);
@@ -61,27 +83,11 @@ function groupByTags(items, sidebarOptions, options, tags, docPath) {
61
83
  const basePath = docPath
62
84
  ? outputDir.split(docPath)[1].replace(/^\/+/g, "")
63
85
  : outputDir.slice(outputDir.indexOf("/", 1)).replace(/^\/+/g, "");
64
- function createDocItem(item) {
65
- var _a, _b;
66
- const sidebar_label = item.frontMatter.sidebar_label;
67
- const title = item.title;
68
- const id = item.type === "schema" ? `schemas/${item.id}` : item.id;
69
- const className = item.type === "api"
70
- ? (0, clsx_1.default)({
71
- "menu__list-item--deprecated": item.api.deprecated,
72
- "api-method": !!item.api.method,
73
- }, item.api.method)
74
- : (0, clsx_1.default)({
75
- "menu__list-item--deprecated": item.schema.deprecated,
76
- }, "schema");
77
- return {
78
- type: "doc",
79
- id: basePath === "" || undefined ? `${id}` : `${basePath}/${id}`,
80
- label: (_b = (_a = sidebar_label) !== null && _a !== void 0 ? _a : title) !== null && _b !== void 0 ? _b : id,
81
- customProps: customProps,
82
- className: className ? className : undefined,
83
- };
84
- }
86
+ const createDocItemFnContext = {
87
+ sidebarOptions,
88
+ basePath,
89
+ };
90
+ const createDocItemFn = (_b = (_a = sidebarOptions.sidebarGenerators) === null || _a === void 0 ? void 0 : _a.createDocItem) !== null && _b !== void 0 ? _b : createDocItem;
85
91
  let rootIntroDoc = undefined;
86
92
  if (infoItems.length === 1) {
87
93
  const infoItem = infoItems[0];
@@ -139,14 +145,14 @@ function groupByTags(items, sidebarOptions, options, tags, docPath) {
139
145
  link: linkConfig,
140
146
  collapsible: sidebarCollapsible,
141
147
  collapsed: sidebarCollapsed,
142
- items: [...taggedSchemaItems, ...taggedApiItems].map(createDocItem),
148
+ items: [...taggedSchemaItems, ...taggedApiItems].map((item) => createDocItemFn(item, createDocItemFnContext)),
143
149
  };
144
150
  })
145
151
  .filter((item) => item.items.length > 0); // Filter out any categories with no items.
146
152
  // Handle items with no tag
147
153
  const untaggedItems = apiItems
148
154
  .filter(({ api }) => api.tags === undefined || api.tags.length === 0)
149
- .map(createDocItem);
155
+ .map((item) => createDocItemFn(item, createDocItemFnContext));
150
156
  let untagged = [];
151
157
  if (untaggedItems.length > 0) {
152
158
  untagged = [
@@ -157,7 +163,7 @@ function groupByTags(items, sidebarOptions, options, tags, docPath) {
157
163
  collapsed: sidebarCollapsed,
158
164
  items: apiItems
159
165
  .filter(({ api }) => api.tags === undefined || api.tags.length === 0)
160
- .map(createDocItem),
166
+ .map((item) => createDocItemFn(item, createDocItemFnContext)),
161
167
  },
162
168
  ];
163
169
  }
@@ -171,7 +177,7 @@ function groupByTags(items, sidebarOptions, options, tags, docPath) {
171
177
  collapsed: sidebarCollapsed,
172
178
  items: schemaItems
173
179
  .filter(({ schema }) => !schema["x-tags"])
174
- .map(createDocItem),
180
+ .map((item) => createDocItemFn(item, createDocItemFnContext)),
175
181
  },
176
182
  ];
177
183
  }
package/lib/types.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { SidebarItemDoc } from "@docusaurus/plugin-content-docs/src/sidebars/types";
1
2
  import type Request from "postman-collection";
2
3
  import { InfoObject, OperationObject, SchemaObject, SecuritySchemeObject, TagObject } from "./openapi/types";
3
4
  export type { PropSidebarItemCategory, SidebarItemLink, PropSidebar, PropSidebarItem, } from "@docusaurus/plugin-content-docs-types";
@@ -34,6 +35,13 @@ export interface MarkdownGenerator {
34
35
  createTagPageMD?: (pageData: TagPageMetadata) => string;
35
36
  createSchemaPageMD?: (pageData: SchemaPageMetadata) => string;
36
37
  }
38
+ export type ApiDocItemGenerator = (item: ApiPageMetadata | SchemaPageMetadata, context: {
39
+ sidebarOptions: SidebarOptions;
40
+ basePath: string;
41
+ }) => SidebarItemDoc;
42
+ export interface SidebarGenerators {
43
+ createDocItem?: ApiDocItemGenerator;
44
+ }
37
45
  export interface SidebarOptions {
38
46
  groupPathsBy?: string;
39
47
  categoryLinkSource?: "info" | "tag" | "auto";
@@ -42,6 +50,7 @@ export interface SidebarOptions {
42
50
  };
43
51
  sidebarCollapsible?: boolean;
44
52
  sidebarCollapsed?: boolean;
53
+ sidebarGenerators?: SidebarGenerators;
45
54
  }
46
55
  export interface APIVersionOptions {
47
56
  specPath: string;
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": "4.0.1",
4
+ "version": "4.1.0",
5
5
  "license": "MIT",
6
6
  "keywords": [
7
7
  "openapi",
@@ -28,7 +28,7 @@
28
28
  "watch": "tsc --watch"
29
29
  },
30
30
  "devDependencies": {
31
- "@docusaurus/types": "^3.0.1",
31
+ "@docusaurus/types": "^3.5.0",
32
32
  "@types/fs-extra": "^9.0.13",
33
33
  "@types/json-pointer": "^1.0.31",
34
34
  "@types/json-schema": "^7.0.9",
@@ -38,9 +38,9 @@
38
38
  },
39
39
  "dependencies": {
40
40
  "@apidevtools/json-schema-ref-parser": "^11.5.4",
41
- "@docusaurus/plugin-content-docs": "^3.0.1",
42
- "@docusaurus/utils": "^3.0.1",
43
- "@docusaurus/utils-validation": "^3.0.1",
41
+ "@docusaurus/plugin-content-docs": "^3.5.0",
42
+ "@docusaurus/utils": "^3.5.0",
43
+ "@docusaurus/utils-validation": "^3.5.0",
44
44
  "@redocly/openapi-core": "^1.10.5",
45
45
  "chalk": "^4.1.2",
46
46
  "clsx": "^1.1.1",
@@ -62,5 +62,5 @@
62
62
  "engines": {
63
63
  "node": ">=14"
64
64
  },
65
- "gitHead": "e228de93d24062c46fb206548dca7af9bc6264bb"
65
+ "gitHead": "4e771d309f6defe395449b26cc3c65814d72cbcc"
66
66
  }