docusaurus-plugin-openapi-docs 0.0.0-beta.638 → 0.0.0-beta.640

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}}}
@@ -196,12 +199,6 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
196
199
  item.downloadUrl = downloadUrl;
197
200
  }
198
201
  }
199
- const markdown = item.type === "api"
200
- ? (0, markdown_1.createApiPageMD)(item)
201
- : item.type === "info"
202
- ? (0, markdown_1.createInfoPageMD)(item)
203
- : (0, markdown_1.createTagPageMD)(item);
204
- item.markdown = markdown;
205
202
  if (item.type === "api") {
206
203
  item.json = JSON.stringify(item.api);
207
204
  let infoBasePath = `${outputDir}/${item.infoId}`;
@@ -213,6 +210,12 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
213
210
  if (item.infoId)
214
211
  item.infoPath = infoBasePath;
215
212
  }
213
+ const markdown = item.type === "api"
214
+ ? (0, markdown_1.createApiPageMD)(item)
215
+ : item.type === "info"
216
+ ? (0, markdown_1.createInfoPageMD)(item)
217
+ : (0, markdown_1.createTagPageMD)(item);
218
+ item.markdown = markdown;
216
219
  const view = (0, mustache_1.render)(mdTemplate, item);
217
220
  const utils = (0, mustache_1.render)(infoMdTemplate, item);
218
221
  // eslint-disable-next-line testing-library/render-result-naming-convention
