docusaurus-plugin-openapi-docs 0.0.0-368 → 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/README.md +6 -6
- package/lib/index.d.ts +5 -1
- package/lib/index.js +9 -5
- package/lib/options.d.ts +0 -2
- package/lib/options.js +18 -7
- package/lib/sidebars/index.js +5 -6
- package/lib/types.d.ts +1 -0
- package/package.json +2 -2
- package/src/index.ts +9 -3
- package/src/options.ts +20 -8
- package/src/sidebars/index.ts +6 -5
- package/src/types.ts +1 -0
package/README.md
CHANGED
|
@@ -101,12 +101,12 @@ Here is an example of properly configuring your `docusaurus.config.js` file for
|
|
|
101
101
|
|
|
102
102
|
`docusaurus-plugin-openapi-docs` can be configured with the following options:
|
|
103
103
|
|
|
104
|
-
| Name | Type | Default | Description
|
|
105
|
-
| ---------------- | -------- | ------- |
|
|
106
|
-
| `specPath` | `string` | `null` | Designated path to the source of an OpenAPI specification file or directory of multiple OpenAPI specification files. |
|
|
107
|
-
| `ouputDir` | `string` | `null` | Desired output path for generated MDX files.
|
|
108
|
-
| `template` | `string` | `null` | _Optional:_ Customize MDX content with a desired template.
|
|
109
|
-
| `sidebarOptions` | `object` | `null` | _Optional:_ Set of options for sidebar configuration. See below for a list of supported options.
|
|
104
|
+
| Name | Type | Default | Description |
|
|
105
|
+
| ---------------- | -------- | ------- | --------------------------------------------------------------------------------------------------------------------------- |
|
|
106
|
+
| `specPath` | `string` | `null` | Designated URL or path to the source of an OpenAPI specification file or directory of multiple OpenAPI specification files. |
|
|
107
|
+
| `ouputDir` | `string` | `null` | Desired output path for generated MDX files. |
|
|
108
|
+
| `template` | `string` | `null` | _Optional:_ Customize MDX content with a desired template. |
|
|
109
|
+
| `sidebarOptions` | `object` | `null` | _Optional:_ Set of options for sidebar configuration. See below for a list of supported options. |
|
|
110
110
|
|
|
111
111
|
`sidebarOptions` can be configured with the following options:
|
|
112
112
|
|
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
|
-
|
|
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
|
|
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,
|
|
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 =
|
|
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
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 =
|
|
9
|
+
exports.OptionsSchema = void 0;
|
|
10
10
|
const utils_validation_1 = require("@docusaurus/utils-validation");
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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().
|
|
17
|
-
config: utils_validation_1.Joi.object()
|
|
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
|
});
|
package/lib/sidebars/index.js
CHANGED
|
@@ -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
|
-
|
|
39
|
-
|
|
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
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-
|
|
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": "
|
|
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
|
|
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!,
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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().
|
|
19
|
-
config: Joi.object()
|
|
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
|
});
|
package/src/sidebars/index.ts
CHANGED
|
@@ -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
|
-
|
|
67
|
-
|
|
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:
|
|
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(
|