docusaurus-theme-openapi-docs 0.0.0-1107 → 0.0.0-1110
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/theme/Schema/index.js +84 -8
- package/package.json +3 -3
- package/src/theme/Schema/index.tsx +98 -8
|
@@ -93,7 +93,68 @@ const mergeAllOf = (allOf) => {
|
|
|
93
93
|
console.warn(msg);
|
|
94
94
|
};
|
|
95
95
|
const mergedSchemas = (0, allof_merge_1.merge)(allOf, { onMergeError });
|
|
96
|
-
return mergedSchemas;
|
|
96
|
+
return mergedSchemas ?? {};
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* Recursively searches for a property in a schema, including nested
|
|
100
|
+
* oneOf, anyOf, and allOf structures. This is needed for discriminators
|
|
101
|
+
* where the property definition may be in a nested schema.
|
|
102
|
+
*/
|
|
103
|
+
const findProperty = (schema, propertyName) => {
|
|
104
|
+
// Check direct properties first
|
|
105
|
+
if (schema.properties?.[propertyName]) {
|
|
106
|
+
return schema.properties[propertyName];
|
|
107
|
+
}
|
|
108
|
+
// Search in oneOf schemas
|
|
109
|
+
if (schema.oneOf) {
|
|
110
|
+
for (const subschema of schema.oneOf) {
|
|
111
|
+
const found = findProperty(subschema, propertyName);
|
|
112
|
+
if (found) return found;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
// Search in anyOf schemas
|
|
116
|
+
if (schema.anyOf) {
|
|
117
|
+
for (const subschema of schema.anyOf) {
|
|
118
|
+
const found = findProperty(subschema, propertyName);
|
|
119
|
+
if (found) return found;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
// Search in allOf schemas
|
|
123
|
+
if (schema.allOf) {
|
|
124
|
+
for (const subschema of schema.allOf) {
|
|
125
|
+
const found = findProperty(subschema, propertyName);
|
|
126
|
+
if (found) return found;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return undefined;
|
|
130
|
+
};
|
|
131
|
+
/**
|
|
132
|
+
* Recursively searches for a discriminator in a schema, including nested
|
|
133
|
+
* oneOf, anyOf, and allOf structures.
|
|
134
|
+
*/
|
|
135
|
+
const findDiscriminator = (schema) => {
|
|
136
|
+
if (schema.discriminator) {
|
|
137
|
+
return schema.discriminator;
|
|
138
|
+
}
|
|
139
|
+
if (schema.oneOf) {
|
|
140
|
+
for (const subschema of schema.oneOf) {
|
|
141
|
+
const found = findDiscriminator(subschema);
|
|
142
|
+
if (found) return found;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
if (schema.anyOf) {
|
|
146
|
+
for (const subschema of schema.anyOf) {
|
|
147
|
+
const found = findDiscriminator(subschema);
|
|
148
|
+
if (found) return found;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
if (schema.allOf) {
|
|
152
|
+
for (const subschema of schema.allOf) {
|
|
153
|
+
const found = findDiscriminator(subschema);
|
|
154
|
+
if (found) return found;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return undefined;
|
|
97
158
|
};
|
|
98
159
|
// Renders string as markdown, useful for descriptions and qualifiers
|
|
99
160
|
const MarkdownWrapper = ({ text }) => {
|
|
@@ -321,6 +382,11 @@ const Properties = ({ schema, schemaType, schemaPath }) => {
|
|
|
321
382
|
discriminator["mapping"] = inferredMapping;
|
|
322
383
|
}
|
|
323
384
|
if (Object.keys(schema.properties).length === 0) {
|
|
385
|
+
// Hide placeholder only for discriminator cleanup artifacts; preserve
|
|
386
|
+
// empty object rendering for schemas that intentionally define no properties.
|
|
387
|
+
if (discriminator) {
|
|
388
|
+
return null;
|
|
389
|
+
}
|
|
324
390
|
return react_1.default.createElement(SchemaItem_1.default, {
|
|
325
391
|
collapsible: false,
|
|
326
392
|
name: "",
|
|
@@ -448,10 +514,9 @@ const PropertyDiscriminator = ({
|
|
|
448
514
|
const DiscriminatorNode = ({ discriminator, schema, schemaType }) => {
|
|
449
515
|
let discriminatedSchemas = {};
|
|
450
516
|
let inferredMapping = {};
|
|
451
|
-
//
|
|
452
|
-
const discriminatorProperty =
|
|
453
|
-
|
|
454
|
-
: {};
|
|
517
|
+
// Search for the discriminator property in the schema, including nested structures
|
|
518
|
+
const discriminatorProperty =
|
|
519
|
+
findProperty(schema, discriminator.propertyName) ?? {};
|
|
455
520
|
if (schema.allOf) {
|
|
456
521
|
const mergedSchemas = mergeAllOf(schema);
|
|
457
522
|
if (mergedSchemas.oneOf || mergedSchemas.anyOf) {
|
|
@@ -901,11 +966,22 @@ const SchemaNode = ({ schema, schemaType, schemaPath }) => {
|
|
|
901
966
|
) {
|
|
902
967
|
return null;
|
|
903
968
|
}
|
|
904
|
-
|
|
905
|
-
|
|
969
|
+
// Resolve discriminator recursively so nested oneOf/anyOf/allOf compositions
|
|
970
|
+
// can still render discriminator tabs.
|
|
971
|
+
let workingSchema = schema;
|
|
972
|
+
const resolvedDiscriminator =
|
|
973
|
+
schema.discriminator ?? findDiscriminator(schema);
|
|
974
|
+
if (schema.allOf && !schema.discriminator && resolvedDiscriminator) {
|
|
975
|
+
workingSchema = mergeAllOf(schema);
|
|
976
|
+
}
|
|
977
|
+
if (!workingSchema.discriminator && resolvedDiscriminator) {
|
|
978
|
+
workingSchema.discriminator = resolvedDiscriminator;
|
|
979
|
+
}
|
|
980
|
+
if (workingSchema.discriminator) {
|
|
981
|
+
const { discriminator } = workingSchema;
|
|
906
982
|
return react_1.default.createElement(DiscriminatorNode, {
|
|
907
983
|
discriminator: discriminator,
|
|
908
|
-
schema:
|
|
984
|
+
schema: workingSchema,
|
|
909
985
|
schemaType: schemaType,
|
|
910
986
|
});
|
|
911
987
|
}
|
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-1110",
|
|
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-1110",
|
|
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": "e4a99880178b660e4ba688b2d13aef1280752322"
|
|
85
85
|
}
|
|
@@ -41,7 +41,81 @@ const mergeAllOf = (allOf: any) => {
|
|
|
41
41
|
|
|
42
42
|
const mergedSchemas = merge(allOf, { onMergeError });
|
|
43
43
|
|
|
44
|
-
return mergedSchemas;
|
|
44
|
+
return mergedSchemas ?? {};
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Recursively searches for a property in a schema, including nested
|
|
49
|
+
* oneOf, anyOf, and allOf structures. This is needed for discriminators
|
|
50
|
+
* where the property definition may be in a nested schema.
|
|
51
|
+
*/
|
|
52
|
+
const findProperty = (
|
|
53
|
+
schema: SchemaObject,
|
|
54
|
+
propertyName: string
|
|
55
|
+
): SchemaObject | undefined => {
|
|
56
|
+
// Check direct properties first
|
|
57
|
+
if (schema.properties?.[propertyName]) {
|
|
58
|
+
return schema.properties[propertyName];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Search in oneOf schemas
|
|
62
|
+
if (schema.oneOf) {
|
|
63
|
+
for (const subschema of schema.oneOf) {
|
|
64
|
+
const found = findProperty(subschema as SchemaObject, propertyName);
|
|
65
|
+
if (found) return found;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Search in anyOf schemas
|
|
70
|
+
if (schema.anyOf) {
|
|
71
|
+
for (const subschema of schema.anyOf) {
|
|
72
|
+
const found = findProperty(subschema as SchemaObject, propertyName);
|
|
73
|
+
if (found) return found;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Search in allOf schemas
|
|
78
|
+
if (schema.allOf) {
|
|
79
|
+
for (const subschema of schema.allOf) {
|
|
80
|
+
const found = findProperty(subschema as SchemaObject, propertyName);
|
|
81
|
+
if (found) return found;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return undefined;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Recursively searches for a discriminator in a schema, including nested
|
|
90
|
+
* oneOf, anyOf, and allOf structures.
|
|
91
|
+
*/
|
|
92
|
+
const findDiscriminator = (schema: SchemaObject): any | undefined => {
|
|
93
|
+
if (schema.discriminator) {
|
|
94
|
+
return schema.discriminator;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (schema.oneOf) {
|
|
98
|
+
for (const subschema of schema.oneOf) {
|
|
99
|
+
const found = findDiscriminator(subschema as SchemaObject);
|
|
100
|
+
if (found) return found;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (schema.anyOf) {
|
|
105
|
+
for (const subschema of schema.anyOf) {
|
|
106
|
+
const found = findDiscriminator(subschema as SchemaObject);
|
|
107
|
+
if (found) return found;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (schema.allOf) {
|
|
112
|
+
for (const subschema of schema.allOf) {
|
|
113
|
+
const found = findDiscriminator(subschema as SchemaObject);
|
|
114
|
+
if (found) return found;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return undefined;
|
|
45
119
|
};
|
|
46
120
|
|
|
47
121
|
interface MarkdownProps {
|
|
@@ -313,6 +387,11 @@ const Properties: React.FC<SchemaProps> = ({
|
|
|
313
387
|
discriminator["mapping"] = inferredMapping;
|
|
314
388
|
}
|
|
315
389
|
if (Object.keys(schema.properties as {}).length === 0) {
|
|
390
|
+
// Hide placeholder only for discriminator cleanup artifacts; preserve
|
|
391
|
+
// empty object rendering for schemas that intentionally define no properties.
|
|
392
|
+
if (discriminator) {
|
|
393
|
+
return null;
|
|
394
|
+
}
|
|
316
395
|
return (
|
|
317
396
|
<SchemaItem
|
|
318
397
|
collapsible={false}
|
|
@@ -442,10 +521,9 @@ const DiscriminatorNode: React.FC<DiscriminatorNodeProps> = ({
|
|
|
442
521
|
let discriminatedSchemas: any = {};
|
|
443
522
|
let inferredMapping: any = {};
|
|
444
523
|
|
|
445
|
-
//
|
|
446
|
-
const discriminatorProperty =
|
|
447
|
-
|
|
448
|
-
: {};
|
|
524
|
+
// Search for the discriminator property in the schema, including nested structures
|
|
525
|
+
const discriminatorProperty =
|
|
526
|
+
findProperty(schema, discriminator.propertyName) ?? {};
|
|
449
527
|
|
|
450
528
|
if (schema.allOf) {
|
|
451
529
|
const mergedSchemas = mergeAllOf(schema) as SchemaObject;
|
|
@@ -997,12 +1075,24 @@ const SchemaNode: React.FC<SchemaProps> = ({
|
|
|
997
1075
|
return null;
|
|
998
1076
|
}
|
|
999
1077
|
|
|
1000
|
-
|
|
1001
|
-
|
|
1078
|
+
// Resolve discriminator recursively so nested oneOf/anyOf/allOf compositions
|
|
1079
|
+
// can still render discriminator tabs.
|
|
1080
|
+
let workingSchema = schema;
|
|
1081
|
+
const resolvedDiscriminator =
|
|
1082
|
+
schema.discriminator ?? findDiscriminator(schema);
|
|
1083
|
+
if (schema.allOf && !schema.discriminator && resolvedDiscriminator) {
|
|
1084
|
+
workingSchema = mergeAllOf(schema) as SchemaObject;
|
|
1085
|
+
}
|
|
1086
|
+
if (!workingSchema.discriminator && resolvedDiscriminator) {
|
|
1087
|
+
workingSchema.discriminator = resolvedDiscriminator;
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
if (workingSchema.discriminator) {
|
|
1091
|
+
const { discriminator } = workingSchema;
|
|
1002
1092
|
return (
|
|
1003
1093
|
<DiscriminatorNode
|
|
1004
1094
|
discriminator={discriminator}
|
|
1005
|
-
schema={
|
|
1095
|
+
schema={workingSchema}
|
|
1006
1096
|
schemaType={schemaType}
|
|
1007
1097
|
/>
|
|
1008
1098
|
);
|