docusaurus-theme-openapi-docs 0.0.0-1253 → 0.0.0-1254
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 +61 -1
- package/package.json +3 -3
- package/src/theme/Schema/index.tsx +61 -1
|
@@ -89,11 +89,71 @@ const isEmpty_1 = __importDefault(require("lodash/isEmpty"));
|
|
|
89
89
|
const schema_1 = require("../../markdown/schema");
|
|
90
90
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
91
91
|
// const jsonSchemaMergeAllOf = require("json-schema-merge-allof");
|
|
92
|
+
/**
|
|
93
|
+
* Strip `additionalProperties: false` from sibling allOf members so the
|
|
94
|
+
* strict-AND semantics of `allof-merge` don't collapse the result to an
|
|
95
|
+
* unsatisfiable empty schema.
|
|
96
|
+
*
|
|
97
|
+
* Per JSON Schema, two allOf members that each set `additionalProperties: false`
|
|
98
|
+
* with disjoint `properties` sets define an unsatisfiable schema (no value can
|
|
99
|
+
* satisfy both — each member rejects the other's properties). `allof-merge` is
|
|
100
|
+
* technically correct to drop all properties in that case, but it leaves the
|
|
101
|
+
* rendered schema blank.
|
|
102
|
+
*
|
|
103
|
+
* NSwag and Swashbuckle emit this pattern by default whenever a model uses
|
|
104
|
+
* inheritance/composition, so it's the dominant style for .NET-generated specs.
|
|
105
|
+
* Redoc, Swagger UI, and Stoplight all union the properties and ignore the
|
|
106
|
+
* conflicting flag — the approach this helper emulates by stripping the flag
|
|
107
|
+
* before delegating to `allof-merge`. The flag is render-irrelevant anyway:
|
|
108
|
+
* `additionalProperties: false` is treated identically to `undefined` by the
|
|
109
|
+
* AdditionalProperties component below (line ~641).
|
|
110
|
+
*
|
|
111
|
+
* Strips from every allOf member whenever the parent has ≥2 members. The
|
|
112
|
+
* collapse triggers symmetrically (both siblings strict) or asymmetrically
|
|
113
|
+
* (one strict member rejects another's properties as "additional"), so the
|
|
114
|
+
* presence of multiple members is the right gate. Single-member allOf is left
|
|
115
|
+
* alone — it can't conflict with anything.
|
|
116
|
+
*
|
|
117
|
+
* See https://github.com/PaloAltoNetworks/docusaurus-openapi-docs/issues/1119
|
|
118
|
+
* Mirrored in plugin: docusaurus-plugin-openapi-docs/src/markdown/createSchema.ts
|
|
119
|
+
*/
|
|
120
|
+
const stripConflictingAdditionalProps = (node) => {
|
|
121
|
+
if (Array.isArray(node)) return node.map(stripConflictingAdditionalProps);
|
|
122
|
+
if (!node || typeof node !== "object") return node;
|
|
123
|
+
let working = node;
|
|
124
|
+
if (Array.isArray(node.allOf) && node.allOf.length > 1) {
|
|
125
|
+
const hasStrictMember = node.allOf.some(
|
|
126
|
+
(m) => m && m.additionalProperties === false
|
|
127
|
+
);
|
|
128
|
+
if (hasStrictMember) {
|
|
129
|
+
working = {
|
|
130
|
+
...node,
|
|
131
|
+
allOf: node.allOf.map((m) => {
|
|
132
|
+
if (m && m.additionalProperties === false) {
|
|
133
|
+
const { additionalProperties: _drop, ...rest } = m;
|
|
134
|
+
return rest;
|
|
135
|
+
}
|
|
136
|
+
return m;
|
|
137
|
+
}),
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
const result = {};
|
|
142
|
+
for (const [k, v] of Object.entries(working)) {
|
|
143
|
+
result[k] = stripConflictingAdditionalProps(v);
|
|
144
|
+
}
|
|
145
|
+
return result;
|
|
146
|
+
};
|
|
92
147
|
const mergeAllOf = (allOf) => {
|
|
93
148
|
const onMergeError = (msg) => {
|
|
94
149
|
console.warn(msg);
|
|
95
150
|
};
|
|
96
|
-
const mergedSchemas = (0, allof_merge_1.merge)(
|
|
151
|
+
const mergedSchemas = (0, allof_merge_1.merge)(
|
|
152
|
+
stripConflictingAdditionalProps(allOf),
|
|
153
|
+
{
|
|
154
|
+
onMergeError,
|
|
155
|
+
}
|
|
156
|
+
);
|
|
97
157
|
return mergedSchemas ?? {};
|
|
98
158
|
};
|
|
99
159
|
/**
|
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-1254",
|
|
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-1254",
|
|
42
42
|
"docusaurus-plugin-sass": "^0.2.6",
|
|
43
43
|
"eslint-plugin-prettier": "^5.5.1"
|
|
44
44
|
},
|
|
@@ -82,5 +82,5 @@
|
|
|
82
82
|
"engines": {
|
|
83
83
|
"node": ">=14"
|
|
84
84
|
},
|
|
85
|
-
"gitHead": "
|
|
85
|
+
"gitHead": "733be4b792c884f5a88b6930cd46a249fffd6197"
|
|
86
86
|
}
|
|
@@ -34,12 +34,72 @@ import type { SchemaObject } from "../../types.d";
|
|
|
34
34
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
35
35
|
// const jsonSchemaMergeAllOf = require("json-schema-merge-allof");
|
|
36
36
|
|
|
37
|
+
/**
|
|
38
|
+
* Strip `additionalProperties: false` from sibling allOf members so the
|
|
39
|
+
* strict-AND semantics of `allof-merge` don't collapse the result to an
|
|
40
|
+
* unsatisfiable empty schema.
|
|
41
|
+
*
|
|
42
|
+
* Per JSON Schema, two allOf members that each set `additionalProperties: false`
|
|
43
|
+
* with disjoint `properties` sets define an unsatisfiable schema (no value can
|
|
44
|
+
* satisfy both — each member rejects the other's properties). `allof-merge` is
|
|
45
|
+
* technically correct to drop all properties in that case, but it leaves the
|
|
46
|
+
* rendered schema blank.
|
|
47
|
+
*
|
|
48
|
+
* NSwag and Swashbuckle emit this pattern by default whenever a model uses
|
|
49
|
+
* inheritance/composition, so it's the dominant style for .NET-generated specs.
|
|
50
|
+
* Redoc, Swagger UI, and Stoplight all union the properties and ignore the
|
|
51
|
+
* conflicting flag — the approach this helper emulates by stripping the flag
|
|
52
|
+
* before delegating to `allof-merge`. The flag is render-irrelevant anyway:
|
|
53
|
+
* `additionalProperties: false` is treated identically to `undefined` by the
|
|
54
|
+
* AdditionalProperties component below (line ~641).
|
|
55
|
+
*
|
|
56
|
+
* Strips from every allOf member whenever the parent has ≥2 members. The
|
|
57
|
+
* collapse triggers symmetrically (both siblings strict) or asymmetrically
|
|
58
|
+
* (one strict member rejects another's properties as "additional"), so the
|
|
59
|
+
* presence of multiple members is the right gate. Single-member allOf is left
|
|
60
|
+
* alone — it can't conflict with anything.
|
|
61
|
+
*
|
|
62
|
+
* See https://github.com/PaloAltoNetworks/docusaurus-openapi-docs/issues/1119
|
|
63
|
+
* Mirrored in plugin: docusaurus-plugin-openapi-docs/src/markdown/createSchema.ts
|
|
64
|
+
*/
|
|
65
|
+
const stripConflictingAdditionalProps = (node: any): any => {
|
|
66
|
+
if (Array.isArray(node)) return node.map(stripConflictingAdditionalProps);
|
|
67
|
+
if (!node || typeof node !== "object") return node;
|
|
68
|
+
|
|
69
|
+
let working: any = node;
|
|
70
|
+
if (Array.isArray(node.allOf) && node.allOf.length > 1) {
|
|
71
|
+
const hasStrictMember = node.allOf.some(
|
|
72
|
+
(m: any) => m && m.additionalProperties === false
|
|
73
|
+
);
|
|
74
|
+
if (hasStrictMember) {
|
|
75
|
+
working = {
|
|
76
|
+
...node,
|
|
77
|
+
allOf: node.allOf.map((m: any) => {
|
|
78
|
+
if (m && m.additionalProperties === false) {
|
|
79
|
+
const { additionalProperties: _drop, ...rest } = m;
|
|
80
|
+
return rest;
|
|
81
|
+
}
|
|
82
|
+
return m;
|
|
83
|
+
}),
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const result: any = {};
|
|
89
|
+
for (const [k, v] of Object.entries(working)) {
|
|
90
|
+
result[k] = stripConflictingAdditionalProps(v);
|
|
91
|
+
}
|
|
92
|
+
return result;
|
|
93
|
+
};
|
|
94
|
+
|
|
37
95
|
const mergeAllOf = (allOf: any) => {
|
|
38
96
|
const onMergeError = (msg: string) => {
|
|
39
97
|
console.warn(msg);
|
|
40
98
|
};
|
|
41
99
|
|
|
42
|
-
const mergedSchemas = merge(allOf, {
|
|
100
|
+
const mergedSchemas = merge(stripConflictingAdditionalProps(allOf), {
|
|
101
|
+
onMergeError,
|
|
102
|
+
});
|
|
43
103
|
|
|
44
104
|
return mergedSchemas ?? {};
|
|
45
105
|
};
|