docusaurus-plugin-openapi-docs 4.2.0 → 4.3.1

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
@@ -41,7 +41,7 @@ Key Features:
41
41
 
42
42
  | Docusaurus OpenAPI Docs | Docusaurus |
43
43
  | ----------------------- | --------------- |
44
- | 4.0.x (current) | `3.5.0 - 3.5.2` |
44
+ | 4.0.x (current) | `3.5.0 - 3.6.x` |
45
45
  | 3.0.x (end-of-support) | `3.0.1 - 3.4.0` |
46
46
  | 2.2.3 (legacy) | `2.4.1 - 2.4.3` |
47
47
  | 1.7.3 (end-of-support) | `2.0.1 - 2.2.0` |
@@ -51,7 +51,7 @@ Key Features:
51
51
  Run the following to bootstrap a Docsaurus v3 site (classic theme) with `docusaurus-openapi-docs`:
52
52
 
53
53
  ```bash
54
- npx create-docusaurus@3.5.2my-website --package-manager yarn
54
+ npx create-docusaurus@3.6.3 my-website --package-manager yarn
55
55
  ```
56
56
 
57
57
  > When prompted to select a template choose `Git repository`.
@@ -268,6 +268,16 @@ yarn docusaurus gen-api-docs petstore
268
268
 
269
269
  > The example above will only generate API docs relative to `petstore`.
270
270
 
271
+ If you have multiple versions of the same API, `gen-api-docs` only generates the latest. To generate all versions, use the `--all-versions` flag.
272
+
273
+ Example:
274
+
275
+ ```bash
276
+ yarn docusaurus gen-api-docs all --all-versions
277
+ ```
278
+
279
+ > This will generate API docs for all versions of all the OpenAPI specification (OAS) files referenced in your `docusaurus-plugin-openapi-docs` config.
280
+
271
281
  ### Cleaning API Docs
272
282
 
273
283
  To clean/remove all API Docs, run the following command from the root directory of your project:
@@ -290,6 +300,16 @@ yarn docusaurus clean-api-docs petstore
290
300
 
291
301
  > The example above will remove all API docs relative to `burgers`.
292
302
 
303
+ If you have multiple versions of the same API, `clean-api-docs` only cleans the latest. To clean all versions, use the `--all-versions` flag.
304
+
305
+ Example:
306
+
307
+ ```bash
308
+ yarn docusaurus clean-api-docs all --all-versions
309
+ ```
310
+
311
+ > This will clean API docs for all versions of all the OpenAPI specification (OAS) files referenced in your `docusaurus-plugin-openapi-docs` config.
312
+
293
313
  ### Versioning OpenAPI docs
294
314
 
295
315
  To generate _all_ versioned OpenAPI docs, run the following command from the root directory of your project:
package/lib/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { LoadContext, Plugin } from "@docusaurus/types";
2
- import type { PluginOptions, LoadedContent } from "./types";
2
+ import type { LoadedContent, PluginOptions } from "./types";
3
3
  export declare function isURL(str: string): boolean;
4
4
  export declare function getDocsPluginConfig(presetsPlugins: any[], plugin: string, pluginId: string): Object | undefined;
5
5
  declare function pluginOpenAPIDocs(context: LoadContext, options: PluginOptions): Plugin<LoadedContent>;
package/lib/index.js CHANGED
@@ -409,6 +409,52 @@ custom_edit_url: null
409
409
  });
410
410
  }
411
411
  }
