docusaurus-plugin-openapi-docs 1.1.5 → 1.1.8

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 (schema.additionalProperties !== undefined) {
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 > 1) {
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, createDetails_1.createDetails)({
572
- "data-collapsed": false,
573
- open: true,
574
- ...rest,
576
+ (0, utils_1.create)("SchemaTabs", {
577
+ groupId: "schema-tabs",
575
578
  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),
579
+ firstBody &&
580
+ (0, utils_1.create)("TabItem", {
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, utils_1.create)("ul", {
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
- const randomFirstKey = Object.keys(body.content)[0];
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");
@@ -55,20 +55,54 @@ function createResponseHeaders(responseHeaders) {
55
55
  }
56
56
  function createResponseExamples(responseExamples) {
57
57
  return Object.entries(responseExamples).map(([exampleName, exampleValue]) => {
58
- var _a;
59
58
  const camelToSpaceName = exampleName.replace(/([A-Z])/g, " $1");
60
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
+ }
61
71
  return (0, utils_1.create)("TabItem", {
62
72
  label: `${finalFormattedName}`,
63
73
  value: `${finalFormattedName}`,
64
74
  children: [
65
75
  (0, utils_1.create)("ResponseSamples", {
66
- responseExample: JSON.stringify((_a = exampleValue.value) !== null && _a !== void 0 ? _a : exampleValue, null, 2),
76
+ responseExample: exampleValue.value,
67
77
  }),
68
78
  ],
69
79
  });
70
80
  });
71
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;
72
106
  function createStatusCodes({ responses }) {
73
107
  if (responses === undefined) {
74
108
  return undefined;
@@ -80,13 +114,10 @@ function createStatusCodes({ responses }) {
80
114
  return (0, utils_1.create)("div", {
81
115
  children: [
82
116
  (0, utils_1.create)("ApiTabs", {
117
+ // TODO: determine if we should persist status code selection
118
+ // groupId: "api-tabs",
83
119
  children: codes.map((code) => {
84
120
  const responseHeaders = responses[code].headers;
85
- const responseContent = responses[code].content;
86
- const responseContentKey = responseContent && Object.keys(responseContent)[0];
87
- const responseExamples = responseContentKey &&
88
- (responseContent[responseContentKey].examples ||
89
- responseContent[responseContentKey].example);
90
121
  return (0, utils_1.create)("TabItem", {
91
122
  label: code,
92
123
  value: code,
@@ -94,62 +125,30 @@ function createStatusCodes({ responses }) {
94
125
  (0, utils_1.create)("div", {
95
126
  children: (0, createDescription_1.createDescription)(responses[code].description),
96
127
  }),
97
- (0, utils_2.guard)(responseExamples, () => (0, utils_1.create)("SchemaTabs", {
98
- children: [
99
- (0, utils_1.create)("TabTtem", {
100
- label: "Schema",
101
- value: "Schema",
102
- children: [
103
- responseHeaders &&
104
- (0, createDetails_1.createDetails)({
105
- "data-collaposed": false,
106
- open: true,
107
- style: { textAlign: "left", marginBottom: "1rem" },
108
- children: [
109
- (0, createDetailsSummary_1.createDetailsSummary)({
110
- children: [
111
- (0, utils_1.create)("strong", {
112
- children: "Response Headers",
113
- }),
114
- ],
115
- }),
116
- createResponseHeaders(responseHeaders),
117
- ],
118
- }),
119
- (0, utils_1.create)("div", {
120
- children: (0, createResponseSchema_1.createResponseSchema)({
121
- title: "Schema",
122
- body: {
123
- content: responses[code].content,
124
- },
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",
125
138
  }),
126
- }),
127
- ],
128
- }),
129
- createResponseExamples(responseExamples),
130
- ],
131
- })),
132
- (0, utils_2.guard)(responseHeaders && !responseExamples, () => (0, createDetails_1.createDetails)({
133
- "data-collaposed": false,
134
- open: true,
135
- style: { textAlign: "left" },
136
- children: [
137
- (0, createDetailsSummary_1.createDetailsSummary)({
138
- children: [
139
- (0, utils_1.create)("strong", { children: "Response Headers" }),
140
- ],
141
- }),
142
- createResponseHeaders(responseHeaders),
143
- ],
144
- })),
145
- (0, utils_2.guard)(!responseExamples, () => (0, utils_1.create)("div", {
139
+ ],
140
+ }),
141
+ createResponseHeaders(responseHeaders),
142
+ ],
143
+ }),
144
+ (0, utils_1.create)("div", {
146
145
  children: (0, createResponseSchema_1.createResponseSchema)({
147
146
  title: "Schema",
148
147
  body: {
149
148
  content: responses[code].content,
150
149
  },
151
150
  }),
152
- })),
151
+ }),
153
152
  ],
154
153
  });
155
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": "1.1.5",
4
+ "version": "1.1.8",
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": "21d33582a9fcac2ddd23443497af910982b36dae"
70
+ "gitHead": "619aa16c52e6de8fd752ff583681b0da093b679c"
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 (schema.additionalProperties !== undefined) {
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 > 1) {
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
- if (firstBody === undefined) {
728
+
729
+ if (
730
+ firstBody === undefined &&
731
+ responseExample === undefined &&
732
+ responseExamples === undefined
733
+ ) {
724
734
  return undefined;
725
735
  }
726
- if (firstBody.properties !== undefined) {
727
- if (Object.keys(firstBody.properties).length === 0) {
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
- createDetails({
736
- "data-collapsed": false,
737
- open: true,
738
- ...rest,
747
+ create("SchemaTabs", {
748
+ groupId: "schema-tabs",
739
749
  children: [
740
- createDetailsSummary({
741
- style: { textAlign: "left" },
742
- children: [
743
- create("strong", { children: `${title}` }),
744
- guard(firstBody.type === "array", (format) =>
745
- create("span", {
746
- style: { opacity: "0.6" },
747
- children: ` array`,
748
- })
749
- ),
750
- guard(body.required && body.required === true, () => [
751
- create("strong", {
752
- style: {
753
- fontSize: "var(--ifm-code-font-size)",
754
- color: "var(--openapi-required)",
755
- },
756
- children: " required",
757
- }),
758
- ]),
759
- ],
760
- }),
761
- create("div", {
762
- style: { textAlign: "left", marginLeft: "1rem" },
763
- children: [
764
- guard(body.description, () => [
765
- create("div", {
766
- style: { marginTop: "1rem", marginBottom: "1rem" },
767
- children: createDescription(body.description),
750
+ firstBody &&
751
+ create("TabItem", {
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
- create("ul", {
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
- const randomFirstKey = Object.keys(body.content)[0];
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,23 +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: JSON.stringify(
83
- exampleValue.value ?? exampleValue,
84
- null,
85
- 2
86
- ),
93
+ responseExample: exampleValue.value,
87
94
  }),
88
95
  ],
89
96
  });
@@ -91,6 +98,29 @@ function createResponseExamples(responseExamples: any) {
91
98
  );
92
99
  }
93
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
+
94
124
  export function createStatusCodes({ responses }: Props) {
95
125
  if (responses === undefined) {
96
126
  return undefined;
@@ -104,16 +134,10 @@ export function createStatusCodes({ responses }: Props) {
104
134
  return create("div", {
105
135
  children: [
106
136
  create("ApiTabs", {
137
+ // TODO: determine if we should persist status code selection
138
+ // groupId: "api-tabs",
107
139
  children: codes.map((code) => {
108
140
  const responseHeaders: any = responses[code].headers;
109
- const responseContent: any = responses[code].content;
110
- const responseContentKey: any =
111
- responseContent && Object.keys(responseContent)[0];
112
- const responseExamples: any =
113
- responseContentKey &&
114
- (responseContent[responseContentKey].examples ||
115
- responseContent[responseContentKey].example);
116
-
117
141
  return create("TabItem", {
118
142
  label: code,
119
143
  value: code,
@@ -121,68 +145,30 @@ export function createStatusCodes({ responses }: Props) {
121
145
  create("div", {
122
146
  children: createDescription(responses[code].description),
123
147
  }),
124
- guard(responseExamples, () =>
125
- create("SchemaTabs", {
126
- children: [
127
- create("TabTtem", {
128
- label: "Schema",
129
- value: "Schema",
130
- children: [
131
- responseHeaders &&
132
- createDetails({
133
- "data-collaposed": false,
134
- open: true,
135
- style: { textAlign: "left", marginBottom: "1rem" },
136
- children: [
137
- createDetailsSummary({
138
- children: [
139
- create("strong", {
140
- children: "Response Headers",
141
- }),
142
- ],
143
- }),
144
- createResponseHeaders(responseHeaders),
145
- ],
146
- }),
147
- create("div", {
148
- children: createResponseSchema({
149
- title: "Schema",
150
- body: {
151
- content: responses[code].content,
152
- },
153
- }),
154
- }),
155
- ],
156
- }),
157
- createResponseExamples(responseExamples),
158
- ],
159
- })
160
- ),
161
- guard(responseHeaders && !responseExamples, () =>
148
+ responseHeaders &&
162
149
  createDetails({
163
150
  "data-collaposed": false,
164
151
  open: true,
165
- style: { textAlign: "left" },
152
+ style: { textAlign: "left", marginBottom: "1rem" },
166
153
  children: [
167
154
  createDetailsSummary({
168
155
  children: [
169
- create("strong", { children: "Response Headers" }),
156
+ create("strong", {
157
+ children: "Response Headers",
158
+ }),
170
159
  ],
171
160
  }),
172
161
  createResponseHeaders(responseHeaders),
173
162
  ],
174
- })
175
- ),
176
- guard(!responseExamples, () =>
177
- create("div", {
178
- children: createResponseSchema({
179
- title: "Schema",
180
- body: {
181
- content: responses[code].content,
182
- },
183
- }),
184
- })
185
- ),
163
+ }),
164
+ create("div", {
165
+ children: createResponseSchema({
166
+ title: "Schema",
167
+ body: {
168
+ content: responses[code].content,
169
+ },
170
+ }),
171
+ }),
186
172
  ],
187
173
  });
188
174
  }),