docusaurus-plugin-openapi-docs 0.0.0-1039 → 0.0.0-1041

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.
@@ -98,7 +98,7 @@ async function createPostmanCollection(openapiData) {
98
98
  return await jsonToCollection(data);
99
99
  }
100
100
  function createItems(openapiData, options, sidebarOptions) {
101
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7;
101
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8;
102
102
  // TODO: Find a better way to handle this
103
103
  let items = [];
104
104
  const infoIdSpaces = openapiData.info.title.replace(" ", "-").toLowerCase();
@@ -251,10 +251,15 @@ function createItems(openapiData, options, sidebarOptions) {
251
251
  }
252
252
  // Gather x-webhooks endpoints
253
253
  for (let [path, pathObject] of Object.entries((_q = (_p = openapiData["x-webhooks"]) !== null && _p !== void 0 ? _p : openapiData["webhooks"]) !== null && _q !== void 0 ? _q : {})) {
254
+ const eventName = path;
254
255
  path = "webhook";
255
256
  const { $ref, description, parameters, servers, summary, ...rest } = pathObject;
256
257
  for (let [method, operationObject] of Object.entries({ ...rest })) {
257
258
  method = "event";
259
+ if (operationObject.summary === undefined &&
260
+ operationObject.operationId === undefined) {
261
+ operationObject.summary = eventName;
262
+ }
258
263
  const title = (_s = (_r = operationObject.summary) !== null && _r !== void 0 ? _r : operationObject.operationId) !== null && _s !== void 0 ? _s : "Missing summary";
259
264
  if (operationObject.description === undefined) {
260
265
  operationObject.description =
@@ -262,7 +267,7 @@ function createItems(openapiData, options, sidebarOptions) {
262
267
  }
263
268
  const baseId = operationObject.operationId
264
269
  ? (0, kebabCase_1.default)(operationObject.operationId)
265
- : (0, kebabCase_1.default)(operationObject.summary);
270
+ : (0, kebabCase_1.default)((_v = operationObject.summary) !== null && _v !== void 0 ? _v : eventName);
266
271
  const extensions = [];
267
272
  const commonExtensions = ["x-codeSamples"];
268
273
  for (const [key, value] of Object.entries(operationObject)) {
@@ -270,10 +275,10 @@ function createItems(openapiData, options, sidebarOptions) {
270
275
  extensions.push({ key, value });
271
276
  }
272
277
  }
273
- const servers = (_w = (_v = operationObject.servers) !== null && _v !== void 0 ? _v : pathObject.servers) !== null && _w !== void 0 ? _w : openapiData.servers;
274
- const security = (_x = operationObject.security) !== null && _x !== void 0 ? _x : openapiData.security;
278
+ const servers = (_x = (_w = operationObject.servers) !== null && _w !== void 0 ? _w : pathObject.servers) !== null && _x !== void 0 ? _x : openapiData.servers;
279
+ const security = (_y = operationObject.security) !== null && _y !== void 0 ? _y : openapiData.security;
275
280
  // Add security schemes so we know how to handle security.
276
- const securitySchemes = (_y = openapiData.components) === null || _y === void 0 ? void 0 : _y.securitySchemes;
281
+ const securitySchemes = (_z = openapiData.components) === null || _z === void 0 ? void 0 : _z.securitySchemes;
277
282
  // Make sure schemes are lowercase. See: https://github.com/cloud-annotations/docusaurus-plugin-openapi/issues/79
278
283
  if (securitySchemes) {
279
284
  for (let securityScheme of Object.values(securitySchemes)) {
@@ -283,7 +288,7 @@ function createItems(openapiData, options, sidebarOptions) {
283
288
  }
284
289
  }
285
290
  let jsonRequestBodyExample;
286
- const content = (_z = operationObject.requestBody) === null || _z === void 0 ? void 0 : _z.content;
291
+ const content = (_0 = operationObject.requestBody) === null || _0 === void 0 ? void 0 : _0.content;
287
292
  let body;
288
293
  for (let key in content) {
289
294
  if (key.toLowerCase() === "application/json" ||
@@ -296,7 +301,7 @@ function createItems(openapiData, options, sidebarOptions) {
296
301
  jsonRequestBodyExample = (0, createRequestExample_1.sampleRequestFromSchema)(body.schema);
297
302
  }
298
303
  // Handle vendor JSON media types
299
- const bodyContent = (_0 = operationObject.requestBody) === null || _0 === void 0 ? void 0 : _0.content;
304
+ const bodyContent = (_1 = operationObject.requestBody) === null || _1 === void 0 ? void 0 : _1.content;
300
305
  if (bodyContent) {
301
306
  const firstBodyContentKey = Object.keys(bodyContent)[0];
302
307
  if (firstBodyContentKey.endsWith("+json")) {
@@ -363,13 +368,13 @@ function createItems(openapiData, options, sidebarOptions) {
363
368
  }
364
369
  }
365
370
  if ((options === null || options === void 0 ? void 0 : options.showSchemas) === true ||
366
- Object.entries((_2 = (_1 = openapiData === null || openapiData === void 0 ? void 0 : openapiData.components) === null || _1 === void 0 ? void 0 : _1.schemas) !== null && _2 !== void 0 ? _2 : {})
371
+ Object.entries((_3 = (_2 = openapiData === null || openapiData === void 0 ? void 0 : openapiData.components) === null || _2 === void 0 ? void 0 : _2.schemas) !== null && _3 !== void 0 ? _3 : {})
367
372
  .flatMap(([_, s]) => s["x-tags"])
368
373
  .filter((item) => !!item).length > 0) {
369
374
  // Gather schemas
370
- for (let [schema, schemaObject] of Object.entries((_4 = (_3 = openapiData === null || openapiData === void 0 ? void 0 : openapiData.components) === null || _3 === void 0 ? void 0 : _3.schemas) !== null && _4 !== void 0 ? _4 : {})) {
375
+ for (let [schema, schemaObject] of Object.entries((_5 = (_4 = openapiData === null || openapiData === void 0 ? void 0 : openapiData.components) === null || _4 === void 0 ? void 0 : _4.schemas) !== null && _5 !== void 0 ? _5 : {})) {
371
376
  if ((options === null || options === void 0 ? void 0 : options.showSchemas) === true || schemaObject["x-tags"]) {
372
- const baseIdSpaces = (_6 = (_5 = schemaObject === null || schemaObject === void 0 ? void 0 : schemaObject.title) === null || _5 === void 0 ? void 0 : _5.replace(" ", "-").toLowerCase()) !== null && _6 !== void 0 ? _6 : "";
377
+ const baseIdSpaces = (_7 = (_6 = schemaObject === null || schemaObject === void 0 ? void 0 : schemaObject.title) === null || _6 === void 0 ? void 0 : _6.replace(" ", "-").toLowerCase()) !== null && _7 !== void 0 ? _7 : "";
373
378
  const baseId = (0, kebabCase_1.default)(baseIdSpaces);
374
379
  const schemaDescription = schemaObject.description;
375
380
  let splitDescription;
@@ -403,7 +408,7 @@ function createItems(openapiData, options, sidebarOptions) {
403
408
  }
404
409
  if ((sidebarOptions === null || sidebarOptions === void 0 ? void 0 : sidebarOptions.categoryLinkSource) === "tag") {
405
410
  // Get global tags
406
- const tags = (_7 = openapiData.tags) !== null && _7 !== void 0 ? _7 : [];
411
+ const tags = (_8 = openapiData.tags) !== null && _8 !== void 0 ? _8 : [];
407
412
  // Get operation tags
408
413
  const apiItems = items.filter((item) => {
409
414
  return item.type === "api";
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,23 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
9
+ return (mod && mod.__esModule) ? mod : { "default": mod };
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const path_1 = __importDefault(require("path"));
13
+ // eslint-disable-next-line import/no-extraneous-dependencies
14
+ const utils_1 = require("@docusaurus/utils");
15
+ const _1 = require(".");
16
+ describe("webhooks", () => {
17
+ it("uses event name when summary and operationId are missing", async () => {
18
+ const files = await (0, _1.readOpenapiFiles)((0, utils_1.posixPath)(path_1.default.join(__dirname, "__fixtures__/webhook/openapi.yaml")));
19
+ const [items] = await (0, _1.processOpenapiFiles)(files, { specPath: "", outputDir: "" }, {});
20
+ const webhookItem = items.find((item) => item.type === "api");
21
+ expect(webhookItem === null || webhookItem === void 0 ? void 0 : webhookItem.id).toBe("order-created");
22
+ });
23
+ });
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-1039",
4
+ "version": "0.0.0-1041",
5
5
  "license": "MIT",
6
6
  "keywords": [
7
7
  "openapi",
@@ -65,5 +65,5 @@
65
65
  "engines": {
66
66
  "node": ">=14"
67
67
  },
68
- "gitHead": "ee41eb40583f2139a83c7d26534bc427fe7dc667"
68
+ "gitHead": "d45e2fae00fed0f6effd002c1d6dccd94f258e19"
69
69
  }
@@ -0,0 +1,17 @@
1
+ openapi: 3.0.3
2
+ info:
3
+ title: Webhook Example
4
+ version: 1.0.0
5
+ paths: {}
6
+ webhooks:
7
+ order.created:
8
+ post:
9
+ requestBody:
10
+ description: example body
11
+ content:
12
+ application/json:
13
+ schema:
14
+ type: object
15
+ responses:
16
+ "200":
17
+ description: OK
@@ -274,11 +274,19 @@ function createItems(
274
274
  for (let [path, pathObject] of Object.entries(
275
275
  openapiData["x-webhooks"] ?? openapiData["webhooks"] ?? {}
276
276
  )) {
277
+ const eventName = path;
277
278
  path = "webhook";
278
279
  const { $ref, description, parameters, servers, summary, ...rest } =
279
280
  pathObject;
280
281
  for (let [method, operationObject] of Object.entries({ ...rest })) {
281
282
  method = "event";
283
+ if (
284
+ operationObject.summary === undefined &&
285
+ operationObject.operationId === undefined
286
+ ) {
287
+ operationObject.summary = eventName;
288
+ }
289
+
282
290
  const title =
283
291
  operationObject.summary ??
284
292
  operationObject.operationId ??
@@ -290,7 +298,7 @@ function createItems(
290
298
 
291
299
  const baseId = operationObject.operationId
292
300
  ? kebabCase(operationObject.operationId)
293
- : kebabCase(operationObject.summary);
301
+ : kebabCase(operationObject.summary ?? eventName);
294
302
 
295
303
  const extensions = [];
296
304
  const commonExtensions = ["x-codeSamples"];
@@ -0,0 +1,30 @@
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 path from "path";
9
+
10
+ // eslint-disable-next-line import/no-extraneous-dependencies
11
+ import { posixPath } from "@docusaurus/utils";
12
+
13
+ import { readOpenapiFiles, processOpenapiFiles } from ".";
14
+
15
+ describe("webhooks", () => {
16
+ it("uses event name when summary and operationId are missing", async () => {
17
+ const files = await readOpenapiFiles(
18
+ posixPath(path.join(__dirname, "__fixtures__/webhook/openapi.yaml"))
19
+ );
20
+
21
+ const [items] = await processOpenapiFiles(
22
+ files,
23
+ { specPath: "", outputDir: "" } as any,
24
+ {}
25
+ );
26
+
27
+ const webhookItem = items.find((item) => item.type === "api");
28
+ expect(webhookItem?.id).toBe("order-created");
29
+ });
30
+ });