412
+ async function generateAllVersions(options, pluginId) {
413
+ const parentOptions = Object.assign({}, options);
414
+ const { versions } = parentOptions;
415
+ if (versions != null && Object.keys(versions).length > 0) {
416
+ const version = parentOptions.version;
417
+ const label = parentOptions.label;
418
+ const baseUrl = parentOptions.baseUrl;
419
+ let parentVersion = {};
420
+ parentVersion[version] = { label: label, baseUrl: baseUrl };
421
+ const mergedVersions = Object.assign(parentVersion, versions);
422
+ // Prepare for merge
423
+ delete parentOptions.versions;
424
+ delete parentOptions.version;
425
+ delete parentOptions.label;
426
+ delete parentOptions.baseUrl;
427
+ delete parentOptions.downloadUrl;
428
+ await generateVersions(mergedVersions, parentOptions.outputDir);
429
+ Object.keys(versions).forEach(async (key) => {
430
+ if (key === "all") {
431
+ console.error(chalk_1.default.red("Can't use id 'all' for OpenAPI docs versions configuration key."));
432
+ }
433
+ const versionOptions = versions[key];
434
+ const mergedOptions = {
435
+ ...parentOptions,
436
+ ...versionOptions,
437
+ };
438
+ await generateApiDocs(mergedOptions, pluginId);
439
+ });
440
+ }
441
+ }
442
+ async function cleanAllVersions(options) {
443
+ const parentOptions = Object.assign({}, options);
444
+ const { versions } = parentOptions;
445
+ delete parentOptions.versions;
446
+ if (versions != null && Object.keys(versions).length > 0) {
447
+ await cleanVersions(parentOptions.outputDir);
448
+ Object.keys(versions).forEach(async (key) => {
449
+ const versionOptions = versions[key];
450
+ const mergedOptions = {
451
+ ...parentOptions,
452
+ ...versionOptions,
453
+ };
454
+ await cleanApiDocs(mergedOptions);
455
+ });
456
+ }
457
+ }
412
458
  return {
413
459
  name: `docusaurus-plugin-openapi-docs`,
414
460
  extendCli(cli) {
@@ -418,10 +464,12 @@ custom_edit_url: null
418
464
  .usage("<id>")
419
465
  .arguments("<id>")
420
466
  .option("-p, --plugin-id <plugin>", "OpenAPI docs plugin ID.")
467
+ .option("--all-versions", "Generate all versions.")
421
468
  .action(async (id, instance) => {
422
469
  var _a;
423
470
  const options = instance.opts();
424
471
  const pluginId = options.pluginId;
472
+ const allVersions = options.allVersions;
425
473
  const pluginInstances = getPluginInstances(plugins);
426
474
  let targetConfig;
427
475
  let targetDocsPluginId;
@@ -450,6 +498,9 @@ custom_edit_url: null
450
498
  else {
451
499
  Object.keys(targetConfig).forEach(async function (key) {
452
500
  await generateApiDocs(targetConfig[key], targetDocsPluginId);
501
+ if (allVersions) {
502
+ await generateAllVersions(targetConfig[key], targetDocsPluginId);
503
+ }
453
504
  });
454
505
  }
455
506
  }
@@ -458,6 +509,9 @@ custom_edit_url: null
458
509
  }
459
510
  else {
460
511
  await generateApiDocs(targetConfig[id], targetDocsPluginId);
512
+ if (allVersions) {
513
+ await generateAllVersions(targetConfig[id], targetDocsPluginId);
514
+ }
461
515
  }
462
516
  });
463
517
  cli
@@ -542,10 +596,12 @@ custom_edit_url: null
542
596
  .usage("<id>")
543
597
  .arguments("<id>")
544
598
  .option("-p, --plugin-id <plugin>", "OpenAPI docs plugin ID.")
599
+ .option("--all-versions", "Clean all versions.")
545
600
  .action(async (id, instance) => {
546
601
  var _a;
547
602
  const options = instance.opts();
548
603
  const pluginId = options.pluginId;
604
+ const allVersions = options.allVersions;
549
605
  const pluginInstances = getPluginInstances(plugins);
550
606
  let targetConfig;
551
607
  if (pluginId) {
@@ -572,11 +628,17 @@ custom_edit_url: null
572
628
  else {
573
629
  Object.keys(targetConfig).forEach(async function (key) {
574
630
  await cleanApiDocs(targetConfig[key]);
631
+ if (allVersions) {
632
+ await cleanAllVersions(targetConfig[key]);
633
+ }
575
634
  });
576
635
  }
577
636
  }
578
637
  else {
579
638
  await cleanApiDocs(targetConfig[id]);
639
+ if (allVersions) {
640
+ await cleanAllVersions(targetConfig[id]);
641
+ }
580
642
  }
581
643
  });
