docusaurus-plugin-openapi-docs 0.0.0-422 → 0.0.0-425
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.
|
@@ -10,6 +10,7 @@ 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");
|
|
13
|
+
const createStatusCodes_1 = require("./createStatusCodes");
|
|
13
14
|
const schema_1 = require("./schema");
|
|
14
15
|
const utils_1 = require("./utils");
|
|
15
16
|
const jsonSchemaMergeAllOf = require("json-schema-merge-allof");
|
|
@@ -428,7 +429,6 @@ function createPropertyDiscriminator(name, schemaName, schema, discriminator, re
|
|
|
428
429
|
function createEdges({ name, schema, required, discriminator, }) {
|
|
429
430
|
var _a, _b;
|
|
430
431
|
const schemaName = (0, schema_1.getSchemaName)(schema);
|
|
431
|
-
// if (name === "id") console.log(name, schema, required);
|
|
432
432
|
if (discriminator !== undefined && discriminator.propertyName === name) {
|
|
433
433
|
return createPropertyDiscriminator(name, "string", schema, discriminator, required);
|
|
434
434
|
}
|
|
@@ -509,7 +509,8 @@ function createNodes(schema) {
|
|
|
509
509
|
if (schema.properties !== undefined) {
|
|
510
510
|
return createProperties(schema);
|
|
511
511
|
}
|
|
512
|
-
if
|
|
512
|
+
// Could be set to false to just check if evals to true
|
|
513
|
+
if (schema.additionalProperties) {
|
|
513
514
|
return createAdditionalProperties(schema);
|
|
514
515
|
}
|
|
515
516
|
// TODO: figure out how to handle array of objects
|
|
@@ -551,62 +552,83 @@ function createResponseSchema({ title, body, ...rest }) {
|
|
|
551
552
|
}
|
|
552
553
|
// Get all MIME types, including vendor-specific
|
|
553
554
|
const mimeTypes = Object.keys(body.content);
|
|
554
|
-
if (mimeTypes && mimeTypes.length
|
|
555
|
+
if (mimeTypes && mimeTypes.length) {
|
|
555
556
|
return (0, utils_1.create)("MimeTabs", {
|
|
556
557
|
groupId: "mime-type",
|
|
557
558
|
children: mimeTypes.map((mimeType) => {
|
|
559
|
+
const responseExamples = body.content[mimeType].examples;
|
|
560
|
+
const responseExample = body.content[mimeType].example;
|
|
558
561
|
const firstBody = body.content[mimeType].schema;
|
|
559
|
-
if (firstBody === undefined
|
|
562
|
+
if (firstBody === undefined &&
|
|
563
|
+
responseExample === undefined &&
|
|
564
|
+
responseExamples === undefined) {
|
|
560
565
|
return undefined;
|
|
561
566
|
}
|
|
562
|
-
if (firstBody.properties !== undefined) {
|
|
563
|
-
if (Object.keys(firstBody.properties).length === 0) {
|
|
567
|
+
if ((firstBody === null || firstBody === void 0 ? void 0 : firstBody.properties) !== undefined) {
|
|
568
|
+
if (Object.keys(firstBody === null || firstBody === void 0 ? void 0 : firstBody.properties).length === 0) {
|
|
564
569
|
return undefined;
|
|
565
570
|
}
|
|
566
571
|
}
|
|
567
572
|
return (0, utils_1.create)("TabItem", {
|
|
568
|
-
label: mimeType
|
|
573
|
+
label: `${mimeType}`,
|
|
569
574
|
value: `${mimeType}`,
|
|
570
575
|
children: [
|
|
571
|
-
(0,
|
|
572
|
-
"
|
|
573
|
-
open: true,
|
|
574
|
-
...rest,
|
|
576
|
+
(0, utils_1.create)("SchemaTabs", {
|
|
577
|
+
groupId: "schema-tabs",
|
|
575
578
|
children: [
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
579
|
+
firstBody &&
|
|
580
|
+
(0, utils_1.create)("TabTtem", {
|
|
581
|
+
label: `${title}`,
|
|
582
|
+
value: `${title}`,
|
|
583
|
+
children: [
|
|
584
|
+
(0, createDetails_1.createDetails)({
|
|
585
|
+
"data-collapsed": false,
|
|
586
|
+
open: true,
|
|
587
|
+
...rest,
|
|
588
|
+
children: [
|
|
589
|
+
(0, createDetailsSummary_1.createDetailsSummary)({
|
|
590
|
+
style: { textAlign: "left" },
|
|
591
|
+
children: [
|
|
592
|
+
(0, utils_1.create)("strong", { children: `${title}` }),
|
|
593
|
+
(0, utils_1.guard)(firstBody.type === "array", (format) => (0, utils_1.create)("span", {
|
|
594
|
+
style: { opacity: "0.6" },
|
|
595
|
+
children: ` array`,
|
|
596
|
+
})),
|
|
597
|
+
(0, utils_1.guard)(body.required && body.required === true, () => [
|
|
598
|
+
(0, utils_1.create)("strong", {
|
|
599
|
+
style: {
|
|
600
|
+
fontSize: "var(--ifm-code-font-size)",
|
|
601
|
+
color: "var(--openapi-required)",
|
|
602
|
+
},
|
|
603
|
+
children: " required",
|
|
604
|
+
}),
|
|
605
|
+
]),
|
|
606
|
+
],
|
|
607
|
+
}),
|
|
608
|
+
(0, utils_1.create)("div", {
|
|
609
|
+
style: { textAlign: "left", marginLeft: "1rem" },
|
|
610
|
+
children: [
|
|
611
|
+
(0, utils_1.guard)(body.description, () => [
|
|
612
|
+
(0, utils_1.create)("div", {
|
|
613
|
+
style: {
|
|
614
|
+
marginTop: "1rem",
|
|
615
|
+
marginBottom: "1rem",
|
|
616
|
+
},
|
|
617
|
+
children: (0, createDescription_1.createDescription)(body.description),
|
|
618
|
+
}),
|
|
619
|
+
]),
|
|
620
|
+
],
|
|
621
|
+
}),
|
|
622
|
+
(0, utils_1.create)("ul", {
|
|
623
|
+
style: { marginLeft: "1rem" },
|
|
624
|
+
children: createNodes(firstBody),
|
|
625
|
+
}),
|
|
626
|
+
],
|
|
602
627
|
}),
|
|
603
|
-
]
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
(0,
|
|
607
|
-
style: { marginLeft: "1rem" },
|
|
608
|
-
children: createNodes(firstBody),
|
|
609
|
-
}),
|
|
628
|
+
],
|
|
629
|
+
}),
|
|
630
|
+
responseExamples && (0, createStatusCodes_1.createResponseExamples)(responseExamples),
|
|
631
|
+
responseExample && (0, createStatusCodes_1.createResponseExample)(responseExample),
|
|
610
632
|
],
|
|
611
633
|
}),
|
|
612
634
|
],
|
|
@@ -614,67 +636,6 @@ function createResponseSchema({ title, body, ...rest }) {
|
|
|
614
636
|
}),
|
|
615
637
|
});
|
|
616
638
|
}
|
|
617
|
-
|
|
618
|
-
const firstBody = body.content[randomFirstKey].schema;
|
|
619
|
-
if (firstBody === undefined) {
|
|
620
|
-
return undefined;
|
|
621
|
-
}
|
|
622
|
-
// we don't show the table if there is no properties to show
|
|
623
|
-
if (firstBody.properties !== undefined) {
|
|
624
|
-
if (Object.keys(firstBody.properties).length === 0) {
|
|
625
|
-
return undefined;
|
|
626
|
-
}
|
|
627
|
-
}
|
|
628
|
-
return (0, utils_1.create)("MimeTabs", {
|
|
629
|
-
children: [
|
|
630
|
-
(0, utils_1.create)("TabItem", {
|
|
631
|
-
label: randomFirstKey,
|
|
632
|
-
value: `${randomFirstKey}-schema`,
|
|
633
|
-
children: [
|
|
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
|
-
}),
|
|
675
|
-
],
|
|
676
|
-
}),
|
|
677
|
-
],
|
|
678
|
-
});
|
|
639
|
+
return undefined;
|
|
679
640
|
}
|
|
680
641
|
exports.createResponseSchema = createResponseSchema;
|
|
@@ -2,5 +2,7 @@ import { ApiItem } from "../types";
|
|
|
2
2
|
interface Props {
|
|
3
3
|
responses: ApiItem["responses"];
|
|
4
4
|
}
|
|
5
|
+
export declare function createResponseExamples(responseExamples: any): string[];
|
|
6
|
+
export declare function createResponseExample(responseExample: any): string;
|
|
5
7
|
export declare function createStatusCodes({ responses }: Props): string | undefined;
|
|
6
8
|
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.createStatusCodes = void 0;
|
|
9
|
+
exports.createStatusCodes = exports.createResponseExample = exports.createResponseExamples = void 0;
|
|
10
10
|
const createDescription_1 = require("./createDescription");
|
|
11
11
|
const createDetails_1 = require("./createDetails");
|
|
12
12
|
const createDetailsSummary_1 = require("./createDetailsSummary");
|
|
@@ -57,17 +57,52 @@ function createResponseExamples(responseExamples) {
|
|
|
57
57
|
return Object.entries(responseExamples).map(([exampleName, exampleValue]) => {
|
|
58
58
|
const camelToSpaceName = exampleName.replace(/([A-Z])/g, " $1");
|
|
59
59
|
let finalFormattedName = camelToSpaceName.charAt(0).toUpperCase() + camelToSpaceName.slice(1);
|
|
60
|
+
if (typeof exampleValue.value === "object") {
|
|
61
|
+
return (0, utils_1.create)("TabItem", {
|
|
62
|
+
label: `${finalFormattedName}`,
|
|
63
|
+
value: `${finalFormattedName}`,
|
|
64
|
+
children: [
|
|
65
|
+
(0, utils_1.create)("ResponseSamples", {
|
|
66
|
+
responseExample: JSON.stringify(exampleValue.value, null, 2),
|
|
67
|
+
}),
|
|
68
|
+
],
|
|
69
|
+
});
|
|
70
|
+
}
|
|
60
71
|
return (0, utils_1.create)("TabItem", {
|
|
61
72
|
label: `${finalFormattedName}`,
|
|
62
73
|
value: `${finalFormattedName}`,
|
|
63
74
|
children: [
|
|
64
75
|
(0, utils_1.create)("ResponseSamples", {
|
|
65
|
-
responseExample:
|
|
76
|
+
responseExample: exampleValue.value,
|
|
66
77
|
}),
|
|
67
78
|
],
|
|
68
79
|
});
|
|
69
80
|
});
|
|
70
81
|
}
|
|
82
|
+
exports.createResponseExamples = createResponseExamples;
|
|
83
|
+
function createResponseExample(responseExample) {
|
|
84
|
+
if (typeof responseExample === "object") {
|
|
85
|
+
return (0, utils_1.create)("TabItem", {
|
|
86
|
+
label: `Example`,
|
|
87
|
+
value: `Example`,
|
|
88
|
+
children: [
|
|
89
|
+
(0, utils_1.create)("ResponseSamples", {
|
|
90
|
+
responseExample: JSON.stringify(responseExample, null, 2),
|
|
91
|
+
}),
|
|
92
|
+
],
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
return (0, utils_1.create)("TabItem", {
|
|
96
|
+
label: `Example`,
|
|
97
|
+
value: `Example`,
|
|
98
|
+
children: [
|
|
99
|
+
(0, utils_1.create)("ResponseSamples", {
|
|
100
|
+
responseExample: responseExample,
|
|
101
|
+
}),
|
|
102
|
+
],
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
exports.createResponseExample = createResponseExample;
|
|
71
106
|
function createStatusCodes({ responses }) {
|
|
72
107
|
if (responses === undefined) {
|
|
73
108
|
return undefined;
|
|
@@ -79,11 +114,10 @@ function createStatusCodes({ responses }) {
|
|
|
79
114
|
return (0, utils_1.create)("div", {
|
|
80
115
|
children: [
|
|
81
116
|
(0, utils_1.create)("ApiTabs", {
|
|
117
|
+
// TODO: determine if we should persist status code selection
|
|
118
|
+
// groupId: "api-tabs",
|
|
82
119
|
children: codes.map((code) => {
|
|
83
120
|
const responseHeaders = responses[code].headers;
|
|
84
|
-
const responseContent = responses[code].content;
|
|
85
|
-
const responseContentKey = responseContent && Object.keys(responseContent)[0];
|
|
86
|
-
const responseExamples = responseContentKey && responseContent[responseContentKey].examples;
|
|
87
121
|
return (0, utils_1.create)("TabItem", {
|
|
88
122
|
label: code,
|
|
89
123
|
value: code,
|
|
@@ -91,62 +125,30 @@ function createStatusCodes({ responses }) {
|
|
|
91
125
|
(0, utils_1.create)("div", {
|
|
92
126
|
children: (0, createDescription_1.createDescription)(responses[code].description),
|
|
93
127
|
}),
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
style: { textAlign: "left" },
|
|
105
|
-
children: [
|
|
106
|
-
(0, createDetailsSummary_1.createDetailsSummary)({
|
|
107
|
-
children: [
|
|
108
|
-
(0, utils_1.create)("strong", {
|
|
109
|
-
children: "Response Headers",
|
|
110
|
-
}),
|
|
111
|
-
],
|
|
112
|
-
}),
|
|
113
|
-
createResponseHeaders(responseHeaders),
|
|
114
|
-
],
|
|
115
|
-
}),
|
|
116
|
-
(0, utils_1.create)("div", {
|
|
117
|
-
children: (0, createResponseSchema_1.createResponseSchema)({
|
|
118
|
-
title: "Schema",
|
|
119
|
-
body: {
|
|
120
|
-
content: responses[code].content,
|
|
121
|
-
},
|
|
128
|
+
responseHeaders &&
|
|
129
|
+
(0, createDetails_1.createDetails)({
|
|
130
|
+
"data-collaposed": false,
|
|
131
|
+
open: true,
|
|
132
|
+
style: { textAlign: "left", marginBottom: "1rem" },
|
|
133
|
+
children: [
|
|
134
|
+
(0, createDetailsSummary_1.createDetailsSummary)({
|
|
135
|
+
children: [
|
|
136
|
+
(0, utils_1.create)("strong", {
|
|
137
|
+
children: "Response Headers",
|
|
122
138
|
}),
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
(0, utils_2.guard)(responseHeaders, () => (0, createDetails_1.createDetails)({
|
|
130
|
-
"data-collaposed": false,
|
|
131
|
-
open: true,
|
|
132
|
-
style: { textAlign: "left" },
|
|
133
|
-
children: [
|
|
134
|
-
(0, createDetailsSummary_1.createDetailsSummary)({
|
|
135
|
-
children: [
|
|
136
|
-
(0, utils_1.create)("strong", { children: "Response Headers" }),
|
|
137
|
-
],
|
|
138
|
-
}),
|
|
139
|
-
createResponseHeaders(responseHeaders),
|
|
140
|
-
],
|
|
141
|
-
})),
|
|
142
|
-
(0, utils_2.guard)(!responseExamples, () => (0, utils_1.create)("div", {
|
|
139
|
+
],
|
|
140
|
+
}),
|
|
141
|
+
createResponseHeaders(responseHeaders),
|
|
142
|
+
],
|
|
143
|
+
}),
|
|
144
|
+
(0, utils_1.create)("div", {
|
|
143
145
|
children: (0, createResponseSchema_1.createResponseSchema)({
|
|
144
146
|
title: "Schema",
|
|
145
147
|
body: {
|
|
146
148
|
content: responses[code].content,
|
|
147
149
|
},
|
|
148
150
|
}),
|
|
149
|
-
})
|
|
151
|
+
}),
|
|
150
152
|
],
|
|
151
153
|
});
|
|
152
154
|
}),
|
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-
|
|
4
|
+
"version": "0.0.0-425",
|
|
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": "0a721e65db34612b89ef1a3ce8c53213fed32e03"
|
|
71
71
|
}
|
|
@@ -9,6 +9,10 @@ import { MediaTypeObject, SchemaObject } from "../openapi/types";
|
|
|
9
9
|
import { createDescription } from "./createDescription";
|
|
10
10
|
import { createDetails } from "./createDetails";
|
|
11
11
|
import { createDetailsSummary } from "./createDetailsSummary";
|
|
12
|
+
import {
|
|
13
|
+
createResponseExample,
|
|
14
|
+
createResponseExamples,
|
|
15
|
+
} from "./createStatusCodes";
|
|
12
16
|
import { getQualifierMessage, getSchemaName } from "./schema";
|
|
13
17
|
import { create, guard } from "./utils";
|
|
14
18
|
|
|
@@ -534,8 +538,6 @@ function createEdges({
|
|
|
534
538
|
}: EdgeProps): any {
|
|
535
539
|
const schemaName = getSchemaName(schema);
|
|
536
540
|
|
|
537
|
-
// if (name === "id") console.log(name, schema, required);
|
|
538
|
-
|
|
539
541
|
if (discriminator !== undefined && discriminator.propertyName === name) {
|
|
540
542
|
return createPropertyDiscriminator(
|
|
541
543
|
name,
|
|
@@ -647,7 +649,8 @@ function createNodes(schema: SchemaObject): any {
|
|
|
647
649
|
return createProperties(schema);
|
|
648
650
|
}
|
|
649
651
|
|
|
650
|
-
if
|
|
652
|
+
// Could be set to false to just check if evals to true
|
|
653
|
+
if (schema.additionalProperties) {
|
|
651
654
|
return createAdditionalProperties(schema);
|
|
652
655
|
}
|
|
653
656
|
|
|
@@ -715,64 +718,93 @@ export function createResponseSchema({ title, body, ...rest }: Props) {
|
|
|
715
718
|
// Get all MIME types, including vendor-specific
|
|
716
719
|
const mimeTypes = Object.keys(body.content);
|
|
717
720
|
|
|
718
|
-
if (mimeTypes && mimeTypes.length
|
|
721
|
+
if (mimeTypes && mimeTypes.length) {
|
|
719
722
|
return create("MimeTabs", {
|
|
720
723
|
groupId: "mime-type",
|
|
721
|
-
children: mimeTypes.map((mimeType) => {
|
|
724
|
+
children: mimeTypes.map((mimeType: any) => {
|
|
725
|
+
const responseExamples = body.content![mimeType].examples;
|
|
726
|
+
const responseExample = body.content![mimeType].example;
|
|
722
727
|
const firstBody = body.content![mimeType].schema;
|
|
723
|
-
|
|
728
|
+
|
|
729
|
+
if (
|
|
730
|
+
firstBody === undefined &&
|
|
731
|
+
responseExample === undefined &&
|
|
732
|
+
responseExamples === undefined
|
|
733
|
+
) {
|
|
724
734
|
return undefined;
|
|
725
735
|
}
|
|
726
|
-
|
|
727
|
-
|
|
736
|
+
|
|
737
|
+
if (firstBody?.properties !== undefined) {
|
|
738
|
+
if (Object.keys(firstBody?.properties).length === 0) {
|
|
728
739
|
return undefined;
|
|
729
740
|
}
|
|
730
741
|
}
|
|
742
|
+
|
|
731
743
|
return create("TabItem", {
|
|
732
|
-
label: mimeType
|
|
744
|
+
label: `${mimeType}`,
|
|
733
745
|
value: `${mimeType}`,
|
|
734
746
|
children: [
|
|
735
|
-
|
|
736
|
-
"
|
|
737
|
-
open: true,
|
|
738
|
-
...rest,
|
|
747
|
+
create("SchemaTabs", {
|
|
748
|
+
groupId: "schema-tabs",
|
|
739
749
|
children: [
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
750
|
+
firstBody &&
|
|
751
|
+
create("TabTtem", {
|
|
752
|
+
label: `${title}`,
|
|
753
|
+
value: `${title}`,
|
|
754
|
+
children: [
|
|
755
|
+
createDetails({
|
|
756
|
+
"data-collapsed": false,
|
|
757
|
+
open: true,
|
|
758
|
+
...rest,
|
|
759
|
+
children: [
|
|
760
|
+
createDetailsSummary({
|
|
761
|
+
style: { textAlign: "left" },
|
|
762
|
+
children: [
|
|
763
|
+
create("strong", { children: `${title}` }),
|
|
764
|
+
guard(firstBody!.type === "array", (format) =>
|
|
765
|
+
create("span", {
|
|
766
|
+
style: { opacity: "0.6" },
|
|
767
|
+
children: ` array`,
|
|
768
|
+
})
|
|
769
|
+
),
|
|
770
|
+
guard(
|
|
771
|
+
body.required && body.required === true,
|
|
772
|
+
() => [
|
|
773
|
+
create("strong", {
|
|
774
|
+
style: {
|
|
775
|
+
fontSize: "var(--ifm-code-font-size)",
|
|
776
|
+
color: "var(--openapi-required)",
|
|
777
|
+
},
|
|
778
|
+
children: " required",
|
|
779
|
+
}),
|
|
780
|
+
]
|
|
781
|
+
),
|
|
782
|
+
],
|
|
783
|
+
}),
|
|
784
|
+
create("div", {
|
|
785
|
+
style: { textAlign: "left", marginLeft: "1rem" },
|
|
786
|
+
children: [
|
|
787
|
+
guard(body.description, () => [
|
|
788
|
+
create("div", {
|
|
789
|
+
style: {
|
|
790
|
+
marginTop: "1rem",
|
|
791
|
+
marginBottom: "1rem",
|
|
792
|
+
},
|
|
793
|
+
children: createDescription(body.description),
|
|
794
|
+
}),
|
|
795
|
+
]),
|
|
796
|
+
],
|
|
797
|
+
}),
|
|
798
|
+
create("ul", {
|
|
799
|
+
style: { marginLeft: "1rem" },
|
|
800
|
+
children: createNodes(firstBody!),
|
|
801
|
+
}),
|
|
802
|
+
],
|
|
768
803
|
}),
|
|
769
|
-
]
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
style: { marginLeft: "1rem" },
|
|
774
|
-
children: createNodes(firstBody),
|
|
775
|
-
}),
|
|
804
|
+
],
|
|
805
|
+
}),
|
|
806
|
+
responseExamples && createResponseExamples(responseExamples),
|
|
807
|
+
responseExample && createResponseExample(responseExample),
|
|
776
808
|
],
|
|
777
809
|
}),
|
|
778
810
|
],
|
|
@@ -781,70 +813,5 @@ export function createResponseSchema({ title, body, ...rest }: Props) {
|
|
|
781
813
|
});
|
|
782
814
|
}
|
|
783
815
|
|
|
784
|
-
|
|
785
|
-
const firstBody = body.content[randomFirstKey].schema;
|
|
786
|
-
|
|
787
|
-
if (firstBody === undefined) {
|
|
788
|
-
return undefined;
|
|
789
|
-
}
|
|
790
|
-
|
|
791
|
-
// we don't show the table if there is no properties to show
|
|
792
|
-
if (firstBody.properties !== undefined) {
|
|
793
|
-
if (Object.keys(firstBody.properties).length === 0) {
|
|
794
|
-
return undefined;
|
|
795
|
-
}
|
|
796
|
-
}
|
|
797
|
-
return create("MimeTabs", {
|
|
798
|
-
children: [
|
|
799
|
-
create("TabItem", {
|
|
800
|
-
label: randomFirstKey,
|
|
801
|
-
value: `${randomFirstKey}-schema`,
|
|
802
|
-
children: [
|
|
803
|
-
createDetails({
|
|
804
|
-
"data-collapsed": false,
|
|
805
|
-
open: true,
|
|
806
|
-
...rest,
|
|
807
|
-
children: [
|
|
808
|
-
createDetailsSummary({
|
|
809
|
-
style: { textAlign: "left" },
|
|
810
|
-
children: [
|
|
811
|
-
create("strong", { children: `${title}` }),
|
|
812
|
-
guard(firstBody.type === "array", (format) =>
|
|
813
|
-
create("span", {
|
|
814
|
-
style: { opacity: "0.6" },
|
|
815
|
-
children: ` array`,
|
|
816
|
-
})
|
|
817
|
-
),
|
|
818
|
-
guard(body.required, () => [
|
|
819
|
-
create("strong", {
|
|
820
|
-
style: {
|
|
821
|
-
fontSize: "var(--ifm-code-font-size)",
|
|
822
|
-
color: "var(--openapi-required)",
|
|
823
|
-
},
|
|
824
|
-
children: " required",
|
|
825
|
-
}),
|
|
826
|
-
]),
|
|
827
|
-
],
|
|
828
|
-
}),
|
|
829
|
-
create("div", {
|
|
830
|
-
style: { textAlign: "left", marginLeft: "1rem" },
|
|
831
|
-
children: [
|
|
832
|
-
guard(body.description, () => [
|
|
833
|
-
create("div", {
|
|
834
|
-
style: { marginTop: "1rem", marginBottom: "1rem" },
|
|
835
|
-
children: createDescription(body.description),
|
|
836
|
-
}),
|
|
837
|
-
]),
|
|
838
|
-
],
|
|
839
|
-
}),
|
|
840
|
-
create("ul", {
|
|
841
|
-
style: { marginLeft: "1rem" },
|
|
842
|
-
children: createNodes(firstBody),
|
|
843
|
-
}),
|
|
844
|
-
],
|
|
845
|
-
}),
|
|
846
|
-
],
|
|
847
|
-
}),
|
|
848
|
-
],
|
|
849
|
-
});
|
|
816
|
+
return undefined;
|
|
850
817
|
}
|
|
@@ -67,19 +67,30 @@ function createResponseHeaders(responseHeaders: any) {
|
|
|
67
67
|
);
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
function createResponseExamples(responseExamples: any) {
|
|
70
|
+
export function createResponseExamples(responseExamples: any) {
|
|
71
71
|
return Object.entries(responseExamples).map(
|
|
72
72
|
([exampleName, exampleValue]: any) => {
|
|
73
73
|
const camelToSpaceName = exampleName.replace(/([A-Z])/g, " $1");
|
|
74
74
|
let finalFormattedName =
|
|
75
75
|
camelToSpaceName.charAt(0).toUpperCase() + camelToSpaceName.slice(1);
|
|
76
76
|
|
|
77
|
+
if (typeof exampleValue.value === "object") {
|
|
78
|
+
return create("TabItem", {
|
|
79
|
+
label: `${finalFormattedName}`,
|
|
80
|
+
value: `${finalFormattedName}`,
|
|
81
|
+
children: [
|
|
82
|
+
create("ResponseSamples", {
|
|
83
|
+
responseExample: JSON.stringify(exampleValue.value, null, 2),
|
|
84
|
+
}),
|
|
85
|
+
],
|
|
86
|
+
});
|
|
87
|
+
}
|
|
77
88
|
return create("TabItem", {
|
|
78
89
|
label: `${finalFormattedName}`,
|
|
79
90
|
value: `${finalFormattedName}`,
|
|
80
91
|
children: [
|
|
81
92
|
create("ResponseSamples", {
|
|
82
|
-
responseExample:
|
|
93
|
+
responseExample: exampleValue.value,
|
|
83
94
|
}),
|
|
84
95
|
],
|
|
85
96
|
});
|
|
@@ -87,6 +98,29 @@ function createResponseExamples(responseExamples: any) {
|
|
|
87
98
|
);
|
|
88
99
|
}
|
|
89
100
|
|
|
101
|
+
export function createResponseExample(responseExample: any) {
|
|
102
|
+
if (typeof responseExample === "object") {
|
|
103
|
+
return create("TabItem", {
|
|
104
|
+
label: `Example`,
|
|
105
|
+
value: `Example`,
|
|
106
|
+
children: [
|
|
107
|
+
create("ResponseSamples", {
|
|
108
|
+
responseExample: JSON.stringify(responseExample, null, 2),
|
|
109
|
+
}),
|
|
110
|
+
],
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
return create("TabItem", {
|
|
114
|
+
label: `Example`,
|
|
115
|
+
value: `Example`,
|
|
116
|
+
children: [
|
|
117
|
+
create("ResponseSamples", {
|
|
118
|
+
responseExample: responseExample,
|
|
119
|
+
}),
|
|
120
|
+
],
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
|
|
90
124
|
export function createStatusCodes({ responses }: Props) {
|
|
91
125
|
if (responses === undefined) {
|
|
92
126
|
return undefined;
|
|
@@ -100,14 +134,10 @@ export function createStatusCodes({ responses }: Props) {
|
|
|
100
134
|
return create("div", {
|
|
101
135
|
children: [
|
|
102
136
|
create("ApiTabs", {
|
|
137
|
+
// TODO: determine if we should persist status code selection
|
|
138
|
+
// groupId: "api-tabs",
|
|
103
139
|
children: codes.map((code) => {
|
|
104
140
|
const responseHeaders: any = responses[code].headers;
|
|
105
|
-
const responseContent: any = responses[code].content;
|
|
106
|
-
const responseContentKey: any =
|
|
107
|
-
responseContent && Object.keys(responseContent)[0];
|
|
108
|
-
const responseExamples: any =
|
|
109
|
-
responseContentKey && responseContent[responseContentKey].examples;
|
|
110
|
-
|
|
111
141
|
return create("TabItem", {
|
|
112
142
|
label: code,
|
|
113
143
|
value: code,
|
|
@@ -115,68 +145,30 @@ export function createStatusCodes({ responses }: Props) {
|
|
|
115
145
|
create("div", {
|
|
116
146
|
children: createDescription(responses[code].description),
|
|
117
147
|
}),
|
|
118
|
-
|
|
119
|
-
create("SchemaTabs", {
|
|
120
|
-
children: [
|
|
121
|
-
create("TabTtem", {
|
|
122
|
-
label: "Schema",
|
|
123
|
-
value: "Schema",
|
|
124
|
-
children: [
|
|
125
|
-
responseHeaders &&
|
|
126
|
-
createDetails({
|
|
127
|
-
"data-collaposed": false,
|
|
128
|
-
open: true,
|
|
129
|
-
style: { textAlign: "left" },
|
|
130
|
-
children: [
|
|
131
|
-
createDetailsSummary({
|
|
132
|
-
children: [
|
|
133
|
-
create("strong", {
|
|
134
|
-
children: "Response Headers",
|
|
135
|
-
}),
|
|
136
|
-
],
|
|
137
|
-
}),
|
|
138
|
-
createResponseHeaders(responseHeaders),
|
|
139
|
-
],
|
|
140
|
-
}),
|
|
141
|
-
create("div", {
|
|
142
|
-
children: createResponseSchema({
|
|
143
|
-
title: "Schema",
|
|
144
|
-
body: {
|
|
145
|
-
content: responses[code].content,
|
|
146
|
-
},
|
|
147
|
-
}),
|
|
148
|
-
}),
|
|
149
|
-
],
|
|
150
|
-
}),
|
|
151
|
-
createResponseExamples(responseExamples),
|
|
152
|
-
],
|
|
153
|
-
})
|
|
154
|
-
),
|
|
155
|
-
guard(responseHeaders, () =>
|
|
148
|
+
responseHeaders &&
|
|
156
149
|
createDetails({
|
|
157
150
|
"data-collaposed": false,
|
|
158
151
|
open: true,
|
|
159
|
-
style: { textAlign: "left" },
|
|
152
|
+
style: { textAlign: "left", marginBottom: "1rem" },
|
|
160
153
|
children: [
|
|
161
154
|
createDetailsSummary({
|
|
162
155
|
children: [
|
|
163
|
-
create("strong", {
|
|
156
|
+
create("strong", {
|
|
157
|
+
children: "Response Headers",
|
|
158
|
+
}),
|
|
164
159
|
],
|
|
165
160
|
}),
|
|
166
161
|
createResponseHeaders(responseHeaders),
|
|
167
162
|
],
|
|
168
|
-
})
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
}),
|
|
178
|
-
})
|
|
179
|
-
),
|
|
163
|
+
}),
|
|
164
|
+
create("div", {
|
|
165
|
+
children: createResponseSchema({
|
|
166
|
+
title: "Schema",
|
|
167
|
+
body: {
|
|
168
|
+
content: responses[code].content,
|
|
169
|
+
},
|
|
170
|
+
}),
|
|
171
|
+
}),
|
|
180
172
|
],
|
|
181
173
|
});
|
|
182
174
|
}),
|