docusaurus-theme-openapi-docs 0.0.0-1068 → 0.0.0-1070
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.
|
@@ -13,7 +13,6 @@ var __importDefault =
|
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
14
|
const react_1 = __importDefault(require("react"));
|
|
15
15
|
const Translate_1 = require("@docusaurus/Translate");
|
|
16
|
-
const translationIds_1 = require("@theme/translationIds");
|
|
17
16
|
const ArrayBrackets_1 = require("@theme/ArrayBrackets");
|
|
18
17
|
const Details_1 = __importDefault(require("@theme/Details"));
|
|
19
18
|
const DiscriminatorTabs_1 = __importDefault(
|
|
@@ -23,6 +22,7 @@ const Markdown_1 = __importDefault(require("@theme/Markdown"));
|
|
|
23
22
|
const SchemaItem_1 = __importDefault(require("@theme/SchemaItem"));
|
|
24
23
|
const SchemaTabs_1 = __importDefault(require("@theme/SchemaTabs"));
|
|
25
24
|
const TabItem_1 = __importDefault(require("@theme/TabItem"));
|
|
25
|
+
const translationIds_1 = require("@theme/translationIds");
|
|
26
26
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
27
27
|
const allof_merge_1 = require("allof-merge");
|
|
28
28
|
const clsx_1 = __importDefault(require("clsx"));
|
|
@@ -116,6 +116,11 @@ const AnyOneOf = ({ schema, schemaType }) => {
|
|
|
116
116
|
id: translationIds_1.OPENAPI_SCHEMA_ITEM.ANY_OF,
|
|
117
117
|
message: "anyOf",
|
|
118
118
|
});
|
|
119
|
+
// Generate a unique ID for this anyOf/oneOf to prevent tab value collisions
|
|
120
|
+
const uniqueId = react_1.default.useMemo(
|
|
121
|
+
() => Math.random().toString(36).substring(7),
|
|
122
|
+
[]
|
|
123
|
+
);
|
|
119
124
|
return react_1.default.createElement(
|
|
120
125
|
react_1.default.Fragment,
|
|
121
126
|
null,
|
|
@@ -126,14 +131,31 @@ const AnyOneOf = ({ schema, schemaType }) => {
|
|
|
126
131
|
),
|
|
127
132
|
react_1.default.createElement(
|
|
128
133
|
SchemaTabs_1.default,
|
|
129
|
-
|
|
134
|
+
{ groupId: `schema-${uniqueId}`, lazy: true },
|
|
130
135
|
schema[key]?.map((anyOneSchema, index) => {
|
|
131
|
-
|
|
136
|
+
// Determine label for the tab
|
|
137
|
+
// If schema is just oneOf/anyOf without title/type, use a generic label
|
|
138
|
+
let label = anyOneSchema.title || anyOneSchema.type;
|
|
139
|
+
if (!label) {
|
|
140
|
+
if (anyOneSchema.oneOf) {
|
|
141
|
+
label = (0, Translate_1.translate)({
|
|
142
|
+
id: translationIds_1.OPENAPI_SCHEMA_ITEM.ONE_OF,
|
|
143
|
+
message: "oneOf",
|
|
144
|
+
});
|
|
145
|
+
} else if (anyOneSchema.anyOf) {
|
|
146
|
+
label = (0, Translate_1.translate)({
|
|
147
|
+
id: translationIds_1.OPENAPI_SCHEMA_ITEM.ANY_OF,
|
|
148
|
+
message: "anyOf",
|
|
149
|
+
});
|
|
150
|
+
} else {
|
|
151
|
+
label = `Option ${index + 1}`;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
132
154
|
return (
|
|
133
155
|
// @ts-ignore
|
|
134
156
|
react_1.default.createElement(
|
|
135
157
|
TabItem_1.default,
|
|
136
|
-
{ key: index, label: label, value: `${index}-item
|
|
158
|
+
{ key: index, label: label, value: `${uniqueId}-${index}-item` },
|
|
137
159
|
(isPrimitive(anyOneSchema) || anyOneSchema.const) &&
|
|
138
160
|
react_1.default.createElement(SchemaItem_1.default, {
|
|
139
161
|
collapsible: false,
|
|
@@ -162,7 +184,7 @@ const AnyOneOf = ({ schema, schemaType }) => {
|
|
|
162
184
|
discriminator: false,
|
|
163
185
|
children: null,
|
|
164
186
|
}),
|
|
165
|
-
anyOneSchema.type === "object" &&
|
|
187
|
+
(anyOneSchema.type === "object" || !anyOneSchema.type) &&
|
|
166
188
|
anyOneSchema.properties &&
|
|
167
189
|
react_1.default.createElement(Properties, {
|
|
168
190
|
schema: anyOneSchema,
|
|
@@ -775,6 +797,47 @@ const SchemaNode = ({ schema, schemaType }) => {
|
|
|
775
797
|
}
|
|
776
798
|
// Handle allOf, oneOf, anyOf without discriminators
|
|
777
799
|
if (schema.allOf) {
|
|
800
|
+
// Check if allOf contains multiple oneOf/anyOf items that should be rendered separately
|
|
801
|
+
const oneOfItems = schema.allOf.filter((item) => item.oneOf || item.anyOf);
|
|
802
|
+
const hasMultipleChoices = oneOfItems.length > 1;
|
|
803
|
+
if (hasMultipleChoices) {
|
|
804
|
+
// Render each oneOf/anyOf constraint first, then shared properties
|
|
805
|
+
const mergedSchemas = mergeAllOf(schema);
|
|
806
|
+
if (
|
|
807
|
+
(schemaType === "request" && mergedSchemas.readOnly) ||
|
|
808
|
+
(schemaType === "response" && mergedSchemas.writeOnly)
|
|
809
|
+
) {
|
|
810
|
+
return null;
|
|
811
|
+
}
|
|
812
|
+
return react_1.default.createElement(
|
|
813
|
+
"div",
|
|
814
|
+
null,
|
|
815
|
+
schema.allOf.map((item, index) => {
|
|
816
|
+
if (item.oneOf || item.anyOf) {
|
|
817
|
+
return react_1.default.createElement(
|
|
818
|
+
"div",
|
|
819
|
+
{ key: index },
|
|
820
|
+
react_1.default.createElement(AnyOneOf, {
|
|
821
|
+
schema: item,
|
|
822
|
+
schemaType: schemaType,
|
|
823
|
+
})
|
|
824
|
+
);
|
|
825
|
+
}
|
|
826
|
+
return null;
|
|
827
|
+
}),
|
|
828
|
+
mergedSchemas.properties &&
|
|
829
|
+
react_1.default.createElement(Properties, {
|
|
830
|
+
schema: mergedSchemas,
|
|
831
|
+
schemaType: schemaType,
|
|
832
|
+
}),
|
|
833
|
+
mergedSchemas.items &&
|
|
834
|
+
react_1.default.createElement(Items, {
|
|
835
|
+
schema: mergedSchemas,
|
|
836
|
+
schemaType: schemaType,
|
|
837
|
+
})
|
|
838
|
+
);
|
|
839
|
+
}
|
|
840
|
+
// For other allOf cases, use standard merge behavior
|
|
778
841
|
const mergedSchemas = mergeAllOf(schema);
|
|
779
842
|
if (
|
|
780
843
|
(schemaType === "request" && mergedSchemas.readOnly) ||
|
|
@@ -141,7 +141,10 @@ function TabList({ className, block, selectedValue, selectValue, tabValues }) {
|
|
|
141
141
|
};
|
|
142
142
|
return react_1.default.createElement(
|
|
143
143
|
"div",
|
|
144
|
-
{
|
|
144
|
+
{
|
|
145
|
+
className: "openapi-tabs__schema-tabs-container",
|
|
146
|
+
style: { marginBottom: "1rem" },
|
|
147
|
+
},
|
|
145
148
|
showTabArrows &&
|
|
146
149
|
react_1.default.createElement("button", {
|
|
147
150
|
className: "openapi-tabs__arrow left",
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "docusaurus-theme-openapi-docs",
|
|
3
3
|
"description": "OpenAPI theme for Docusaurus.",
|
|
4
|
-
"version": "0.0.0-
|
|
4
|
+
"version": "0.0.0-1070",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"openapi",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"@types/postman-collection": "^3.5.11",
|
|
39
39
|
"@types/react-modal": "^3.16.3",
|
|
40
40
|
"concurrently": "^9.2.0",
|
|
41
|
-
"docusaurus-plugin-openapi-docs": "0.0.0-
|
|
41
|
+
"docusaurus-plugin-openapi-docs": "0.0.0-1070",
|
|
42
42
|
"docusaurus-plugin-sass": "^0.2.6",
|
|
43
43
|
"eslint-plugin-prettier": "^5.5.1"
|
|
44
44
|
},
|
|
@@ -81,5 +81,5 @@
|
|
|
81
81
|
"engines": {
|
|
82
82
|
"node": ">=14"
|
|
83
83
|
},
|
|
84
|
-
"gitHead": "
|
|
84
|
+
"gitHead": "17e82a49d111895a400d787e51d081cdd60c7964"
|
|
85
85
|
}
|
|
@@ -8,8 +8,6 @@
|
|
|
8
8
|
import React from "react";
|
|
9
9
|
|
|
10
10
|
import { translate } from "@docusaurus/Translate";
|
|
11
|
-
import { OPENAPI_SCHEMA_ITEM } from "@theme/translationIds";
|
|
12
|
-
|
|
13
11
|
import { ClosingArrayBracket, OpeningArrayBracket } from "@theme/ArrayBrackets";
|
|
14
12
|
import Details from "@theme/Details";
|
|
15
13
|
import DiscriminatorTabs from "@theme/DiscriminatorTabs";
|
|
@@ -17,6 +15,7 @@ import Markdown from "@theme/Markdown";
|
|
|
17
15
|
import SchemaItem from "@theme/SchemaItem";
|
|
18
16
|
import SchemaTabs from "@theme/SchemaTabs";
|
|
19
17
|
import TabItem from "@theme/TabItem";
|
|
18
|
+
import { OPENAPI_SCHEMA_ITEM } from "@theme/translationIds";
|
|
20
19
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
21
20
|
import { merge } from "allof-merge";
|
|
22
21
|
import clsx from "clsx";
|
|
@@ -132,20 +131,44 @@ const AnyOneOf: React.FC<SchemaProps> = ({ schema, schemaType }) => {
|
|
|
132
131
|
const type = schema.oneOf
|
|
133
132
|
? translate({ id: OPENAPI_SCHEMA_ITEM.ONE_OF, message: "oneOf" })
|
|
134
133
|
: translate({ id: OPENAPI_SCHEMA_ITEM.ANY_OF, message: "anyOf" });
|
|
134
|
+
|
|
135
|
+
// Generate a unique ID for this anyOf/oneOf to prevent tab value collisions
|
|
136
|
+
const uniqueId = React.useMemo(
|
|
137
|
+
() => Math.random().toString(36).substring(7),
|
|
138
|
+
[]
|
|
139
|
+
);
|
|
140
|
+
|
|
135
141
|
return (
|
|
136
142
|
<>
|
|
137
143
|
<span className="badge badge--info" style={{ marginBottom: "1rem" }}>
|
|
138
144
|
{type}
|
|
139
145
|
</span>
|
|
140
|
-
<SchemaTabs>
|
|
146
|
+
<SchemaTabs groupId={`schema-${uniqueId}`} lazy>
|
|
141
147
|
{schema[key]?.map((anyOneSchema: any, index: number) => {
|
|
142
|
-
|
|
148
|
+
// Determine label for the tab
|
|
149
|
+
// If schema is just oneOf/anyOf without title/type, use a generic label
|
|
150
|
+
let label = anyOneSchema.title || anyOneSchema.type;
|
|
151
|
+
if (!label) {
|
|
152
|
+
if (anyOneSchema.oneOf) {
|
|
153
|
+
label = translate({
|
|
154
|
+
id: OPENAPI_SCHEMA_ITEM.ONE_OF,
|
|
155
|
+
message: "oneOf",
|
|
156
|
+
});
|
|
157
|
+
} else if (anyOneSchema.anyOf) {
|
|
158
|
+
label = translate({
|
|
159
|
+
id: OPENAPI_SCHEMA_ITEM.ANY_OF,
|
|
160
|
+
message: "anyOf",
|
|
161
|
+
});
|
|
162
|
+
} else {
|
|
163
|
+
label = `Option ${index + 1}`;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
143
166
|
return (
|
|
144
167
|
// @ts-ignore
|
|
145
168
|
<TabItem
|
|
146
169
|
key={index}
|
|
147
170
|
label={label}
|
|
148
|
-
value={`${index}-item
|
|
171
|
+
value={`${uniqueId}-${index}-item`}
|
|
149
172
|
>
|
|
150
173
|
{/* Handle primitive types directly */}
|
|
151
174
|
{(isPrimitive(anyOneSchema) || anyOneSchema.const) && (
|
|
@@ -178,9 +201,11 @@ const AnyOneOf: React.FC<SchemaProps> = ({ schema, schemaType }) => {
|
|
|
178
201
|
)}
|
|
179
202
|
|
|
180
203
|
{/* Handle actual object types with properties or nested schemas */}
|
|
181
|
-
{
|
|
182
|
-
|
|
183
|
-
|
|
204
|
+
{/* Note: In OpenAPI, properties implies type: object even if not explicitly set */}
|
|
205
|
+
{(anyOneSchema.type === "object" || !anyOneSchema.type) &&
|
|
206
|
+
anyOneSchema.properties && (
|
|
207
|
+
<Properties schema={anyOneSchema} schemaType={schemaType} />
|
|
208
|
+
)}
|
|
184
209
|
{anyOneSchema.allOf && (
|
|
185
210
|
<SchemaNode schema={anyOneSchema} schemaType={schemaType} />
|
|
186
211
|
)}
|
|
@@ -860,6 +885,48 @@ const SchemaNode: React.FC<SchemaProps> = ({ schema, schemaType }) => {
|
|
|
860
885
|
|
|
861
886
|
// Handle allOf, oneOf, anyOf without discriminators
|
|
862
887
|
if (schema.allOf) {
|
|
888
|
+
// Check if allOf contains multiple oneOf/anyOf items that should be rendered separately
|
|
889
|
+
const oneOfItems = schema.allOf.filter(
|
|
890
|
+
(item: any) => item.oneOf || item.anyOf
|
|
891
|
+
);
|
|
892
|
+
const hasMultipleChoices = oneOfItems.length > 1;
|
|
893
|
+
|
|
894
|
+
if (hasMultipleChoices) {
|
|
895
|
+
// Render each oneOf/anyOf constraint first, then shared properties
|
|
896
|
+
const mergedSchemas = mergeAllOf(schema) as SchemaObject;
|
|
897
|
+
|
|
898
|
+
if (
|
|
899
|
+
(schemaType === "request" && mergedSchemas.readOnly) ||
|
|
900
|
+
(schemaType === "response" && mergedSchemas.writeOnly)
|
|
901
|
+
) {
|
|
902
|
+
return null;
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
return (
|
|
906
|
+
<div>
|
|
907
|
+
{/* Render all oneOf/anyOf constraints first */}
|
|
908
|
+
{schema.allOf.map((item: any, index: number) => {
|
|
909
|
+
if (item.oneOf || item.anyOf) {
|
|
910
|
+
return (
|
|
911
|
+
<div key={index}>
|
|
912
|
+
<AnyOneOf schema={item} schemaType={schemaType} />
|
|
913
|
+
</div>
|
|
914
|
+
);
|
|
915
|
+
}
|
|
916
|
+
return null;
|
|
917
|
+
})}
|
|
918
|
+
{/* Then render shared properties from the merge */}
|
|
919
|
+
{mergedSchemas.properties && (
|
|
920
|
+
<Properties schema={mergedSchemas} schemaType={schemaType} />
|
|
921
|
+
)}
|
|
922
|
+
{mergedSchemas.items && (
|
|
923
|
+
<Items schema={mergedSchemas} schemaType={schemaType} />
|
|
924
|
+
)}
|
|
925
|
+
</div>
|
|
926
|
+
);
|
|
927
|
+
}
|
|
928
|
+
|
|
929
|
+
// For other allOf cases, use standard merge behavior
|
|
863
930
|
const mergedSchemas = mergeAllOf(schema) as SchemaObject;
|
|
864
931
|
|
|
865
932
|
if (
|
|
@@ -115,7 +115,10 @@ function TabList({
|
|
|
115
115
|
};
|
|
116
116
|
|
|
117
117
|
return (
|
|
118
|
-
<div
|
|
118
|
+
<div
|
|
119
|
+
className="openapi-tabs__schema-tabs-container"
|
|
120
|
+
style={{ marginBottom: "1rem" }}
|
|
121
|
+
>
|
|
119
122
|
{showTabArrows && (
|
|
120
123
|
<button
|
|
121
124
|
className="openapi-tabs__arrow left"
|