docusaurus-plugin-openapi-docs 0.0.0-531 → 0.0.0-533

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
@@ -121,6 +121,7 @@ The `docusaurus-plugin-openapi-docs` plugin can be configured with the following
121
121
  | ---------------- | -------- | ------- | --------------------------------------------------------------------------------------------------------------------------- |
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
+ | `proxy` | `string` | `null` | _Optional:_ Proxy URL to prepend to base URL when performing API requests from browser. |
124
125
  | `template` | `string` | `null` | _Optional:_ Customize MDX content with a desired template. |
125
126
  | `downloadUrl` | `string` | `null` | _Optional:_ Designated URL for downloading OpenAPI specification. (requires `info` section/doc) |
126
127
  | `sidebarOptions` | `object` | `null` | _Optional:_ Set of options for sidebar configuration. See below for a list of supported options. |
@@ -61,7 +61,7 @@ async function createPostmanCollection(openapiData) {
61
61
  return await jsonToCollection(data);
62
62
  }
63
63
  function createItems(openapiData, options, sidebarOptions) {
64
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
64
+ 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;
65
65
  // TODO: Find a better way to handle this
66
66
  let items = [];
67
67
  const infoIdSpaces = openapiData.info.title.replace(" ", "-").toLowerCase();
@@ -189,9 +189,100 @@ function createItems(openapiData, options, sidebarOptions) {
189
189
  items.push(apiPage);
190
190
  }
191
191
  }
