docusaurus-plugin-openapi-docs 0.0.0-380 → 0.0.0-381

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
@@ -103,23 +103,30 @@ Here is an example of properly configuring your `docusaurus.config.js` file for
103
103
 
104
104
  > Note: You may optionally configure a dedicated `@docusaurus/plugin-content-docs` instance for use with `docusaurus-theme-openapi-docs` by setting `docItemComponent` to `@theme/ApiItem`.
105
105
 
106
- ### Plugin Configuration Options
107
-
108
- `docusaurus-plugin-openapi-docs` can be configured with the following options:
109
-
110
- | Name | Type | Default | Description |
111
- | ----------------- | -------- | ------- | --------------------------------------------------------------------------------------------------------------------------- |
112
- | `specPath` | `string` | `null` | Designated URL or path to the source of an OpenAPI specification file or directory of multiple OpenAPI specification files. |
113
- | `ouputDir` | `string` | `null` | Desired output path for generated MDX files. |
114
- | `contentDocsPath` | `string` | `null` | Should be equal to the `path` value set in `plugin-content-docs` or preset. |
115
- | `ouputDir` | `string` | `null` | Desired output path for generated MDX files. |
116
- | `routeBasePath` | `string` | `null` | _Optional:_ Should be equal to the `routeBasePath` value set in `plugin-content-docs or preset (if present). |
117
- | `template` | `string` | `null` | _Optional:_ Customize MDX content with a desired template. |
118
- | `sidebarOptions` | `object` | `null` | _Optional:_ Set of options for sidebar configuration. See below for a list of supported options. |
119
- | `version` | `string` | `null` | _Optional:_ Version assigned to single or micro-spec API specified in `specPath`. |
120
- | `label` | `string` | `null` | _Optional:_ Version label used when generating version selector dropdown menu. |
121
- | `baseUrl` | `string` | `null` | _Optional:_ Version base URL used when generating version selector dropdown menu. |
122
- | `versions` | `object` | `null` | _Optional:_ Set of options for versioning configuration. See below for a list of supported options. |
106
+ ## Plugin Configuration Options
107
+
108
+ The `docusaurus-plugin-openapi-docs` plugin can be configured with the following options:
109
+
110
+ | Name | Type | Default | Description |
111
+ | ------------- | -------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
112
+ | `id` | `string` | `null` | A unique document id. |
113
+ | `docPluginId` | `string` | `null` | The ID associated with the `plugin-content-docs` or `preset` instance used to render the OpenAPI docs (e.g. "your-plugin-id", "classic", "default"). |
114
+
115
+ ### config
116
+
117
+ `config` can be configured with the following options:
118
+
119
+ | Name | Type | Default | Description |
120
+ | ---------------- | -------- | ------- | --------------------------------------------------------------------------------------------------------------------------- |
121
+ | `specPath` | `string` | `null` | Designated URL or path to the source of an OpenAPI specification file or directory of multiple OpenAPI specification files. |
122
+ | `ouputDir` | `string` | `null` | Desired output path for generated MDX files. |
123
+ | `ouputDir` | `string` | `null` | Desired output path for generated MDX files. |
124
+ | `template` | `string` | `null` | _Optional:_ Customize MDX content with a desired template. |
125
+ | `sidebarOptions` | `object` | `null` | _Optional:_ Set of options for sidebar configuration. See below for a list of supported options. |
126
+ | `version` | `string` | `null` | _Optional:_ Version assigned to single or micro-spec API specified in `specPath`. |
127
+ | `label` | `string` | `null` | _Optional:_ Version label used when generating version selector dropdown menu. |
128
+ | `baseUrl` | `string` | `null` | _Optional:_ Version base URL used when generating version selector dropdown menu. |
129
+ | `versions` | `object` | `null` | _Optional:_ Set of options for versioning configuration. See below for a list of supported options. |
123
130
 
124
131
  `sidebarOptions` can be configured with the following options:
125
132
 
package/lib/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type { LoadContext, Plugin } from "@docusaurus/types";
2
2
  import type { PluginOptions, LoadedContent } from "./types";
3
3
  export declare function isURL(str: string): boolean;
4
+ export declare function getDocsData(dataArray: any[], filter: string): Object | undefined;
4
5
  declare function pluginOpenAPIDocs(context: LoadContext, options: PluginOptions): Plugin<LoadedContent>;
5
6
  declare namespace pluginOpenAPIDocs {
6
7
  var validateOptions: ({ options, validate }: any) => any;
package/lib/index.js CHANGED
@@ -9,7 +9,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
9
9
  return (mod && mod.__esModule) ? mod : { "default": mod };
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.isURL = void 0;
12
+ exports.getDocsData = exports.isURL = void 0;
13
13
  const fs_1 = __importDefault(require("fs"));
14
14
  const path_1 = __importDefault(require("path"));
15
15
  const utils_1 = require("@docusaurus/utils");
@@ -23,11 +23,48 @@ function isURL(str) {
23
23
  return /^(https?:)\/\//m.test(str);
24
24
  }
25
25
  exports.isURL = isURL;
26
+ function getDocsData(dataArray, filter) {
27
+ // eslint-disable-next-line array-callback-return
28
+ const filteredData = dataArray.filter((data) => {
29
+ if (data[0] === filter) {
30
+ return data[1];
31
+ }
32
+ // Search plugin-content-docs instances
33
+ if (data[0] === "@docusaurus/plugin-content-docs") {
34
+ const pluginId = data[1].id ? data[1].id : "default";
35
+ if (pluginId === filter) {
36
+ return data[1];
37
+ }
38
+ }
39
+ })[0];
40
+ if (filteredData) {
41
+ // Search presets, e.g. "classic"
42
+ if (filteredData[0] === filter) {
43
+ return filteredData[1].docs;
44
+ }
45
+ // Search plugin-content-docs instances
46
+ if (filteredData[0] === "@docusaurus/plugin-content-docs") {
47
+ const pluginId = filteredData[1].id ? filteredData[1].id : "default";
48
+ if (pluginId === filter) {
49
+ return filteredData[1];
50
+ }
51
+ }
52
+ }
53
+ return;
54
+ }
55
+ exports.getDocsData = getDocsData;
26
56
  function pluginOpenAPIDocs(context, options) {
27
- let { config } = options;
28
- let { siteDir } = context;
57
+ const { config, docPluginId } = options;
58
+ const { siteDir, siteConfig } = context;
59
+ // Get routeBasePath and path from plugin-content-docs or preset
60
+ const presets = siteConfig.presets;
61
+ const plugins = siteConfig.plugins;
62
+ const presetsPlugins = presets.concat(plugins);
63
+ const docData = getDocsData(presetsPlugins, docPluginId);
64
+ const docRouteBasePath = docData ? docData.routeBasePath : undefined;
65
+ const docPath = docData ? (docData.path ? docData.path : "docs") : undefined;
29
66
  async function generateApiDocs(options) {
30
- let { specPath, outputDir, contentDocsPath, routeBasePath, template, sidebarOptions, } = options;
67
+ let { specPath, outputDir, template, sidebarOptions } = options;
31
68
  const contentPath = isURL(specPath)
32
69
  ? specPath
33
70
  : path_1.default.resolve(siteDir, specPath);
@@ -45,7 +82,7 @@ function pluginOpenAPIDocs(context, options) {
45
82
  }
46
83
  // TODO: figure out better way to set default
47
84
  if (Object.keys(sidebarOptions !== null && sidebarOptions !== void 0 ? sidebarOptions : {}).length > 0) {
48
- const sidebarSlice = (0, sidebars_1.default)(sidebarOptions, options, loadedApi, tags);
85
+ const sidebarSlice = (0, sidebars_1.default)(sidebarOptions, options, loadedApi, tags, docPath);
49
86
  const sidebarSliceTemplate = template
50
87
  ? fs_1.default.readFileSync(template).toString()
51
88
  : `module.exports = {{{slice}}};`;
@@ -136,9 +173,9 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
136
173
  if (item.type === "api") {
137
174
  item.json = JSON.stringify(item.api);
138
175
  let infoBasePath = `${outputDir}/${item.infoId}`;
139
- if (routeBasePath) {
140
- infoBasePath = `${routeBasePath}/${outputDir
141
- .split(contentDocsPath)[1]
176
+ if (docRouteBasePath) {
177
+ infoBasePath = `${docRouteBasePath}/${outputDir
178
+ .split(docPath)[1]
142
179
  .replace(/^\/+/g, "")}/${item.infoId}`.replace(/^\/+/g, "");
143
180
  }
144
181
  if (item.infoId)
package/lib/options.js CHANGED
@@ -17,12 +17,11 @@ const sidebarOptions = utils_validation_1.Joi.object({
17
17
  });
18
18
  exports.OptionsSchema = utils_validation_1.Joi.object({
19
19
  id: utils_validation_1.Joi.string().required(),
20
+ docPluginId: utils_validation_1.Joi.string().required(),
20
21
  config: utils_validation_1.Joi.object()
21
22
  .pattern(/^/, utils_validation_1.Joi.object({
22
23
  specPath: utils_validation_1.Joi.string().required(),
23
24
  outputDir: utils_validation_1.Joi.string().required(),
24
- contentDocsPath: utils_validation_1.Joi.string().required(),
25
- routeBasePath: utils_validation_1.Joi.string(),
26
25
  template: utils_validation_1.Joi.string(),
27
26
  sidebarOptions: sidebarOptions,
28
27
  version: utils_validation_1.Joi.string().when("versions", {
@@ -1,4 +1,4 @@
1
1
  import { ProcessedSidebar } from "@docusaurus/plugin-content-docs/src/sidebars/types";
2
2
  import { TagObject } from "../openapi/types";
3
3
  import type { SidebarOptions, APIOptions, ApiMetadata } from "../types";
4
- export default function generateSidebarSlice(sidebarOptions: SidebarOptions, options: APIOptions, api: ApiMetadata[], tags: TagObject[]): ProcessedSidebar;
4
+ export default function generateSidebarSlice(sidebarOptions: SidebarOptions, options: APIOptions, api: ApiMetadata[], tags: TagObject[], docPath: string): ProcessedSidebar;
@@ -18,10 +18,9 @@ function isApiItem(item) {
18
18
  function isInfoItem(item) {
19
19
  return item.type === "info";
20
20
  }
21
- function groupByTags(items, sidebarOptions, options, tags) {
21
+ function groupByTags(items, sidebarOptions, options, tags, docPath) {
22
22
  const { outputDir } = options;
23
23
  const { sidebarCollapsed, sidebarCollapsible, customProps, categoryLinkSource, } = sidebarOptions;
24
- const { contentDocsPath } = options;
25
24
  const apiItems = items.filter(isApiItem);
26
25
  const infoItems = items.filter(isInfoItem);
27
26
  const intros = infoItems.map((item) => {
@@ -36,8 +35,8 @@ function groupByTags(items, sidebarOptions, options, tags) {
36
35
  const apiTags = (0, uniq_1.default)(apiItems
37
36
  .flatMap((item) => item.api.tags)
38
37
  .filter((item) => !!item));
39
- const basePath = contentDocsPath
40
- ? outputDir.split(contentDocsPath)[1].replace(/^\/+/g, "")
38
+ const basePath = docPath
39
+ ? outputDir.split(docPath)[1].replace(/^\/+/g, "")
41
40
  : outputDir.slice(outputDir.indexOf("/", 1)).replace(/^\/+/g, "");
42
41
  function createDocItem(item) {
43
42
  var _a, _b;
@@ -136,10 +135,10 @@ function groupByTags(items, sidebarOptions, options, tags) {
136
135
  }
137
136
  return [...tagged, ...untagged];
138
137
  }
139
- function generateSidebarSlice(sidebarOptions, options, api, tags) {
138
+ function generateSidebarSlice(sidebarOptions, options, api, tags, docPath) {
140
139
  let sidebarSlice = [];
141
140
  if (sidebarOptions.groupPathsBy === "tag") {
142
- sidebarSlice = groupByTags(api, sidebarOptions, options, tags);
141
+ sidebarSlice = groupByTags(api, sidebarOptions, options, tags, docPath);
143
142
  }
144
143
  return sidebarSlice;
145
144
  }
package/lib/types.d.ts CHANGED
@@ -3,6 +3,7 @@ import { InfoObject, OperationObject, SecuritySchemeObject, TagObject } from "./
3
3
  export type { PropSidebarItemCategory, SidebarItemLink, PropSidebar, PropSidebarItem, } from "@docusaurus/plugin-content-docs-types";
4
4
  export interface PluginOptions {
5
5
  id?: string;
6
+ docPluginId: string;
6
7
  config: {
7
8
  [key: string]: APIOptions;
8
9
  };
@@ -10,8 +11,6 @@ export interface PluginOptions {
10
11
  export interface APIOptions {
11
12
  specPath: string;
12
13
  outputDir: string;
13
- contentDocsPath: string;
14
- routeBasePath?: string;
15
14
  template?: string;
16
15
  sidebarOptions?: SidebarOptions;
17
16
  version?: 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": "0.0.0-380",
4
+ "version": "0.0.0-381",
5
5
  "license": "MIT",
6
6
  "keywords": [
7
7
  "openapi",
@@ -62,5 +62,5 @@
62
62
  "engines": {
63
63
  "node": ">=14"
64
64
  },
65
- "gitHead": "3322e621893b40124fed23abd7f7aa8f12fed5af"
65
+ "gitHead": "788943d4760ff1b1c4145d289b2d6ab0f92b1e51"
66
66
  }
package/src/index.ts CHANGED
@@ -23,22 +23,58 @@ export function isURL(str: string): boolean {
23
23
  return /^(https?:)\/\//m.test(str);
24
24
  }
25
25
 
26
+ export function getDocsData(
27
+ dataArray: any[],
28
+ filter: string
29
+ ): Object | undefined {
30
+ // eslint-disable-next-line array-callback-return
31
+ const filteredData = dataArray.filter((data) => {
32
+ if (data[0] === filter) {
33
+ return data[1];
34
+ }
35
+
36
+ // Search plugin-content-docs instances
37
+ if (data[0] === "@docusaurus/plugin-content-docs") {
38
+ const pluginId = data[1].id ? data[1].id : "default";
39
+ if (pluginId === filter) {
40
+ return data[1];
41
+ }
42
+ }
43
+ })[0];
44
+ if (filteredData) {
45
+ // Search presets, e.g. "classic"
46
+ if (filteredData[0] === filter) {
47
+ return filteredData[1].docs;
48
+ }
49
+
50
+ // Search plugin-content-docs instances
51
+ if (filteredData[0] === "@docusaurus/plugin-content-docs") {
52
+ const pluginId = filteredData[1].id ? filteredData[1].id : "default";
53
+ if (pluginId === filter) {
54
+ return filteredData[1];
55
+ }
56
+ }
57
+ }
58
+ return;
59
+ }
60
+
26
61
  export default function pluginOpenAPIDocs(
27
62
  context: LoadContext,
28
63
  options: PluginOptions
29
64
  ): Plugin<LoadedContent> {
30
- let { config } = options;
31
- let { siteDir } = context;
65
+ const { config, docPluginId } = options;
66
+ const { siteDir, siteConfig } = context;
67
+
68
+ // Get routeBasePath and path from plugin-content-docs or preset
69
+ const presets: any = siteConfig.presets;
70
+ const plugins: any = siteConfig.plugins;
71
+ const presetsPlugins = presets.concat(plugins);
72
+ const docData: any = getDocsData(presetsPlugins, docPluginId);
73
+ const docRouteBasePath = docData ? docData.routeBasePath : undefined;
74
+ const docPath = docData ? (docData.path ? docData.path : "docs") : undefined;
32
75
 
33
76
  async function generateApiDocs(options: APIOptions) {
34
- let {
35
- specPath,
36
- outputDir,
37
- contentDocsPath,
38
- routeBasePath,
39
- template,
40
- sidebarOptions,
41
- } = options;
77
+ let { specPath, outputDir, template, sidebarOptions } = options;
42
78
 
43
79
  const contentPath = isURL(specPath)
44
80
  ? specPath
@@ -68,7 +104,8 @@ export default function pluginOpenAPIDocs(
68
104
  sidebarOptions!,
69
105
  options,
70
106
  loadedApi,
71
- tags
107
+ tags,
108
+ docPath
72
109
  );
73
110
 
74
111
  const sidebarSliceTemplate = template
@@ -172,9 +209,9 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
172
209
  if (item.type === "api") {
173
210
  item.json = JSON.stringify(item.api);
174
211
  let infoBasePath = `${outputDir}/${item.infoId}`;
175
- if (routeBasePath) {
176
- infoBasePath = `${routeBasePath}/${outputDir
177
- .split(contentDocsPath!)[1]
212
+ if (docRouteBasePath) {
213
+ infoBasePath = `${docRouteBasePath}/${outputDir
214
+ .split(docPath!)[1]
178
215
  .replace(/^\/+/g, "")}/${item.infoId}`.replace(/^\/+/g, "");
179
216
  }
180
217
  if (item.infoId) item.infoPath = infoBasePath;
package/src/options.ts CHANGED
@@ -17,14 +17,13 @@ const sidebarOptions = Joi.object({
17
17
 
18
18
  export const OptionsSchema = Joi.object({
19
19
  id: Joi.string().required(),
20
+ docPluginId: Joi.string().required(),
20
21
  config: Joi.object()
21
22
  .pattern(
22
23
  /^/,
23
24
  Joi.object({
24
25
  specPath: Joi.string().required(),
25
26
  outputDir: Joi.string().required(),
26
- contentDocsPath: Joi.string().required(),
27
- routeBasePath: Joi.string(),
28
27
  template: Joi.string(),
29
28
  sidebarOptions: sidebarOptions,
30
29
  version: Joi.string().when("versions", {
@@ -35,7 +35,8 @@ function groupByTags(
35
35
  items: ApiPageMetadata[],
36
36
  sidebarOptions: SidebarOptions,
37
37
  options: APIOptions,
38
- tags: TagObject[]
38
+ tags: TagObject[],
39
+ docPath: string
39
40
  ): ProcessedSidebar {
40
41
  const { outputDir } = options;
41
42
  const {
@@ -45,8 +46,6 @@ function groupByTags(
45
46
  categoryLinkSource,
46
47
  } = sidebarOptions;
47
48
 
48
- const { contentDocsPath } = options;
49
-
50
49
  const apiItems = items.filter(isApiItem);
51
50
  const infoItems = items.filter(isInfoItem);
52
51
  const intros = infoItems.map((item: any) => {
@@ -65,8 +64,8 @@ function groupByTags(
65
64
  .filter((item): item is string => !!item)
66
65
  );
67
66
 
68
- const basePath = contentDocsPath
69
- ? outputDir.split(contentDocsPath!)[1].replace(/^\/+/g, "")
67
+ const basePath = docPath
68
+ ? outputDir.split(docPath!)[1].replace(/^\/+/g, "")
70
69
  : outputDir.slice(outputDir.indexOf("/", 1)).replace(/^\/+/g, "");
71
70
 
72
71
  function createDocItem(item: ApiPageMetadata): SidebarItemDoc {
@@ -185,7 +184,8 @@ export default function generateSidebarSlice(
185
184
  sidebarOptions: SidebarOptions,
186
185
  options: APIOptions,
187
186
  api: ApiMetadata[],
188
- tags: TagObject[]
187
+ tags: TagObject[],
188
+ docPath: string
189
189
  ) {
190
190
  let sidebarSlice: ProcessedSidebar = [];
191
191
  if (sidebarOptions.groupPathsBy === "tag") {
@@ -193,7 +193,8 @@ export default function generateSidebarSlice(
193
193
  api as ApiPageMetadata[],
194
194
  sidebarOptions,
195
195
  options,
196
- tags
196
+ tags,
197
+ docPath
197
198
  );
198
199
  }
199
200
  return sidebarSlice;
package/src/types.ts CHANGED
@@ -22,6 +22,7 @@ export type {
22
22
  } from "@docusaurus/plugin-content-docs-types";
23
23
  export interface PluginOptions {
24
24
  id?: string;
25
+ docPluginId: string;
25
26
  config: {
26
27
  [key: string]: APIOptions;
27
28
  };
@@ -30,8 +31,6 @@ export interface PluginOptions {
30
31
  export interface APIOptions {
31
32
  specPath: string;
32
33
  outputDir: string;
33
- contentDocsPath: string;
34
- routeBasePath?: string;
35
34
  template?: string;
36
35
  sidebarOptions?: SidebarOptions;
37
36
  version?: string;