docusaurus-plugin-openapi-docs 0.0.0-416 → 0.0.0-419

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 {};
@@ -7,7 +7,7 @@ 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
13
  export declare function createSchemaDetails({ title, body, ...rest }: Props): string | undefined;
@@ -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
- const { mergedSchemas } = mergeAllOf((_f = schema.items) === null || _f === void 0 ? void 0 : _f.allOf);
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
  }
@@ -453,7 +455,7 @@ function createEdges({ name, schema, required, discriminator, }) {
453
455
  return (0, utils_1.create)("SchemaItem", {
454
456
  collapsible: false,
455
457
  name,
456
- required,
458
+ required: Array.isArray(required) ? required.includes(name) : required,
457
459
  schemaDescription: mergedSchemas.description,
458
460
  schemaName: schemaName,
459
461
  qualifierMessage: (0, schema_1.getQualifierMessage)(schema),
@@ -474,7 +476,7 @@ function createEdges({ name, schema, required, discriminator, }) {
474
476
  return (0, utils_1.create)("SchemaItem", {
475
477
  collapsible: false,
476
478
  name,
477
- required,
479
+ required: Array.isArray(required) ? required.includes(name) : required,
478
480
  schemaDescription: schema.description,
479
481
  schemaName: schemaName,
480
482
  qualifierMessage: (0, schema_1.getQualifierMessage)(schema),
@@ -541,8 +543,71 @@ function createSchemaDetails({ title, body, ...rest }) {
541
543
  Object.keys(body.content).length === 0) {
542
544
  return undefined;
543
545
  }
544
- // NOTE: We just pick a random content-type.
545
- // How common is it to have multiple?
546
+ // Get all MIME types, including vendor-specific
547
+ const mimeTypes = Object.keys(body.content);
548
+ if (mimeTypes && mimeTypes.length > 1) {
549
+ return (0, utils_1.create)("MimeTabs", {
550
+ groupId: "mime-type",
551
+ children: mimeTypes.map((mimeType) => {
552
+ const firstBody = body.content[mimeType].schema;
553
+ if (firstBody === undefined) {
554
+ return undefined;
555
+ }
556
+ if (firstBody.properties !== undefined) {
557
+ if (Object.keys(firstBody.properties).length === 0) {
558
+ return undefined;
559
+ }
560
+ }
561
+ return (0, utils_1.create)("TabItem", {
562
+ label: mimeType,
563
+ value: `${mimeType}`,
564
+ children: [
565
+ (0, createDetails_1.createDetails)({
566
+ "data-collapsed": false,
567
+ open: true,
568
+ ...rest,
569
+ children: [
570
+ (0, createDetailsSummary_1.createDetailsSummary)({
571
+ style: { textAlign: "left" },
572
+ children: [
573
+ (0, utils_1.create)("strong", { children: `${title}` }),
574
+ (0, utils_1.guard)(firstBody.type === "array", (format) => (0, utils_1.create)("span", {
575
+ style: { opacity: "0.6" },
576
+ children: ` array`,
577
+ })),
578
+ (0, utils_1.guard)(body.required && body.required === true, () => [
579
+ (0, utils_1.create)("strong", {
580
+ style: {
581
+ fontSize: "var(--ifm-code-font-size)",
582
+ color: "var(--openapi-required)",
583
+ },
584
+ children: " required",
585
+ }),
586
+ ]),
587
+ ],
588
+ }),
589
+ (0, utils_1.create)("div", {
590
+ style: { textAlign: "left", marginLeft: "1rem" },
591
+ children: [
592
+ (0, utils_1.guard)(body.description, () => [
593
+ (0, utils_1.create)("div", {
594
+ style: { marginTop: "1rem", marginBottom: "1rem" },
595
+ children: (0, createDescription_1.createDescription)(body.description),
596
+ }),
597
+ ]),
598
+ ],
599
+ }),
600
+ (0, utils_1.create)("ul", {
601
+ style: { marginLeft: "1rem" },
602
+ children: createNodes(firstBody),
603
+ }),
604
+ ],
605
+ }),
606
+ ],
607
+ });
608
+ }),
609
+ });
610
+ }
546
611
  const randomFirstKey = Object.keys(body.content)[0];
547
612
  const firstBody = body.content[randomFirstKey].schema;
548
613
  if (firstBody === undefined) {
@@ -554,46 +619,55 @@ function createSchemaDetails({ title, body, ...rest }) {
554
619
  return undefined;
555
620
  }
556
621
  }
557
- // Root-level schema dropdown
558
- return (0, createDetails_1.createDetails)({
559
- "data-collapsed": false,
560
- open: true,
561
- ...rest,
622
+ return (0, utils_1.create)("MimeTabs", {
562
623
  children: [
563
- (0, createDetailsSummary_1.createDetailsSummary)({
564
- style: { textAlign: "left" },
624
+ (0, utils_1.create)("TabItem", {
625
+ label: randomFirstKey,
626
+ value: `${randomFirstKey}-schema`,
565
627
  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
- ]),
628
+ (0, createDetails_1.createDetails)({
629
+ "data-collapsed": false,
630
+ open: true,
631
+ ...rest,
632
+ children: [
633
+ (0, createDetailsSummary_1.createDetailsSummary)({
634
+ style: { textAlign: "left" },
635
+ children: [
636
+ (0, utils_1.create)("strong", { children: `${title}` }),
637
+ (0, utils_1.guard)(firstBody.type === "array", (format) => (0, utils_1.create)("span", {
638
+ style: { opacity: "0.6" },
639
+ children: ` array`,
640
+ })),
641
+ (0, utils_1.guard)(body.required, () => [
642
+ (0, utils_1.create)("strong", {
643
+ style: {
644
+ fontSize: "var(--ifm-code-font-size)",
645
+ color: "var(--openapi-required)",
646
+ },
647
+ children: " required",
648
+ }),
649
+ ]),
650
+ ],
651
+ }),
652
+ (0, utils_1.create)("div", {
653
+ style: { textAlign: "left", marginLeft: "1rem" },
654
+ children: [
655
+ (0, utils_1.guard)(body.description, () => [
656
+ (0, utils_1.create)("div", {
657
+ style: { marginTop: "1rem", marginBottom: "1rem" },
658
+ children: (0, createDescription_1.createDescription)(body.description),
659
+ }),
660
+ ]),
661
+ ],
662
+ }),
663
+ (0, utils_1.create)("ul", {
664
+ style: { marginLeft: "1rem" },
665
+ children: createNodes(firstBody),
666
+ }),
667
+ ],
668
+ }),
591
669
  ],
592
670
  }),
593
- (0, utils_1.create)("ul", {
594
- style: { marginLeft: "1rem" },
595
- children: createNodes(firstBody),
596
- }),
597
671
  ],
598
672
  });
599
673
  }
@@ -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-416",
4
+ "version": "0.0.0-419",
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": "84a35572bf6f740b5b08204fc1947e4da4313a35"
70
+ "gitHead": "c5df2d9c69e2d3881b329ba3586cbc3853ba553b"
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
  }
@@ -227,8 +227,12 @@ function createItems(schema: SchemaObject) {
227
227
  }
228
228
 
229
229
  if (schema.items?.allOf !== undefined) {
230
- const { mergedSchemas }: { mergedSchemas: SchemaObject; required: any } =
231
- mergeAllOf(schema.items?.allOf);
230
+ // TODO: figure out if and how we should pass merged required array
231
+ const {
232
+ mergedSchemas,
233
+ }: { mergedSchemas: SchemaObject; required: string[] } = mergeAllOf(
234
+ schema.items?.allOf
235
+ );
232
236
 
233
237
  // Handles combo anyOf/oneOf + properties
234
238
  if (
@@ -387,7 +391,7 @@ function createDetailsNode(
387
391
  name: string,
388
392
  schemaName: string,
389
393
  schema: SchemaObject,
390
- required: any
394
+ required: string[] | boolean
391
395
  ): any {
392
396
  return create("SchemaItem", {
393
397
  collapsible: true,
@@ -402,7 +406,7 @@ function createDetailsNode(
402
406
  style: { opacity: "0.6" },
403
407
  children: ` ${schemaName}`,
404
408
  }),
405
- guard(required, () => [
409
+ guard(schema.required && schema.required === true, () => [
406
410
  create("strong", {
407
411
  style: {
408
412
  fontSize: "var(--ifm-code-font-size)",
@@ -446,7 +450,7 @@ function createPropertyDiscriminator(
446
450
  schemaName: string,
447
451
  schema: SchemaObject,
448
452
  discriminator: any,
449
- required: any
453
+ required: string[] | boolean
450
454
  ): any {
451
455
  if (schema === undefined) {
452
456
  return undefined;
@@ -515,7 +519,7 @@ function createPropertyDiscriminator(
515
519
  interface EdgeProps {
516
520
  name: string;
517
521
  schema: SchemaObject;
518
- required: boolean;
522
+ required: string[] | boolean;
519
523
  discriminator?: any | unknown;
520
524
  }
521
525
 
@@ -530,6 +534,8 @@ function createEdges({
530
534
  }: EdgeProps): any {
531
535
  const schemaName = getSchemaName(schema);
532
536
 
537
+ // if (name === "id") console.log(name, schema, required);
538
+
533
539
  if (discriminator !== undefined && discriminator.propertyName === name) {
534
540
  return createPropertyDiscriminator(
535
541
  name,
@@ -548,9 +554,8 @@ function createEdges({
548
554
  const {
549
555
  mergedSchemas,
550
556
  required,
551
- }: { mergedSchemas: SchemaObject; required: any } = mergeAllOf(
552
- schema.allOf
553
- );
557
+ }: { mergedSchemas: SchemaObject; required: string[] | boolean } =
558
+ mergeAllOf(schema.allOf);
554
559
  const mergedSchemaName = getSchemaName(mergedSchemas);
555
560
 
556
561
  if (
@@ -576,7 +581,7 @@ function createEdges({
576
581
  return create("SchemaItem", {
577
582
  collapsible: false,
578
583
  name,
579
- required,
584
+ required: Array.isArray(required) ? required.includes(name) : required,
580
585
  schemaDescription: mergedSchemas.description,
581
586
  schemaName: schemaName,
582
587
  qualifierMessage: getQualifierMessage(schema),
@@ -601,7 +606,7 @@ function createEdges({
601
606
  return create("SchemaItem", {
602
607
  collapsible: false,
603
608
  name,
604
- required,
609
+ required: Array.isArray(required) ? required.includes(name) : required,
605
610
  schemaDescription: schema.description,
606
611
  schemaName: schemaName,
607
612
  qualifierMessage: getQualifierMessage(schema),
@@ -685,7 +690,7 @@ interface Props {
685
690
  [key: string]: MediaTypeObject;
686
691
  };
687
692
  description?: string;
688
- required?: boolean;
693
+ required?: string[] | boolean;
689
694
  };
690
695
  }
691
696
 
@@ -699,8 +704,75 @@ export function createSchemaDetails({ title, body, ...rest }: Props) {
699
704
  return undefined;
700
705
  }
701
706
 
702
- // NOTE: We just pick a random content-type.
703
- // How common is it to have multiple?
707
+ // Get all MIME types, including vendor-specific
708
+ const mimeTypes = Object.keys(body.content);
709
+
710
+ if (mimeTypes && mimeTypes.length > 1) {
711
+ return create("MimeTabs", {
712
+ groupId: "mime-type",
713
+ children: mimeTypes.map((mimeType) => {
714
+ const firstBody = body.content![mimeType].schema;
715
+ if (firstBody === undefined) {
716
+ return undefined;
717
+ }
718
+ if (firstBody.properties !== undefined) {
719
+ if (Object.keys(firstBody.properties).length === 0) {
720
+ return undefined;
721
+ }
722
+ }
723
+ return create("TabItem", {
724
+ label: mimeType,
725
+ value: `${mimeType}`,
726
+ children: [
727
+ createDetails({
728
+ "data-collapsed": false,
729
+ open: true,
730
+ ...rest,
731
+ children: [
732
+ createDetailsSummary({
733
+ style: { textAlign: "left" },
734
+ children: [
735
+ create("strong", { children: `${title}` }),
736
+ guard(firstBody.type === "array", (format) =>
737
+ create("span", {
738
+ style: { opacity: "0.6" },
739
+ children: ` array`,
740
+ })
741
+ ),
742
+ guard(body.required && body.required === true, () => [
743
+ create("strong", {
744
+ style: {
745
+ fontSize: "var(--ifm-code-font-size)",
746
+ color: "var(--openapi-required)",
747
+ },
748
+ children: " required",
749
+ }),
750
+ ]),
751
+ ],
752
+ }),
753
+ create("div", {
754
+ style: { textAlign: "left", marginLeft: "1rem" },
755
+ children: [
756
+ guard(body.description, () => [
757
+ create("div", {
758
+ style: { marginTop: "1rem", marginBottom: "1rem" },
759
+ children: createDescription(body.description),
760
+ }),
761
+ ]),
762
+ ],
763
+ }),
764
+ create("ul", {
765
+ style: { marginLeft: "1rem" },
766
+ children: createNodes(firstBody),
767
+ }),
768
+ ],
769
+ }),
770
+ ],
771
+ });
772
+ }),
773
+ });
774
+ }
775
+
704
776
  const randomFirstKey = Object.keys(body.content)[0];
705
777
  const firstBody = body.content[randomFirstKey].schema;
706
778
 
@@ -714,49 +786,57 @@ export function createSchemaDetails({ title, body, ...rest }: Props) {
714
786
  return undefined;
715
787
  }
716
788
  }
717
-
718
- // Root-level schema dropdown
719
- return createDetails({
720
- "data-collapsed": false,
721
- open: true,
722
- ...rest,
789
+ return create("MimeTabs", {
723
790
  children: [
724
- createDetailsSummary({
725
- style: { textAlign: "left" },
791
+ create("TabItem", {
792
+ label: randomFirstKey,
793
+ value: `${randomFirstKey}-schema`,
726
794
  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
- ]),
795
+ createDetails({
796
+ "data-collapsed": false,
797
+ open: true,
798
+ ...rest,
799
+ children: [
800
+ createDetailsSummary({
801
+ style: { textAlign: "left" },
802
+ children: [
803
+ create("strong", { children: `${title}` }),
804
+ guard(firstBody.type === "array", (format) =>
805
+ create("span", {
806
+ style: { opacity: "0.6" },
807
+ children: ` array`,
808
+ })
809
+ ),
810
+ guard(body.required, () => [
811
+ create("strong", {
812
+ style: {
813
+ fontSize: "var(--ifm-code-font-size)",
814
+ color: "var(--openapi-required)",
815
+ },
816
+ children: " required",
817
+ }),
818
+ ]),
819
+ ],
820
+ }),
821
+ create("div", {
822
+ style: { textAlign: "left", marginLeft: "1rem" },
823
+ children: [
824
+ guard(body.description, () => [
825
+ create("div", {
826
+ style: { marginTop: "1rem", marginBottom: "1rem" },
827
+ children: createDescription(body.description),
828
+ }),
829
+ ]),
830
+ ],
831
+ }),
832
+ create("ul", {
833
+ style: { marginLeft: "1rem" },
834
+ children: createNodes(firstBody),
835
+ }),
836
+ ],
837
+ }),
754
838
  ],
755
839
  }),
756
- create("ul", {
757
- style: { marginLeft: "1rem" },
758
- children: createNodes(firstBody),
759
- }),
760
840
  ],
761
841
  });
762
842
  }
@@ -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