docusaurus-plugin-openapi-docs 0.0.0-372 → 0.0.0-374

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/index.d.ts CHANGED
@@ -1,4 +1,8 @@
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 default function pluginOpenAPI(context: LoadContext, options: PluginOptions): Plugin<LoadedContent>;
4
+ declare function pluginOpenAPIDocs(context: LoadContext, options: PluginOptions): Plugin<LoadedContent>;
5
+ declare namespace pluginOpenAPIDocs {
6
+ var validateOptions: ({ options, validate }: any) => any;
7
+ }
8
+ export default pluginOpenAPIDocs;
package/lib/index.js CHANGED
@@ -17,12 +17,13 @@ const chalk_1 = __importDefault(require("chalk"));
17
17
  const mustache_1 = require("mustache");
18
18
  const markdown_1 = require("./markdown");
19
19
  const openapi_1 = require("./openapi");
20
+ const options_1 = require("./options");
20
21
  const sidebars_1 = __importDefault(require("./sidebars"));
21
22
  function isURL(str) {
22
23
  return /^(https?:)\/\//m.test(str);
23
24
  }
24
25
  exports.isURL = isURL;
25
- function pluginOpenAPI(context, options) {
26
+ function pluginOpenAPIDocs(context, options) {
26
27
  let { config } = options;
27
28
  let { siteDir } = context;
28
29
  async function generateApiDocs(options) {
@@ -44,8 +45,7 @@ function pluginOpenAPI(context, options) {
44
45
  }
45
46
  // TODO: figure out better way to set default
46
47
  if (Object.keys(sidebarOptions !== null && sidebarOptions !== void 0 ? sidebarOptions : {}).length > 0) {
47
- const sidebarSlice = (0, sidebars_1.default)(sidebarOptions, // TODO: find a better way to handle null
48
- options, loadedApi, tags);
48
+ const sidebarSlice = (0, sidebars_1.default)(sidebarOptions, options, loadedApi, tags);
49
49
  const sidebarSliceTemplate = template
50
50
  ? fs_1.default.readFileSync(template).toString()
51
51
  : `module.exports = {{{slice}}};`;
@@ -214,7 +214,7 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
214
214
  }));
215
215
  }
216
216
  return {
217
- name: `docusaurus-plugin-openapi`,
217
+ name: `docusaurus-plugin-openapi-docs`,
218
218
  extendCli(cli) {
219
219
  cli
220
220
  .command(`gen-api-docs`)
@@ -262,4 +262,8 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
262
262
  },
263
263
  };
264
264
  }
265
- exports.default = pluginOpenAPI;
265
+ exports.default = pluginOpenAPIDocs;
266
+ pluginOpenAPIDocs.validateOptions = ({ options, validate }) => {
267
+ const validatedOptions = validate(options_1.OptionsSchema, options);
268
+ return validatedOptions;
269
+ };
package/lib/options.d.ts CHANGED
@@ -1,4 +1,2 @@
1
1
  import { Joi } from "@docusaurus/utils-validation";
2
- import type { PluginOptions } from "./types";
3
- export declare const DEFAULT_OPTIONS: PluginOptions;
4
2
  export declare const OptionsSchema: Joi.ObjectSchema<any>;
package/lib/options.js CHANGED
@@ -6,13 +6,24 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  * ========================================================================== */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.OptionsSchema = exports.DEFAULT_OPTIONS = void 0;
9
+ exports.OptionsSchema = void 0;
10
10
  const utils_validation_1 = require("@docusaurus/utils-validation");
11
- exports.DEFAULT_OPTIONS = {
12
- id: "default",
13
- config: {},
14
- };
11
+ const sidebarOptions = utils_validation_1.Joi.object({
12
+ contentDocsPath: utils_validation_1.Joi.string(),
13
+ groupPathsBy: utils_validation_1.Joi.string().valid("tag"),
14
+ categoryLinkSource: utils_validation_1.Joi.string().valid("tag", "info"),
15
+ customProps: utils_validation_1.Joi.object(),
16
+ sidebarCollapsible: utils_validation_1.Joi.boolean(),
17
+ sidebarCollapsed: utils_validation_1.Joi.boolean(),
18
+ }).with("groupPathsBy", "contentDocsPath");
15
19
  exports.OptionsSchema = utils_validation_1.Joi.object({
16
- id: utils_validation_1.Joi.string().default(exports.DEFAULT_OPTIONS.id),
17
- config: utils_validation_1.Joi.object().default(exports.DEFAULT_OPTIONS.config),
20
+ id: utils_validation_1.Joi.string().required(),
21
+ config: utils_validation_1.Joi.object()
22
+ .pattern(/^/, utils_validation_1.Joi.object({
23
+ specPath: utils_validation_1.Joi.string().required(),
24
+ outputDir: utils_validation_1.Joi.string().required(),
25
+ template: utils_validation_1.Joi.string(),
26
+ sidebarOptions: sidebarOptions,
27
+ }))
28
+ .required(),
18
29
  });
