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/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.0",
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": "79d74177cfd54d2750dde1e15c6ea166f9ca4be9"
65
+ "gitHead": "4e771d309f6defe395449b26cc3c65814d72cbcc"
66
66
  }