docusaurus-plugin-openapi-docs 0.0.0-415 → 0.0.0-418
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/createSchemaDetails.js +118 -40
- package/lib/markdown/index.js +5 -1
- package/lib/openapi/openapi.js +13 -2
- package/package.json +2 -2
- package/src/markdown/createRequestBodyDetails.ts +9 -2
- package/src/markdown/createSchemaDetails.ts +123 -41
- package/src/markdown/index.ts +17 -1
- package/src/openapi/openapi.ts +12 -0
|
@@ -1,6 +1,13 @@
|
|
|
1
|
+
import { MediaTypeObject } from "../openapi/types";
|
|
1
2
|
interface Props {
|
|
2
3
|
title: string;
|
|
3
|
-
body:
|
|
4
|
+
body: {
|
|
5
|
+
content?: {
|
|
6
|
+
[key: string]: MediaTypeObject;
|
|
7
|
+
};
|
|
8
|
+
description?: string;
|
|
9
|
+
required?: boolean;
|
|
10
|
+
};
|
|
4
11
|
}
|
|
5
|
-
export declare function createRequestBodyDetails({ title, body }: Props):
|
|
12
|
+
export declare function createRequestBodyDetails({ title, body }: Props): any;
|
|
6
13
|
export {};
|
|
@@ -425,7 +425,7 @@ function createPropertyDiscriminator(name, schemaName, schema, discriminator, re
|
|
|
425
425
|
* Creates the edges or "leaves" of a schema tree. Edges can branch into sub-nodes with createDetails().
|
|
426
426
|
*/
|
|
427
427
|
function createEdges({ name, schema, required, discriminator, }) {
|
|
428
|
-
var _a;
|
|
428
|
+
var _a, _b;
|
|
429
429
|
const schemaName = (0, schema_1.getSchemaName)(schema);
|
|
430
430
|
if (discriminator !== undefined && discriminator.propertyName === name) {
|
|
431
431
|
return createPropertyDiscriminator(name, "string", schema, discriminator, required);
|
|
@@ -446,6 +446,10 @@ function createEdges({ name, schema, required, discriminator, }) {
|
|
|
446
446
|
if (mergedSchemas.additionalProperties !== undefined) {
|
|
447
447
|
return createDetailsNode(name, mergedSchemaName, mergedSchemas, required);
|
|
448
448
|
}
|
|
449
|
+
// array of objects
|
|
450
|
+
if (((_a = mergedSchemas.items) === null || _a === void 0 ? void 0 : _a.properties) !== undefined) {
|
|
451
|
+
return createDetailsNode(name, mergedSchemaName, mergedSchemas, required);
|
|
452
|
+
}
|
|
449
453
|
return (0, utils_1.create)("SchemaItem", {
|
|
450
454
|
collapsible: false,
|
|
451
455
|
name,
|
|
@@ -453,6 +457,7 @@ function createEdges({ name, schema, required, discriminator, }) {
|
|
|
453
457
|
schemaDescription: mergedSchemas.description,
|
|
454
458
|
schemaName: schemaName,
|
|
455
459
|
qualifierMessage: (0, schema_1.getQualifierMessage)(schema),
|
|
460
|
+
defaultValue: schema.default,
|
|
456
461
|
});
|
|
457
462
|
}
|
|
458
463
|
if (schema.properties !== undefined) {
|
|
@@ -462,7 +467,7 @@ function createEdges({ name, schema, required, discriminator, }) {
|
|
|
462
467
|
return createDetailsNode(name, schemaName, schema, required);
|
|
463
468
|
}
|
|
464
469
|
// array of objects
|
|
465
|
-
if (((
|
|
470
|
+
if (((_b = schema.items) === null || _b === void 0 ? void 0 : _b.properties) !== undefined) {
|
|
466
471
|
return createDetailsNode(name, schemaName, schema, required);
|
|
467
472
|
}
|
|
468
473
|
// primitives and array of non-objects
|
|
@@ -473,6 +478,7 @@ function createEdges({ name, schema, required, discriminator, }) {
|
|
|
473
478
|
schemaDescription: schema.description,
|
|
474
479
|
schemaName: schemaName,
|
|
475
480
|
qualifierMessage: (0, schema_1.getQualifierMessage)(schema),
|
|
481
|
+
defaultValue: schema.default,
|
|
476
482
|
});
|
|
477
483
|
}
|
|
478
484
|
/**
|
|
@@ -535,8 +541,71 @@ function createSchemaDetails({ title, body, ...rest }) {
|
|
|
535
541
|
Object.keys(body.content).length === 0) {
|
|
536
542
|
return undefined;
|
|
537
543
|
}
|
|
538
|
-
//
|
|
539
|
-
|
|
544
|
+
// Get all MIME types, including vendor-specific
|
|
545
|
+
const mimeTypes = Object.keys(body.content);
|
|
546
|
+
if (mimeTypes && mimeTypes.length > 1) {
|
|
547
|
+
return (0, utils_1.create)("MimeTabs", {
|
|
548
|
+
groupId: "mime-type",
|
|
549
|
+
children: mimeTypes.map((mimeType) => {
|
|
550
|
+
const firstBody = body.content[mimeType].schema;
|
|
551
|
+
if (firstBody === undefined) {
|
|
552
|
+
return undefined;
|
|
553
|
+
}
|
|
554
|
+
if (firstBody.properties !== undefined) {
|
|
555
|
+
if (Object.keys(firstBody.properties).length === 0) {
|
|
556
|
+
return undefined;
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
return (0, utils_1.create)("TabItem", {
|
|
560
|
+
label: mimeType,
|
|
561
|
+
value: `${mimeType}`,
|
|
562
|
+
children: [
|
|
563
|
+
(0, createDetails_1.createDetails)({
|
|
564
|
+
"data-collapsed": false,
|
|
565
|
+
open: true,
|
|
566
|
+
...rest,
|
|
567
|
+
children: [
|
|
568
|
+
(0, createDetailsSummary_1.createDetailsSummary)({
|
|
569
|
+
style: { textAlign: "left" },
|
|
570
|
+
children: [
|
|
571
|
+
(0, utils_1.create)("strong", { children: `${title}` }),
|
|
572
|
+
(0, utils_1.guard)(firstBody.type === "array", (format) => (0, utils_1.create)("span", {
|
|
573
|
+
style: { opacity: "0.6" },
|
|
574
|
+
children: ` array`,
|
|
575
|
+
})),
|
|
576
|
+
(0, utils_1.guard)(body.required, () => [
|
|
577
|
+
(0, utils_1.create)("strong", {
|
|
578
|
+
style: {
|
|
579
|
+
fontSize: "var(--ifm-code-font-size)",
|
|
580
|
+
color: "var(--openapi-required)",
|
|
581
|
+
},
|
|
582
|
+
children: " required",
|
|
583
|
+
}),
|
|
584
|
+
]),
|
|
585
|
+
],
|
|
586
|
+
}),
|
|
587
|
+
(0, utils_1.create)("div", {
|
|
588
|
+
style: { textAlign: "left", marginLeft: "1rem" },
|
|
589
|
+
children: [
|
|
590
|
+
(0, utils_1.guard)(body.description, () => [
|
|
591
|
+
(0, utils_1.create)("div", {
|
|
592
|
+
style: { marginTop: "1rem", marginBottom: "1rem" },
|
|
593
|
+
children: (0, createDescription_1.createDescription)(body.description),
|
|
594
|
+
}),
|
|
595
|
+
]),
|
|
596
|
+
],
|
|
597
|
+
}),
|
|
598
|
+
(0, utils_1.create)("ul", {
|
|
599
|
+
style: { marginLeft: "1rem" },
|
|
600
|
+
children: createNodes(firstBody),
|
|
601
|
+
}),
|
|
602
|
+
],
|
|
603
|
+
}),
|
|
604
|
+
],
|
|
605
|
+
});
|
|
606
|
+
}),
|
|
607
|
+
});
|
|
608
|
+
}
|
|
540
609
|
const randomFirstKey = Object.keys(body.content)[0];
|
|
541
610
|
const firstBody = body.content[randomFirstKey].schema;
|
|
542
611
|
if (firstBody === undefined) {
|
|
@@ -548,46 +617,55 @@ function createSchemaDetails({ title, body, ...rest }) {
|
|
|
548
617
|
return undefined;
|
|
549
618
|
}
|
|
550
619
|
}
|
|
551
|
-
|
|
552
|
-
return (0, createDetails_1.createDetails)({
|
|
553
|
-
"data-collapsed": false,
|
|
554
|
-
open: true,
|
|
555
|
-
...rest,
|
|
620
|
+
return (0, utils_1.create)("MimeTabs", {
|
|
556
621
|
children: [
|
|
557
|
-
(0,
|
|
558
|
-
|
|
622
|
+
(0, utils_1.create)("TabItem", {
|
|
623
|
+
label: randomFirstKey,
|
|
624
|
+
value: `${randomFirstKey}-schema`,
|
|
559
625
|
children: [
|
|
560
|
-
(0,
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
626
|
+
(0, createDetails_1.createDetails)({
|
|
627
|
+
"data-collapsed": false,
|
|
628
|
+
open: true,
|
|
629
|
+
...rest,
|
|
630
|
+
children: [
|
|
631
|
+
(0, createDetailsSummary_1.createDetailsSummary)({
|
|
632
|
+
style: { textAlign: "left" },
|
|
633
|
+
children: [
|
|
634
|
+
(0, utils_1.create)("strong", { children: `${title}` }),
|
|
635
|
+
(0, utils_1.guard)(firstBody.type === "array", (format) => (0, utils_1.create)("span", {
|
|
636
|
+
style: { opacity: "0.6" },
|
|
637
|
+
children: ` array`,
|
|
638
|
+
})),
|
|
639
|
+
(0, utils_1.guard)(body.required, () => [
|
|
640
|
+
(0, utils_1.create)("strong", {
|
|
641
|
+
style: {
|
|
642
|
+
fontSize: "var(--ifm-code-font-size)",
|
|
643
|
+
color: "var(--openapi-required)",
|
|
644
|
+
},
|
|
645
|
+
children: " required",
|
|
646
|
+
}),
|
|
647
|
+
]),
|
|
648
|
+
],
|
|
649
|
+
}),
|
|
650
|
+
(0, utils_1.create)("div", {
|
|
651
|
+
style: { textAlign: "left", marginLeft: "1rem" },
|
|
652
|
+
children: [
|
|
653
|
+
(0, utils_1.guard)(body.description, () => [
|
|
654
|
+
(0, utils_1.create)("div", {
|
|
655
|
+
style: { marginTop: "1rem", marginBottom: "1rem" },
|
|
656
|
+
children: (0, createDescription_1.createDescription)(body.description),
|
|
657
|
+
}),
|
|
658
|
+
]),
|
|
659
|
+
],
|
|
660
|
+
}),
|
|
661
|
+
(0, utils_1.create)("ul", {
|
|
662
|
+
style: { marginLeft: "1rem" },
|
|
663
|
+
children: createNodes(firstBody),
|
|
664
|
+
}),
|
|
665
|
+
],
|
|
666
|
+
}),
|
|
585
667
|
],
|
|
586
668
|
}),
|
|
587
|
-
(0, utils_1.create)("ul", {
|
|
588
|
-
style: { marginLeft: "1rem" },
|
|
589
|
-
children: createNodes(firstBody),
|
|
590
|
-
}),
|
|
591
669
|
],
|
|
592
670
|
});
|
|
593
671
|
}
|
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
|
}
|
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, _q;
|
|
62
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
|
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);
|
|
@@ -136,6 +136,17 @@ function createItems(openapiData, sidebarOptions) {
|
|
|
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 = (_q = operationObject.requestBody) === null || _q === void 0 ? void 0 : _q.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: (_r = operationObject.tags) === null || _r === void 0 ? void 0 : _r.map((tagName) => { var _a; return getTagDisplayName(tagName, (_a = openapiData.tags) !== null && _a !== void 0 ? _a : []); }),
|
|
152
163
|
method,
|
|
153
164
|
path,
|
|
154
165
|
servers,
|
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-418",
|
|
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": "67e537ef8240524a94e5cdb38220b2fd499c61e0"
|
|
71
71
|
}
|
|
@@ -5,13 +5,20 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
* ========================================================================== */
|
|
7
7
|
|
|
8
|
+
import { MediaTypeObject } from "../openapi/types";
|
|
8
9
|
import { createSchemaDetails } from "./createSchemaDetails";
|
|
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) {
|
|
22
|
+
export function createRequestBodyDetails({ title, body }: Props): any {
|
|
16
23
|
return createSchemaDetails({ title, body });
|
|
17
24
|
}
|
|
@@ -568,6 +568,11 @@ function createEdges({
|
|
|
568
568
|
return createDetailsNode(name, mergedSchemaName, mergedSchemas, required);
|
|
569
569
|
}
|
|
570
570
|
|
|
571
|
+
// array of objects
|
|
572
|
+
if (mergedSchemas.items?.properties !== undefined) {
|
|
573
|
+
return createDetailsNode(name, mergedSchemaName, mergedSchemas, required);
|
|
574
|
+
}
|
|
575
|
+
|
|
571
576
|
return create("SchemaItem", {
|
|
572
577
|
collapsible: false,
|
|
573
578
|
name,
|
|
@@ -575,6 +580,7 @@ function createEdges({
|
|
|
575
580
|
schemaDescription: mergedSchemas.description,
|
|
576
581
|
schemaName: schemaName,
|
|
577
582
|
qualifierMessage: getQualifierMessage(schema),
|
|
583
|
+
defaultValue: schema.default,
|
|
578
584
|
});
|
|
579
585
|
}
|
|
580
586
|
|
|
@@ -599,6 +605,7 @@ function createEdges({
|
|
|
599
605
|
schemaDescription: schema.description,
|
|
600
606
|
schemaName: schemaName,
|
|
601
607
|
qualifierMessage: getQualifierMessage(schema),
|
|
608
|
+
defaultValue: schema.default,
|
|
602
609
|
});
|
|
603
610
|
}
|
|
604
611
|
|
|
@@ -692,8 +699,75 @@ export function createSchemaDetails({ title, body, ...rest }: Props) {
|
|
|
692
699
|
return undefined;
|
|
693
700
|
}
|
|
694
701
|
|
|
695
|
-
//
|
|
696
|
-
|
|
702
|
+
// Get all MIME types, including vendor-specific
|
|
703
|
+
const mimeTypes = Object.keys(body.content);
|
|
704
|
+
|
|
705
|
+
if (mimeTypes && mimeTypes.length > 1) {
|
|
706
|
+
return create("MimeTabs", {
|
|
707
|
+
groupId: "mime-type",
|
|
708
|
+
children: mimeTypes.map((mimeType) => {
|
|
709
|
+
const firstBody = body.content![mimeType].schema;
|
|
710
|
+
if (firstBody === undefined) {
|
|
711
|
+
return undefined;
|
|
712
|
+
}
|
|
713
|
+
if (firstBody.properties !== undefined) {
|
|
714
|
+
if (Object.keys(firstBody.properties).length === 0) {
|
|
715
|
+
return undefined;
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
return create("TabItem", {
|
|
719
|
+
label: mimeType,
|
|
720
|
+
value: `${mimeType}`,
|
|
721
|
+
children: [
|
|
722
|
+
createDetails({
|
|
723
|
+
"data-collapsed": false,
|
|
724
|
+
open: true,
|
|
725
|
+
...rest,
|
|
726
|
+
children: [
|
|
727
|
+
createDetailsSummary({
|
|
728
|
+
style: { textAlign: "left" },
|
|
729
|
+
children: [
|
|
730
|
+
create("strong", { children: `${title}` }),
|
|
731
|
+
guard(firstBody.type === "array", (format) =>
|
|
732
|
+
create("span", {
|
|
733
|
+
style: { opacity: "0.6" },
|
|
734
|
+
children: ` array`,
|
|
735
|
+
})
|
|
736
|
+
),
|
|
737
|
+
guard(body.required, () => [
|
|
738
|
+
create("strong", {
|
|
739
|
+
style: {
|
|
740
|
+
fontSize: "var(--ifm-code-font-size)",
|
|
741
|
+
color: "var(--openapi-required)",
|
|
742
|
+
},
|
|
743
|
+
children: " required",
|
|
744
|
+
}),
|
|
745
|
+
]),
|
|
746
|
+
],
|
|
747
|
+
}),
|
|
748
|
+
create("div", {
|
|
749
|
+
style: { textAlign: "left", marginLeft: "1rem" },
|
|
750
|
+
children: [
|
|
751
|
+
guard(body.description, () => [
|
|
752
|
+
create("div", {
|
|
753
|
+
style: { marginTop: "1rem", marginBottom: "1rem" },
|
|
754
|
+
children: createDescription(body.description),
|
|
755
|
+
}),
|
|
756
|
+
]),
|
|
757
|
+
],
|
|
758
|
+
}),
|
|
759
|
+
create("ul", {
|
|
760
|
+
style: { marginLeft: "1rem" },
|
|
761
|
+
children: createNodes(firstBody),
|
|
762
|
+
}),
|
|
763
|
+
],
|
|
764
|
+
}),
|
|
765
|
+
],
|
|
766
|
+
});
|
|
767
|
+
}),
|
|
768
|
+
});
|
|
769
|
+
}
|
|
770
|
+
|
|
697
771
|
const randomFirstKey = Object.keys(body.content)[0];
|
|
698
772
|
const firstBody = body.content[randomFirstKey].schema;
|
|
699
773
|
|
|
@@ -707,49 +781,57 @@ export function createSchemaDetails({ title, body, ...rest }: Props) {
|
|
|
707
781
|
return undefined;
|
|
708
782
|
}
|
|
709
783
|
}
|
|
710
|
-
|
|
711
|
-
// Root-level schema dropdown
|
|
712
|
-
return createDetails({
|
|
713
|
-
"data-collapsed": false,
|
|
714
|
-
open: true,
|
|
715
|
-
...rest,
|
|
784
|
+
return create("MimeTabs", {
|
|
716
785
|
children: [
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
create("strong", { children: `${title}` }),
|
|
721
|
-
guard(firstBody.type === "array", (format) =>
|
|
722
|
-
create("span", {
|
|
723
|
-
style: { opacity: "0.6" },
|
|
724
|
-
children: ` array`,
|
|
725
|
-
})
|
|
726
|
-
),
|
|
727
|
-
guard(body.required, () => [
|
|
728
|
-
create("strong", {
|
|
729
|
-
style: {
|
|
730
|
-
fontSize: "var(--ifm-code-font-size)",
|
|
731
|
-
color: "var(--openapi-required)",
|
|
732
|
-
},
|
|
733
|
-
children: " required",
|
|
734
|
-
}),
|
|
735
|
-
]),
|
|
736
|
-
],
|
|
737
|
-
}),
|
|
738
|
-
create("div", {
|
|
739
|
-
style: { textAlign: "left", marginLeft: "1rem" },
|
|
786
|
+
create("TabItem", {
|
|
787
|
+
label: randomFirstKey,
|
|
788
|
+
value: `${randomFirstKey}-schema`,
|
|
740
789
|
children: [
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
790
|
+
createDetails({
|
|
791
|
+
"data-collapsed": false,
|
|
792
|
+
open: true,
|
|
793
|
+
...rest,
|
|
794
|
+
children: [
|
|
795
|
+
createDetailsSummary({
|
|
796
|
+
style: { textAlign: "left" },
|
|
797
|
+
children: [
|
|
798
|
+
create("strong", { children: `${title}` }),
|
|
799
|
+
guard(firstBody.type === "array", (format) =>
|
|
800
|
+
create("span", {
|
|
801
|
+
style: { opacity: "0.6" },
|
|
802
|
+
children: ` array`,
|
|
803
|
+
})
|
|
804
|
+
),
|
|
805
|
+
guard(body.required, () => [
|
|
806
|
+
create("strong", {
|
|
807
|
+
style: {
|
|
808
|
+
fontSize: "var(--ifm-code-font-size)",
|
|
809
|
+
color: "var(--openapi-required)",
|
|
810
|
+
},
|
|
811
|
+
children: " required",
|
|
812
|
+
}),
|
|
813
|
+
]),
|
|
814
|
+
],
|
|
815
|
+
}),
|
|
816
|
+
create("div", {
|
|
817
|
+
style: { textAlign: "left", marginLeft: "1rem" },
|
|
818
|
+
children: [
|
|
819
|
+
guard(body.description, () => [
|
|
820
|
+
create("div", {
|
|
821
|
+
style: { marginTop: "1rem", marginBottom: "1rem" },
|
|
822
|
+
children: createDescription(body.description),
|
|
823
|
+
}),
|
|
824
|
+
]),
|
|
825
|
+
],
|
|
826
|
+
}),
|
|
827
|
+
create("ul", {
|
|
828
|
+
style: { marginLeft: "1rem" },
|
|
829
|
+
children: createNodes(firstBody),
|
|
830
|
+
}),
|
|
831
|
+
],
|
|
832
|
+
}),
|
|
747
833
|
],
|
|
748
834
|
}),
|
|
749
|
-
create("ul", {
|
|
750
|
-
style: { marginLeft: "1rem" },
|
|
751
|
-
children: createNodes(firstBody),
|
|
752
|
-
}),
|
|
753
835
|
],
|
|
754
836
|
});
|
|
755
837
|
}
|
package/src/markdown/index.ts
CHANGED
|
@@ -10,6 +10,7 @@ import { escape } from "lodash";
|
|
|
10
10
|
import {
|
|
11
11
|
ContactObject,
|
|
12
12
|
LicenseObject,
|
|
13
|
+
MediaTypeObject,
|
|
13
14
|
SecuritySchemeObject,
|
|
14
15
|
} from "../openapi/types";
|
|
15
16
|
import { ApiPageMetadata, InfoPageMetadata, TagPageMetadata } from "../types";
|
|
@@ -26,6 +27,17 @@ import { createTermsOfService } from "./createTermsOfService";
|
|
|
26
27
|
import { createVersionBadge } from "./createVersionBadge";
|
|
27
28
|
import { render } from "./utils";
|
|
28
29
|
|
|
30
|
+
interface Props {
|
|
31
|
+
title: string;
|
|
32
|
+
body: {
|
|
33
|
+
content?: {
|
|
34
|
+
[key: string]: MediaTypeObject;
|
|
35
|
+
};
|
|
36
|
+
description?: string;
|
|
37
|
+
required?: boolean;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
29
41
|
export function createApiPageMD({
|
|
30
42
|
title,
|
|
31
43
|
api: {
|
|
@@ -39,6 +51,7 @@ export function createApiPageMD({
|
|
|
39
51
|
}: ApiPageMetadata) {
|
|
40
52
|
return render([
|
|
41
53
|
`import ApiTabs from "@theme/ApiTabs";\n`,
|
|
54
|
+
`import MimeTabs from "@theme/MimeTabs";\n`,
|
|
42
55
|
`import ParamsItem from "@theme/ParamsItem";\n`,
|
|
43
56
|
`import ResponseSamples from "@theme/ResponseSamples";\n`,
|
|
44
57
|
`import SchemaItem from "@theme/SchemaItem"\n`,
|
|
@@ -52,7 +65,10 @@ export function createApiPageMD({
|
|
|
52
65
|
createParamsDetails({ parameters, type: "query" }),
|
|
53
66
|
createParamsDetails({ parameters, type: "header" }),
|
|
54
67
|
createParamsDetails({ parameters, type: "cookie" }),
|
|
55
|
-
createRequestBodyDetails({
|
|
68
|
+
createRequestBodyDetails({
|
|
69
|
+
title: "Request Body",
|
|
70
|
+
body: requestBody,
|
|
71
|
+
} as Props),
|
|
56
72
|
createStatusCodes({ responses }),
|
|
57
73
|
]);
|
|
58
74
|
}
|
package/src/openapi/openapi.ts
CHANGED
|
@@ -175,6 +175,18 @@ function createItems(
|
|
|
175
175
|
jsonRequestBodyExample = sampleFromSchema(body.schema);
|
|
176
176
|
}
|
|
177
177
|
|
|
178
|
+
// Handle vendor JSON media types
|
|
179
|
+
const bodyContent = operationObject.requestBody?.content;
|
|
180
|
+
if (bodyContent) {
|
|
181
|
+
const firstBodyContentKey = Object.keys(bodyContent)[0];
|
|
182
|
+
if (firstBodyContentKey.endsWith("+json")) {
|
|
183
|
+
const firstBody = bodyContent[firstBodyContentKey];
|
|
184
|
+
if (firstBody?.schema) {
|
|
185
|
+
jsonRequestBodyExample = sampleFromSchema(firstBody.schema);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
178
190
|
// TODO: Don't include summary temporarilly
|
|
179
191
|
const { summary, ...defaults } = operationObject;
|
|
180
192
|
|