@@ -0,0 +1 @@
1
+ export declare function createAuthorization(infoPath: string): string[] | undefined;
@@ -0,0 +1,16 @@
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.createAuthorization = void 0;
10
+ const utils_1 = require("./utils");
11
+ function createAuthorization(infoPath) {
12
+ if (!infoPath)
13
+ return undefined;
14
+ return [(0, utils_1.create)("SecuritySchemes", { infoPath: infoPath }), "\n\n"];
15
+ }
16
+ exports.createAuthorization = createAuthorization;
@@ -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, method, path, parameters, requestBody, responses, }, }: ApiPageMetadata): string;
2
+ export declare function createApiPageMD({ title, api: { deprecated, "x-deprecated-description": deprecatedDescription, description, method, path, extensions, parameters, requestBody, responses, }, infoPath, 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;
@@ -8,6 +8,7 @@
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.createTagPageMD = exports.createInfoPageMD = exports.createApiPageMD = void 0;
10
10
  const createAuthentication_1 = require("./createAuthentication");
11
+ const createAuthorization_1 = require("./createAuthorization");
11
12
  const createContactInfo_1 = require("./createContactInfo");
12
13
  const createDeprecationNotice_1 = require("./createDeprecationNotice");
13
14
  const createDescription_1 = require("./createDescription");
@@ -20,13 +21,15 @@ const createParamsDetails_1 = require("./createParamsDetails");
20
21
  const createRequestBodyDetails_1 = require("./createRequestBodyDetails");
21
22
  const createStatusCodes_1 = require("./createStatusCodes");
22
23
  const createTermsOfService_1 = require("./createTermsOfService");
24
+ const createVendorExtensions_1 = require("./createVendorExtensions");
23
25
  const createVersionBadge_1 = require("./createVersionBadge");
24
26
  const utils_1 = require("./utils");
25
- function createApiPageMD({ title, api: { deprecated, "x-deprecated-description": deprecatedDescription, description, method, path, parameters, requestBody, responses, }, }) {
27
+ function createApiPageMD({ title, api: { deprecated, "x-deprecated-description": deprecatedDescription, description, method, path, extensions, parameters, requestBody, responses, }, infoPath, frontMatter, }) {
26
28
  return (0, utils_1.render)([
27
29
  `import ApiTabs from "@theme/ApiTabs";\n`,
28
30
  `import DiscriminatorTabs from "@theme/DiscriminatorTabs";\n`,
29
31
  `import MethodEndpoint from "@theme/ApiDemoPanel/MethodEndpoint";\n`,
32
+ `import SecuritySchemes from "@theme/ApiDemoPanel/SecuritySchemes";\n`,
30
33
  `import MimeTabs from "@theme/MimeTabs";\n`,
31
34
  `import ParamsItem from "@theme/ParamsItem";\n`,
32
35
  `import ResponseSamples from "@theme/ResponseSamples";\n`,
@@ -35,6 +38,9 @@ function createApiPageMD({ title, api: { deprecated, "x-deprecated-description":
35
38
  `import TabItem from "@theme/TabItem";\n\n`,
36
39
  (0, createHeading_1.createHeading)(title.replace(utils_1.lessThan, "<").replace(utils_1.greaterThan, ">")),
37
40
  (0, createMethodEndpoint_1.createMethodEndpoint)(method, path),
41
+ `## ${title.replace(utils_1.lessThan, "<").replace(utils_1.greaterThan, ">")}\n\n`,
42
+ infoPath && (0, createAuthorization_1.createAuthorization)(infoPath),
43
+ frontMatter.show_extensions && (0, createVendorExtensions_1.createVendorExtensions)(extensions),
38
44
  (0, createDeprecationNotice_1.createDeprecationNotice)({ deprecated, description: deprecatedDescription }),
39
45
  (0, createDescription_1.createDescription)(description),
40
46
  (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
@@ -26,6 +26,7 @@ exports.OptionsSchema = utils_validation_1.Joi.object({
26
26
  template: utils_validation_1.Joi.string(),
27
27
  downloadUrl: utils_validation_1.Joi.string(),
28
28
  hideSendButton: utils_validation_1.Joi.boolean(),
29
+ showExtensions: utils_validation_1.Joi.boolean(),
29
30
  sidebarOptions: sidebarOptions,
30
31
  version: utils_validation_1.Joi.string().when("versions", {
31
32
  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;
@@ -78,6 +79,7 @@ export interface ApiItem extends OperationObject {
78
79
  postman?: Request;
79
80
  proxy?: string;
80
81
  info: InfoObject;
82
+ extensions?: object;
81
83
  }
82
84
  export interface InfoPageMetadata extends ApiMetadataBase {
83
85
  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": "0.0.0-beta.638",
4
+ "version": "0.0.0-beta.640",
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": "9542413e1a3fdfef18eea605ce80799f5fc10686"
71
+ "gitHead": "78bb9c3cb5278a19b341dda5fb3fdab5b1901ecc"
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}}}
@@ -240,13 +243,6 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
240
243
  item.downloadUrl = downloadUrl;
241
244
  }
242
245
  }
243
- const markdown =
244
- item.type === "api"
245
- ? createApiPageMD(item)
246
- : item.type === "info"
247
- ? createInfoPageMD(item)
248
- : createTagPageMD(item);
249
- item.markdown = markdown;
250
246
  if (item.type === "api") {
251
247
  item.json = JSON.stringify(item.api);
252
248
  let infoBasePath = `${outputDir}/${item.infoId}`;
@@ -257,6 +253,13 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
257
253
  }
258
254
  if (item.infoId) item.infoPath = infoBasePath;
259
255
  }
256
+ const markdown =
257
+ item.type === "api"
258
+ ? createApiPageMD(item)
259
+ : item.type === "info"
260
+ ? createInfoPageMD(item)
261
+ : createTagPageMD(item);
262
+ item.markdown = markdown;
260
263
 
261
264
  const view = render(mdTemplate, item);
262
265
  const utils = render(infoMdTemplate, item);
@@ -0,0 +1,13 @@
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 } from "./utils";
9
+
10
+ export function createAuthorization(infoPath: string) {
11
+ if (!infoPath) return undefined;
12
+ return [create("SecuritySchemes", { infoPath: infoPath }), "\n\n"];
13
+ }
@@ -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
+ }
@@ -13,6 +13,7 @@ import {
13
13
  } from "../openapi/types";
14
14
  import { ApiPageMetadata, InfoPageMetadata, TagPageMetadata } from "../types";
15
15
  import { createAuthentication } from "./createAuthentication";
16
+ import { createAuthorization } from "./createAuthorization";
16
17
  import { createContactInfo } from "./createContactInfo";
17
18
  import { createDeprecationNotice } from "./createDeprecationNotice";
18
19
  import { createDescription } from "./createDescription";
@@ -25,6 +26,7 @@ import { createParamsDetails } from "./createParamsDetails";
25
26
  import { createRequestBodyDetails } from "./createRequestBodyDetails";
26
27
  import { createStatusCodes } from "./createStatusCodes";
27
28
  import { createTermsOfService } from "./createTermsOfService";
29
+ import { createVendorExtensions } from "./createVendorExtensions";
28
30
  import { createVersionBadge } from "./createVersionBadge";
29
31
  import { greaterThan, lessThan, render } from "./utils";
30
32
 
@@ -47,15 +49,19 @@ export function createApiPageMD({
47
49
  description,
48
50
  method,
49
51
  path,
52
+ extensions,
50
53
  parameters,
51
54
  requestBody,
52
55
  responses,
53
56
  },
57
+ infoPath,
58
+ frontMatter,
54
59
  }: ApiPageMetadata) {
55
60
  return render([
56
61
  `import ApiTabs from "@theme/ApiTabs";\n`,
57
62
  `import DiscriminatorTabs from "@theme/DiscriminatorTabs";\n`,
58
63
  `import MethodEndpoint from "@theme/ApiDemoPanel/MethodEndpoint";\n`,
64
+ `import SecuritySchemes from "@theme/ApiDemoPanel/SecuritySchemes";\n`,
59
65
  `import MimeTabs from "@theme/MimeTabs";\n`,
60
66
  `import ParamsItem from "@theme/ParamsItem";\n`,
61
67
  `import ResponseSamples from "@theme/ResponseSamples";\n`,
@@ -64,6 +70,9 @@ export function createApiPageMD({
64
70
  `import TabItem from "@theme/TabItem";\n\n`,
65
71
  createHeading(title.replace(lessThan, "&lt;").replace(greaterThan, "&gt;")),
66
72
  createMethodEndpoint(method, path),
73
+ `## ${title.replace(lessThan, "&lt;").replace(greaterThan, "&gt;")}\n\n`,
74
+ infoPath && createAuthorization(infoPath),
75
+ frontMatter.show_extensions && createVendorExtensions(extensions),
67
76
  createDeprecationNotice({ deprecated, description: deprecatedDescription }),
68
77
  createDescription(description),
69
78
  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
@@ -28,6 +28,7 @@ export const OptionsSchema = Joi.object({
28
28
  template: Joi.string(),
29
29
  downloadUrl: Joi.string(),
30
30
  hideSendButton: Joi.boolean(),
31
+ showExtensions: Joi.boolean(),
31
32
  sidebarOptions: sidebarOptions,
32
33
  version: Joi.string().when("versions", {
33
34
  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;
@@ -105,6 +106,7 @@ export interface ApiItem extends OperationObject {
105
106
  postman?: Request;
106
107
  proxy?: string;
107
108
  info: InfoObject;
109
+ extensions?: object;
108
110
  }
109
111
 
110
112
  export interface InfoPageMetadata extends ApiMetadataBase {