docusaurus-plugin-openapi-docs 1.5.1-hotfix1 → 1.5.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/LICENSE +21 -0
- package/lib/markdown/createArrayBracket.d.ts +2 -0
- package/lib/markdown/createArrayBracket.js +37 -0
- package/lib/markdown/createRequestSchema.js +119 -79
- package/lib/markdown/createResponseSchema.js +123 -82
- package/lib/markdown/createStatusCodes.js +4 -6
- package/lib/openapi/createRequestExample.js +26 -7
- package/lib/openapi/createResponseExample.js +26 -7
- package/lib/openapi/utils/loadAndResolveSpec.js +1 -1
- package/package.json +4 -3
- package/src/markdown/createArrayBracket.ts +35 -0
- package/src/markdown/createRequestSchema.ts +136 -95
- package/src/markdown/createResponseSchema.ts +143 -98
- package/src/markdown/createStatusCodes.ts +4 -8
- package/src/openapi/createRequestExample.ts +35 -12
- package/src/openapi/createResponseExample.ts +35 -12
- package/src/openapi/utils/loadAndResolveSpec.ts +1 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Palo Alto Networks
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,37 @@
|
|
|
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.createClosingArrayBracket = exports.createOpeningArrayBracket = void 0;
|
|
10
|
+
const utils_1 = require("./utils");
|
|
11
|
+
function createOpeningArrayBracket() {
|
|
12
|
+
return (0, utils_1.create)("li", {
|
|
13
|
+
children: (0, utils_1.create)("div", {
|
|
14
|
+
style: {
|
|
15
|
+
fontSize: "var(--ifm-code-font-size)",
|
|
16
|
+
opacity: "0.6",
|
|
17
|
+
marginLeft: "-.5rem",
|
|
18
|
+
paddingBottom: ".5rem",
|
|
19
|
+
},
|
|
20
|
+
children: ["Array ["],
|
|
21
|
+
}),
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
exports.createOpeningArrayBracket = createOpeningArrayBracket;
|
|
25
|
+
function createClosingArrayBracket() {
|
|
26
|
+
return (0, utils_1.create)("li", {
|
|
27
|
+
children: (0, utils_1.create)("div", {
|
|
28
|
+
style: {
|
|
29
|
+
fontSize: "var(--ifm-code-font-size)",
|
|
30
|
+
opacity: "0.6",
|
|
31
|
+
marginLeft: "-.5rem",
|
|
32
|
+
},
|
|
33
|
+
children: ["]"],
|
|
34
|
+
}),
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
exports.createClosingArrayBracket = createClosingArrayBracket;
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* ========================================================================== */
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.createRequestSchema = exports.mergeAllOf = void 0;
|
|
10
|
+
const createArrayBracket_1 = require("./createArrayBracket");
|
|
10
11
|
const createDescription_1 = require("./createDescription");
|
|
11
12
|
const createDetails_1 = require("./createDetails");
|
|
12
13
|
const createDetailsSummary_1 = require("./createDetailsSummary");
|
|
@@ -46,46 +47,55 @@ exports.mergeAllOf = mergeAllOf;
|
|
|
46
47
|
*/
|
|
47
48
|
function createAnyOneOf(schema) {
|
|
48
49
|
const type = schema.oneOf ? "oneOf" : "anyOf";
|
|
49
|
-
return (0, utils_1.create)("
|
|
50
|
+
return (0, utils_1.create)("li", {
|
|
50
51
|
children: [
|
|
51
|
-
(0, utils_1.create)("
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
52
|
+
(0, utils_1.create)("span", {
|
|
53
|
+
className: "badge badge--info",
|
|
54
|
+
children: type,
|
|
55
|
+
}),
|
|
56
|
+
(0, utils_1.create)("SchemaTabs", {
|
|
57
|
+
children: schema[type].map((anyOneSchema, index) => {
|
|
58
|
+
const label = anyOneSchema.title
|
|
59
|
+
? anyOneSchema.title
|
|
60
|
+
: `MOD${index + 1}`;
|
|
61
|
+
const anyOneChildren = [];
|
|
62
|
+
if (anyOneSchema.properties !== undefined) {
|
|
63
|
+
anyOneChildren.push(createProperties(anyOneSchema));
|
|
64
|
+
}
|
|
65
|
+
if (anyOneSchema.allOf !== undefined) {
|
|
66
|
+
anyOneChildren.push(createNodes(anyOneSchema));
|
|
67
|
+
}
|
|
68
|
+
if (anyOneSchema.items !== undefined) {
|
|
69
|
+
anyOneChildren.push(createItems(anyOneSchema));
|
|
70
|
+
}
|
|
71
|
+
if (anyOneSchema.type === "string" ||
|
|
72
|
+
anyOneSchema.type === "number" ||
|
|
73
|
+
anyOneSchema.type === "integer" ||
|
|
74
|
+
anyOneSchema.type === "boolean") {
|
|
75
|
+
anyOneChildren.push(createNodes(anyOneSchema));
|
|
76
|
+
}
|
|
77
|
+
if (anyOneChildren.length) {
|
|
78
|
+
if (schema.type === "array") {
|
|
79
|
+
return (0, utils_1.create)("TabItem", {
|
|
80
|
+
label: label,
|
|
81
|
+
value: `${index}-item-properties`,
|
|
82
|
+
children: [
|
|
83
|
+
(0, createArrayBracket_1.createOpeningArrayBracket)(),
|
|
84
|
+
anyOneChildren,
|
|
85
|
+
(0, createArrayBracket_1.createClosingArrayBracket)(),
|
|
86
|
+
]
|
|
87
|
+
.filter(Boolean)
|
|
88
|
+
.flat(),
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
return (0, utils_1.create)("TabItem", {
|
|
92
|
+
label: label,
|
|
93
|
+
value: `${index}-item-properties`,
|
|
94
|
+
children: anyOneChildren.filter(Boolean).flat(),
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
return undefined;
|
|
98
|
+
}),
|
|
89
99
|
}),
|
|
90
100
|
],
|
|
91
101
|
});
|
|
@@ -188,15 +198,27 @@ function createAdditionalProperties(schema) {
|
|
|
188
198
|
}
|
|
189
199
|
// TODO: figure out how to handle array of objects
|
|
190
200
|
function createItems(schema) {
|
|
191
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
201
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
192
202
|
if (((_a = schema.items) === null || _a === void 0 ? void 0 : _a.properties) !== undefined) {
|
|
193
|
-
return
|
|
203
|
+
return [
|
|
204
|
+
(0, createArrayBracket_1.createOpeningArrayBracket)(),
|
|
205
|
+
createProperties(schema.items),
|
|
206
|
+
(0, createArrayBracket_1.createClosingArrayBracket)(),
|
|
207
|
+
].flat();
|
|
194
208
|
}
|
|
195
209
|
if (((_b = schema.items) === null || _b === void 0 ? void 0 : _b.additionalProperties) !== undefined) {
|
|
196
|
-
return
|
|
210
|
+
return [
|
|
211
|
+
(0, createArrayBracket_1.createOpeningArrayBracket)(),
|
|
212
|
+
createAdditionalProperties(schema.items),
|
|
213
|
+
(0, createArrayBracket_1.createClosingArrayBracket)(),
|
|
214
|
+
].flat();
|
|
197
215
|
}
|
|
198
216
|
if (((_c = schema.items) === null || _c === void 0 ? void 0 : _c.oneOf) !== undefined || ((_d = schema.items) === null || _d === void 0 ? void 0 : _d.anyOf) !== undefined) {
|
|
199
|
-
return
|
|
217
|
+
return [
|
|
218
|
+
(0, createArrayBracket_1.createOpeningArrayBracket)(),
|
|
219
|
+
createAnyOneOf(schema.items),
|
|
220
|
+
(0, createArrayBracket_1.createClosingArrayBracket)(),
|
|
221
|
+
].flat();
|
|
200
222
|
}
|
|
201
223
|
if (((_e = schema.items) === null || _e === void 0 ? void 0 : _e.allOf) !== undefined) {
|
|
202
224
|
// TODO: figure out if and how we should pass merged required array
|
|
@@ -205,41 +227,54 @@ function createItems(schema) {
|
|
|
205
227
|
if ((mergedSchemas.oneOf !== undefined ||
|
|
206
228
|
mergedSchemas.anyOf !== undefined) &&
|
|
207
229
|
mergedSchemas.properties) {
|
|
208
|
-
return
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
230
|
+
return [
|
|
231
|
+
(0, createArrayBracket_1.createOpeningArrayBracket)(),
|
|
232
|
+
createAnyOneOf(mergedSchemas),
|
|
233
|
+
createProperties(mergedSchemas),
|
|
234
|
+
(0, createArrayBracket_1.createClosingArrayBracket)(),
|
|
235
|
+
].flat();
|
|
214
236
|
}
|
|
215
237
|
// Handles only anyOf/oneOf
|
|
216
238
|
if (mergedSchemas.oneOf !== undefined ||
|
|
217
239
|
mergedSchemas.anyOf !== undefined) {
|
|
218
|
-
return
|
|
219
|
-
|
|
220
|
-
|
|
240
|
+
return [
|
|
241
|
+
(0, createArrayBracket_1.createOpeningArrayBracket)(),
|
|
242
|
+
createAnyOneOf(mergedSchemas),
|
|
243
|
+
(0, createArrayBracket_1.createClosingArrayBracket)(),
|
|
244
|
+
].flat();
|
|
221
245
|
}
|
|
222
246
|
// Handles properties
|
|
223
247
|
if (mergedSchemas.properties !== undefined) {
|
|
224
|
-
return
|
|
225
|
-
|
|
226
|
-
|
|
248
|
+
return [
|
|
249
|
+
(0, createArrayBracket_1.createOpeningArrayBracket)(),
|
|
250
|
+
createProperties(mergedSchemas),
|
|
251
|
+
(0, createArrayBracket_1.createClosingArrayBracket)(),
|
|
252
|
+
].flat();
|
|
227
253
|
}
|
|
228
254
|
}
|
|
229
255
|
if (((_g = schema.items) === null || _g === void 0 ? void 0 : _g.type) === "string" ||
|
|
230
256
|
((_h = schema.items) === null || _h === void 0 ? void 0 : _h.type) === "number" ||
|
|
231
257
|
((_j = schema.items) === null || _j === void 0 ? void 0 : _j.type) === "integer" ||
|
|
232
|
-
((_k = schema.items) === null || _k === void 0 ? void 0 : _k.type) === "boolean"
|
|
233
|
-
|
|
258
|
+
((_k = schema.items) === null || _k === void 0 ? void 0 : _k.type) === "boolean" ||
|
|
259
|
+
((_l = schema.items) === null || _l === void 0 ? void 0 : _l.type) === "object") {
|
|
260
|
+
return [
|
|
261
|
+
(0, createArrayBracket_1.createOpeningArrayBracket)(),
|
|
262
|
+
createNodes(schema.items),
|
|
263
|
+
(0, createArrayBracket_1.createClosingArrayBracket)(),
|
|
264
|
+
].flat();
|
|
234
265
|
}
|
|
235
266
|
// TODO: clean this up or eliminate it?
|
|
236
|
-
return
|
|
237
|
-
|
|
238
|
-
schema
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
:
|
|
242
|
-
|
|
267
|
+
return [
|
|
268
|
+
(0, createArrayBracket_1.createOpeningArrayBracket)(),
|
|
269
|
+
Object.entries(schema.items).map(([key, val]) => createEdges({
|
|
270
|
+
name: key,
|
|
271
|
+
schema: val,
|
|
272
|
+
required: Array.isArray(schema.required)
|
|
273
|
+
? schema.required.includes(key)
|
|
274
|
+
: false,
|
|
275
|
+
})),
|
|
276
|
+
(0, createArrayBracket_1.createClosingArrayBracket)(),
|
|
277
|
+
].flat();
|
|
243
278
|
}
|
|
244
279
|
/**
|
|
245
280
|
* For handling discriminators that do not map to a same-level property
|
|
@@ -352,6 +387,15 @@ function createDetailsNode(name, schemaName, schema, required) {
|
|
|
352
387
|
style: { opacity: "0.6" },
|
|
353
388
|
children: ` ${schemaName}`,
|
|
354
389
|
}),
|
|
390
|
+
(0, utils_1.guard)(schema.nullable && schema.nullable === true, () => [
|
|
391
|
+
(0, utils_1.create)("strong", {
|
|
392
|
+
style: {
|
|
393
|
+
fontSize: "var(--ifm-code-font-size)",
|
|
394
|
+
color: "var(--openapi-nullable)",
|
|
395
|
+
},
|
|
396
|
+
children: " nullable",
|
|
397
|
+
}),
|
|
398
|
+
]),
|
|
355
399
|
(0, utils_1.guard)(Array.isArray(required)
|
|
356
400
|
? required.includes(name)
|
|
357
401
|
: required === true, () => [
|
|
@@ -480,11 +524,9 @@ function createEdges({ name, schema, required, discriminator, }) {
|
|
|
480
524
|
collapsible: false,
|
|
481
525
|
name,
|
|
482
526
|
required: Array.isArray(required) ? required.includes(name) : required,
|
|
483
|
-
deprecated: mergedSchemas.deprecated,
|
|
484
|
-
schemaDescription: mergedSchemas.description,
|
|
485
527
|
schemaName: schemaName,
|
|
486
528
|
qualifierMessage: (0, schema_1.getQualifierMessage)(schema),
|
|
487
|
-
|
|
529
|
+
schema: mergedSchemas,
|
|
488
530
|
});
|
|
489
531
|
}
|
|
490
532
|
if (schema.properties !== undefined) {
|
|
@@ -508,39 +550,41 @@ function createEdges({ name, schema, required, discriminator, }) {
|
|
|
508
550
|
collapsible: false,
|
|
509
551
|
name,
|
|
510
552
|
required: Array.isArray(required) ? required.includes(name) : required,
|
|
511
|
-
deprecated: schema.deprecated,
|
|
512
|
-
schemaDescription: schema.description,
|
|
513
553
|
schemaName: schemaName,
|
|
514
554
|
qualifierMessage: (0, schema_1.getQualifierMessage)(schema),
|
|
515
|
-
|
|
555
|
+
schema: schema,
|
|
516
556
|
});
|
|
517
557
|
}
|
|
518
558
|
/**
|
|
519
559
|
* Creates a hierarchical level of a schema tree. Nodes produce edges that can branch into sub-nodes with edges, recursively.
|
|
520
560
|
*/
|
|
521
561
|
function createNodes(schema) {
|
|
562
|
+
const nodes = [];
|
|
522
563
|
// if (schema.discriminator !== undefined) {
|
|
523
564
|
// return createDiscriminator(schema);
|
|
524
565
|
// }
|
|
525
566
|
if (schema.oneOf !== undefined || schema.anyOf !== undefined) {
|
|
526
|
-
|
|
567
|
+
nodes.push(createAnyOneOf(schema));
|
|
527
568
|
}
|
|
528
569
|
if (schema.allOf !== undefined) {
|
|
529
570
|
const { mergedSchemas } = mergeAllOf(schema.allOf);
|
|
530
571
|
// allOf seems to always result in properties
|
|
531
572
|
if (mergedSchemas.properties !== undefined) {
|
|
532
|
-
|
|
573
|
+
nodes.push(createProperties(mergedSchemas));
|
|
533
574
|
}
|
|
534
575
|
}
|
|
535
576
|
if (schema.properties !== undefined) {
|
|
536
|
-
|
|
577
|
+
nodes.push(createProperties(schema));
|
|
537
578
|
}
|
|
538
579
|
if (schema.additionalProperties !== undefined) {
|
|
539
|
-
|
|
580
|
+
nodes.push(createAdditionalProperties(schema));
|
|
540
581
|
}
|
|
541
582
|
// TODO: figure out how to handle array of objects
|
|
542
583
|
if (schema.items !== undefined) {
|
|
543
|
-
|
|
584
|
+
nodes.push(createItems(schema));
|
|
585
|
+
}
|
|
586
|
+
if (nodes.length && nodes.length > 0) {
|
|
587
|
+
return nodes.filter(Boolean).flat();
|
|
544
588
|
}
|
|
545
589
|
// primitive
|
|
546
590
|
if (schema.type !== undefined) {
|
|
@@ -603,10 +647,6 @@ function createRequestSchema({ title, body, ...rest }) {
|
|
|
603
647
|
style: { textAlign: "left" },
|
|
604
648
|
children: [
|
|
605
649
|
(0, utils_1.create)("strong", { children: `${title}` }),
|
|
606
|
-
(0, utils_1.guard)(firstBody.type === "array", (format) => (0, utils_1.create)("span", {
|
|
607
|
-
style: { opacity: "0.6" },
|
|
608
|
-
children: ` array`,
|
|
609
|
-
})),
|
|
610
650
|
(0, utils_1.guard)(body.required && body.required === true, () => [
|
|
611
651
|
(0, utils_1.create)("strong", {
|
|
612
652
|
style: {
|