docusaurus-plugin-openapi-docs 2.0.0-beta.4 → 2.0.0-beta.5

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.
@@ -13,7 +13,7 @@ function createAdmonition({ children }) {
13
13
  }
14
14
  function createDeprecationNotice({ deprecated, description, }) {
15
15
  return (0, utils_1.guard)(deprecated, () => createAdmonition({
16
- children: description !== null && description !== void 0 ? description : "This endpoint has been deprecated and may be removed in future versions of the API.",
16
+ children: description !== null && description !== void 0 ? description : "This endpoint has been deprecated and may be replaced or removed in future versions of the API.",
17
17
  }));
18
18
  }
19
19
  exports.createDeprecationNotice = createDeprecationNotice;
@@ -356,8 +356,6 @@ function createDetailsNode(name, schemaName, schema, required, nullable) {
356
356
  * For handling anyOf/oneOf properties.
357
357
  */
358
358
  function createAnyOneOfProperty(name, schemaName, schema, required, nullable) {
359
- const type = schema.oneOf ? "oneOf" : "anyOf";
360
- const children = schema[type] || [];
361
359
  return (0, utils_1.create)("SchemaItem", {
362
360
  collapsible: true,
363
361
  className: "schemaItem",
@@ -408,38 +406,7 @@ function createAnyOneOfProperty(name, schemaName, schema, required, nullable) {
408
406
  })),
409
407
  ],
410
408
  }),
411
- (0, utils_1.create)("div", {
412
- children: [
413
- (0, utils_1.create)("span", {
414
- className: "badge badge--info",
415
- children: type,
416
- }),
417
- (0, utils_1.create)("SchemaTabs", {
418
- children: children.map((property, index) => {
419
- var _a;
420
- const label = (_a = property.title) !== null && _a !== void 0 ? _a : `MOD${index + 1}`;
421
- if (property.properties) {
422
- return (0, utils_1.create)("TabItem", {
423
- label: label,
424
- value: `${index}-property`,
425
- children: [createNodes(property)],
426
- });
427
- }
428
- return (0, utils_1.create)("TabItem", {
429
- label: label,
430
- value: `${index}-property`,
431
- children: [
432
- (0, utils_1.create)("p", { children: label }),
433
- (0, utils_1.guard)(schema.description, (description) => (0, utils_1.create)("div", {
434
- style: { marginTop: ".5rem", marginBottom: ".5rem" },
435
- children: (0, createDescription_1.createDescription)(description),
436
- })),
437
- ],
438
- });
439
- }),
440
- }),
441
- ],
442
- }),
409
+ createAnyOneOf(schema),
443
410
  ],
444
411
  }),
445
412
  ],
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,73 @@
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 __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9
+ if (k2 === undefined) k2 = k;
10
+ var desc = Object.getOwnPropertyDescriptor(m, k);
11
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
12
+ desc = { enumerable: true, get: function() { return m[k]; } };
13
+ }
14
+ Object.defineProperty(o, k2, desc);
15
+ }) : (function(o, m, k, k2) {
16
+ if (k2 === undefined) k2 = k;
17
+ o[k2] = m[k];
18
+ }));
19
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
20
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
21
+ }) : function(o, v) {
22
+ o["default"] = v;
23
+ });
24
+ var __importStar = (this && this.__importStar) || function (mod) {
25
+ if (mod && mod.__esModule) return mod;
26
+ var result = {};
27
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
28
+ __setModuleDefault(result, mod);
29
+ return result;
30
+ };
31
+ Object.defineProperty(exports, "__esModule", { value: true });
32
+ const prettier = __importStar(require("prettier"));
33
+ const createSchema_1 = require("./createSchema");
34
+ describe("createNodes", () => {
35
+ it("should create readable MODs for oneOf primitive properties", () => {
36
+ const schema = {
37
+ type: "object",
38
+ properties: {
39
+ oneOfProperty: {
40
+ oneOf: [
41
+ {
42
+ type: "object",
43
+ properties: {
44
+ noseLength: {
45
+ type: "number",
46
+ },
47
+ },
48
+ required: ["noseLength"],
49
+ description: "Clown's nose length",
50
+ },
51
+ {
52
+ type: "array",
53
+ items: {
54
+ type: "string",
55
+ },
56
+ description: "Array of strings",
57
+ },
58
+ {
59
+ type: "boolean",
60
+ },
61
+ {
62
+ type: "number",
63
+ },
64
+ {
65
+ type: "string",
66
+ },
67
+ ],
68
+ },
69
+ },
70
+ };
71
+ expect((0, createSchema_1.createNodes)(schema).map((md) => prettier.format(md, { parser: "babel" }))).toMatchSnapshot();
72
+ });
73
+ });
@@ -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, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2;
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;
65
65
  // TODO: Find a better way to handle this
