docusaurus-plugin-openapi-docs 0.0.0-438 → 0.0.0-441
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 +132 -32
- package/package.json +2 -2
- package/src/index.ts +147 -32
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
|
|
4
|
+
export declare function getDocsPluginConfig(presetsPlugins: any[], 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
|
@@ -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.
|
|
12
|
+
exports.getDocsPluginConfig = 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,36 +23,44 @@ function isURL(str) {
|
|
|
23
23
|
return /^(https?:)\/\//m.test(str);
|
|
24
24
|
}
|
|
25
25
|
exports.isURL = isURL;
|
|
26
|
-
function
|
|
26
|
+
function getDocsPluginConfig(presetsPlugins, pluginId) {
|
|
27
27
|
// eslint-disable-next-line array-callback-return
|
|
28
|
-
const
|
|
29
|
-
if (data[0] ===
|
|
28
|
+
const filteredConfig = presetsPlugins.filter((data) => {
|
|
29
|
+
if (data[0] === pluginId) {
|
|
30
30
|
return data[1];
|
|
31
31
|
}
|
|
32
32
|
// Search plugin-content-docs instances
|
|
33
33
|
if (data[0] === "@docusaurus/plugin-content-docs") {
|
|
34
|
-
const
|
|
35
|
-
if (
|
|
34
|
+
const configPluginId = data[1].id ? data[1].id : "default";
|
|
35
|
+
if (configPluginId === pluginId) {
|
|
36
36
|
return data[1];
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
})[0];
|
|
40
|
-
if (
|
|
40
|
+
if (filteredConfig) {
|
|
41
41
|
// Search presets, e.g. "classic"
|
|
42
|
-
if (
|
|
43
|
-
return
|
|
42
|
+
if (filteredConfig[0] === pluginId) {
|
|
43
|
+
return filteredConfig[1].docs;
|
|
44
44
|
}
|
|
45
45
|
// Search plugin-content-docs instances
|
|
46
|
-
if (
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
if (filteredConfig[0] === "@docusaurus/plugin-content-docs") {
|
|
47
|
+
const configPluginId = filteredConfig[1].id
|
|
48
|
+
? filteredConfig[1].id
|
|
49
|
+
: "default";
|
|
50
|
+
if (configPluginId === pluginId) {
|
|
51
|
+
return filteredConfig[1];
|
|
50
52
|
}
|
|
51
53
|
}
|
|
52
54
|
}
|
|
53
55
|
return;
|
|
54
56
|
}
|
|
55
|
-
exports.
|
|
57
|
+
exports.getDocsPluginConfig = getDocsPluginConfig;
|
|
58
|
+
function getPluginConfig(plugins, pluginId) {
|
|
59
|
+
return plugins.filter((data) => data[1].id === pluginId)[0][1];
|
|
60
|
+
}
|
|
61
|
+
function getPluginInstances(plugins) {
|
|
62
|
+
return plugins.filter((data) => data[0] === "docusaurus-plugin-openapi-docs");
|
|
63
|
+
}
|
|
56
64
|
function pluginOpenAPIDocs(context, options) {
|
|
57
65
|
const { config, docsPluginId } = options;
|
|
58
66
|
const { siteDir, siteConfig } = context;
|
|
@@ -60,7 +68,7 @@ function pluginOpenAPIDocs(context, options) {
|
|
|
60
68
|
const presets = siteConfig.presets;
|
|
61
69
|
const plugins = siteConfig.plugins;
|
|
62
70
|
const presetsPlugins = presets.concat(plugins);
|
|
63
|
-
const docData =
|
|
71
|
+
const docData = getDocsPluginConfig(presetsPlugins, docsPluginId);
|
|
64
72
|
const docRouteBasePath = docData ? docData.routeBasePath : undefined;
|
|
65
73
|
const docPath = docData ? (docData.path ? docData.path : "docs") : undefined;
|
|
66
74
|
async function generateApiDocs(options) {
|
|
@@ -292,22 +300,45 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
|
|
|
292
300
|
.description(`Generates OpenAPI docs in MDX file format and sidebar.js (if enabled).`)
|
|
293
301
|
.usage("<id>")
|
|
294
302
|
.arguments("<id>")
|
|
295
|
-
.
|
|
303
|
+
.option("-p, --plugin-id <plugin>", "OpenAPI docs plugin ID.")
|
|
304
|
+
.action(async (id, instance) => {
|
|
305
|
+
var _a;
|
|
306
|
+
const options = instance.opts();
|
|
307
|
+
const pluginId = options.pluginId;
|
|
308
|
+
const pluginInstances = getPluginInstances(plugins);
|
|
309
|
+
let targetConfig;
|
|
310
|
+
if (pluginId) {
|
|
311
|
+
try {
|
|
312
|
+
const pluginConfig = getPluginConfig(plugins, pluginId);
|
|
313
|
+
targetConfig = (_a = pluginConfig.config) !== null && _a !== void 0 ? _a : {};
|
|
314
|
+
}
|
|
315
|
+
catch {
|
|
316
|
+
console.error(chalk_1.default.red(`OpenAPI docs plugin ID '${pluginId}' not found.`));
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
else {
|
|
321
|
+
if (pluginInstances.length > 1) {
|
|
322
|
+
console.error(chalk_1.default.red("OpenAPI docs plugin ID must be specified when more than one plugin instance exists."));
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
targetConfig = config;
|
|
326
|
+
}
|
|
296
327
|
if (id === "all") {
|
|
297
|
-
if (
|
|
328
|
+
if (targetConfig[id]) {
|
|
298
329
|
console.error(chalk_1.default.red("Can't use id 'all' for OpenAPI docs configuration key."));
|
|
299
330
|
}
|
|
300
331
|
else {
|
|
301
|
-
Object.keys(
|
|
302
|
-
await generateApiDocs(
|
|
332
|
+
Object.keys(targetConfig).forEach(async function (key) {
|
|
333
|
+
await generateApiDocs(targetConfig[key]);
|
|
303
334
|
});
|
|
304
335
|
}
|
|
305
336
|
}
|
|
306
|
-
else if (!
|
|
337
|
+
else if (!targetConfig[id]) {
|
|
307
338
|
console.error(chalk_1.default.red(`ID '${id}' does not exist in OpenAPI docs config.`));
|
|
308
339
|
}
|
|
309
340
|
else {
|
|
310
|
-
await generateApiDocs(
|
|
341
|
+
await generateApiDocs(targetConfig[id]);
|
|
311
342
|
}
|
|
312
343
|
});
|
|
313
344
|
cli
|
|
@@ -315,15 +346,38 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
|
|
|
315
346
|
.description(`Generates versioned OpenAPI docs in MDX file format, versions.js and sidebar.js (if enabled).`)
|
|
316
347
|
.usage("<id:version>")
|
|
317
348
|
.arguments("<id:version>")
|
|
318
|
-
.
|
|
349
|
+
.option("-p, --plugin-id <plugin>", "OpenAPI docs plugin ID.")
|
|
350
|
+
.action(async (id, instance) => {
|
|
351
|
+
var _a;
|
|
352
|
+
const options = instance.opts();
|
|
353
|
+
const pluginId = options.pluginId;
|
|
354
|
+
const pluginInstances = getPluginInstances(plugins);
|
|
355
|
+
let targetConfig;
|
|
356
|
+
if (pluginId) {
|
|
357
|
+
try {
|
|
358
|
+
const pluginConfig = getPluginConfig(plugins, pluginId);
|
|
359
|
+
targetConfig = (_a = pluginConfig.config) !== null && _a !== void 0 ? _a : {};
|
|
360
|
+
}
|
|
361
|
+
catch {
|
|
362
|
+
console.error(chalk_1.default.red(`OpenAPI docs plugin ID '${pluginId}' not found.`));
|
|
363
|
+
return;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
else {
|
|
367
|
+
if (pluginInstances.length > 1) {
|
|
368
|
+
console.error(chalk_1.default.red("OpenAPI docs plugin ID must be specified when more than one plugin instance exists."));
|
|
369
|
+
return;
|
|
370
|
+
}
|
|
371
|
+
targetConfig = config;
|
|
372
|
+
}
|
|
319
373
|
const [parentId, versionId] = id.split(":");
|
|
320
|
-
const parentConfig = Object.assign({},
|
|
374
|
+
const parentConfig = Object.assign({}, targetConfig[parentId]);
|
|
321
375
|
const version = parentConfig.version;
|
|
322
376
|
const label = parentConfig.label;
|
|
323
377
|
const baseUrl = parentConfig.baseUrl;
|
|
324
378
|
let parentVersion = {};
|
|
325
379
|
parentVersion[version] = { label: label, baseUrl: baseUrl };
|
|
326
|
-
const { versions } =
|
|
380
|
+
const { versions } = targetConfig[parentId];
|
|
327
381
|
const mergedVersions = Object.assign(parentVersion, versions);
|
|
328
382
|
// Prepare for merge
|
|
329
383
|
delete parentConfig.versions;
|
|
@@ -365,19 +419,42 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
|
|
|
365
419
|
.description(`Clears the generated OpenAPI docs MDX files and sidebar.js (if enabled).`)
|
|
366
420
|
.usage("<id>")
|
|
367
421
|
.arguments("<id>")
|
|
368
|
-
.
|
|
422
|
+
.option("-p, --plugin-id <plugin>", "OpenAPI docs plugin ID.")
|
|
423
|
+
.action(async (id, instance) => {
|
|
424
|
+
var _a;
|
|
425
|
+
const options = instance.opts();
|
|
426
|
+
const pluginId = options.pluginId;
|
|
427
|
+
const pluginInstances = getPluginInstances(plugins);
|
|
428
|
+
let targetConfig;
|
|
429
|
+
if (pluginId) {
|
|
430
|
+
try {
|
|
431
|
+
const pluginConfig = getPluginConfig(plugins, pluginId);
|
|
432
|
+
targetConfig = (_a = pluginConfig.config) !== null && _a !== void 0 ? _a : {};
|
|
433
|
+
}
|
|
434
|
+
catch {
|
|
435
|
+
console.error(chalk_1.default.red(`OpenAPI docs plugin ID '${pluginId}' not found.`));
|
|
436
|
+
return;
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
else {
|
|
440
|
+
if (pluginInstances.length > 1) {
|
|
441
|
+
console.error(chalk_1.default.red("OpenAPI docs plugin ID must be specified when more than one plugin instance exists."));
|
|
442
|
+
return;
|
|
443
|
+
}
|
|
444
|
+
targetConfig = config;
|
|
445
|
+
}
|
|
369
446
|
if (id === "all") {
|
|
370
|
-
if (
|
|
447
|
+
if (targetConfig[id]) {
|
|
371
448
|
console.error(chalk_1.default.red("Can't use id 'all' for OpenAPI docs configuration key."));
|
|
372
449
|
}
|
|
373
450
|
else {
|
|
374
|
-
Object.keys(
|
|
375
|
-
await cleanApiDocs(
|
|
451
|
+
Object.keys(targetConfig).forEach(async function (key) {
|
|
452
|
+
await cleanApiDocs(targetConfig[key]);
|
|
376
453
|
});
|
|
377
454
|
}
|
|
378
455
|
}
|
|
379
456
|
else {
|
|
380
|
-
await cleanApiDocs(
|
|
457
|
+
await cleanApiDocs(targetConfig[id]);
|
|
381
458
|
}
|
|
382
459
|
});
|
|
383
460
|
cli
|
|
@@ -385,10 +462,33 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
|
|
|
385
462
|
.description(`Clears the versioned, generated OpenAPI docs MDX files, versions.json and sidebar.js (if enabled).`)
|
|
386
463
|
.usage("<id:version>")
|
|
387
464
|
.arguments("<id:version>")
|
|
388
|
-
.
|
|
465
|
+
.option("-p, --plugin-id <plugin>", "OpenAPI docs plugin ID.")
|
|
466
|
+
.action(async (id, instance) => {
|
|
467
|
+
var _a;
|
|
468
|
+
const options = instance.opts();
|
|
469
|
+
const pluginId = options.pluginId;
|
|
470
|
+
const pluginInstances = getPluginInstances(plugins);
|
|
471
|
+
let targetConfig;
|
|
472
|
+
if (pluginId) {
|
|
473
|
+
try {
|
|
474
|
+
const pluginConfig = getPluginConfig(plugins, pluginId);
|
|
475
|
+
targetConfig = (_a = pluginConfig.config) !== null && _a !== void 0 ? _a : {};
|
|
476
|
+
}
|
|
477
|
+
catch {
|
|
478
|
+
console.error(chalk_1.default.red(`OpenAPI docs plugin ID '${pluginId}' not found.`));
|
|
479
|
+
return;
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
else {
|
|
483
|
+
if (pluginInstances.length > 1) {
|
|
484
|
+
console.error(chalk_1.default.red("OpenAPI docs plugin ID must be specified when more than one plugin instance exists."));
|
|
485
|
+
return;
|
|
486
|
+
}
|
|
487
|
+
targetConfig = config;
|
|
488
|
+
}
|
|
389
489
|
const [parentId, versionId] = id.split(":");
|
|
390
|
-
const { versions } =
|
|
391
|
-
const parentConfig = Object.assign({},
|
|
490
|
+
const { versions } = targetConfig[parentId];
|
|
491
|
+
const parentConfig = Object.assign({}, targetConfig[parentId]);
|
|
392
492
|
delete parentConfig.versions;
|
|
393
493
|
if (versionId === "all") {
|
|
394
494
|
if (versions[id]) {
|
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-441",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"openapi",
|
|
@@ -68,5 +68,5 @@
|
|
|
68
68
|
"engines": {
|
|
69
69
|
"node": ">=14"
|
|
70
70
|
},
|
|
71
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "cbf2a3b0a4f5d5cb7a98471dcec5ff8a67db1e77"
|
|
72
72
|
}
|
package/src/index.ts
CHANGED
|
@@ -23,41 +23,51 @@ export function isURL(str: string): boolean {
|
|
|
23
23
|
return /^(https?:)\/\//m.test(str);
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
export function
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
export function getDocsPluginConfig(
|
|
27
|
+
presetsPlugins: any[],
|
|
28
|
+
pluginId: string
|
|
29
29
|
): Object | undefined {
|
|
30
30
|
// eslint-disable-next-line array-callback-return
|
|
31
|
-
const
|
|
32
|
-
if (data[0] ===
|
|
31
|
+
const filteredConfig = presetsPlugins.filter((data) => {
|
|
32
|
+
if (data[0] === pluginId) {
|
|
33
33
|
return data[1];
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
// Search plugin-content-docs instances
|
|
37
37
|
if (data[0] === "@docusaurus/plugin-content-docs") {
|
|
38
|
-
const
|
|
39
|
-
if (
|
|
38
|
+
const configPluginId = data[1].id ? data[1].id : "default";
|
|
39
|
+
if (configPluginId === pluginId) {
|
|
40
40
|
return data[1];
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
})[0];
|
|
44
|
-
if (
|
|
44
|
+
if (filteredConfig) {
|
|
45
45
|
// Search presets, e.g. "classic"
|
|
46
|
-
if (
|
|
47
|
-
return
|
|
46
|
+
if (filteredConfig[0] === pluginId) {
|
|
47
|
+
return filteredConfig[1].docs;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
// Search plugin-content-docs instances
|
|
51
|
-
if (
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
51
|
+
if (filteredConfig[0] === "@docusaurus/plugin-content-docs") {
|
|
52
|
+
const configPluginId = filteredConfig[1].id
|
|
53
|
+
? filteredConfig[1].id
|
|
54
|
+
: "default";
|
|
55
|
+
if (configPluginId === pluginId) {
|
|
56
|
+
return filteredConfig[1];
|
|
55
57
|
}
|
|
56
58
|
}
|
|
57
59
|
}
|
|
58
60
|
return;
|
|
59
61
|
}
|
|
60
62
|
|
|
63
|
+
function getPluginConfig(plugins: any[], pluginId: string): any {
|
|
64
|
+
return plugins.filter((data) => data[1].id === pluginId)[0][1];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function getPluginInstances(plugins: any[]): any {
|
|
68
|
+
return plugins.filter((data) => data[0] === "docusaurus-plugin-openapi-docs");
|
|
69
|
+
}
|
|
70
|
+
|
|
61
71
|
export default function pluginOpenAPIDocs(
|
|
62
72
|
context: LoadContext,
|
|
63
73
|
options: PluginOptions
|
|
@@ -69,7 +79,7 @@ export default function pluginOpenAPIDocs(
|
|
|
69
79
|
const presets: any = siteConfig.presets;
|
|
70
80
|
const plugins: any = siteConfig.plugins;
|
|
71
81
|
const presetsPlugins = presets.concat(plugins);
|
|
72
|
-
const docData: any =
|
|
82
|
+
const docData: any = getDocsPluginConfig(presetsPlugins, docsPluginId);
|
|
73
83
|
const docRouteBasePath = docData ? docData.routeBasePath : undefined;
|
|
74
84
|
const docPath = docData ? (docData.path ? docData.path : "docs") : undefined;
|
|
75
85
|
|
|
@@ -388,25 +398,52 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
|
|
|
388
398
|
)
|
|
389
399
|
.usage("<id>")
|
|
390
400
|
.arguments("<id>")
|
|
391
|
-
.
|
|
401
|
+
.option("-p, --plugin-id <plugin>", "OpenAPI docs plugin ID.")
|
|
402
|
+
.action(async (id, instance) => {
|
|
403
|
+
const options = instance.opts();
|
|
404
|
+
const pluginId = options.pluginId;
|
|
405
|
+
const pluginInstances = getPluginInstances(plugins);
|
|
406
|
+
let targetConfig: any;
|
|
407
|
+
if (pluginId) {
|
|
408
|
+
try {
|
|
409
|
+
const pluginConfig = getPluginConfig(plugins, pluginId);
|
|
410
|
+
targetConfig = pluginConfig.config ?? {};
|
|
411
|
+
} catch {
|
|
412
|
+
console.error(
|
|
413
|
+
chalk.red(`OpenAPI docs plugin ID '${pluginId}' not found.`)
|
|
414
|
+
);
|
|
415
|
+
return;
|
|
416
|
+
}
|
|
417
|
+
} else {
|
|
418
|
+
if (pluginInstances.length > 1) {
|
|
419
|
+
console.error(
|
|
420
|
+
chalk.red(
|
|
421
|
+
"OpenAPI docs plugin ID must be specified when more than one plugin instance exists."
|
|
422
|
+
)
|
|
423
|
+
);
|
|
424
|
+
return;
|
|
425
|
+
}
|
|
426
|
+
targetConfig = config;
|
|
427
|
+
}
|
|
428
|
+
|
|
392
429
|
if (id === "all") {
|
|
393
|
-
if (
|
|
430
|
+
if (targetConfig[id]) {
|
|
394
431
|
console.error(
|
|
395
432
|
chalk.red(
|
|
396
433
|
"Can't use id 'all' for OpenAPI docs configuration key."
|
|
397
434
|
)
|
|
398
435
|
);
|
|
399
436
|
} else {
|
|
400
|
-
Object.keys(
|
|
401
|
-
await generateApiDocs(
|
|
437
|
+
Object.keys(targetConfig).forEach(async function (key) {
|
|
438
|
+
await generateApiDocs(targetConfig[key]);
|
|
402
439
|
});
|
|
403
440
|
}
|
|
404
|
-
} else if (!
|
|
441
|
+
} else if (!targetConfig[id]) {
|
|
405
442
|
console.error(
|
|
406
443
|
chalk.red(`ID '${id}' does not exist in OpenAPI docs config.`)
|
|
407
444
|
);
|
|
408
445
|
} else {
|
|
409
|
-
await generateApiDocs(
|
|
446
|
+
await generateApiDocs(targetConfig[id]);
|
|
410
447
|
}
|
|
411
448
|
});
|
|
412
449
|
|
|
@@ -417,9 +454,35 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
|
|
|
417
454
|
)
|
|
418
455
|
.usage("<id:version>")
|
|
419
456
|
.arguments("<id:version>")
|
|
420
|
-
.
|
|
457
|
+
.option("-p, --plugin-id <plugin>", "OpenAPI docs plugin ID.")
|
|
458
|
+
.action(async (id, instance) => {
|
|
459
|
+
const options = instance.opts();
|
|
460
|
+
const pluginId = options.pluginId;
|
|
461
|
+
const pluginInstances = getPluginInstances(plugins);
|
|
462
|
+
let targetConfig: any;
|
|
463
|
+
if (pluginId) {
|
|
464
|
+
try {
|
|
465
|
+
const pluginConfig = getPluginConfig(plugins, pluginId);
|
|
466
|
+
targetConfig = pluginConfig.config ?? {};
|
|
467
|
+
} catch {
|
|
468
|
+
console.error(
|
|
469
|
+
chalk.red(`OpenAPI docs plugin ID '${pluginId}' not found.`)
|
|
470
|
+
);
|
|
471
|
+
return;
|
|
472
|
+
}
|
|
473
|
+
} else {
|
|
474
|
+
if (pluginInstances.length > 1) {
|
|
475
|
+
console.error(
|
|
476
|
+
chalk.red(
|
|
477
|
+
"OpenAPI docs plugin ID must be specified when more than one plugin instance exists."
|
|
478
|
+
)
|
|
479
|
+
);
|
|
480
|
+
return;
|
|
481
|
+
}
|
|
482
|
+
targetConfig = config;
|
|
483
|
+
}
|
|
421
484
|
const [parentId, versionId] = id.split(":");
|
|
422
|
-
const parentConfig = Object.assign({},
|
|
485
|
+
const parentConfig = Object.assign({}, targetConfig[parentId]);
|
|
423
486
|
|
|
424
487
|
const version = parentConfig.version as string;
|
|
425
488
|
const label = parentConfig.label as string;
|
|
@@ -428,7 +491,7 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
|
|
|
428
491
|
let parentVersion = {} as any;
|
|
429
492
|
parentVersion[version] = { label: label, baseUrl: baseUrl };
|
|
430
493
|
|
|
431
|
-
const { versions } =
|
|
494
|
+
const { versions } = targetConfig[parentId] as any;
|
|
432
495
|
const mergedVersions = Object.assign(parentVersion, versions);
|
|
433
496
|
|
|
434
497
|
// Prepare for merge
|
|
@@ -480,21 +543,47 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
|
|
|
480
543
|
)
|
|
481
544
|
.usage("<id>")
|
|
482
545
|
.arguments("<id>")
|
|
483
|
-
.
|
|
546
|
+
.option("-p, --plugin-id <plugin>", "OpenAPI docs plugin ID.")
|
|
547
|
+
.action(async (id, instance) => {
|
|
548
|
+
const options = instance.opts();
|
|
549
|
+
const pluginId = options.pluginId;
|
|
550
|
+
const pluginInstances = getPluginInstances(plugins);
|
|
551
|
+
let targetConfig: any;
|
|
552
|
+
if (pluginId) {
|
|
553
|
+
try {
|
|
554
|
+
const pluginConfig = getPluginConfig(plugins, pluginId);
|
|
555
|
+
targetConfig = pluginConfig.config ?? {};
|
|
556
|
+
} catch {
|
|
557
|
+
console.error(
|
|
558
|
+
chalk.red(`OpenAPI docs plugin ID '${pluginId}' not found.`)
|
|
559
|
+
);
|
|
560
|
+
return;
|
|
561
|
+
}
|
|
562
|
+
} else {
|
|
563
|
+
if (pluginInstances.length > 1) {
|
|
564
|
+
console.error(
|
|
565
|
+
chalk.red(
|
|
566
|
+
"OpenAPI docs plugin ID must be specified when more than one plugin instance exists."
|
|
567
|
+
)
|
|
568
|
+
);
|
|
569
|
+
return;
|
|
570
|
+
}
|
|
571
|
+
targetConfig = config;
|
|
572
|
+
}
|
|
484
573
|
if (id === "all") {
|
|
485
|
-
if (
|
|
574
|
+
if (targetConfig[id]) {
|
|
486
575
|
console.error(
|
|
487
576
|
chalk.red(
|
|
488
577
|
"Can't use id 'all' for OpenAPI docs configuration key."
|
|
489
578
|
)
|
|
490
579
|
);
|
|
491
580
|
} else {
|
|
492
|
-
Object.keys(
|
|
493
|
-
await cleanApiDocs(
|
|
581
|
+
Object.keys(targetConfig).forEach(async function (key) {
|
|
582
|
+
await cleanApiDocs(targetConfig[key]);
|
|
494
583
|
});
|
|
495
584
|
}
|
|
496
585
|
} else {
|
|
497
|
-
await cleanApiDocs(
|
|
586
|
+
await cleanApiDocs(targetConfig[id]);
|
|
498
587
|
}
|
|
499
588
|
});
|
|
500
589
|
|
|
@@ -505,11 +594,37 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
|
|
|
505
594
|
)
|
|
506
595
|
.usage("<id:version>")
|
|
507
596
|
.arguments("<id:version>")
|
|
508
|
-
.
|
|
597
|
+
.option("-p, --plugin-id <plugin>", "OpenAPI docs plugin ID.")
|
|
598
|
+
.action(async (id, instance) => {
|
|
599
|
+
const options = instance.opts();
|
|
600
|
+
const pluginId = options.pluginId;
|
|
601
|
+
const pluginInstances = getPluginInstances(plugins);
|
|
602
|
+
let targetConfig: any;
|
|
603
|
+
if (pluginId) {
|
|
604
|
+
try {
|
|
605
|
+
const pluginConfig = getPluginConfig(plugins, pluginId);
|
|
606
|
+
targetConfig = pluginConfig.config ?? {};
|
|
607
|
+
} catch {
|
|
608
|
+
console.error(
|
|
609
|
+
chalk.red(`OpenAPI docs plugin ID '${pluginId}' not found.`)
|
|
610
|
+
);
|
|
611
|
+
return;
|
|
612
|
+
}
|
|
613
|
+
} else {
|
|
614
|
+
if (pluginInstances.length > 1) {
|
|
615
|
+
console.error(
|
|
616
|
+
chalk.red(
|
|
617
|
+
"OpenAPI docs plugin ID must be specified when more than one plugin instance exists."
|
|
618
|
+
)
|
|
619
|
+
);
|
|
620
|
+
return;
|
|
621
|
+
}
|
|
622
|
+
targetConfig = config;
|
|
623
|
+
}
|
|
509
624
|
const [parentId, versionId] = id.split(":");
|
|
510
|
-
const { versions } =
|
|
625
|
+
const { versions } = targetConfig[parentId] as any;
|
|
511
626
|
|
|
512
|
-
const parentConfig = Object.assign({},
|
|
627
|
+
const parentConfig = Object.assign({}, targetConfig[parentId]);
|
|
513
628
|
delete parentConfig.versions;
|
|
514
629
|
|
|
515
630
|
if (versionId === "all") {
|