docusaurus-plugin-openapi-docs 0.0.0-beta.721 → 0.0.0-beta.724
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 +1 -1
- package/lib/index.js +15 -19
- package/lib/options.js +1 -0
- package/lib/types.d.ts +1 -0
- package/package.json +2 -2
- package/src/index.ts +26 -27
- package/src/options.ts +1 -0
- package/src/types.ts +1 -0
package/lib/index.d.ts
CHANGED
|
@@ -1,7 +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 getDocsPluginConfig(presetsPlugins: any[], pluginId: string): Object | undefined;
|
|
4
|
+
export declare function getDocsPluginConfig(presetsPlugins: any[], plugin: string, pluginId: string): Object | undefined;
|
|
5
5
|
declare function pluginOpenAPIDocs(context: LoadContext, options: PluginOptions): Plugin<LoadedContent>;
|
|
6
6
|
declare namespace pluginOpenAPIDocs {
|
|
7
7
|
var validateOptions: ({ options, validate }: any) => any;
|
package/lib/index.js
CHANGED
|
@@ -25,7 +25,7 @@ function isURL(str) {
|
|
|
25
25
|
return /^(https?:)\/\//m.test(str);
|
|
26
26
|
}
|
|
27
27
|
exports.isURL = isURL;
|
|
28
|
-
function getDocsPluginConfig(presetsPlugins, pluginId) {
|
|
28
|
+
function getDocsPluginConfig(presetsPlugins, plugin, pluginId) {
|
|
29
29
|
// eslint-disable-next-line array-callback-return
|
|
30
30
|
const filteredConfig = presetsPlugins.filter((data) => {
|
|
31
31
|
// Search presets
|
|
@@ -34,8 +34,7 @@ function getDocsPluginConfig(presetsPlugins, pluginId) {
|
|
|
34
34
|
return data[1];
|
|
35
35
|
}
|
|
36
36
|
// Search plugin-content-docs instances
|
|
37
|
-
if (typeof data[0] === "string" &&
|
|
38
|
-
data[0] === "@docusaurus/plugin-content-docs") {
|
|
37
|
+
if (typeof data[0] === "string" && data[0] === plugin) {
|
|
39
38
|
const configPluginId = data[1].id ? data[1].id : "default";
|
|
40
39
|
if (configPluginId === pluginId) {
|
|
41
40
|
return data[1];
|
|
@@ -49,7 +48,7 @@ function getDocsPluginConfig(presetsPlugins, pluginId) {
|
|
|
49
48
|
return filteredConfig[1].docs;
|
|
50
49
|
}
|
|
51
50
|
// Search plugin-content-docs instances
|
|
52
|
-
if (filteredConfig[0] ===
|
|
51
|
+
if (filteredConfig[0] === plugin) {
|
|
53
52
|
const configPluginId = filteredConfig[1].id
|
|
54
53
|
? filteredConfig[1].id
|
|
55
54
|
: "default";
|
|
@@ -68,13 +67,13 @@ function getPluginInstances(plugins) {
|
|
|
68
67
|
return plugins.filter((data) => data[0] === "docusaurus-plugin-openapi-docs");
|
|
69
68
|
}
|
|
70
69
|
function pluginOpenAPIDocs(context, options) {
|
|
71
|
-
const { config, docsPluginId } = options;
|
|
70
|
+
const { config, docsPlugin = "@docusaurus/plugin-content-docs", docsPluginId, } = options;
|
|
72
71
|
const { siteDir, siteConfig } = context;
|
|
73
72
|
// Get routeBasePath and path from plugin-content-docs or preset
|
|
74
73
|
const presets = siteConfig.presets;
|
|
75
74
|
const plugins = siteConfig.plugins;
|
|
76
75
|
const presetsPlugins = presets.concat(plugins);
|
|
77
|
-
let docData = getDocsPluginConfig(presetsPlugins, docsPluginId);
|
|
76
|
+
let docData = getDocsPluginConfig(presetsPlugins, docsPlugin, docsPluginId);
|
|
78
77
|
let docRouteBasePath = docData ? docData.routeBasePath : undefined;
|
|
79
78
|
let docPath = docData ? (docData.path ? docData.path : "docs") : undefined;
|
|
80
79
|
async function generateApiDocs(options, pluginId) {
|
|
@@ -84,7 +83,7 @@ function pluginOpenAPIDocs(context, options) {
|
|
|
84
83
|
outputDir = outputDir.replace(/\/$/, "");
|
|
85
84
|
// Override docPath if pluginId provided
|
|
86
85
|
if (pluginId) {
|
|
87
|
-
docData = getDocsPluginConfig(presetsPlugins, pluginId);
|
|
86
|
+
docData = getDocsPluginConfig(presetsPlugins, docsPlugin, pluginId);
|
|
88
87
|
docRouteBasePath = docData ? docData.routeBasePath : undefined;
|
|
89
88
|
docPath = docData ? (docData.path ? docData.path : "docs") : undefined;
|
|
90
89
|
}
|
|
@@ -334,11 +333,7 @@ custom_edit_url: null
|
|
|
334
333
|
cwd: path_1.default.resolve(apiDir),
|
|
335
334
|
deep: 1,
|
|
336
335
|
});
|
|
337
|
-
const
|
|
338
|
-
cwd: path_1.default.resolve(apiDir, "schemas"),
|
|
339
|
-
deep: 1,
|
|
340
|
-
});
|
|
341
|
-
const sidebarFile = await (0, utils_1.Globby)(["sidebar.js"], {
|
|
336
|
+
const sidebarFile = await (0, utils_1.Globby)(["sidebar.js", "sidebar.ts"], {
|
|
342
337
|
cwd: path_1.default.resolve(apiDir),
|
|
343
338
|
deep: 1,
|
|
344
339
|
});
|
|
@@ -350,14 +345,15 @@ custom_edit_url: null
|
|
|
350
345
|
console.log(chalk_1.default.green(`Cleanup succeeded for "${apiDir}/${mdx}"`));
|
|
351
346
|
}
|
|
352
347
|
}));
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
348
|
+
try {
|
|
349
|
+
fs_1.default.rmSync(`${apiDir}/schemas`, { recursive: true });
|
|
350
|
+
console.log(chalk_1.default.green(`Cleanup succeeded for "${apiDir}/schemas"`));
|
|
351
|
+
}
|
|
352
|
+
catch (err) {
|
|
353
|
+
if (err.code !== "ENOENT") {
|
|
354
|
+
console.error(chalk_1.default.red(`Cleanup failed for "${apiDir}/schemas"`), chalk_1.default.yellow(err));
|
|
359
355
|
}
|
|
360
|
-
}
|
|
356
|
+
}
|
|
361
357
|
sidebarFile.map((sidebar) => fs_1.default.unlink(`${apiDir}/${sidebar}`, (err) => {
|
|
362
358
|
if (err) {
|
|
363
359
|
console.error(chalk_1.default.red(`Cleanup failed for "${apiDir}/${sidebar}"`), chalk_1.default.yellow(err));
|
package/lib/options.js
CHANGED
|
@@ -22,6 +22,7 @@ const markdownGenerators = utils_validation_1.Joi.object({
|
|
|
22
22
|
});
|
|
23
23
|
exports.OptionsSchema = utils_validation_1.Joi.object({
|
|
24
24
|
id: utils_validation_1.Joi.string().required(),
|
|
25
|
+
docsPlugin: utils_validation_1.Joi.string(),
|
|
25
26
|
docsPluginId: utils_validation_1.Joi.string().required(),
|
|
26
27
|
config: utils_validation_1.Joi.object()
|
|
27
28
|
.pattern(/^/, utils_validation_1.Joi.object({
|
package/lib/types.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { InfoObject, OperationObject, SchemaObject, SecuritySchemeObject, TagObj
|
|
|
3
3
|
export type { PropSidebarItemCategory, SidebarItemLink, PropSidebar, PropSidebarItem, } from "@docusaurus/plugin-content-docs-types";
|
|
4
4
|
export interface PluginOptions {
|
|
5
5
|
id?: string;
|
|
6
|
+
docsPlugin?: string;
|
|
6
7
|
docsPluginId: string;
|
|
7
8
|
config: {
|
|
8
9
|
[key: string]: APIOptions;
|
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-beta.
|
|
4
|
+
"version": "0.0.0-beta.724",
|
|
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": "76903beba80972a5bcd88c74a33dc5e4bbbaa631"
|
|
66
66
|
}
|
package/src/index.ts
CHANGED
|
@@ -41,6 +41,7 @@ export function isURL(str: string): boolean {
|
|
|
41
41
|
|
|
42
42
|
export function getDocsPluginConfig(
|
|
43
43
|
presetsPlugins: any[],
|
|
44
|
+
plugin: string,
|
|
44
45
|
pluginId: string
|
|
45
46
|
): Object | undefined {
|
|
46
47
|
// eslint-disable-next-line array-callback-return
|
|
@@ -52,10 +53,7 @@ export function getDocsPluginConfig(
|
|
|
52
53
|
}
|
|
53
54
|
|
|
54
55
|
// Search plugin-content-docs instances
|
|
55
|
-
if (
|
|
56
|
-
typeof data[0] === "string" &&
|
|
57
|
-
data[0] === "@docusaurus/plugin-content-docs"
|
|
58
|
-
) {
|
|
56
|
+
if (typeof data[0] === "string" && data[0] === plugin) {
|
|
59
57
|
const configPluginId = data[1].id ? data[1].id : "default";
|
|
60
58
|
if (configPluginId === pluginId) {
|
|
61
59
|
return data[1];
|
|
@@ -71,7 +69,7 @@ export function getDocsPluginConfig(
|
|
|
71
69
|
}
|
|
72
70
|
|
|
73
71
|
// Search plugin-content-docs instances
|
|
74
|
-
if (filteredConfig[0] ===
|
|
72
|
+
if (filteredConfig[0] === plugin) {
|
|
75
73
|
const configPluginId = filteredConfig[1].id
|
|
76
74
|
? filteredConfig[1].id
|
|
77
75
|
: "default";
|
|
@@ -95,14 +93,22 @@ export default function pluginOpenAPIDocs(
|
|
|
95
93
|
context: LoadContext,
|
|
96
94
|
options: PluginOptions
|
|
97
95
|
): Plugin<LoadedContent> {
|
|
98
|
-
const {
|
|
96
|
+
const {
|
|
97
|
+
config,
|
|
98
|
+
docsPlugin = "@docusaurus/plugin-content-docs",
|
|
99
|
+
docsPluginId,
|
|
100
|
+
} = options;
|
|
99
101
|
const { siteDir, siteConfig } = context;
|
|
100
102
|
|
|
101
103
|
// Get routeBasePath and path from plugin-content-docs or preset
|
|
102
104
|
const presets: any = siteConfig.presets;
|
|
103
105
|
const plugins: any = siteConfig.plugins;
|
|
104
106
|
const presetsPlugins = presets.concat(plugins);
|
|
105
|
-
let docData: any = getDocsPluginConfig(
|
|
107
|
+
let docData: any = getDocsPluginConfig(
|
|
108
|
+
presetsPlugins,
|
|
109
|
+
docsPlugin,
|
|
110
|
+
docsPluginId
|
|
111
|
+
);
|
|
106
112
|
let docRouteBasePath = docData ? docData.routeBasePath : undefined;
|
|
107
113
|
let docPath = docData ? (docData.path ? docData.path : "docs") : undefined;
|
|
108
114
|
|
|
@@ -121,7 +127,7 @@ export default function pluginOpenAPIDocs(
|
|
|
121
127
|
|
|
122
128
|
// Override docPath if pluginId provided
|
|
123
129
|
if (pluginId) {
|
|
124
|
-
docData = getDocsPluginConfig(presetsPlugins, pluginId);
|
|
130
|
+
docData = getDocsPluginConfig(presetsPlugins, docsPlugin, pluginId);
|
|
125
131
|
docRouteBasePath = docData ? docData.routeBasePath : undefined;
|
|
126
132
|
docPath = docData ? (docData.path ? docData.path : "docs") : undefined;
|
|
127
133
|
}
|
|
@@ -470,11 +476,7 @@ custom_edit_url: null
|
|
|
470
476
|
cwd: path.resolve(apiDir),
|
|
471
477
|
deep: 1,
|
|
472
478
|
});
|
|
473
|
-
const
|
|
474
|
-
cwd: path.resolve(apiDir, "schemas"),
|
|
475
|
-
deep: 1,
|
|
476
|
-
});
|
|
477
|
-
const sidebarFile = await Globby(["sidebar.js"], {
|
|
479
|
+
const sidebarFile = await Globby(["sidebar.js", "sidebar.ts"], {
|
|
478
480
|
cwd: path.resolve(apiDir),
|
|
479
481
|
deep: 1,
|
|
480
482
|
});
|
|
@@ -491,20 +493,17 @@ custom_edit_url: null
|
|
|
491
493
|
})
|
|
492
494
|
);
|
|
493
495
|
|
|
494
|
-
|
|
495
|
-
fs.
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
)
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
}
|
|
506
|
-
})
|
|
507
|
-
);
|
|
496
|
+
try {
|
|
497
|
+
fs.rmSync(`${apiDir}/schemas`, { recursive: true });
|
|
498
|
+
console.log(chalk.green(`Cleanup succeeded for "${apiDir}/schemas"`));
|
|
499
|
+
} catch (err: any) {
|
|
500
|
+
if (err.code !== "ENOENT") {
|
|
501
|
+
console.error(
|
|
502
|
+
chalk.red(`Cleanup failed for "${apiDir}/schemas"`),
|
|
503
|
+
chalk.yellow(err)
|
|
504
|
+
);
|
|
505
|
+
}
|
|
506
|
+
}
|
|
508
507
|
|
|
509
508
|
sidebarFile.map((sidebar) =>
|
|
510
509
|
fs.unlink(`${apiDir}/${sidebar}`, (err) => {
|
package/src/options.ts
CHANGED