66
66
  let items = [];
67
67
  const infoIdSpaces = openapiData.info.title.replace(" ", "-").toLowerCase();
@@ -132,12 +132,20 @@ function createItems(openapiData, options, sidebarOptions) {
132
132
  }
133
133
  }
134
134
  let jsonRequestBodyExample;
135
- const body = (_o = (_m = operationObject.requestBody) === null || _m === void 0 ? void 0 : _m.content) === null || _o === void 0 ? void 0 : _o["application/json"];
135
+ const content = (_m = operationObject.requestBody) === null || _m === void 0 ? void 0 : _m.content;
136
+ let body;
137
+ for (let key in content) {
138
+ if (key.toLowerCase() === "application/json" ||
139
+ key.toLowerCase() === "application/json; charset=utf-8") {
140
+ body = content[key];
141
+ break;
142
+ }
143
+ }
136
144
  if (body === null || body === void 0 ? void 0 : body.schema) {
137
145
  jsonRequestBodyExample = (0, createRequestExample_1.sampleRequestFromSchema)(body.schema);
138
146
  }
139
147
  // Handle vendor JSON media types
140
- const bodyContent = (_p = operationObject.requestBody) === null || _p === void 0 ? void 0 : _p.content;
148
+ const bodyContent = (_o = operationObject.requestBody) === null || _o === void 0 ? void 0 : _o.content;
141
149
  if (bodyContent) {
142
150
  const firstBodyContentKey = Object.keys(bodyContent)[0];
143
151
  if (firstBodyContentKey.endsWith("+json")) {
@@ -204,15 +212,15 @@ function createItems(openapiData, options, sidebarOptions) {
204
212
  }
205
213
  }
206
214
  // Gather x-webhooks endpoints
207
- for (let [path, pathObject] of Object.entries((_q = openapiData["x-webhooks"]) !== null && _q !== void 0 ? _q : {})) {
215
+ for (let [path, pathObject] of Object.entries((_p = openapiData["x-webhooks"]) !== null && _p !== void 0 ? _p : {})) {
208
216
  path = "webhook";
209
217
  const { $ref, description, parameters, servers, summary, ...rest } = pathObject;
210
218
  for (let [method, operationObject] of Object.entries({ ...rest })) {
211
219
  method = "event";
212
- const title = (_s = (_r = operationObject.summary) !== null && _r !== void 0 ? _r : operationObject.operationId) !== null && _s !== void 0 ? _s : "Missing summary";
220
+ const title = (_r = (_q = operationObject.summary) !== null && _q !== void 0 ? _q : operationObject.operationId) !== null && _r !== void 0 ? _r : "Missing summary";
213
221
  if (operationObject.description === undefined) {
214
222
  operationObject.description =
215
- (_u = (_t = operationObject.summary) !== null && _t !== void 0 ? _t : operationObject.operationId) !== null && _u !== void 0 ? _u : "";
223
+ (_t = (_s = operationObject.summary) !== null && _s !== void 0 ? _s : operationObject.operationId) !== null && _t !== void 0 ? _t : "";
216
224
  }
217
225
  const baseId = operationObject.operationId
218
226
  ? (0, kebabCase_1.default)(operationObject.operationId)
@@ -224,10 +232,10 @@ function createItems(openapiData, options, sidebarOptions) {
224
232
  extensions.push({ key, value });
225
233
  }
226
234
  }
227
- const servers = (_w = (_v = operationObject.servers) !== null && _v !== void 0 ? _v : pathObject.servers) !== null && _w !== void 0 ? _w : openapiData.servers;
228
- const security = (_x = operationObject.security) !== null && _x !== void 0 ? _x : openapiData.security;
235
+ const servers = (_v = (_u = operationObject.servers) !== null && _u !== void 0 ? _u : pathObject.servers) !== null && _v !== void 0 ? _v : openapiData.servers;
236
+ const security = (_w = operationObject.security) !== null && _w !== void 0 ? _w : openapiData.security;
229
237
  // Add security schemes so we know how to handle security.
230
- const securitySchemes = (_y = openapiData.components) === null || _y === void 0 ? void 0 : _y.securitySchemes;
238
+ const securitySchemes = (_x = openapiData.components) === null || _x === void 0 ? void 0 : _x.securitySchemes;
231
239
  // Make sure schemes are lowercase. See: https://github.com/cloud-annotations/docusaurus-plugin-openapi/issues/79
232
240
  if (securitySchemes) {
233
241
  for (let securityScheme of Object.values(securitySchemes)) {
@@ -237,12 +245,20 @@ function createItems(openapiData, options, sidebarOptions) {
237
245
  }
238
246
  }
239
247
  let jsonRequestBodyExample;
240
- const body = (_0 = (_z = operationObject.requestBody) === null || _z === void 0 ? void 0 : _z.content) === null || _0 === void 0 ? void 0 : _0["application/json"];
248
+ const content = (_y = operationObject.requestBody) === null || _y === void 0 ? void 0 : _y.content;
249
+ let body;
250
+ for (let key in content) {
251
+ if (key.toLowerCase() === "application/json" ||
252
+ key.toLowerCase() === "application/json; charset=utf-8") {
253
+ body = content[key];
254
+ break;
255
+ }
256
+ }
241
257
  if (body === null || body === void 0 ? void 0 : body.schema) {
242
258
  jsonRequestBodyExample = (0, createRequestExample_1.sampleRequestFromSchema)(body.schema);
243
259
  }
244
260
  // Handle vendor JSON media types
245
- const bodyContent = (_1 = operationObject.requestBody) === null || _1 === void 0 ? void 0 : _1.content;
261
+ const bodyContent = (_z = operationObject.requestBody) === null || _z === void 0 ? void 0 : _z.content;
246
262
  if (bodyContent) {
247
263
  const firstBodyContentKey = Object.keys(bodyContent)[0];
248
264
  if (firstBodyContentKey.endsWith("+json")) {
@@ -310,7 +326,7 @@ function createItems(openapiData, options, sidebarOptions) {
310
326
  }
311
327
  if ((sidebarOptions === null || sidebarOptions === void 0 ? void 0 : sidebarOptions.categoryLinkSource) === "tag") {
312
328
  // Get global tags
313
- const tags = (_2 = openapiData.tags) !== null && _2 !== void 0 ? _2 : [];
329
+ const tags = (_0 = openapiData.tags) !== null && _0 !== void 0 ? _0 : [];
314
330
  // Get operation tags
315
331
  const apiItems = items.filter((item) => {
316
332
  return item.type === "api";
@@ -10,6 +10,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  const path_1 = __importDefault(require("path"));
13
+ // eslint-disable-next-line import/no-extraneous-dependencies
13
14
  const utils_1 = require("@docusaurus/utils");
14
15
  const _1 = require(".");
15
16
  // npx jest packages/docusaurus-plugin-openapi/src/openapi/openapi.test.ts --watch
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": "2.0.0-beta.4",
4
+ "version": "2.0.0-beta.5",
5
5
  "license": "MIT",
6
6
  "keywords": [
7
7
  "openapi",
@@ -60,5 +60,5 @@
60
60
  "engines": {
61
61
  "node": ">=14"
62
62
  },
63
- "gitHead": "d7c1319c7977c3e7c54827b3950e5c9b66106e30"
63
+ "gitHead": "357d6a5bceaab56924e405b92dec1a3861a23f4f"
64
64
  }
@@ -0,0 +1,98 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`createNodes should create readable MODs for oneOf primitive properties 1`] = `
4
+ Array [
5
+ "<SchemaItem collapsible={true} className={\\"schemaItem\\"}>
6
+ <details style={{}} className={\\"openapi-markdown__details\\"}>
7
+ <summary style={{}}>
8
+ <strong>oneOfProperty</strong>
9
+ <span style={{ opacity: \\"0.6\\" }}> object</span>
10
+ </summary>
11
+ <div style={{ marginLeft: \\"1rem\\" }}></div>
12
+ <div>
13
+ <span className={\\"badge badge--info\\"}>oneOf</span>
14
+ <SchemaTabs>
15
+ <TabItem label={\\"MOD1\\"} value={\\"0-item-properties\\"}>
16
+ <SchemaItem
17
+ collapsible={false}
18
+ name={\\"noseLength\\"}
19
+ required={true}
20
+ schemaName={\\"number\\"}
21
+ qualifierMessage={undefined}
22
+ schema={{ type: \\"number\\" }}
23
+ ></SchemaItem>
24
+ </TabItem>
25
+ <TabItem label={\\"MOD2\\"} value={\\"1-item-properties\\"}>
26
+ <li>
27
+ <div
28
+ style={{
29
+ fontSize: \\"var(--ifm-code-font-size)\\",
30
+ opacity: \\"0.6\\",
31
+ marginLeft: \\"-.5rem\\",
32
+ paddingBottom: \\".5rem\\",
33
+ }}
34
+ >
35
+ Array [
36
+ </div>
37
+ </li>
38
+ <div
39
+ style={{
40
+ marginTop: \\".5rem\\",
41
+ marginBottom: \\".5rem\\",
42
+ marginLeft: \\"1rem\\",
43
+ }}
44
+ >
45
+ string
46
+ </div>
47
+ <li>
48
+ <div
49
+ style={{
50
+ fontSize: \\"var(--ifm-code-font-size)\\",
51
+ opacity: \\"0.6\\",
52
+ marginLeft: \\"-.5rem\\",
53
+ }}
54
+ >
55
+ ]
56
+ </div>
57
+ </li>
58
+ </TabItem>
59
+ <TabItem label={\\"MOD3\\"} value={\\"2-item-properties\\"}>
60
+ <div
61
+ style={{
62
+ marginTop: \\".5rem\\",
63
+ marginBottom: \\".5rem\\",
64
+ marginLeft: \\"1rem\\",
65
+ }}
66
+ >
67
+ boolean
68
+ </div>
69
+ </TabItem>
70
+ <TabItem label={\\"MOD4\\"} value={\\"3-item-properties\\"}>
71
+ <div
72
+ style={{
73
+ marginTop: \\".5rem\\",
74
+ marginBottom: \\".5rem\\",
75
+ marginLeft: \\"1rem\\",
76
+ }}
77
+ >
78
+ number
79
+ </div>
80
+ </TabItem>
81
+ <TabItem label={\\"MOD5\\"} value={\\"4-item-properties\\"}>
82
+ <div
83
+ style={{
84
+ marginTop: \\".5rem\\",
85
+ marginBottom: \\".5rem\\",
86
+ marginLeft: \\"1rem\\",
87
+ }}
88
+ >
89
+ string
90
+ </div>
91
+ </TabItem>
92
+ </SchemaTabs>
93
+ </div>
94
+ </details>
95
+ </SchemaItem>;
96
+ ",
97
+ ]
98
+ `;
@@ -24,7 +24,7 @@ export function createDeprecationNotice({
24
24
  createAdmonition({
25
25
  children:
26
26
  description ??
27
- "This endpoint has been deprecated and may be removed in future versions of the API.",
27
+ "This endpoint has been deprecated and may be replaced or removed in future versions of the API.",
28
28
  })
29
29
  );
30
30
  }
@@ -0,0 +1,56 @@
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 * as prettier from "prettier";
9
+
10
+ import { SchemaObject } from "../openapi/types";
11
+ import { createNodes } from "./createSchema";
12
+
13
+ describe("createNodes", () => {
14
+ it("should create readable MODs for oneOf primitive properties", () => {
15
+ const schema: SchemaObject = {
16
+ type: "object",
17
+ properties: {
18
+ oneOfProperty: {
19
+ oneOf: [
20
+ {
21
+ type: "object",
22
+ properties: {
23
+ noseLength: {
24
+ type: "number",
25
+ },
26
+ },
27
+ required: ["noseLength"],
28
+ description: "Clown's nose length",
29
+ },
30
+ {
31
+ type: "array",
32
+ items: {
33
+ type: "string",
34
+ },
35
+ description: "Array of strings",
36
+ },
37
+ {
38
+ type: "boolean",
39
+ },
40
+ {
41
+ type: "number",
42
+ },
43
+ {
44
+ type: "string",
45
+ },
46
+ ],
47
+ },
48
+ },
49
+ };
50
+ expect(
51
+ createNodes(schema).map((md: any) =>
52
+ prettier.format(md, { parser: "babel" })
53
+ )
54
+ ).toMatchSnapshot();
55
+ });
56
+ });
@@ -430,8 +430,6 @@ function createAnyOneOfProperty(
430
430
  required: string[] | boolean,
431
431
  nullable: boolean | unknown
432
432
  ): any {
433
- const type = schema.oneOf ? "oneOf" : "anyOf";
434
- const children = schema[type] || [];
435
433
  return create("SchemaItem", {
436
434
  collapsible: true,
437
435
  className: "schemaItem",
@@ -492,39 +490,7 @@ function createAnyOneOfProperty(
492
490
  ),
493
491
  ],
494
492
  }),
495
- create("div", {
496
- children: [
497
- create("span", {
498
- className: "badge badge--info",
499
- children: type,
500
- }),
501
- create("SchemaTabs", {
502
- children: children.map((property, index) => {
503
- const label = property.title ?? `MOD${index + 1}`;
504
- if (property.properties) {
505
- return create("TabItem", {
506
- label: label,
507
- value: `${index}-property`,
508
- children: [createNodes(property)],
509
- });
510
- }
511
- return create("TabItem", {
512
- label: label,
513
- value: `${index}-property`,
514
- children: [
515
- create("p", { children: label }),
516
- guard(schema.description, (description) =>
517
- create("div", {
518
- style: { marginTop: ".5rem", marginBottom: ".5rem" },
519
- children: createDescription(description),
520
- })
521
- ),
522
- ],
523
- });
524
- }),
525
- }),
526
- ],
527
- }),
493
+ createAnyOneOf(schema),
528
494
  ],
529
495
  }),
530
496
  ],
@@ -7,6 +7,7 @@
7
7
 
8
8
  import path from "path";
9
9
 
10
+ // eslint-disable-next-line import/no-extraneous-dependencies
10
11
  import { posixPath } from "@docusaurus/utils";
11
12
 
12
13
  import { readOpenapiFiles } from ".";
@@ -171,7 +171,18 @@ function createItems(
171
171
  }
172
172
 
173
173
  let jsonRequestBodyExample;
174
- const body = operationObject.requestBody?.content?.["application/json"];
174
+ const content = operationObject.requestBody?.content;
175
+ let body;
176
+ for (let key in content) {
177
+ if (
178
+ key.toLowerCase() === "application/json" ||
179
+ key.toLowerCase() === "application/json; charset=utf-8"
180
+ ) {
181
+ body = content[key];
182
+ break;
183
+ }
184
+ }
185
+
175
186
  if (body?.schema) {
176
187
  jsonRequestBodyExample = sampleRequestFromSchema(body.schema);
177
188
  }
@@ -304,7 +315,18 @@ function createItems(
304
315
  }
305
316
 
306
317
  let jsonRequestBodyExample;
307
- const body = operationObject.requestBody?.content?.["application/json"];
318
+ const content = operationObject.requestBody?.content;
319
+ let body;
320
+ for (let key in content) {
321
+ if (
322
+ key.toLowerCase() === "application/json" ||
323
+ key.toLowerCase() === "application/json; charset=utf-8"
324
+ ) {
325
+ body = content[key];
326
+ break;
327
+ }
328
+ }
329
+
308
330
  if (body?.schema) {
309
331
  jsonRequestBodyExample = sampleRequestFromSchema(body.schema);
310
332
  }