docusaurus-plugin-openapi-docs 1.7.0 → 1.7.2

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
@@ -125,6 +125,7 @@ The `docusaurus-plugin-openapi-docs` plugin can be configured with the following
125
125
  | `template` | `string` | `null` | _Optional:_ Customize MDX content with a desired template. |
126
126
  | `downloadUrl` | `string` | `null` | _Optional:_ Designated URL for downloading OpenAPI specification. (requires `info` section/doc) |
127
127
  | `hideSendButton` | `boolean` | `null` | _Optional:_ If set to `true`, hides the "Send API Request" button in API demo panel |
128
+ | `showExtensions` | `boolean` | `null` | _Optional:_ If set to `true`, renders operation-level vendor-extensions in description. |
128
129
  | `sidebarOptions` | `object` | `null` | _Optional:_ Set of options for sidebar configuration. See below for a list of supported options. |
129
130
  | `version` | `string` | `null` | _Optional:_ Version assigned to single or micro-spec API specified in `specPath`. |
130
131
  | `label` | `string` | `null` | _Optional:_ Version label used when generating version selector dropdown menu. |
package/lib/index.js CHANGED
@@ -152,6 +152,9 @@ proxy: {{{frontMatter.proxy}}}
152
152
  {{#frontMatter.hide_send_button}}
153
153
  hide_send_button: true
154
154
  {{/frontMatter.hide_send_button}}
155
+ {{#frontMatter.show_extensions}}
156
+ show_extensions: true
157
+ {{/frontMatter.show_extensions}}
155
158
  ---
156
159
 
157
160
  {{{markdown}}}
@@ -0,0 +1 @@
1
+ export declare function createVendorExtensions(extensions: any): string | undefined;
@@ -0,0 +1,25 @@
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.createVendorExtensions = void 0;
10
+ function createVendorExtensions(extensions) {
11
+ if (!extensions || typeof extensions !== "object") {
12
+ return undefined;
13
+ }
14
+ const rows = [];
15
+ extensions.map((extension) => {
16
+ const extensionRow = () => {
17
+ return `${extension.key}: ${JSON.stringify(extension.value)}`;
18
+ };
19
+ return rows.push(extensionRow());
20
+ });
21
+ return `\n\n\`\`\`
22
+ ${rows.join("\n")}
23
+ \`\`\`\n\n`;
24
+ }
25
+ exports.createVendorExtensions = createVendorExtensions;
@@ -1,4 +1,4 @@
1
1
  import { ApiPageMetadata, InfoPageMetadata, TagPageMetadata } from "../types";
2
- export declare function createApiPageMD({ title, api: { deprecated, "x-deprecated-description": deprecatedDescription, description, parameters, requestBody, responses, }, }: ApiPageMetadata): string;
2
+ export declare function createApiPageMD({ title, api: { deprecated, "x-deprecated-description": deprecatedDescription, description, extensions, parameters, requestBody, responses, }, frontMatter, }: ApiPageMetadata): string;
3
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;
@@ -18,9 +18,10 @@ const createParamsDetails_1 = require("./createParamsDetails");
18
18
  const createRequestBodyDetails_1 = require("./createRequestBodyDetails");
19
19
  const createStatusCodes_1 = require("./createStatusCodes");
20
20
  const createTermsOfService_1 = require("./createTermsOfService");
21
+ const createVendorExtensions_1 = require("./createVendorExtensions");
21
22
  const createVersionBadge_1 = require("./createVersionBadge");
22
23
  const utils_1 = require("./utils");
23
- function createApiPageMD({ title, api: { deprecated, "x-deprecated-description": deprecatedDescription, description, parameters, requestBody, responses, }, }) {
24
+ function createApiPageMD({ title, api: { deprecated, "x-deprecated-description": deprecatedDescription, description, extensions, parameters, requestBody, responses, }, frontMatter, }) {
24
25
  return (0, utils_1.render)([
25
26
  `import ApiTabs from "@theme/ApiTabs";\n`,
26
27
  `import MimeTabs from "@theme/MimeTabs";\n`,
@@ -31,6 +32,7 @@ function createApiPageMD({ title, api: { deprecated, "x-deprecated-description":
31
32
  `import DiscriminatorTabs from "@theme/DiscriminatorTabs";\n`,
32
33
  `import TabItem from "@theme/TabItem";\n\n`,
33
34
  `## ${title.replace(utils_1.lessThan, "<").replace(utils_1.greaterThan, ">")}\n\n`,
35
+ frontMatter.show_extensions && (0, createVendorExtensions_1.createVendorExtensions)(extensions),
34
36
  (0, createDeprecationNotice_1.createDeprecationNotice)({ deprecated, description: deprecatedDescription }),
35
37
  (0, createDescription_1.createDescription)(description),
36
38
  (0, createParamsDetails_1.createParamsDetails)({ parameters, type: "path" }),
@@ -112,6 +112,13 @@ function createItems(openapiData, options, sidebarOptions) {
112
112
  const baseId = operationObject.operationId
113
113
  ? (0, kebabCase_1.default)(operationObject.operationId)
114
114
  : (0, kebabCase_1.default)(operationObject.summary);
115
+ const extensions = [];
116
+ const commonExtensions = ["x-codeSamples"];
117
+ for (const [key, value] of Object.entries(operationObject)) {
118
+ if (key.startsWith("x-") && !commonExtensions.includes(key)) {
119
+ extensions.push({ key, value });
120
+ }
121
+ }
115
122
  const servers = (_j = (_h = operationObject.servers) !== null && _h !== void 0 ? _h : pathObject.servers) !== null && _j !== void 0 ? _j : openapiData.servers;
116
123
  const security = (_k = operationObject.security) !== null && _k !== void 0 ? _k : openapiData.security;
117
124
  // Add security schemes so we know how to handle security.
@@ -176,9 +183,13 @@ function createItems(openapiData, options, sidebarOptions) {
176
183
  ...((options === null || options === void 0 ? void 0 : options.hideSendButton) && {
177
184
  hide_send_button: options.hideSendButton,
178
185
  }),
186
+ ...((options === null || options === void 0 ? void 0 : options.showExtensions) && {
187
+ show_extensions: options.showExtensions,
188
+ }),
179
189
  },
180
190
  api: {
181
191
  ...defaults,
192
+ ...(extensions.length > 0 && { extensions: extensions }),
182
193
  tags: operationObject.tags,
183
194
  method,
184
195
  path,
@@ -206,6 +217,13 @@ function createItems(openapiData, options, sidebarOptions) {
206
217
  const baseId = operationObject.operationId
207
218
  ? (0, kebabCase_1.default)(operationObject.operationId)
208
219
  : (0, kebabCase_1.default)(operationObject.summary);
220
+ const extensions = [];
221
+ const commonExtensions = ["x-codeSamples"];
222
+ for (const [key, value] of Object.entries(operationObject)) {
223
+ if (key.startsWith("x-") && !commonExtensions.includes(key)) {
224
+ extensions.push({ key, value });
225
+ }
226
+ }
209
227
  const servers = (_w = (_v = operationObject.servers) !== null && _v !== void 0 ? _v : pathObject.servers) !== null && _w !== void 0 ? _w : openapiData.servers;
210
228
  const security = (_x = operationObject.security) !== null && _x !== void 0 ? _x : openapiData.security;
211
229
  // Add security schemes so we know how to handle security.
@@ -270,9 +288,13 @@ function createItems(openapiData, options, sidebarOptions) {
270
288
  ...((options === null || options === void 0 ? void 0 : options.hideSendButton) && {
271
289
  hide_send_button: options.hideSendButton,
272
290
  }),
291
+ ...((options === null || options === void 0 ? void 0 : options.showExtensions) && {
292
+ show_extensions: options.showExtensions,
293
+ }),
273
294
  },
274
295
  api: {
275
296
  ...defaults,
297
+ ...(extensions.length > 0 && { extensions: extensions }),
276
298
  tags: operationObject.tags,
277
299
  method,
278
300
  path,
package/lib/options.js CHANGED
@@ -27,6 +27,7 @@ exports.OptionsSchema = utils_validation_1.Joi.object({
27
27
  template: utils_validation_1.Joi.string(),
28
28
  downloadUrl: utils_validation_1.Joi.string(),
29
29
  hideSendButton: utils_validation_1.Joi.boolean(),
30
+ showExtensions: utils_validation_1.Joi.boolean(),
30
31
  sidebarOptions: sidebarOptions,
31
32
  version: utils_validation_1.Joi.string().when("versions", {
32
33
  is: utils_validation_1.Joi.exist(),
package/lib/types.d.ts CHANGED
@@ -14,6 +14,7 @@ export interface APIOptions {
14
14
  template?: string;
15
15
  downloadUrl?: string;
16
16
  hideSendButton?: boolean;
17
+ showExtensions?: boolean;
17
18
  sidebarOptions?: SidebarOptions;
18
19
  version?: string;
19
20
  label?: string;
@@ -76,6 +77,7 @@ export interface ApiItem extends OperationObject {
76
77
  postman?: Request;
77
78
  proxy?: string;
78
79
  info: InfoObject;
80
+ extensions?: object;
79
81
  }
80
82
  export interface InfoPageMetadata extends ApiMetadataBase {
81
83
  type: "info";
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.7.0",
4
+ "version": "1.7.2",
5
5
  "license": "MIT",
6
6
  "keywords": [
7
7
  "openapi",
@@ -39,14 +39,14 @@
39
39
  "utility-types": "^3.10.0"
40
40
  },
41
41
  "dependencies": {
42
- "@apidevtools/json-schema-ref-parser": "^9.0.9",
42
+ "@apidevtools/json-schema-ref-parser": "^10.1.0",
43
43
  "@docusaurus/mdx-loader": ">=2.0.1 <2.3.0",
44
44
  "@docusaurus/plugin-content-docs": ">=2.0.1 <2.3.0",
45
45
  "@docusaurus/utils": ">=2.0.1 <2.3.0",
46
46
  "@docusaurus/utils-validation": ">=2.0.1 <2.3.0",
47
47
  "@paloaltonetworks/openapi-to-postmanv2": "3.1.0-hotfix.1",
48
48
  "@paloaltonetworks/postman-collection": "^4.1.0",
49
- "@redocly/openapi-core": "^1.0.0-beta.103",
49
+ "@redocly/openapi-core": "^1.0.0-beta.125",
50
50
  "chalk": "^4.1.2",
51
51
  "clsx": "^1.1.1",
52
52
  "fs-extra": "^9.0.1",
@@ -68,5 +68,5 @@
68
68
  "engines": {
69
69
  "node": ">=14"
70
70
  },
71
- "gitHead": "4b9ac927c85b56054c8d93336b1b5e282ab309e7"
71
+ "gitHead": "d6450052aff8a6fc691aef3d38bf835f4c70b1ef"
72
72
  }
package/src/index.ts CHANGED
@@ -193,6 +193,9 @@ proxy: {{{frontMatter.proxy}}}
193
193
  {{#frontMatter.hide_send_button}}
194
194
  hide_send_button: true
195
195
  {{/frontMatter.hide_send_button}}
196
+ {{#frontMatter.show_extensions}}
197
+ show_extensions: true
198
+ {{/frontMatter.show_extensions}}
196
199
  ---
197
200
 
198
201
  {{{markdown}}}
@@ -0,0 +1,22 @@
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
+ export function createVendorExtensions(extensions: any) {
9
+ if (!extensions || typeof extensions !== "object") {
10
+ return undefined;
11
+ }
12
+ const rows: Array<string> = [];
13
+ extensions.map((extension: any) => {
14
+ const extensionRow = () => {
15
+ return `${extension.key}: ${JSON.stringify(extension.value)}`;
16
+ };
17
+ return rows.push(extensionRow());
18
+ });
19
+ return `\n\n\`\`\`
20
+ ${rows.join("\n")}
21
+ \`\`\`\n\n`;
22
+ }
@@ -23,6 +23,7 @@ import { createParamsDetails } from "./createParamsDetails";
23
23
  import { createRequestBodyDetails } from "./createRequestBodyDetails";
24
24
  import { createStatusCodes } from "./createStatusCodes";
25
25
  import { createTermsOfService } from "./createTermsOfService";
26
+ import { createVendorExtensions } from "./createVendorExtensions";
26
27
  import { createVersionBadge } from "./createVersionBadge";
27
28
  import { greaterThan, lessThan, render } from "./utils";
28
29
 
@@ -43,10 +44,12 @@ export function createApiPageMD({
43
44
  deprecated,
44
45
  "x-deprecated-description": deprecatedDescription,
45
46
  description,
47
+ extensions,
46
48
  parameters,
47
49
  requestBody,
48
50
  responses,
49
51
  },
52
+ frontMatter,
50
53
  }: ApiPageMetadata) {
51
54
  return render([
52
55
  `import ApiTabs from "@theme/ApiTabs";\n`,
@@ -58,6 +61,7 @@ export function createApiPageMD({
58
61
  `import DiscriminatorTabs from "@theme/DiscriminatorTabs";\n`,
59
62
  `import TabItem from "@theme/TabItem";\n\n`,
60
63
  `## ${title.replace(lessThan, "&lt;").replace(greaterThan, "&gt;")}\n\n`,
64
+ frontMatter.show_extensions && createVendorExtensions(extensions),
61
65
  createDeprecationNotice({ deprecated, description: deprecatedDescription }),
62
66
  createDescription(description),
63
67
  createParamsDetails({ parameters, type: "path" }),
@@ -144,6 +144,15 @@ function createItems(
144
144
  ? kebabCase(operationObject.operationId)
145
145
  : kebabCase(operationObject.summary);
146
146
 
147
+ const extensions = [];
148
+ const commonExtensions = ["x-codeSamples"];
149
+
150
+ for (const [key, value] of Object.entries(operationObject)) {
151
+ if (key.startsWith("x-") && !commonExtensions.includes(key)) {
152
+ extensions.push({ key, value });
153
+ }
154
+ }
155
+
147
156
  const servers =
148
157
  operationObject.servers ?? pathObject.servers ?? openapiData.servers;
149
158
 
@@ -224,9 +233,13 @@ function createItems(
224
233
  ...(options?.hideSendButton && {
225
234
  hide_send_button: options.hideSendButton,
226
235
  }),
236
+ ...(options?.showExtensions && {
237
+ show_extensions: options.showExtensions,
238
+ }),
227
239
  },
228
240
  api: {
229
241
  ...defaults,
242
+ ...(extensions.length > 0 && { extensions: extensions }),
230
243
  tags: operationObject.tags,
231
244
  method,
232
245
  path,
@@ -264,6 +277,15 @@ function createItems(
264
277
  ? kebabCase(operationObject.operationId)
265
278
  : kebabCase(operationObject.summary);
266
279
 
280
+ const extensions = [];
281
+ const commonExtensions = ["x-codeSamples"];
282
+
283
+ for (const [key, value] of Object.entries(operationObject)) {
284
+ if (key.startsWith("x-") && !commonExtensions.includes(key)) {
285
+ extensions.push({ key, value });
286
+ }
287
+ }
288
+
267
289
  const servers =
268
290
  operationObject.servers ?? pathObject.servers ?? openapiData.servers;
269
291
 
@@ -344,9 +366,13 @@ function createItems(
344
366
  ...(options?.hideSendButton && {
345
367
  hide_send_button: options.hideSendButton,
346
368
  }),
369
+ ...(options?.showExtensions && {
370
+ show_extensions: options.showExtensions,
371
+ }),
347
372
  },
348
373
  api: {
349
374
  ...defaults,
375
+ ...(extensions.length > 0 && { extensions: extensions }),
350
376
  tags: operationObject.tags,
351
377
  method,
352
378
  path,
package/src/options.ts CHANGED
@@ -29,6 +29,7 @@ export const OptionsSchema = Joi.object({
29
29
  template: Joi.string(),
30
30
  downloadUrl: Joi.string(),
31
31
  hideSendButton: Joi.boolean(),
32
+ showExtensions: Joi.boolean(),
32
33
  sidebarOptions: sidebarOptions,
33
34
  version: Joi.string().when("versions", {
34
35
  is: Joi.exist(),
package/src/types.ts CHANGED
@@ -34,6 +34,7 @@ export interface APIOptions {
34
34
  template?: string;
35
35
  downloadUrl?: string;
36
36
  hideSendButton?: boolean;
37
+ showExtensions?: boolean;
37
38
  sidebarOptions?: SidebarOptions;
38
39
  version?: string;
39
40
  label?: string;
@@ -103,6 +104,7 @@ export interface ApiItem extends OperationObject {
103
104
  postman?: Request;
104
105
  proxy?: string;
105
106
  info: InfoObject;
107
+ extensions?: object;
106
108
  }
107
109
 
108
110
  export interface InfoPageMetadata extends ApiMetadataBase {