@@ -20,7 +20,7 @@ function isInfoItem(item) {
20
20
  }
21
21
  function groupByTags(items, sidebarOptions, options, tags) {
22
22
  const { outputDir } = options;
23
- const { sidebarCollapsed, sidebarCollapsible, customProps, categoryLinkSource, } = sidebarOptions;
23
+ const { sidebarCollapsed, sidebarCollapsible, customProps, categoryLinkSource, contentDocsPath, } = sidebarOptions;
24
24
  const apiItems = items.filter(isApiItem);
25
25
  const infoItems = items.filter(isInfoItem);
26
26
  const intros = infoItems.map((item) => {
@@ -35,10 +35,9 @@ function groupByTags(items, sidebarOptions, options, tags) {
35
35
  const apiTags = (0, uniq_1.default)(apiItems
36
36
  .flatMap((item) => item.api.tags)
37
37
  .filter((item) => !!item));
38
- // TODO: optimize this or make it a function
39
- const basePath = outputDir
40
- .slice(outputDir.indexOf("/", 1))
41
- .replace(/^\/+/g, "");
38
+ const basePath = contentDocsPath
39
+ ? outputDir.split(contentDocsPath)[1].replace(/^\/+/g, "")
40
+ : outputDir.slice(outputDir.indexOf("/", 1)).replace(/^\/+/g, "");
42
41
  function createDocItem(item) {
43
42
  var _a, _b;
44
43
  const sidebar_label = item.frontMatter.sidebar_label;
@@ -46,7 +45,7 @@ function groupByTags(items, sidebarOptions, options, tags) {
46
45
  const id = item.id;
47
46
  return {
48
47
  type: "doc",
49
- id: `${basePath}/${item.id}`,
48
+ id: basePath === "" || undefined ? `${item.id}` : `${basePath}/${item.id}`,
50
49
  label: (_b = (_a = sidebar_label) !== null && _a !== void 0 ? _a : title) !== null && _b !== void 0 ? _b : id,
51
50
  customProps: customProps,
52
51
  className: (0, clsx_1.default)({
package/lib/types.d.ts CHANGED
@@ -69,6 +69,7 @@ export interface ApiNavLink {
69
69
  permalink: string;
70
70
  }
71
71
  export interface SidebarOptions {
72
+ contentDocsPath?: string;
72
73
  groupPathsBy?: string;
73
74
  categoryLinkSource?: string;
74
75
  customProps?: {
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-372",
4
+ "version": "0.0.0-374",
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": "cb2266e68c4453350e2457804dd76897593f052e"
65
+ "gitHead": "1a04b6a59b6ba534893ee06fc0f19b9a90768988"
66
66
  }
package/src/index.ts CHANGED
@@ -15,6 +15,7 @@ import { render } from "mustache";
15
15
 
16
16
  import { createApiPageMD, createInfoPageMD, createTagPageMD } from "./markdown";
17
17
  import { readOpenapiFiles, processOpenapiFiles } from "./openapi";
18
+ import { OptionsSchema } from "./options";
18
19
  import generateSidebarSlice from "./sidebars";
19
20
  import type { PluginOptions, LoadedContent, APIOptions } from "./types";
20
21
 
@@ -22,7 +23,7 @@ export function isURL(str: string): boolean {
22
23
  return /^(https?:)\/\//m.test(str);
23
24
  }
24
25
 
25
- export default function pluginOpenAPI(
26
+ export default function pluginOpenAPIDocs(
26
27
  context: LoadContext,
27
28
  options: PluginOptions
28
29
  ): Plugin<LoadedContent> {
@@ -57,7 +58,7 @@ export default function pluginOpenAPI(
57
58
  // TODO: figure out better way to set default
58
59
  if (Object.keys(sidebarOptions ?? {}).length > 0) {
59
60
  const sidebarSlice = generateSidebarSlice(
60
- sidebarOptions!, // TODO: find a better way to handle null
61
+ sidebarOptions!,
61
62
  options,
62
63
  loadedApi,
63
64
  tags
@@ -288,7 +289,7 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
288
289
  }
289
290
 
290
291
  return {
291
- name: `docusaurus-plugin-openapi`,
292
+ name: `docusaurus-plugin-openapi-docs`,
292
293
 
293
294
  extendCli(cli): void {
294
295
  cli
@@ -339,3 +340,8 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
339
340
  },
340
341
  };
341
342
  }
343
+
344
+ pluginOpenAPIDocs.validateOptions = ({ options, validate }: any) => {
345
+ const validatedOptions = validate(OptionsSchema, options);
346
+ return validatedOptions;
347
+ };
package/src/options.ts CHANGED
@@ -7,14 +7,26 @@
7
7
 
8
8
  import { Joi } from "@docusaurus/utils-validation";
9
9
 
10
- import type { PluginOptions } from "./types";
11
-
12
- export const DEFAULT_OPTIONS: PluginOptions = {
13
- id: "default",
14
- config: {},
15
- };
10
+ const sidebarOptions = Joi.object({
11
+ contentDocsPath: Joi.string(),
12
+ groupPathsBy: Joi.string().valid("tag"),
13
+ categoryLinkSource: Joi.string().valid("tag", "info"),
14
+ customProps: Joi.object(),
15
+ sidebarCollapsible: Joi.boolean(),
16
+ sidebarCollapsed: Joi.boolean(),
17
+ }).with("groupPathsBy", "contentDocsPath");
16
18
 
17
19
  export const OptionsSchema = Joi.object({
18
- id: Joi.string().default(DEFAULT_OPTIONS.id),
19
- config: Joi.object().default(DEFAULT_OPTIONS.config),
20
+ id: Joi.string().required(),
21
+ config: Joi.object()
22
+ .pattern(
23
+ /^/,
24
+ Joi.object({
25
+ specPath: Joi.string().required(),
26
+ outputDir: Joi.string().required(),
27
+ template: Joi.string(),
28
+ sidebarOptions: sidebarOptions,
29
+ })
30
+ )
31
+ .required(),
20
32
  });
@@ -43,6 +43,7 @@ function groupByTags(
43
43
  sidebarCollapsible,
44
44
  customProps,
45
45
  categoryLinkSource,
46
+ contentDocsPath,
46
47
  } = sidebarOptions;
47
48
 
48
49
  const apiItems = items.filter(isApiItem);
@@ -63,10 +64,9 @@ function groupByTags(
63
64
  .filter((item): item is string => !!item)
64
65
  );
65
66
 
66
- // TODO: optimize this or make it a function
67
- const basePath = outputDir
68
- .slice(outputDir.indexOf("/", 1))
69
- .replace(/^\/+/g, "");
67
+ const basePath = contentDocsPath
68
+ ? outputDir.split(contentDocsPath!)[1].replace(/^\/+/g, "")
69
+ : outputDir.slice(outputDir.indexOf("/", 1)).replace(/^\/+/g, "");
70
70
 
71
71
  function createDocItem(item: ApiPageMetadata): SidebarItemDoc {
72
72
  const sidebar_label = item.frontMatter.sidebar_label;
@@ -74,7 +74,8 @@ function groupByTags(
74
74
  const id = item.id;
75
75
  return {
76
76
  type: "doc" as const,
77
- id: `${basePath}/${item.id}`,
77
+ id:
78
+ basePath === "" || undefined ? `${item.id}` : `${basePath}/${item.id}`,
78
79
  label: (sidebar_label as string) ?? title ?? id,
79
80
  customProps: customProps,
80
81
  className: clsx(
package/src/types.ts CHANGED
@@ -101,6 +101,7 @@ export interface ApiNavLink {
101
101
  }
102
102
 
103
103
  export interface SidebarOptions {
104
+ contentDocsPath?: string;
104
105
  groupPathsBy?: string;
105
106
  categoryLinkSource?: string;
106
107
  customProps?: { [key: string]: unknown };