docusaurus-plugin-openapi-docs 1.3.1 → 1.4.0

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
@@ -122,6 +122,7 @@ The `docusaurus-plugin-openapi-docs` plugin can be configured with the following
122
122
  | `specPath` | `string` | `null` | Designated URL or path to the source of an OpenAPI specification file or directory of multiple OpenAPI specification files. |
123
123
  | `ouputDir` | `string` | `null` | Desired output path for generated MDX files. |
124
124
  | `template` | `string` | `null` | _Optional:_ Customize MDX content with a desired template. |
125
+ | `downloadUrl` | `string` | `null` | _Optional:_ Designated URL for downloading OpenAPI specification. (requires `info` section/doc) |
125
126
  | `sidebarOptions` | `object` | `null` | _Optional:_ Set of options for sidebar configuration. See below for a list of supported options. |
126
127
  | `version` | `string` | `null` | _Optional:_ Version assigned to single or micro-spec API specified in `specPath`. |
127
128
  | `label` | `string` | `null` | _Optional:_ Version label used when generating version selector dropdown menu. |
package/lib/index.js CHANGED
@@ -26,7 +26,8 @@ exports.isURL = isURL;
26
26
  function getDocsPluginConfig(presetsPlugins, pluginId) {
27
27
  // eslint-disable-next-line array-callback-return
28
28
  const filteredConfig = presetsPlugins.filter((data) => {
29
- if (data[0] === pluginId) {
29
+ // Search presets
30
+ if (data[0].endsWith(pluginId)) {
30
31
  return data[1];
31
32
  }
32
33
  // Search plugin-content-docs instances
@@ -39,7 +40,7 @@ function getDocsPluginConfig(presetsPlugins, pluginId) {
39
40
  })[0];
40
41
  if (filteredConfig) {
41
42
  // Search presets, e.g. "classic"
42
- if (filteredConfig[0] === pluginId) {
43
+ if (filteredConfig[0].endsWith(pluginId)) {
43
44
  return filteredConfig[1].docs;
44
45
  }
45
46
  // Search plugin-content-docs instances
@@ -72,7 +73,7 @@ function pluginOpenAPIDocs(context, options) {
72
73
  let docRouteBasePath = docData ? docData.routeBasePath : undefined;
73
74
  let docPath = docData ? (docData.path ? docData.path : "docs") : undefined;
74
75
  async function generateApiDocs(options, pluginId) {
75
- let { specPath, outputDir, template, sidebarOptions } = options;
76
+ let { specPath, outputDir, template, downloadUrl, sidebarOptions } = options;
76
77
  // Override docPath if pluginId provided
77
78
  if (pluginId) {
78
79
  docData = getDocsPluginConfig(presetsPlugins, pluginId);
@@ -178,6 +179,11 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
178
179
  \`\`\`
179
180
  `;
180
181
  loadedApi.map(async (item) => {
182
+ if (item.type === "info") {
183
+ if (downloadUrl && isURL(downloadUrl)) {
184
+ item.downloadUrl = downloadUrl;
185
+ }
186
+ }
181
187
  const markdown = item.type === "api"
182
188
  ? (0, markdown_1.createApiPageMD)(item)
183
189
  : item.type === "info"
@@ -0,0 +1 @@
1
+ export declare function createDownload(url: string | undefined): string;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ /* ============================================================================
3
+ * Copyright (c) Palo Alto Networks
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ * ========================================================================== */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.createDownload = void 0;
10
+ const utils_1 = require("./utils");
11
+ function createDownload(url) {
12
+ return (0, utils_1.guard)(url, (url) => [
13
+ (0, utils_1.create)("Export", { url: url, proxy: undefined }),
14
+ `\n\n`,
15
+ ]);
16
+ }
17
+ exports.createDownload = createDownload;
@@ -1,4 +1,4 @@
1
1
  import { ApiPageMetadata, InfoPageMetadata, TagPageMetadata } from "../types";
2
2
  export declare function createApiPageMD({ title, api: { deprecated, "x-deprecated-description": deprecatedDescription, description, parameters, requestBody, responses, }, }: ApiPageMetadata): string;
3
- export declare function createInfoPageMD({ info: { title, version, description, contact, license, termsOfService, logo, darkLogo, }, securitySchemes, }: InfoPageMetadata): string;
3
+ export declare function createInfoPageMD({ info: { title, version, description, contact, license, termsOfService, logo, darkLogo, }, securitySchemes, downloadUrl, }: InfoPageMetadata): string;
4
4
  export declare function createTagPageMD({ tag: { description } }: TagPageMetadata): string;
@@ -11,6 +11,7 @@ const createAuthentication_1 = require("./createAuthentication");
11
11
  const createContactInfo_1 = require("./createContactInfo");
12
12
  const createDeprecationNotice_1 = require("./createDeprecationNotice");
13
13
  const createDescription_1 = require("./createDescription");
14
+ const createDownload_1 = require("./createDownload");
14
15
  const createLicense_1 = require("./createLicense");
15
16
  const createLogo_1 = require("./createLogo");
16
17
  const createParamsDetails_1 = require("./createParamsDetails");
@@ -44,12 +45,14 @@ function createApiPageMD({ title, api: { deprecated, "x-deprecated-description":
44
45
  ]);
45
46
  }
46
47
  exports.createApiPageMD = createApiPageMD;
47
- function createInfoPageMD({ info: { title, version, description, contact, license, termsOfService, logo, darkLogo, }, securitySchemes, }) {
48
+ function createInfoPageMD({ info: { title, version, description, contact, license, termsOfService, logo, darkLogo, }, securitySchemes, downloadUrl, }) {
48
49
  return (0, utils_1.render)([
49
50
  `import ApiLogo from "@theme/ApiLogo";\n`,
50
51
  `import Tabs from "@theme/Tabs";\n`,
51
- `import TabItem from "@theme/TabItem";\n\n`,
52
+ `import TabItem from "@theme/TabItem";\n`,
53
+ `import Export from "@theme/ApiDemoPanel/Export";\n\n`,
52
54
  (0, createVersionBadge_1.createVersionBadge)(version),
55
+ (0, createDownload_1.createDownload)(downloadUrl),
53
56
  `# ${title.replace(utils_1.lessThan, "<").replace(utils_1.greaterThan, ">")}\n\n`,
54
57
  (0, createLogo_1.createLogo)(logo, darkLogo),
55
58
  (0, createDescription_1.createDescription)(description),
@@ -35,5 +35,5 @@ function render(children) {
35
35
  }
36
36
  exports.render = render;
37
37
  // Regex to selectively URL-encode '>' and '<' chars
38
- exports.lessThan = /<(?!(button|\s?\/button|details|\s?\/details|summary|\s?\/summary|hr|\s?\/hr|br|\s?\/br|span|\s?\/span|strong|\s?\/strong|small|\s?\/small|table|\s?\/table|td|\s?\/td|tr|\s?\/tr|th|\s?\/th|h1|\s?\/h1|h2|\s?\/h2|h3|\s?\/h3|h4|\s?\/h4|h5|\s?\/h5|h6|\s?\/h6|title|\s?\/title|p|\s?\/p|em|\s?\/em|b|\s?\/b|i|\s?\/i|u|\s?\/u|strike|\s?\/strike|a|\s?\/a|li|\s?\/li|ol|\s?\/ol|ul|\s?\/ul|img|\s?\/img|div|\s?\/div|center|\s?\/center))/giu;
39
- exports.greaterThan = /(?<!(button|details|summary|hr|br|span|strong|small|table|td|tr|th|h1|h2|h3|h4|h5|h6|title|p|em|b|i|u|strike|a|tag|li|ol|ul|img|div|center|\/|\s|"|'))>/giu;
38
+ exports.lessThan = /<(?!(=|button|\s?\/button|details|\s?\/details|summary|\s?\/summary|hr|\s?\/hr|br|\s?\/br|span|\s?\/span|strong|\s?\/strong|small|\s?\/small|table|\s?\/table|td|\s?\/td|tr|\s?\/tr|th|\s?\/th|h1|\s?\/h1|h2|\s?\/h2|h3|\s?\/h3|h4|\s?\/h4|h5|\s?\/h5|h6|\s?\/h6|title|\s?\/title|p|\s?\/p|em|\s?\/em|b|\s?\/b|i|\s?\/i|u|\s?\/u|strike|\s?\/strike|a|\s?\/a|li|\s?\/li|ol|\s?\/ol|ul|\s?\/ul|img|\s?\/img|div|\s?\/div|center|\s?\/center))/giu;
39
+ exports.greaterThan = /(?<!(button|details|summary|hr|br|span|strong|small|table|td|tr|th|h1|h2|h3|h4|h5|h6|title|p|em|b|i|u|strike|a|tag|li|ol|ul|img|div|center|\/|\s|"|'))>?!=/giu;
package/lib/options.js CHANGED
@@ -23,6 +23,7 @@ exports.OptionsSchema = utils_validation_1.Joi.object({
23
23
  specPath: utils_validation_1.Joi.string().required(),
24
24
  outputDir: utils_validation_1.Joi.string().required(),
25
25
  template: utils_validation_1.Joi.string(),
26
+ downloadUrl: utils_validation_1.Joi.string(),
26
27
  sidebarOptions: sidebarOptions,
27
28
  version: utils_validation_1.Joi.string().when("versions", {
28
29
  is: utils_validation_1.Joi.exist(),
package/lib/types.d.ts CHANGED
@@ -12,6 +12,7 @@ export interface APIOptions {
12
12
  specPath: string;
13
13
  outputDir: string;
14
14
  template?: string;
15
+ downloadUrl?: string;
15
16
  sidebarOptions?: SidebarOptions;
16
17
  version?: string;
17
18
  label?: string;
@@ -47,6 +48,7 @@ export interface ApiMetadataBase {
47
48
  unversionedId: string;
48
49
  infoId?: string;
49
50
  infoPath?: string;
51
+ downloadUrl?: string;
50
52
  title: string;
51
53
  description: string;
52
54
  source: string;
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": "1.3.1",
4
+ "version": "1.4.0",
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": "5f41e8dc4981409902ae96a7d127a2ae7eb9a47d"
71
+ "gitHead": "74c5c52e4aa493eb4943d4899c60669f8722e089"
72
72
  }
package/src/index.ts CHANGED
@@ -29,7 +29,8 @@ export function getDocsPluginConfig(
29
29
  ): Object | undefined {
30
30
  // eslint-disable-next-line array-callback-return
31
31
  const filteredConfig = presetsPlugins.filter((data) => {
32
- if (data[0] === pluginId) {
32
+ // Search presets
33
+ if (data[0].endsWith(pluginId)) {
33
34
  return data[1];
34
35
  }
35
36
 
@@ -43,7 +44,7 @@ export function getDocsPluginConfig(
43
44
  })[0];
44
45
  if (filteredConfig) {
45
46
  // Search presets, e.g. "classic"
46
- if (filteredConfig[0] === pluginId) {
47
+ if (filteredConfig[0].endsWith(pluginId)) {
47
48
  return filteredConfig[1].docs;
48
49
  }
49
50
 
@@ -84,7 +85,8 @@ export default function pluginOpenAPIDocs(
84
85
  let docPath = docData ? (docData.path ? docData.path : "docs") : undefined;
85
86
 
86
87
  async function generateApiDocs(options: APIOptions, pluginId: any) {
87
- let { specPath, outputDir, template, sidebarOptions } = options;
88
+ let { specPath, outputDir, template, downloadUrl, sidebarOptions } =
89
+ options;
88
90
 
89
91
  // Override docPath if pluginId provided
90
92
  if (pluginId) {
@@ -216,6 +218,11 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
216
218
  `;
217
219
 
218
220
  loadedApi.map(async (item) => {
221
+ if (item.type === "info") {
222
+ if (downloadUrl && isURL(downloadUrl)) {
223
+ item.downloadUrl = downloadUrl;
224
+ }
225
+ }
219
226
  const markdown =
220
227
  item.type === "api"
221
228
  ? createApiPageMD(item)
@@ -0,0 +1,15 @@
1
+ /* ============================================================================
2
+ * Copyright (c) Palo Alto Networks
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ * ========================================================================== */
7
+
8
+ import { create, guard } from "./utils";
9
+
10
+ export function createDownload(url: string | undefined) {
11
+ return guard(url, (url) => [
12
+ create("Export", { url: url, proxy: undefined }),
13
+ `\n\n`,
14
+ ]);
15
+ }
@@ -16,6 +16,7 @@ import { createAuthentication } from "./createAuthentication";
16
16
  import { createContactInfo } from "./createContactInfo";
17
17
  import { createDeprecationNotice } from "./createDeprecationNotice";
18
18
  import { createDescription } from "./createDescription";
19
+ import { createDownload } from "./createDownload";
19
20
  import { createLicense } from "./createLicense";
20
21
  import { createLogo } from "./createLogo";
21
22
  import { createParamsDetails } from "./createParamsDetails";
@@ -83,13 +84,16 @@ export function createInfoPageMD({
83
84
  darkLogo,
84
85
  },
85
86
  securitySchemes,
87
+ downloadUrl,
86
88
  }: InfoPageMetadata) {
87
89
  return render([
88
90
  `import ApiLogo from "@theme/ApiLogo";\n`,
89
91
  `import Tabs from "@theme/Tabs";\n`,
90
- `import TabItem from "@theme/TabItem";\n\n`,
92
+ `import TabItem from "@theme/TabItem";\n`,
93
+ `import Export from "@theme/ApiDemoPanel/Export";\n\n`,
91
94
 
92
95
  createVersionBadge(version),
96
+ createDownload(downloadUrl),
93
97
  `# ${title.replace(lessThan, "&lt;").replace(greaterThan, "&gt;")}\n\n`,
94
98
  createLogo(logo, darkLogo),
95
99
  createDescription(description),
@@ -43,6 +43,6 @@ export function render(children: Children): string {
43
43
 
44
44
  // Regex to selectively URL-encode '>' and '<' chars
45
45
  export const lessThan =
46
- /<(?!(button|\s?\/button|details|\s?\/details|summary|\s?\/summary|hr|\s?\/hr|br|\s?\/br|span|\s?\/span|strong|\s?\/strong|small|\s?\/small|table|\s?\/table|td|\s?\/td|tr|\s?\/tr|th|\s?\/th|h1|\s?\/h1|h2|\s?\/h2|h3|\s?\/h3|h4|\s?\/h4|h5|\s?\/h5|h6|\s?\/h6|title|\s?\/title|p|\s?\/p|em|\s?\/em|b|\s?\/b|i|\s?\/i|u|\s?\/u|strike|\s?\/strike|a|\s?\/a|li|\s?\/li|ol|\s?\/ol|ul|\s?\/ul|img|\s?\/img|div|\s?\/div|center|\s?\/center))/giu;
46
+ /<(?!(=|button|\s?\/button|details|\s?\/details|summary|\s?\/summary|hr|\s?\/hr|br|\s?\/br|span|\s?\/span|strong|\s?\/strong|small|\s?\/small|table|\s?\/table|td|\s?\/td|tr|\s?\/tr|th|\s?\/th|h1|\s?\/h1|h2|\s?\/h2|h3|\s?\/h3|h4|\s?\/h4|h5|\s?\/h5|h6|\s?\/h6|title|\s?\/title|p|\s?\/p|em|\s?\/em|b|\s?\/b|i|\s?\/i|u|\s?\/u|strike|\s?\/strike|a|\s?\/a|li|\s?\/li|ol|\s?\/ol|ul|\s?\/ul|img|\s?\/img|div|\s?\/div|center|\s?\/center))/giu;
47
47
  export const greaterThan =
48
- /(?<!(button|details|summary|hr|br|span|strong|small|table|td|tr|th|h1|h2|h3|h4|h5|h6|title|p|em|b|i|u|strike|a|tag|li|ol|ul|img|div|center|\/|\s|"|'))>/giu;
48
+ /(?<!(button|details|summary|hr|br|span|strong|small|table|td|tr|th|h1|h2|h3|h4|h5|h6|title|p|em|b|i|u|strike|a|tag|li|ol|ul|img|div|center|\/|\s|"|'))>?!=/giu;
package/src/options.ts CHANGED
@@ -25,6 +25,7 @@ export const OptionsSchema = Joi.object({
25
25
  specPath: Joi.string().required(),
26
26
  outputDir: Joi.string().required(),
27
27
  template: Joi.string(),
28
+ downloadUrl: Joi.string(),
28
29
  sidebarOptions: sidebarOptions,
29
30
  version: Joi.string().when("versions", {
30
31
  is: Joi.exist(),
package/src/types.ts CHANGED
@@ -32,6 +32,7 @@ export interface APIOptions {
32
32
  specPath: string;
33
33
  outputDir: string;
34
34
  template?: string;
35
+ downloadUrl?: string;
35
36
  sidebarOptions?: SidebarOptions;
36
37
  version?: string;
37
38
  label?: string;
@@ -72,6 +73,7 @@ export interface ApiMetadataBase {
72
73
  unversionedId: string; // TODO new unversioned id => try to rename to "id"
73
74
  infoId?: string;
74
75
  infoPath?: string;
76
+ downloadUrl?: string;
75
77
  title: string;
76
78
  description: string;
77
79
  source: string; // @site aliased source => "@site/docs/folder/subFolder/subSubFolder/myDoc.md"