192
+ // Gather x-webhooks endpoints
193
+ for (let [path, pathObject] of Object.entries((_q = openapiData["x-webhooks"]) !== null && _q !== void 0 ? _q : {})) {
194
+ path = "webhook";
195
+ const { $ref, description, parameters, servers, summary, ...rest } = pathObject;
196
+ for (let [method, operationObject] of Object.entries({ ...rest })) {
197
+ method = "event";
198
+ const title = (_s = (_r = operationObject.summary) !== null && _r !== void 0 ? _r : operationObject.operationId) !== null && _s !== void 0 ? _s : "Missing summary";
199
+ if (operationObject.description === undefined) {
200
+ operationObject.description =
201
+ (_u = (_t = operationObject.summary) !== null && _t !== void 0 ? _t : operationObject.operationId) !== null && _u !== void 0 ? _u : "";
202
+ }
203
+ const baseId = operationObject.operationId
204
+ ? (0, kebabCase_1.default)(operationObject.operationId)
205
+ : (0, kebabCase_1.default)(operationObject.summary);
206
+ const servers = (_w = (_v = operationObject.servers) !== null && _v !== void 0 ? _v : pathObject.servers) !== null && _w !== void 0 ? _w : openapiData.servers;
207
+ const security = (_x = operationObject.security) !== null && _x !== void 0 ? _x : openapiData.security;
208
+ // Add security schemes so we know how to handle security.
209
+ const securitySchemes = (_y = openapiData.components) === null || _y === void 0 ? void 0 : _y.securitySchemes;
210
+ // Make sure schemes are lowercase. See: https://github.com/cloud-annotations/docusaurus-plugin-openapi/issues/79
211
+ if (securitySchemes) {
212
+ for (let securityScheme of Object.values(securitySchemes)) {
213
+ if (securityScheme.type === "http") {
214
+ securityScheme.scheme = securityScheme.scheme.toLowerCase();
215
+ }
216
+ }
217
+ }
218
+ let jsonRequestBodyExample;
219
+ const body = (_0 = (_z = operationObject.requestBody) === null || _z === void 0 ? void 0 : _z.content) === null || _0 === void 0 ? void 0 : _0["application/json"];
220
+ if (body === null || body === void 0 ? void 0 : body.schema) {
221
+ jsonRequestBodyExample = (0, createRequestExample_1.sampleRequestFromSchema)(body.schema);
222
+ }
223
+ // Handle vendor JSON media types
224
+ const bodyContent = (_1 = operationObject.requestBody) === null || _1 === void 0 ? void 0 : _1.content;
225
+ if (bodyContent) {
226
+ const firstBodyContentKey = Object.keys(bodyContent)[0];
227
+ if (firstBodyContentKey.endsWith("+json")) {
228
+ const firstBody = bodyContent[firstBodyContentKey];
229
+ if (firstBody === null || firstBody === void 0 ? void 0 : firstBody.schema) {
230
+ jsonRequestBodyExample = (0, createRequestExample_1.sampleRequestFromSchema)(firstBody.schema);
231
+ }
232
+ }
233
+ }
234
+ // TODO: Don't include summary temporarilly
235
+ const { summary, ...defaults } = operationObject;
236
+ // Merge common parameters with operation parameters
237
+ // Operation params take precendence over common params
238
+ if (parameters !== undefined) {
239
+ if (operationObject.parameters !== undefined) {
240
+ defaults.parameters = (0, unionBy_1.default)(operationObject.parameters, parameters, "name");
241
+ }
242
+ else {
243
+ defaults.parameters = parameters;
244
+ }
245
+ }
246
+ const opDescription = operationObject.description;
247
+ let splitDescription;
248
+ if (opDescription) {
249
+ splitDescription = opDescription.match(/[^\r\n]+/g);
250
+ }
251
+ const apiPage = {
252
+ type: "api",
253
+ id: baseId,
254
+ infoId: infoId !== null && infoId !== void 0 ? infoId : "",
255
+ unversionedId: baseId,
256
+ title: title ? title.replace(/((?:^|[^\\])(?:\\{2})*)"/g, "$1'") : "",
257
+ description: operationObject.description
258
+ ? operationObject.description.replace(/((?:^|[^\\])(?:\\{2})*)"/g, "$1'")
259
+ : "",
260
+ frontMatter: {
261
+ description: splitDescription
262
+ ? splitDescription[0]
263
+ .replace(/((?:^|[^\\])(?:\\{2})*)"/g, "$1'")
264
+ .replace(/\s+$/, "")
265
+ : "",
266
+ ...((options === null || options === void 0 ? void 0 : options.proxy) && { proxy: options.proxy }),
267
+ },
268
+ api: {
269
+ ...defaults,
270
+ tags: operationObject.tags,
271
+ method,
272
+ path,
273
+ servers,
274
+ security,
275
+ securitySchemes,
276
+ jsonRequestBodyExample,
277
+ info: openapiData.info,
278
+ },
279
+ };
280
+ items.push(apiPage);
281
+ }
282
+ }
192
283
  if ((sidebarOptions === null || sidebarOptions === void 0 ? void 0 : sidebarOptions.categoryLinkSource) === "tag") {
193
284
  // Get global tags
194
- const tags = (_q = openapiData.tags) !== null && _q !== void 0 ? _q : [];
285
+ const tags = (_2 = openapiData.tags) !== null && _2 !== void 0 ? _2 : [];
195
286
  // Get operation tags
196
287
  const apiItems = items.filter((item) => {
197
288
  return item.type === "api";
@@ -12,6 +12,7 @@ export interface OpenApiObject {
12
12
  tags?: TagObject[];
13
13
  externalDocs?: ExternalDocumentationObject;
14
14
  swagger?: string;
15
+ "x-webhooks"?: PathsObject;
15
16
  }
16
17
  export interface OpenApiObjectWithRef {
17
18
  openapi: 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": "0.0.0-531",
4
+ "version": "0.0.0-533",
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": "97da2ed70f7bb1d712b85fad818fbed77e611aa0"
71
+ "gitHead": "ca4229525685eed0dcf9c886d4f0d3ec510e175b"
72
72
  }
@@ -239,6 +239,122 @@ function createItems(
239
239
  }
240
240
  }
241
241
 
242
+ // Gather x-webhooks endpoints
243
+ for (let [path, pathObject] of Object.entries(
244
+ openapiData["x-webhooks"] ?? {}
245
+ )) {
246
+ path = "webhook";
247
+ const { $ref, description, parameters, servers, summary, ...rest } =
248
+ pathObject;
249
+ for (let [method, operationObject] of Object.entries({ ...rest })) {
250
+ method = "event";
251
+ const title =
252
+ operationObject.summary ??
253
+ operationObject.operationId ??
254
+ "Missing summary";
255
+ if (operationObject.description === undefined) {
256
+ operationObject.description =
257
+ operationObject.summary ?? operationObject.operationId ?? "";
258
+ }
259
+
260
+ const baseId = operationObject.operationId
261
+ ? kebabCase(operationObject.operationId)
262
+ : kebabCase(operationObject.summary);
263
+
264
+ const servers =
265
+ operationObject.servers ?? pathObject.servers ?? openapiData.servers;
266
+
267
+ const security = operationObject.security ?? openapiData.security;
268
+
269
+ // Add security schemes so we know how to handle security.
270
+ const securitySchemes = openapiData.components?.securitySchemes;
271
+
272
+ // Make sure schemes are lowercase. See: https://github.com/cloud-annotations/docusaurus-plugin-openapi/issues/79
273
+ if (securitySchemes) {
274
+ for (let securityScheme of Object.values(securitySchemes)) {
275
+ if (securityScheme.type === "http") {
276
+ securityScheme.scheme = securityScheme.scheme.toLowerCase();
277
+ }
278
+ }
279
+ }
280
+
281
+ let jsonRequestBodyExample;
282
+ const body = operationObject.requestBody?.content?.["application/json"];
283
+ if (body?.schema) {
284
+ jsonRequestBodyExample = sampleRequestFromSchema(body.schema);
285
+ }
286
+
287
+ // Handle vendor JSON media types
288
+ const bodyContent = operationObject.requestBody?.content;
289
+ if (bodyContent) {
290
+ const firstBodyContentKey = Object.keys(bodyContent)[0];
291
+ if (firstBodyContentKey.endsWith("+json")) {
292
+ const firstBody = bodyContent[firstBodyContentKey];
293
+ if (firstBody?.schema) {
294
+ jsonRequestBodyExample = sampleRequestFromSchema(firstBody.schema);
295
+ }
296
+ }
297
+ }
298
+
299
+ // TODO: Don't include summary temporarilly
300
+ const { summary, ...defaults } = operationObject;
301
+
302
+ // Merge common parameters with operation parameters
303
+ // Operation params take precendence over common params
304
+ if (parameters !== undefined) {
305
+ if (operationObject.parameters !== undefined) {
306
+ defaults.parameters = unionBy(
307
+ operationObject.parameters,
308
+ parameters,
309
+ "name"
310
+ );
311
+ } else {
312
+ defaults.parameters = parameters;
313
+ }
314
+ }
315
+
316
+ const opDescription = operationObject.description;
317
+ let splitDescription: any;
318
+ if (opDescription) {
319
+ splitDescription = opDescription.match(/[^\r\n]+/g);
320
+ }
321
+
322
+ const apiPage: PartialPage<ApiPageMetadata> = {
323
+ type: "api",
324
+ id: baseId,
325
+ infoId: infoId ?? "",
326
+ unversionedId: baseId,
327
+ title: title ? title.replace(/((?:^|[^\\])(?:\\{2})*)"/g, "$1'") : "",
328
+ description: operationObject.description
329
+ ? operationObject.description.replace(
330
+ /((?:^|[^\\])(?:\\{2})*)"/g,
331
+ "$1'"
332
+ )
333
+ : "",
334
+ frontMatter: {
335
+ description: splitDescription
336
+ ? splitDescription[0]
337
+ .replace(/((?:^|[^\\])(?:\\{2})*)"/g, "$1'")
338
+ .replace(/\s+$/, "")
339
+ : "",
340
+ ...(options?.proxy && { proxy: options.proxy }),
341
+ },
342
+ api: {
343
+ ...defaults,
344
+ tags: operationObject.tags,
345
+ method,
346
+ path,
347
+ servers,
348
+ security,
349
+ securitySchemes,
350
+ jsonRequestBodyExample,
351
+ info: openapiData.info,
352
+ },
353
+ };
354
+ items.push(apiPage);
355
+ }
356
+ }
357
+
242
358
  if (sidebarOptions?.categoryLinkSource === "tag") {
243
359
  // Get global tags
244
360
  const tags: TagObject[] = openapiData.tags ?? [];
@@ -21,6 +21,7 @@ export interface OpenApiObject {
21
21
  tags?: TagObject[];
22
22
  externalDocs?: ExternalDocumentationObject;
23
23
  swagger?: string;
24
+ "x-webhooks"?: PathsObject;
24
25
  }
25
26
 
26
27
  export interface OpenApiObjectWithRef {