docusaurus-plugin-openapi-docs 1.1.4 → 1.1.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.
- package/lib/markdown/createRequestBodyDetails.d.ts +9 -2
- package/lib/markdown/createRequestBodyDetails.js +2 -2
- package/lib/markdown/createRequestSchema.d.ts +21 -0
- package/lib/markdown/createRequestSchema.js +680 -0
- package/lib/markdown/{createSchemaDetails.d.ts → createResponseSchema.d.ts} +2 -2
- package/lib/markdown/{createSchemaDetails.js → createResponseSchema.js} +126 -46
- package/lib/markdown/createStatusCodes.js +10 -7
- package/lib/markdown/index.js +5 -1
- package/lib/openapi/createExample.js +27 -14
- package/lib/openapi/openapi.d.ts +1 -1
- package/lib/openapi/openapi.js +21 -10
- package/lib/openapi/types.d.ts +1 -1
- package/lib/sidebars/index.d.ts +1 -1
- package/lib/sidebars/index.js +11 -3
- package/package.json +2 -2
- package/src/markdown/createRequestBodyDetails.ts +11 -4
- package/src/markdown/createRequestSchema.ts +848 -0
- package/src/markdown/{createSchemaDetails.ts → createResponseSchema.ts} +143 -55
- package/src/markdown/createStatusCodes.ts +13 -7
- package/src/markdown/index.ts +17 -1
- package/src/openapi/createExample.ts +31 -14
- package/src/openapi/openapi.ts +16 -8
- package/src/openapi/types.ts +1 -1
- package/src/sidebars/index.ts +13 -5
|
@@ -7,8 +7,8 @@ interface Props {
|
|
|
7
7
|
[key: string]: MediaTypeObject;
|
|
8
8
|
};
|
|
9
9
|
description?: string;
|
|
10
|
-
required?: boolean;
|
|
10
|
+
required?: string[] | boolean;
|
|
11
11
|
};
|
|
12
12
|
}
|
|
13
|
-
export declare function
|
|
13
|
+
export declare function createResponseSchema({ title, body, ...rest }: Props): string | undefined;
|
|
14
14
|
export {};
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
* ========================================================================== */
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.
|
|
9
|
+
exports.createResponseSchema = void 0;
|
|
10
10
|
const createDescription_1 = require("./createDescription");
|
|
11
11
|
const createDetails_1 = require("./createDetails");
|
|
12
12
|
const createDetailsSummary_1 = require("./createDetailsSummary");
|
|
@@ -192,7 +192,8 @@ function createItems(schema) {
|
|
|
192
192
|
return createAnyOneOf(schema.items);
|
|
193
193
|
}
|
|
194
194
|
if (((_e = schema.items) === null || _e === void 0 ? void 0 : _e.allOf) !== undefined) {
|
|
195
|
-
|
|
195
|
+
// TODO: figure out if and how we should pass merged required array
|
|
196
|
+
const { mergedSchemas, } = mergeAllOf((_f = schema.items) === null || _f === void 0 ? void 0 : _f.allOf);
|
|
196
197
|
// Handles combo anyOf/oneOf + properties
|
|
197
198
|
if ((mergedSchemas.oneOf !== undefined ||
|
|
198
199
|
mergedSchemas.anyOf !== undefined) &&
|
|
@@ -331,7 +332,7 @@ function createDetailsNode(name, schemaName, schema, required) {
|
|
|
331
332
|
style: { opacity: "0.6" },
|
|
332
333
|
children: ` ${schemaName}`,
|
|
333
334
|
}),
|
|
334
|
-
(0, utils_1.guard)(required, () => [
|
|
335
|
+
(0, utils_1.guard)(schema.required && schema.required === true, () => [
|
|
335
336
|
(0, utils_1.create)("strong", {
|
|
336
337
|
style: {
|
|
337
338
|
fontSize: "var(--ifm-code-font-size)",
|
|
@@ -427,6 +428,7 @@ function createPropertyDiscriminator(name, schemaName, schema, discriminator, re
|
|
|
427
428
|
function createEdges({ name, schema, required, discriminator, }) {
|
|
428
429
|
var _a, _b;
|
|
429
430
|
const schemaName = (0, schema_1.getSchemaName)(schema);
|
|
431
|
+
// if (name === "id") console.log(name, schema, required);
|
|
430
432
|
if (discriminator !== undefined && discriminator.propertyName === name) {
|
|
431
433
|
return createPropertyDiscriminator(name, "string", schema, discriminator, required);
|
|
432
434
|
}
|
|
@@ -450,14 +452,17 @@ function createEdges({ name, schema, required, discriminator, }) {
|
|
|
450
452
|
if (((_a = mergedSchemas.items) === null || _a === void 0 ? void 0 : _a.properties) !== undefined) {
|
|
451
453
|
return createDetailsNode(name, mergedSchemaName, mergedSchemas, required);
|
|
452
454
|
}
|
|
455
|
+
if (mergedSchemas.writeOnly && mergedSchemas.writeOnly === true) {
|
|
456
|
+
return undefined;
|
|
457
|
+
}
|
|
453
458
|
return (0, utils_1.create)("SchemaItem", {
|
|
454
459
|
collapsible: false,
|
|
455
460
|
name,
|
|
456
|
-
required,
|
|
461
|
+
required: false,
|
|
457
462
|
schemaDescription: mergedSchemas.description,
|
|
458
463
|
schemaName: schemaName,
|
|
459
464
|
qualifierMessage: (0, schema_1.getQualifierMessage)(schema),
|
|
460
|
-
defaultValue:
|
|
465
|
+
defaultValue: mergedSchemas.default,
|
|
461
466
|
});
|
|
462
467
|
}
|
|
463
468
|
if (schema.properties !== undefined) {
|
|
@@ -470,11 +475,14 @@ function createEdges({ name, schema, required, discriminator, }) {
|
|
|
470
475
|
if (((_b = schema.items) === null || _b === void 0 ? void 0 : _b.properties) !== undefined) {
|
|
471
476
|
return createDetailsNode(name, schemaName, schema, required);
|
|
472
477
|
}
|
|
478
|
+
if (schema.writeOnly && schema.writeOnly === true) {
|
|
479
|
+
return undefined;
|
|
480
|
+
}
|
|
473
481
|
// primitives and array of non-objects
|
|
474
482
|
return (0, utils_1.create)("SchemaItem", {
|
|
475
483
|
collapsible: false,
|
|
476
484
|
name,
|
|
477
|
-
required,
|
|
485
|
+
required: false,
|
|
478
486
|
schemaDescription: schema.description,
|
|
479
487
|
schemaName: schemaName,
|
|
480
488
|
qualifierMessage: (0, schema_1.getQualifierMessage)(schema),
|
|
@@ -534,15 +542,78 @@ function createNodes(schema) {
|
|
|
534
542
|
// So far, haven't seen this hit in testing
|
|
535
543
|
return undefined;
|
|
536
544
|
}
|
|
537
|
-
function
|
|
545
|
+
function createResponseSchema({ title, body, ...rest }) {
|
|
538
546
|
if (body === undefined ||
|
|
539
547
|
body.content === undefined ||
|
|
540
548
|
Object.keys(body).length === 0 ||
|
|
541
549
|
Object.keys(body.content).length === 0) {
|
|
542
550
|
return undefined;
|
|
543
551
|
}
|
|
544
|
-
//
|
|
545
|
-
|
|
552
|
+
// Get all MIME types, including vendor-specific
|
|
553
|
+
const mimeTypes = Object.keys(body.content);
|
|
554
|
+
if (mimeTypes && mimeTypes.length > 1) {
|
|
555
|
+
return (0, utils_1.create)("MimeTabs", {
|
|
556
|
+
groupId: "mime-type",
|
|
557
|
+
children: mimeTypes.map((mimeType) => {
|
|
558
|
+
const firstBody = body.content[mimeType].schema;
|
|
559
|
+
if (firstBody === undefined) {
|
|
560
|
+
return undefined;
|
|
561
|
+
}
|
|
562
|
+
if (firstBody.properties !== undefined) {
|
|
563
|
+
if (Object.keys(firstBody.properties).length === 0) {
|
|
564
|
+
return undefined;
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
return (0, utils_1.create)("TabItem", {
|
|
568
|
+
label: mimeType,
|
|
569
|
+
value: `${mimeType}`,
|
|
570
|
+
children: [
|
|
571
|
+
(0, createDetails_1.createDetails)({
|
|
572
|
+
"data-collapsed": false,
|
|
573
|
+
open: true,
|
|
574
|
+
...rest,
|
|
575
|
+
children: [
|
|
576
|
+
(0, createDetailsSummary_1.createDetailsSummary)({
|
|
577
|
+
style: { textAlign: "left" },
|
|
578
|
+
children: [
|
|
579
|
+
(0, utils_1.create)("strong", { children: `${title}` }),
|
|
580
|
+
(0, utils_1.guard)(firstBody.type === "array", (format) => (0, utils_1.create)("span", {
|
|
581
|
+
style: { opacity: "0.6" },
|
|
582
|
+
children: ` array`,
|
|
583
|
+
})),
|
|
584
|
+
(0, utils_1.guard)(body.required && body.required === true, () => [
|
|
585
|
+
(0, utils_1.create)("strong", {
|
|
586
|
+
style: {
|
|
587
|
+
fontSize: "var(--ifm-code-font-size)",
|
|
588
|
+
color: "var(--openapi-required)",
|
|
589
|
+
},
|
|
590
|
+
children: " required",
|
|
591
|
+
}),
|
|
592
|
+
]),
|
|
593
|
+
],
|
|
594
|
+
}),
|
|
595
|
+
(0, utils_1.create)("div", {
|
|
596
|
+
style: { textAlign: "left", marginLeft: "1rem" },
|
|
597
|
+
children: [
|
|
598
|
+
(0, utils_1.guard)(body.description, () => [
|
|
599
|
+
(0, utils_1.create)("div", {
|
|
600
|
+
style: { marginTop: "1rem", marginBottom: "1rem" },
|
|
601
|
+
children: (0, createDescription_1.createDescription)(body.description),
|
|
602
|
+
}),
|
|
603
|
+
]),
|
|
604
|
+
],
|
|
605
|
+
}),
|
|
606
|
+
(0, utils_1.create)("ul", {
|
|
607
|
+
style: { marginLeft: "1rem" },
|
|
608
|
+
children: createNodes(firstBody),
|
|
609
|
+
}),
|
|
610
|
+
],
|
|
611
|
+
}),
|
|
612
|
+
],
|
|
613
|
+
});
|
|
614
|
+
}),
|
|
615
|
+
});
|
|
616
|
+
}
|
|
546
617
|
const randomFirstKey = Object.keys(body.content)[0];
|
|
547
618
|
const firstBody = body.content[randomFirstKey].schema;
|
|
548
619
|
if (firstBody === undefined) {
|
|
@@ -554,47 +625,56 @@ function createSchemaDetails({ title, body, ...rest }) {
|
|
|
554
625
|
return undefined;
|
|
555
626
|
}
|
|
556
627
|
}
|
|
557
|
-
|
|
558
|
-
return (0, createDetails_1.createDetails)({
|
|
559
|
-
"data-collapsed": false,
|
|
560
|
-
open: true,
|
|
561
|
-
...rest,
|
|
628
|
+
return (0, utils_1.create)("MimeTabs", {
|
|
562
629
|
children: [
|
|
563
|
-
(0,
|
|
564
|
-
|
|
630
|
+
(0, utils_1.create)("TabItem", {
|
|
631
|
+
label: randomFirstKey,
|
|
632
|
+
value: `${randomFirstKey}-schema`,
|
|
565
633
|
children: [
|
|
566
|
-
(0,
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
634
|
+
(0, createDetails_1.createDetails)({
|
|
635
|
+
"data-collapsed": false,
|
|
636
|
+
open: true,
|
|
637
|
+
...rest,
|
|
638
|
+
children: [
|
|
639
|
+
(0, createDetailsSummary_1.createDetailsSummary)({
|
|
640
|
+
style: { textAlign: "left" },
|
|
641
|
+
children: [
|
|
642
|
+
(0, utils_1.create)("strong", { children: `${title}` }),
|
|
643
|
+
(0, utils_1.guard)(firstBody.type === "array", (format) => (0, utils_1.create)("span", {
|
|
644
|
+
style: { opacity: "0.6" },
|
|
645
|
+
children: ` array`,
|
|
646
|
+
})),
|
|
647
|
+
(0, utils_1.guard)(body.required, () => [
|
|
648
|
+
(0, utils_1.create)("strong", {
|
|
649
|
+
style: {
|
|
650
|
+
fontSize: "var(--ifm-code-font-size)",
|
|
651
|
+
color: "var(--openapi-required)",
|
|
652
|
+
},
|
|
653
|
+
children: " required",
|
|
654
|
+
}),
|
|
655
|
+
]),
|
|
656
|
+
],
|
|
657
|
+
}),
|
|
658
|
+
(0, utils_1.create)("div", {
|
|
659
|
+
style: { textAlign: "left", marginLeft: "1rem" },
|
|
660
|
+
children: [
|
|
661
|
+
(0, utils_1.guard)(body.description, () => [
|
|
662
|
+
(0, utils_1.create)("div", {
|
|
663
|
+
style: { marginTop: "1rem", marginBottom: "1rem" },
|
|
664
|
+
children: (0, createDescription_1.createDescription)(body.description),
|
|
665
|
+
}),
|
|
666
|
+
]),
|
|
667
|
+
],
|
|
668
|
+
}),
|
|
669
|
+
(0, utils_1.create)("ul", {
|
|
670
|
+
style: { marginLeft: "1rem" },
|
|
671
|
+
children: createNodes(firstBody),
|
|
672
|
+
}),
|
|
673
|
+
],
|
|
674
|
+
}),
|
|
591
675
|
],
|
|
592
676
|
}),
|
|
593
|
-
(0, utils_1.create)("ul", {
|
|
594
|
-
style: { marginLeft: "1rem" },
|
|
595
|
-
children: createNodes(firstBody),
|
|
596
|
-
}),
|
|
597
677
|
],
|
|
598
678
|
});
|
|
599
679
|
}
|
|
600
|
-
exports.
|
|
680
|
+
exports.createResponseSchema = createResponseSchema;
|
|
@@ -10,7 +10,7 @@ exports.createStatusCodes = void 0;
|
|
|
10
10
|
const createDescription_1 = require("./createDescription");
|
|
11
11
|
const createDetails_1 = require("./createDetails");
|
|
12
12
|
const createDetailsSummary_1 = require("./createDetailsSummary");
|
|
13
|
-
const
|
|
13
|
+
const createResponseSchema_1 = require("./createResponseSchema");
|
|
14
14
|
const utils_1 = require("./utils");
|
|
15
15
|
const utils_2 = require("./utils");
|
|
16
16
|
function createResponseHeaders(responseHeaders) {
|
|
@@ -55,6 +55,7 @@ function createResponseHeaders(responseHeaders) {
|
|
|
55
55
|
}
|
|
56
56
|
function createResponseExamples(responseExamples) {
|
|
57
57
|
return Object.entries(responseExamples).map(([exampleName, exampleValue]) => {
|
|
58
|
+
var _a;
|
|
58
59
|
const camelToSpaceName = exampleName.replace(/([A-Z])/g, " $1");
|
|
59
60
|
let finalFormattedName = camelToSpaceName.charAt(0).toUpperCase() + camelToSpaceName.slice(1);
|
|
60
61
|
return (0, utils_1.create)("TabItem", {
|
|
@@ -62,7 +63,7 @@ function createResponseExamples(responseExamples) {
|
|
|
62
63
|
value: `${finalFormattedName}`,
|
|
63
64
|
children: [
|
|
64
65
|
(0, utils_1.create)("ResponseSamples", {
|
|
65
|
-
responseExample: JSON.stringify(exampleValue.value, null, 2),
|
|
66
|
+
responseExample: JSON.stringify((_a = exampleValue.value) !== null && _a !== void 0 ? _a : exampleValue, null, 2),
|
|
66
67
|
}),
|
|
67
68
|
],
|
|
68
69
|
});
|
|
@@ -83,7 +84,9 @@ function createStatusCodes({ responses }) {
|
|
|
83
84
|
const responseHeaders = responses[code].headers;
|
|
84
85
|
const responseContent = responses[code].content;
|
|
85
86
|
const responseContentKey = responseContent && Object.keys(responseContent)[0];
|
|
86
|
-
const responseExamples = responseContentKey &&
|
|
87
|
+
const responseExamples = responseContentKey &&
|
|
88
|
+
(responseContent[responseContentKey].examples ||
|
|
89
|
+
responseContent[responseContentKey].example);
|
|
87
90
|
return (0, utils_1.create)("TabItem", {
|
|
88
91
|
label: code,
|
|
89
92
|
value: code,
|
|
@@ -101,7 +104,7 @@ function createStatusCodes({ responses }) {
|
|
|
101
104
|
(0, createDetails_1.createDetails)({
|
|
102
105
|
"data-collaposed": false,
|
|
103
106
|
open: true,
|
|
104
|
-
style: { textAlign: "left" },
|
|
107
|
+
style: { textAlign: "left", marginBottom: "1rem" },
|
|
105
108
|
children: [
|
|
106
109
|
(0, createDetailsSummary_1.createDetailsSummary)({
|
|
107
110
|
children: [
|
|
@@ -114,7 +117,7 @@ function createStatusCodes({ responses }) {
|
|
|
114
117
|
],
|
|
115
118
|
}),
|
|
116
119
|
(0, utils_1.create)("div", {
|
|
117
|
-
children: (0,
|
|
120
|
+
children: (0, createResponseSchema_1.createResponseSchema)({
|
|
118
121
|
title: "Schema",
|
|
119
122
|
body: {
|
|
120
123
|
content: responses[code].content,
|
|
@@ -126,7 +129,7 @@ function createStatusCodes({ responses }) {
|
|
|
126
129
|
createResponseExamples(responseExamples),
|
|
127
130
|
],
|
|
128
131
|
})),
|
|
129
|
-
(0, utils_2.guard)(responseHeaders, () => (0, createDetails_1.createDetails)({
|
|
132
|
+
(0, utils_2.guard)(responseHeaders && !responseExamples, () => (0, createDetails_1.createDetails)({
|
|
130
133
|
"data-collaposed": false,
|
|
131
134
|
open: true,
|
|
132
135
|
style: { textAlign: "left" },
|
|
@@ -140,7 +143,7 @@ function createStatusCodes({ responses }) {
|
|
|
140
143
|
],
|
|
141
144
|
})),
|
|
142
145
|
(0, utils_2.guard)(!responseExamples, () => (0, utils_1.create)("div", {
|
|
143
|
-
children: (0,
|
|
146
|
+
children: (0, createResponseSchema_1.createResponseSchema)({
|
|
144
147
|
title: "Schema",
|
|
145
148
|
body: {
|
|
146
149
|
content: responses[code].content,
|
package/lib/markdown/index.js
CHANGED
|
@@ -23,6 +23,7 @@ const utils_1 = require("./utils");
|
|
|
23
23
|
function createApiPageMD({ title, api: { deprecated, "x-deprecated-description": deprecatedDescription, description, parameters, requestBody, responses, }, }) {
|
|
24
24
|
return (0, utils_1.render)([
|
|
25
25
|
`import ApiTabs from "@theme/ApiTabs";\n`,
|
|
26
|
+
`import MimeTabs from "@theme/MimeTabs";\n`,
|
|
26
27
|
`import ParamsItem from "@theme/ParamsItem";\n`,
|
|
27
28
|
`import ResponseSamples from "@theme/ResponseSamples";\n`,
|
|
28
29
|
`import SchemaItem from "@theme/SchemaItem"\n`,
|
|
@@ -36,7 +37,10 @@ function createApiPageMD({ title, api: { deprecated, "x-deprecated-description":
|
|
|
36
37
|
(0, createParamsDetails_1.createParamsDetails)({ parameters, type: "query" }),
|
|
37
38
|
(0, createParamsDetails_1.createParamsDetails)({ parameters, type: "header" }),
|
|
38
39
|
(0, createParamsDetails_1.createParamsDetails)({ parameters, type: "cookie" }),
|
|
39
|
-
(0, createRequestBodyDetails_1.createRequestBodyDetails)({
|
|
40
|
+
(0, createRequestBodyDetails_1.createRequestBodyDetails)({
|
|
41
|
+
title: "Request Body",
|
|
42
|
+
body: requestBody,
|
|
43
|
+
}),
|
|
40
44
|
(0, createStatusCodes_1.createStatusCodes)({ responses }),
|
|
41
45
|
]);
|
|
42
46
|
}
|
|
@@ -11,11 +11,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.sampleFromSchema = void 0;
|
|
13
13
|
const chalk_1 = __importDefault(require("chalk"));
|
|
14
|
+
const createRequestSchema_1 = require("../markdown/createRequestSchema");
|
|
14
15
|
const primitives = {
|
|
15
16
|
string: {
|
|
16
17
|
default: () => "string",
|
|
17
18
|
email: () => "user@example.com",
|
|
18
19
|
date: () => new Date().toISOString().substring(0, 10),
|
|
20
|
+
"date-time": () => new Date().toISOString().substring(0, 10),
|
|
19
21
|
uuid: () => "3fa85f64-5717-4562-b3fc-2c963f66afa6",
|
|
20
22
|
hostname: () => "example.com",
|
|
21
23
|
ipv4: () => "198.51.100.42",
|
|
@@ -41,21 +43,15 @@ const sampleFromSchema = (schema = {}) => {
|
|
|
41
43
|
return example;
|
|
42
44
|
}
|
|
43
45
|
if (allOf) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
for (let item of allOf) {
|
|
51
|
-
if (item.properties) {
|
|
52
|
-
obj.properties = {
|
|
53
|
-
...obj.properties,
|
|
54
|
-
...item.properties,
|
|
55
|
-
};
|
|
46
|
+
const { mergedSchemas } = (0, createRequestSchema_1.mergeAllOf)(allOf);
|
|
47
|
+
if (mergedSchemas.properties) {
|
|
48
|
+
for (const [key, value] of Object.entries(mergedSchemas.properties)) {
|
|
49
|
+
if (value.readOnly && value.readOnly === true) {
|
|
50
|
+
delete mergedSchemas.properties[key];
|
|
51
|
+
}
|
|
56
52
|
}
|
|
57
53
|
}
|
|
58
|
-
return (0, exports.sampleFromSchema)(
|
|
54
|
+
return (0, exports.sampleFromSchema)(mergedSchemas);
|
|
59
55
|
}
|
|
60
56
|
if (!type) {
|
|
61
57
|
if (properties) {
|
|
@@ -71,6 +67,20 @@ const sampleFromSchema = (schema = {}) => {
|
|
|
71
67
|
if (type === "object") {
|
|
72
68
|
let obj = {};
|
|
73
69
|
for (let [name, prop] of Object.entries(properties !== null && properties !== void 0 ? properties : {})) {
|
|
70
|
+
if (prop.properties) {
|
|
71
|
+
for (const [key, value] of Object.entries(prop.properties)) {
|
|
72
|
+
if (value.readOnly && value.readOnly === true) {
|
|
73
|
+
delete prop.properties[key];
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (prop.items && prop.items.properties) {
|
|
78
|
+
for (const [key, value] of Object.entries(prop.items.properties)) {
|
|
79
|
+
if (value.readOnly && value.readOnly === true) {
|
|
80
|
+
delete prop.items.properties[key];
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
74
84
|
if (prop.deprecated) {
|
|
75
85
|
continue;
|
|
76
86
|
}
|
|
@@ -93,6 +103,9 @@ const sampleFromSchema = (schema = {}) => {
|
|
|
93
103
|
}
|
|
94
104
|
return normalizeArray(schema.enum)[0];
|
|
95
105
|
}
|
|
106
|
+
if (schema.readOnly && schema.readOnly === true) {
|
|
107
|
+
return undefined;
|
|
108
|
+
}
|
|
96
109
|
return primitive(schema);
|
|
97
110
|
}
|
|
98
111
|
catch (err) {
|
|
@@ -106,7 +119,7 @@ function primitive(schema = {}) {
|
|
|
106
119
|
if (type === undefined) {
|
|
107
120
|
return;
|
|
108
121
|
}
|
|
109
|
-
let fn = primitives[type].default;
|
|
122
|
+
let fn = schema.default ? () => schema.default : primitives[type].default;
|
|
110
123
|
if (format !== undefined) {
|
|
111
124
|
fn = primitives[type][format] || fn;
|
|
112
125
|
}
|
package/lib/openapi/openapi.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ interface OpenApiFiles {
|
|
|
6
6
|
data: OpenApiObject;
|
|
7
7
|
}
|
|
8
8
|
export declare function readOpenapiFiles(openapiPath: string, options: APIOptions): Promise<OpenApiFiles[]>;
|
|
9
|
-
export declare function processOpenapiFiles(files: OpenApiFiles[], sidebarOptions: SidebarOptions): Promise<[ApiMetadata[], TagObject[]]>;
|
|
9
|
+
export declare function processOpenapiFiles(files: OpenApiFiles[], sidebarOptions: SidebarOptions): Promise<[ApiMetadata[], TagObject[][]]>;
|
|
10
10
|
export declare function processOpenapiFile(openapiData: OpenApiObject, sidebarOptions: SidebarOptions): Promise<[ApiMetadata[], TagObject[]]>;
|
|
11
11
|
export declare function getTagDisplayName(tagName: string, tags: TagObject[]): string;
|
|
12
12
|
export {};
|
package/lib/openapi/openapi.js
CHANGED
|
@@ -59,7 +59,7 @@ async function createPostmanCollection(openapiData) {
|
|
|
59
59
|
return await jsonToCollection(data);
|
|
60
60
|
}
|
|
61
61
|
function createItems(openapiData, sidebarOptions) {
|
|
62
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p
|
|
62
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
63
63
|
// TODO: Find a better way to handle this
|
|
64
64
|
let items = [];
|
|
65
65
|
const infoId = (0, kebabCase_1.default)(openapiData.info.title);
|
|
@@ -100,8 +100,8 @@ function createItems(openapiData, sidebarOptions) {
|
|
|
100
100
|
securitySchemes: (_b = openapiData.components) === null || _b === void 0 ? void 0 : _b.securitySchemes,
|
|
101
101
|
info: {
|
|
102
102
|
...openapiData.info,
|
|
103
|
-
tags:
|
|
104
|
-
title: (
|
|
103
|
+
tags: openapiData.tags,
|
|
104
|
+
title: (_c = openapiData.info.title) !== null && _c !== void 0 ? _c : "Introduction",
|
|
105
105
|
logo: openapiData.info["x-logo"],
|
|
106
106
|
darkLogo: openapiData.info["x-dark-logo"],
|
|
107
107
|
},
|
|
@@ -111,18 +111,18 @@ function createItems(openapiData, sidebarOptions) {
|
|
|
111
111
|
for (let [path, pathObject] of Object.entries(openapiData.paths)) {
|
|
112
112
|
const { $ref, description, parameters, servers, summary, ...rest } = pathObject;
|
|
113
113
|
for (let [method, operationObject] of Object.entries({ ...rest })) {
|
|
114
|
-
const title = (
|
|
114
|
+
const title = (_e = (_d = operationObject.summary) !== null && _d !== void 0 ? _d : operationObject.operationId) !== null && _e !== void 0 ? _e : "Missing summary";
|
|
115
115
|
if (operationObject.description === undefined) {
|
|
116
116
|
operationObject.description =
|
|
117
|
-
(
|
|
117
|
+
(_g = (_f = operationObject.summary) !== null && _f !== void 0 ? _f : operationObject.operationId) !== null && _g !== void 0 ? _g : "";
|
|
118
118
|
}
|
|
119
119
|
const baseId = operationObject.operationId
|
|
120
120
|
? (0, kebabCase_1.default)(operationObject.operationId)
|
|
121
121
|
: (0, kebabCase_1.default)(operationObject.summary);
|
|
122
|
-
const servers = (
|
|
123
|
-
const security = (
|
|
122
|
+
const servers = (_j = (_h = operationObject.servers) !== null && _h !== void 0 ? _h : pathObject.servers) !== null && _j !== void 0 ? _j : openapiData.servers;
|
|
123
|
+
const security = (_k = operationObject.security) !== null && _k !== void 0 ? _k : openapiData.security;
|
|
124
124
|
// Add security schemes so we know how to handle security.
|
|
125
|
-
const securitySchemes = (
|
|
125
|
+
const securitySchemes = (_l = openapiData.components) === null || _l === void 0 ? void 0 : _l.securitySchemes;
|
|
126
126
|
// Make sure schemes are lowercase. See: https://github.com/cloud-annotations/docusaurus-plugin-openapi/issues/79
|
|
127
127
|
if (securitySchemes) {
|
|
128
128
|
for (let securityScheme of Object.values(securitySchemes)) {
|
|
@@ -132,10 +132,21 @@ function createItems(openapiData, sidebarOptions) {
|
|
|
132
132
|
}
|
|
133
133
|
}
|
|
134
134
|
let jsonRequestBodyExample;
|
|
135
|
-
const body = (
|
|
135
|
+
const body = (_o = (_m = operationObject.requestBody) === null || _m === void 0 ? void 0 : _m.content) === null || _o === void 0 ? void 0 : _o["application/json"];
|
|
136
136
|
if (body === null || body === void 0 ? void 0 : body.schema) {
|
|
137
137
|
jsonRequestBodyExample = (0, createExample_1.sampleFromSchema)(body.schema);
|
|
138
138
|
}
|
|
139
|
+
// Handle vendor JSON media types
|
|
140
|
+
const bodyContent = (_p = operationObject.requestBody) === null || _p === void 0 ? void 0 : _p.content;
|
|
141
|
+
if (bodyContent) {
|
|
142
|
+
const firstBodyContentKey = Object.keys(bodyContent)[0];
|
|
143
|
+
if (firstBodyContentKey.endsWith("+json")) {
|
|
144
|
+
const firstBody = bodyContent[firstBodyContentKey];
|
|
145
|
+
if (firstBody === null || firstBody === void 0 ? void 0 : firstBody.schema) {
|
|
146
|
+
jsonRequestBodyExample = (0, createExample_1.sampleFromSchema)(firstBody.schema);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
139
150
|
// TODO: Don't include summary temporarilly
|
|
140
151
|
const { summary, ...defaults } = operationObject;
|
|
141
152
|
const apiPage = {
|
|
@@ -148,7 +159,7 @@ function createItems(openapiData, sidebarOptions) {
|
|
|
148
159
|
frontMatter: {},
|
|
149
160
|
api: {
|
|
150
161
|
...defaults,
|
|
151
|
-
tags:
|
|
162
|
+
tags: operationObject.tags,
|
|
152
163
|
method,
|
|
153
164
|
path,
|
|
154
165
|
servers,
|
package/lib/openapi/types.d.ts
CHANGED
package/lib/sidebars/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { ProcessedSidebar } from "@docusaurus/plugin-content-docs/src/sidebars/types";
|
|
2
2
|
import { TagObject } from "../openapi/types";
|
|
3
3
|
import type { SidebarOptions, APIOptions, ApiMetadata } from "../types";
|
|
4
|
-
export default function generateSidebarSlice(sidebarOptions: SidebarOptions, options: APIOptions, api: ApiMetadata[], tags: TagObject[], docPath: string): ProcessedSidebar;
|
|
4
|
+
export default function generateSidebarSlice(sidebarOptions: SidebarOptions, options: APIOptions, api: ApiMetadata[], tags: TagObject[][], docPath: string): ProcessedSidebar;
|
package/lib/sidebars/index.js
CHANGED
|
@@ -33,9 +33,16 @@ function groupByTags(items, sidebarOptions, options, tags, docPath) {
|
|
|
33
33
|
};
|
|
34
34
|
});
|
|
35
35
|
// TODO: make sure we only take the first tag
|
|
36
|
-
const
|
|
36
|
+
const operationTags = (0, uniq_1.default)(apiItems
|
|
37
37
|
.flatMap((item) => item.api.tags)
|
|
38
38
|
.filter((item) => !!item));
|
|
39
|
+
// Only include operation tags that are globally defined
|
|
40
|
+
const apiTags = [];
|
|
41
|
+
tags.flat().forEach((tag) => {
|
|
42
|
+
if (operationTags.includes(tag.name)) {
|
|
43
|
+
apiTags.push(tag.name);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
39
46
|
const basePath = docPath
|
|
40
47
|
? outputDir.split(docPath)[1].replace(/^\/+/g, "")
|
|
41
48
|
: outputDir.slice(outputDir.indexOf("/", 1)).replace(/^\/+/g, "");
|
|
@@ -66,11 +73,12 @@ function groupByTags(items, sidebarOptions, options, tags, docPath) {
|
|
|
66
73
|
}
|
|
67
74
|
const tagged = apiTags
|
|
68
75
|
.map((tag) => {
|
|
76
|
+
var _a;
|
|
69
77
|
// Map info object to tag
|
|
70
78
|
const taggedInfoObject = intros.find((i) => i.tags ? i.tags.includes(tag) : undefined);
|
|
71
79
|
const tagObject = tags.flat().find((t) => {
|
|
72
80
|
var _a;
|
|
73
|
-
return (_a =
|
|
81
|
+
return (_a = tag === t.name) !== null && _a !== void 0 ? _a : {
|
|
74
82
|
name: tag,
|
|
75
83
|
description: `${tag} Index`,
|
|
76
84
|
};
|
|
@@ -105,7 +113,7 @@ function groupByTags(items, sidebarOptions, options, tags, docPath) {
|
|
|
105
113
|
}
|
|
106
114
|
return {
|
|
107
115
|
type: "category",
|
|
108
|
-
label: tag,
|
|
116
|
+
label: (_a = tagObject === null || tagObject === void 0 ? void 0 : tagObject["x-displayName"]) !== null && _a !== void 0 ? _a : tag,
|
|
109
117
|
link: linkConfig,
|
|
110
118
|
collapsible: sidebarCollapsible,
|
|
111
119
|
collapsed: sidebarCollapsed,
|
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": "1.1.
|
|
4
|
+
"version": "1.1.5",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"openapi",
|
|
@@ -67,5 +67,5 @@
|
|
|
67
67
|
"engines": {
|
|
68
68
|
"node": ">=14"
|
|
69
69
|
},
|
|
70
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "21d33582a9fcac2ddd23443497af910982b36dae"
|
|
71
71
|
}
|
|
@@ -5,13 +5,20 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
* ========================================================================== */
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import { MediaTypeObject } from "../openapi/types";
|
|
9
|
+
import { createRequestSchema } from "./createRequestSchema";
|
|
9
10
|
|
|
10
11
|
interface Props {
|
|
11
12
|
title: string;
|
|
12
|
-
body:
|
|
13
|
+
body: {
|
|
14
|
+
content?: {
|
|
15
|
+
[key: string]: MediaTypeObject;
|
|
16
|
+
};
|
|
17
|
+
description?: string;
|
|
18
|
+
required?: boolean;
|
|
19
|
+
};
|
|
13
20
|
}
|
|
14
21
|
|
|
15
|
-
export function createRequestBodyDetails({ title, body }: Props) {
|
|
16
|
-
return
|
|
22
|
+
export function createRequestBodyDetails({ title, body }: Props): any {
|
|
23
|
+
return createRequestSchema({ title, body });
|
|
17
24
|
}
|