582
644
  cli
@@ -28,11 +28,11 @@ function createAuthentication(securitySchemes) {
28
28
  (0, utils_1.create)("th", { children: `OAuth Flow (${flowType}):` }),
29
29
  (0, utils_1.create)("td", {
30
30
  children: [
31
- (0, utils_1.guard)(tokenUrl, () => (0, utils_1.create)("p", { children: `Token URL: ${tokenUrl}` })),
32
- (0, utils_1.guard)(authorizationUrl, () => (0, utils_1.create)("p", {
31
+ (0, utils_1.guard)(tokenUrl, () => (0, utils_1.create)("div", { children: `Token URL: ${tokenUrl}` })),
32
+ (0, utils_1.guard)(authorizationUrl, () => (0, utils_1.create)("div", {
33
33
  children: `Authorization URL: ${authorizationUrl}`,
34
34
  })),
35
- (0, utils_1.guard)(refreshUrl, () => (0, utils_1.create)("p", { children: `Refresh URL: ${refreshUrl}` })),
35
+ (0, utils_1.guard)(refreshUrl, () => (0, utils_1.create)("div", { children: `Refresh URL: ${refreshUrl}` })),
36
36
  (0, utils_1.create)("span", { children: "Scopes:" }),
37
37
  (0, utils_1.create)("ul", {
38
38
  children: Object.entries(scopes).map(([scope, description]) => (0, utils_1.create)("li", { children: `${scope}: ${description}` })),
@@ -24,7 +24,7 @@ function createTermsOfService(termsOfService) {
24
24
  }),
25
25
  (0, utils_1.create)("a", {
26
26
  href: `${termsOfService}`,
27
- children: termsOfService,
27
+ children: `{'${termsOfService}'}`,
28
28
  }),
29
29
  ],
30
30
  });
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": "4.2.0",
4
+ "version": "4.3.1",
5
5
  "license": "MIT",
6
6
  "keywords": [
7
7
  "openapi",
@@ -28,7 +28,10 @@
28
28
  "watch": "tsc --watch"
29
29
  },
30
30
  "devDependencies": {
31
+ "@docusaurus/plugin-content-docs": "^3.5.0",
31
32
  "@docusaurus/types": "^3.5.0",
33
+ "@docusaurus/utils": "^3.5.0",
34
+ "@docusaurus/utils-validation": "^3.5.0",
32
35
  "@types/fs-extra": "^9.0.13",
33
36
  "@types/json-pointer": "^1.0.31",
34
37
  "@types/json-schema": "^7.0.9",
@@ -38,9 +41,6 @@
38
41
  },
39
42
  "dependencies": {
40
43
  "@apidevtools/json-schema-ref-parser": "^11.5.4",
41
- "@docusaurus/plugin-content-docs": "^3.5.0",
42
- "@docusaurus/utils": "^3.5.0",
43
- "@docusaurus/utils-validation": "^3.5.0",
44
44
  "@redocly/openapi-core": "^1.10.5",
45
45
  "allof-merge": "^0.6.6",
46
46
  "chalk": "^4.1.2",
@@ -57,10 +57,13 @@
57
57
  "xml-formatter": "^2.6.1"
58
58
  },
59
59
  "peerDependencies": {
60
+ "@docusaurus/plugin-content-docs": "^3.5.0",
61
+ "@docusaurus/utils": "^3.5.0",
62
+ "@docusaurus/utils-validation": "^3.5.0",
60
63
  "react": "^16.8.4 || ^17.0.0 || ^18.0.0"
61
64
  },
62
65
  "engines": {
63
66
  "node": ">=14"
64
67
  },
65
- "gitHead": "e7295a8aa6f3fab5ccc4f8f9ad0e6c33d785aa16"
68
+ "gitHead": "78bfd444c557f94a67344d6276025f4958a921bd"
66
69
  }
package/src/index.ts CHANGED
@@ -21,18 +21,18 @@ import {
21
21
  createSchemaPageMD,
22
22
  createTagPageMD,
23
23
  } from "./markdown";
24
- import { readOpenapiFiles, processOpenapiFiles } from "./openapi";
24
+ import { processOpenapiFiles, readOpenapiFiles } from "./openapi";
25
25
  import { OptionsSchema } from "./options";
26
26
  import generateSidebarSlice from "./sidebars";
27
27
  import type {
28
- PluginOptions,
29
- LoadedContent,
30
- APIOptions,
31
28
  ApiMetadata,
29
+ APIOptions,
32
30
  ApiPageMetadata,
33
31
  InfoPageMetadata,
34
- TagPageMetadata,
32
+ LoadedContent,
33
+ PluginOptions,
35
34
  SchemaPageMetadata,
35
+ TagPageMetadata,
36
36
  } from "./types";
37
37
 
38
38
  export function isURL(str: string): boolean {
@@ -586,6 +586,66 @@ custom_edit_url: null
586
586
  }
587
587
  }
588
588
 
589
+ async function generateAllVersions(options: APIOptions, pluginId: any) {
590
+ const parentOptions = Object.assign({}, options);
591
+ const { versions } = parentOptions as any;
592
+
593
+ if (versions != null && Object.keys(versions).length > 0) {
594
+ const version = parentOptions.version as string;
595
+ const label = parentOptions.label as string;
596
+
597
+ const baseUrl = parentOptions.baseUrl as string;
598
+ let parentVersion = {} as any;
599
+
600
+ parentVersion[version] = { label: label, baseUrl: baseUrl };
601
+ const mergedVersions = Object.assign(parentVersion, versions);
602
+
603
+ // Prepare for merge
604
+ delete parentOptions.versions;
605
+ delete parentOptions.version;
606
+ delete parentOptions.label;
607
+ delete parentOptions.baseUrl;
608
+ delete parentOptions.downloadUrl;
609
+
610
+ await generateVersions(mergedVersions, parentOptions.outputDir);
611
+ Object.keys(versions).forEach(async (key) => {
612
+ if (key === "all") {
613
+ console.error(
614
+ chalk.red(
615
+ "Can't use id 'all' for OpenAPI docs versions configuration key."
616
+ )
617
+ );
618
+ }
619
+ const versionOptions = versions[key];
620
+ const mergedOptions = {
621
+ ...parentOptions,
622
+ ...versionOptions,
623
+ };
624
+ await generateApiDocs(mergedOptions, pluginId);
625
+ });
626
+ }
627
+ }
628
+
629
+ async function cleanAllVersions(options: APIOptions) {
630
+ const parentOptions = Object.assign({}, options);
631
+
632
+ const { versions } = parentOptions as any;
633
+
634
+ delete parentOptions.versions;
635
+
636
+ if (versions != null && Object.keys(versions).length > 0) {
637
+ await cleanVersions(parentOptions.outputDir);
638
+ Object.keys(versions).forEach(async (key) => {
639
+ const versionOptions = versions[key];
640
+ const mergedOptions = {
641
+ ...parentOptions,
642
+ ...versionOptions,
643
+ };
644
+ await cleanApiDocs(mergedOptions);
645
+ });
646
+ }
647
+ }
648
+
589
649
  return {
590
650
  name: `docusaurus-plugin-openapi-docs`,
591
651
 
@@ -598,9 +658,11 @@ custom_edit_url: null
598
658
  .usage("<id>")
599
659
  .arguments("<id>")
600
660
  .option("-p, --plugin-id <plugin>", "OpenAPI docs plugin ID.")
661
+ .option("--all-versions", "Generate all versions.")
601
662
  .action(async (id, instance) => {
602
663
  const options = instance.opts();
603
664
  const pluginId = options.pluginId;
665
+ const allVersions = options.allVersions;
604
666
  const pluginInstances = getPluginInstances(plugins);
605
667
  let targetConfig: any;
606
668
  let targetDocsPluginId: any;
@@ -637,6 +699,12 @@ custom_edit_url: null
637
699
  } else {
638
700
  Object.keys(targetConfig).forEach(async function (key) {
639
701
  await generateApiDocs(targetConfig[key], targetDocsPluginId);
702
+ if (allVersions) {
703
+ await generateAllVersions(
704
+ targetConfig[key],
705
+ targetDocsPluginId
706
+ );
707
+ }
640
708
  });
641
709
  }
642
710
  } else if (!targetConfig[id]) {
@@ -645,6 +713,9 @@ custom_edit_url: null
645
713
  );
646
714
  } else {
647
715
  await generateApiDocs(targetConfig[id], targetDocsPluginId);
716
+ if (allVersions) {
717
+ await generateAllVersions(targetConfig[id], targetDocsPluginId);
718
+ }
648
719
  }
649
720
  });
650
721
 
@@ -748,9 +819,11 @@ custom_edit_url: null
748
819
  .usage("<id>")
749
820
  .arguments("<id>")
750
821
  .option("-p, --plugin-id <plugin>", "OpenAPI docs plugin ID.")
822
+ .option("--all-versions", "Clean all versions.")
751
823
  .action(async (id, instance) => {
752
824
  const options = instance.opts();
753
825
  const pluginId = options.pluginId;
826
+ const allVersions = options.allVersions;
754
827
  const pluginInstances = getPluginInstances(plugins);
755
828
  let targetConfig: any;
756
829
  if (pluginId) {
@@ -784,10 +857,16 @@ custom_edit_url: null
784
857
  } else {
785
858
  Object.keys(targetConfig).forEach(async function (key) {
786
859
  await cleanApiDocs(targetConfig[key]);
860
+ if (allVersions) {
861
+ await cleanAllVersions(targetConfig[key]);
862
+ }
787
863
  });
788
864
  }
789
865
  } else {
790
866
  await cleanApiDocs(targetConfig[id]);
867
+ if (allVersions) {
868
+ await cleanAllVersions(targetConfig[id]);
869
+ }
791
870
  }
792
871
  });
793
872
 
@@ -35,15 +35,15 @@ export function createAuthentication(securitySchemes: SecuritySchemeObject) {
35
35
  create("td", {
36
36
  children: [
37
37
  guard(tokenUrl, () =>
38
- create("p", { children: `Token URL: ${tokenUrl}` })
38
+ create("div", { children: `Token URL: ${tokenUrl}` })
39
39
  ),
40
40
  guard(authorizationUrl, () =>
41
- create("p", {
41
+ create("div", {
42
42
  children: `Authorization URL: ${authorizationUrl}`,
43
43
  })
44
44
  ),
45
45
  guard(refreshUrl, () =>
46
- create("p", { children: `Refresh URL: ${refreshUrl}` })
46
+ create("div", { children: `Refresh URL: ${refreshUrl}` })
47
47
  ),
48
48
  create("span", { children: "Scopes:" }),
49
49
  create("ul", {
@@ -23,7 +23,7 @@ export function createTermsOfService(termsOfService: string | undefined) {
23
23
  }),
24
24
  create("a", {
25
25
  href: `${termsOfService}`,
26
- children: termsOfService,
26
+ children: `{'${termsOfService}'}`,
27
27
  }),
28
28
  ],
29
29
  });