docusaurus-plugin-openapi-docs 0.0.0-417 → 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.
@@ -1,6 +1,13 @@
1
+ import { MediaTypeObject } from "../openapi/types";
1
2
  interface Props {
2
3
  title: string;
3
- body: any;
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): string | undefined;
12
+ export declare function createRequestBodyDetails({ title, body }: Props): any;
6
13
  export {};
@@ -541,8 +541,71 @@ function createSchemaDetails({ title, body, ...rest }) {
541
541
  Object.keys(body.content).length === 0) {
542
542
  return undefined;
543
543
  }
544
- // NOTE: We just pick a random content-type.
545
- // How common is it to have multiple?
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
+ }
546
609
  const randomFirstKey = Object.keys(body.content)[0];
547
610
  const firstBody = body.content[randomFirstKey].schema;
548
611
  if (firstBody === undefined) {
@@ -554,46 +617,55 @@ function createSchemaDetails({ title, body, ...rest }) {
554
617
  return undefined;
555
618
  }
556
619
  }
557
- // Root-level schema dropdown
558
- return (0, createDetails_1.createDetails)({
559
- "data-collapsed": false,
560
- open: true,
561
- ...rest,
620
+ return (0, utils_1.create)("MimeTabs", {
562
621
  children: [
563
- (0, createDetailsSummary_1.createDetailsSummary)({
564
- style: { textAlign: "left" },
622
+ (0, utils_1.create)("TabItem", {
623
+ label: randomFirstKey,
624
+ value: `${randomFirstKey}-schema`,
565
625
  children: [
566
- (0, utils_1.create)("strong", { children: `${title}` }),
567
- (0, utils_1.guard)(firstBody.type === "array", (format) => (0, utils_1.create)("span", {
568
- style: { opacity: "0.6" },
569
- children: ` array`,
570
- })),
571
- (0, utils_1.guard)(body.required, () => [
572
- (0, utils_1.create)("strong", {
573
- style: {
574
- fontSize: "var(--ifm-code-font-size)",
575
- color: "var(--openapi-required)",
576
- },
577
- children: " required",
578
- }),
579
- ]),
580
- ],
581
- }),
582
- (0, utils_1.create)("div", {
583
- style: { textAlign: "left", marginLeft: "1rem" },
584
- children: [
585
- (0, utils_1.guard)(body.description, () => [
586
- (0, utils_1.create)("div", {
587
- style: { marginTop: "1rem", marginBottom: "1rem" },
588
- children: (0, createDescription_1.createDescription)(body.description),
589
- }),
590
- ]),
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
+ }),
591
667
  ],
592
668
  }),
593
- (0, utils_1.create)("ul", {
594
- style: { marginLeft: "1rem" },
595
- children: createNodes(firstBody),
596
- }),
597
669
  ],
598
670
  });
599
671
  }
@@ -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)({ title: "Request Body", body: requestBody }),
40
+ (0, createRequestBodyDetails_1.createRequestBodyDetails)({
41
+ title: "Request Body",
42
+ body: requestBody,
43
+ }),
40
44
  (0, createStatusCodes_1.createStatusCodes)({ responses }),
41
45
  ]);
42
46
  }
@@ -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: (_q = operationObject.tags) === null || _q === void 0 ? void 0 : _q.map((tagName) => { var _a; return getTagDisplayName(tagName, (_a = openapiData.tags) !== null && _a !== void 0 ? _a : []); }),
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-417",
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": "ba966845b63e38ad91bfdef96905f353ef6edac5"
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: any;
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
  }
@@ -699,8 +699,75 @@ export function createSchemaDetails({ title, body, ...rest }: Props) {
699
699
  return undefined;
700
700
  }
701
701
 
702
- // NOTE: We just pick a random content-type.
703
- // How common is it to have multiple?
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
+
704
771
  const randomFirstKey = Object.keys(body.content)[0];
705
772
  const firstBody = body.content[randomFirstKey].schema;
706
773
 
@@ -714,49 +781,57 @@ export function createSchemaDetails({ title, body, ...rest }: Props) {
714
781
  return undefined;
715
782
  }
716
783
  }
717
-
718
- // Root-level schema dropdown
719
- return createDetails({
720
- "data-collapsed": false,
721
- open: true,
722
- ...rest,
784
+ return create("MimeTabs", {
723
785
  children: [
724
- createDetailsSummary({
725
- style: { textAlign: "left" },
786
+ create("TabItem", {
787
+ label: randomFirstKey,
788
+ value: `${randomFirstKey}-schema`,
726
789
  children: [
727
- create("strong", { children: `${title}` }),
728
- guard(firstBody.type === "array", (format) =>
729
- create("span", {
730
- style: { opacity: "0.6" },
731
- children: ` array`,
732
- })
733
- ),
734
- guard(body.required, () => [
735
- create("strong", {
736
- style: {
737
- fontSize: "var(--ifm-code-font-size)",
738
- color: "var(--openapi-required)",
739
- },
740
- children: " required",
741
- }),
742
- ]),
743
- ],
744
- }),
745
- create("div", {
746
- style: { textAlign: "left", marginLeft: "1rem" },
747
- children: [
748
- guard(body.description, () => [
749
- create("div", {
750
- style: { marginTop: "1rem", marginBottom: "1rem" },
751
- children: createDescription(body.description),
752
- }),
753
- ]),
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
+ }),
754
833
  ],
755
834
  }),
756
- create("ul", {
757
- style: { marginLeft: "1rem" },
758
- children: createNodes(firstBody),
759
- }),
760
835
  ],
761
836
  });
762
837
  }
@@ -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({ title: "Request Body", body: requestBody }),
68
+ createRequestBodyDetails({
69
+ title: "Request Body",
70
+ body: requestBody,
71
+ } as Props),
56
72
  createStatusCodes({ responses }),
57
73
  ]);
58
74
  }
@@ -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