@stoplight/elements-core 9.0.20 → 9.0.21
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/index.esm.js +111 -13
- package/index.js +111 -13
- package/index.mjs +111 -13
- package/package.json +1 -1
- package/utils/ref-resolving/resolvedObject.d.ts +1 -0
package/index.esm.js
CHANGED
|
@@ -112,6 +112,71 @@ const recursivelyCreateResolvedObject = (currentObject, rootCurrentObject, prope
|
|
|
112
112
|
const isResolvedObjectProxy = (someObject) => {
|
|
113
113
|
return !!someObject[originalObjectSymbol];
|
|
114
114
|
};
|
|
115
|
+
const getResolvedObject = (obj, cache = new WeakMap()) => {
|
|
116
|
+
if (!isPlainObject(obj) && !isArray(obj)) {
|
|
117
|
+
return obj;
|
|
118
|
+
}
|
|
119
|
+
if (cache.has(obj)) {
|
|
120
|
+
return cache.get(obj);
|
|
121
|
+
}
|
|
122
|
+
if (isArray(obj)) {
|
|
123
|
+
const result = [];
|
|
124
|
+
cache.set(obj, result);
|
|
125
|
+
for (let i = 0; i < obj.length; i++) {
|
|
126
|
+
result[i] = getResolvedObject(obj[i], cache);
|
|
127
|
+
}
|
|
128
|
+
return result;
|
|
129
|
+
}
|
|
130
|
+
const result = {};
|
|
131
|
+
cache.set(obj, result);
|
|
132
|
+
for (const key in obj) {
|
|
133
|
+
if (!Object.prototype.hasOwnProperty.call(obj, key))
|
|
134
|
+
continue;
|
|
135
|
+
const value = obj[key];
|
|
136
|
+
if (isArray(value)) {
|
|
137
|
+
result[key] = getResolvedObject(value, cache);
|
|
138
|
+
}
|
|
139
|
+
else if (isPlainObject(value)) {
|
|
140
|
+
result[key] = getResolvedObject(value, cache);
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
result[key] = value;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return result;
|
|
147
|
+
};
|
|
148
|
+
const deepUnwrapObject = (obj, cache = new WeakMap()) => {
|
|
149
|
+
const unwrapped = (obj === null || obj === void 0 ? void 0 : obj[originalObjectSymbol]) || obj;
|
|
150
|
+
if (!isPlainObject(unwrapped)) {
|
|
151
|
+
return unwrapped;
|
|
152
|
+
}
|
|
153
|
+
if (cache.has(obj)) {
|
|
154
|
+
return cache.get(obj);
|
|
155
|
+
}
|
|
156
|
+
const hasComposition = Object.prototype.hasOwnProperty.call(unwrapped, 'oneOf') ||
|
|
157
|
+
Object.prototype.hasOwnProperty.call(unwrapped, 'anyOf') ||
|
|
158
|
+
Object.prototype.hasOwnProperty.call(unwrapped, 'allOf');
|
|
159
|
+
if (!hasComposition && unwrapped === obj) {
|
|
160
|
+
return unwrapped;
|
|
161
|
+
}
|
|
162
|
+
const result = {};
|
|
163
|
+
cache.set(obj, result);
|
|
164
|
+
for (const key in unwrapped) {
|
|
165
|
+
if (!Object.prototype.hasOwnProperty.call(unwrapped, key))
|
|
166
|
+
continue;
|
|
167
|
+
const value = unwrapped[key];
|
|
168
|
+
if (isArray(value)) {
|
|
169
|
+
result[key] = value.map(item => (isPlainObject(item) || isArray(item) ? deepUnwrapObject(item, cache) : item));
|
|
170
|
+
}
|
|
171
|
+
else if (isPlainObject(value)) {
|
|
172
|
+
result[key] = deepUnwrapObject(value, cache);
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
result[key] = value;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return result;
|
|
179
|
+
};
|
|
115
180
|
const getOriginalObject = (resolvedObject) => {
|
|
116
181
|
const originalObject = resolvedObject[originalObjectSymbol] || resolvedObject;
|
|
117
182
|
if (!originalObject) {
|
|
@@ -120,21 +185,22 @@ const getOriginalObject = (resolvedObject) => {
|
|
|
120
185
|
const hasAllSchemaErrors = (array) => {
|
|
121
186
|
return array.every(item => item['x-sl-error-message'] !== undefined);
|
|
122
187
|
};
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
188
|
+
const deepUnwrapped = deepUnwrapObject(originalObject);
|
|
189
|
+
if (deepUnwrapped.anyOf) {
|
|
190
|
+
if (hasAllSchemaErrors(deepUnwrapped.anyOf)) {
|
|
191
|
+
return Object.assign(Object.assign({}, deepUnwrapped), { anyOf: [deepUnwrapped.anyOf] });
|
|
126
192
|
}
|
|
127
|
-
const filteredArray =
|
|
128
|
-
return Object.assign(Object.assign({},
|
|
193
|
+
const filteredArray = deepUnwrapped.anyOf.filter((item) => !item['x-sl-error-message']);
|
|
194
|
+
return Object.assign(Object.assign({}, deepUnwrapped), { anyOf: filteredArray });
|
|
129
195
|
}
|
|
130
|
-
else if (
|
|
131
|
-
if (hasAllSchemaErrors(
|
|
132
|
-
return Object.assign(Object.assign({},
|
|
196
|
+
else if (deepUnwrapped.oneOf) {
|
|
197
|
+
if (hasAllSchemaErrors(deepUnwrapped.oneOf)) {
|
|
198
|
+
return Object.assign(Object.assign({}, deepUnwrapped), { oneOf: [deepUnwrapped.oneOf] });
|
|
133
199
|
}
|
|
134
|
-
const filteredArray =
|
|
135
|
-
return Object.assign(Object.assign({},
|
|
200
|
+
const filteredArray = deepUnwrapped.oneOf.filter((item) => !item['x-sl-error-message']);
|
|
201
|
+
return Object.assign(Object.assign({}, deepUnwrapped), { oneOf: filteredArray });
|
|
136
202
|
}
|
|
137
|
-
return
|
|
203
|
+
return deepUnwrapped;
|
|
138
204
|
};
|
|
139
205
|
const isReference = hasRef;
|
|
140
206
|
|
|
@@ -1752,6 +1818,34 @@ function ExampleMenu({ examples, requestBody, onChange }) {
|
|
|
1752
1818
|
return (React.createElement(Menu, { "aria-label": "Examples", items: menuItems, renderTrigger: ({ isOpen }) => (React.createElement(Button, { appearance: "minimal", size: "sm", iconRight: ['fas', 'sort'], active: isOpen }, "Examples")) }));
|
|
1753
1819
|
}
|
|
1754
1820
|
|
|
1821
|
+
const mergeOneOfAnyOf = (schema) => {
|
|
1822
|
+
if (!isPlainObject$1(schema)) {
|
|
1823
|
+
return schema;
|
|
1824
|
+
}
|
|
1825
|
+
let result = Object.assign({}, schema);
|
|
1826
|
+
if (result.oneOf && result.oneOf.length > 0) {
|
|
1827
|
+
const firstOption = result.oneOf[0];
|
|
1828
|
+
const { oneOf } = result, rest = __rest(result, ["oneOf"]);
|
|
1829
|
+
result = Object.assign(Object.assign({}, rest), firstOption);
|
|
1830
|
+
}
|
|
1831
|
+
else if (result.anyOf && result.anyOf.length > 0) {
|
|
1832
|
+
const firstOption = result.anyOf[0];
|
|
1833
|
+
const { anyOf } = result, rest = __rest(result, ["anyOf"]);
|
|
1834
|
+
result = Object.assign(Object.assign({}, rest), firstOption);
|
|
1835
|
+
}
|
|
1836
|
+
if (result.properties) {
|
|
1837
|
+
result.properties = Object.fromEntries(Object.entries(result.properties).map(([key, value]) => [key, mergeOneOfAnyOf(value)]));
|
|
1838
|
+
}
|
|
1839
|
+
if (result.items) {
|
|
1840
|
+
result.items = mergeOneOfAnyOf(result.items);
|
|
1841
|
+
}
|
|
1842
|
+
if (result.allOf) {
|
|
1843
|
+
result.allOf = result.allOf.map((item) => mergeOneOfAnyOf(item));
|
|
1844
|
+
}
|
|
1845
|
+
delete result.oneOf;
|
|
1846
|
+
delete result.anyOf;
|
|
1847
|
+
return result;
|
|
1848
|
+
};
|
|
1755
1849
|
const useGenerateExampleFromMediaTypeContent = (mediaTypeContent, chosenExampleIndex, { skipReadOnly, skipWriteOnly, skipNonRequired, ticks } = {}) => {
|
|
1756
1850
|
const document = useDocument();
|
|
1757
1851
|
return React__default.useMemo(() => generateExampleFromMediaTypeContent(mediaTypeContent, document, chosenExampleIndex, {
|
|
@@ -1770,7 +1864,9 @@ const generateExampleFromMediaTypeContent = (mediaTypeContent, document, chosenE
|
|
|
1770
1864
|
return ((_a = safeStringify(textRequestBodyExamples === null || textRequestBodyExamples === void 0 ? void 0 : textRequestBodyExamples[chosenExampleIndex]['value'], undefined, 2)) !== null && _a !== void 0 ? _a : '');
|
|
1771
1865
|
}
|
|
1772
1866
|
else if (textRequestBodySchema) {
|
|
1773
|
-
|
|
1867
|
+
let unwrappedSchema = getResolvedObject(textRequestBodySchema);
|
|
1868
|
+
unwrappedSchema = mergeOneOfAnyOf(unwrappedSchema);
|
|
1869
|
+
const generated = Sampler.sample(unwrappedSchema, options, document);
|
|
1774
1870
|
return generated !== null ? (_b = safeStringify(generated, undefined, 2)) !== null && _b !== void 0 ? _b : '' : '';
|
|
1775
1871
|
}
|
|
1776
1872
|
}
|
|
@@ -1807,7 +1903,9 @@ const generateExamplesFromJsonSchema = (schema) => {
|
|
|
1807
1903
|
return examples;
|
|
1808
1904
|
}
|
|
1809
1905
|
try {
|
|
1810
|
-
|
|
1906
|
+
let resolvedSchema = getResolvedObject(schema);
|
|
1907
|
+
resolvedSchema = mergeOneOfAnyOf(resolvedSchema);
|
|
1908
|
+
const generated = Sampler.sample(resolvedSchema, {
|
|
1811
1909
|
maxSampleDepth: 4,
|
|
1812
1910
|
ticks: 6000,
|
|
1813
1911
|
});
|
package/index.js
CHANGED
|
@@ -133,6 +133,71 @@ const recursivelyCreateResolvedObject = (currentObject, rootCurrentObject, prope
|
|
|
133
133
|
const isResolvedObjectProxy = (someObject) => {
|
|
134
134
|
return !!someObject[originalObjectSymbol];
|
|
135
135
|
};
|
|
136
|
+
const getResolvedObject = (obj, cache = new WeakMap()) => {
|
|
137
|
+
if (!isPlainObject(obj) && !isArray(obj)) {
|
|
138
|
+
return obj;
|
|
139
|
+
}
|
|
140
|
+
if (cache.has(obj)) {
|
|
141
|
+
return cache.get(obj);
|
|
142
|
+
}
|
|
143
|
+
if (isArray(obj)) {
|
|
144
|
+
const result = [];
|
|
145
|
+
cache.set(obj, result);
|
|
146
|
+
for (let i = 0; i < obj.length; i++) {
|
|
147
|
+
result[i] = getResolvedObject(obj[i], cache);
|
|
148
|
+
}
|
|
149
|
+
return result;
|
|
150
|
+
}
|
|
151
|
+
const result = {};
|
|
152
|
+
cache.set(obj, result);
|
|
153
|
+
for (const key in obj) {
|
|
154
|
+
if (!Object.prototype.hasOwnProperty.call(obj, key))
|
|
155
|
+
continue;
|
|
156
|
+
const value = obj[key];
|
|
157
|
+
if (isArray(value)) {
|
|
158
|
+
result[key] = getResolvedObject(value, cache);
|
|
159
|
+
}
|
|
160
|
+
else if (isPlainObject(value)) {
|
|
161
|
+
result[key] = getResolvedObject(value, cache);
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
result[key] = value;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return result;
|
|
168
|
+
};
|
|
169
|
+
const deepUnwrapObject = (obj, cache = new WeakMap()) => {
|
|
170
|
+
const unwrapped = (obj === null || obj === void 0 ? void 0 : obj[originalObjectSymbol]) || obj;
|
|
171
|
+
if (!isPlainObject(unwrapped)) {
|
|
172
|
+
return unwrapped;
|
|
173
|
+
}
|
|
174
|
+
if (cache.has(obj)) {
|
|
175
|
+
return cache.get(obj);
|
|
176
|
+
}
|
|
177
|
+
const hasComposition = Object.prototype.hasOwnProperty.call(unwrapped, 'oneOf') ||
|
|
178
|
+
Object.prototype.hasOwnProperty.call(unwrapped, 'anyOf') ||
|
|
179
|
+
Object.prototype.hasOwnProperty.call(unwrapped, 'allOf');
|
|
180
|
+
if (!hasComposition && unwrapped === obj) {
|
|
181
|
+
return unwrapped;
|
|
182
|
+
}
|
|
183
|
+
const result = {};
|
|
184
|
+
cache.set(obj, result);
|
|
185
|
+
for (const key in unwrapped) {
|
|
186
|
+
if (!Object.prototype.hasOwnProperty.call(unwrapped, key))
|
|
187
|
+
continue;
|
|
188
|
+
const value = unwrapped[key];
|
|
189
|
+
if (isArray(value)) {
|
|
190
|
+
result[key] = value.map(item => (isPlainObject(item) || isArray(item) ? deepUnwrapObject(item, cache) : item));
|
|
191
|
+
}
|
|
192
|
+
else if (isPlainObject(value)) {
|
|
193
|
+
result[key] = deepUnwrapObject(value, cache);
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
result[key] = value;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
return result;
|
|
200
|
+
};
|
|
136
201
|
const getOriginalObject = (resolvedObject) => {
|
|
137
202
|
const originalObject = resolvedObject[originalObjectSymbol] || resolvedObject;
|
|
138
203
|
if (!originalObject) {
|
|
@@ -141,21 +206,22 @@ const getOriginalObject = (resolvedObject) => {
|
|
|
141
206
|
const hasAllSchemaErrors = (array) => {
|
|
142
207
|
return array.every(item => item['x-sl-error-message'] !== undefined);
|
|
143
208
|
};
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
209
|
+
const deepUnwrapped = deepUnwrapObject(originalObject);
|
|
210
|
+
if (deepUnwrapped.anyOf) {
|
|
211
|
+
if (hasAllSchemaErrors(deepUnwrapped.anyOf)) {
|
|
212
|
+
return Object.assign(Object.assign({}, deepUnwrapped), { anyOf: [deepUnwrapped.anyOf] });
|
|
147
213
|
}
|
|
148
|
-
const filteredArray =
|
|
149
|
-
return Object.assign(Object.assign({},
|
|
214
|
+
const filteredArray = deepUnwrapped.anyOf.filter((item) => !item['x-sl-error-message']);
|
|
215
|
+
return Object.assign(Object.assign({}, deepUnwrapped), { anyOf: filteredArray });
|
|
150
216
|
}
|
|
151
|
-
else if (
|
|
152
|
-
if (hasAllSchemaErrors(
|
|
153
|
-
return Object.assign(Object.assign({},
|
|
217
|
+
else if (deepUnwrapped.oneOf) {
|
|
218
|
+
if (hasAllSchemaErrors(deepUnwrapped.oneOf)) {
|
|
219
|
+
return Object.assign(Object.assign({}, deepUnwrapped), { oneOf: [deepUnwrapped.oneOf] });
|
|
154
220
|
}
|
|
155
|
-
const filteredArray =
|
|
156
|
-
return Object.assign(Object.assign({},
|
|
221
|
+
const filteredArray = deepUnwrapped.oneOf.filter((item) => !item['x-sl-error-message']);
|
|
222
|
+
return Object.assign(Object.assign({}, deepUnwrapped), { oneOf: filteredArray });
|
|
157
223
|
}
|
|
158
|
-
return
|
|
224
|
+
return deepUnwrapped;
|
|
159
225
|
};
|
|
160
226
|
const isReference = json.hasRef;
|
|
161
227
|
|
|
@@ -1773,6 +1839,34 @@ function ExampleMenu({ examples, requestBody, onChange }) {
|
|
|
1773
1839
|
return (React__namespace.createElement(mosaic.Menu, { "aria-label": "Examples", items: menuItems, renderTrigger: ({ isOpen }) => (React__namespace.createElement(mosaic.Button, { appearance: "minimal", size: "sm", iconRight: ['fas', 'sort'], active: isOpen }, "Examples")) }));
|
|
1774
1840
|
}
|
|
1775
1841
|
|
|
1842
|
+
const mergeOneOfAnyOf = (schema) => {
|
|
1843
|
+
if (!json.isPlainObject(schema)) {
|
|
1844
|
+
return schema;
|
|
1845
|
+
}
|
|
1846
|
+
let result = Object.assign({}, schema);
|
|
1847
|
+
if (result.oneOf && result.oneOf.length > 0) {
|
|
1848
|
+
const firstOption = result.oneOf[0];
|
|
1849
|
+
const { oneOf } = result, rest = tslib.__rest(result, ["oneOf"]);
|
|
1850
|
+
result = Object.assign(Object.assign({}, rest), firstOption);
|
|
1851
|
+
}
|
|
1852
|
+
else if (result.anyOf && result.anyOf.length > 0) {
|
|
1853
|
+
const firstOption = result.anyOf[0];
|
|
1854
|
+
const { anyOf } = result, rest = tslib.__rest(result, ["anyOf"]);
|
|
1855
|
+
result = Object.assign(Object.assign({}, rest), firstOption);
|
|
1856
|
+
}
|
|
1857
|
+
if (result.properties) {
|
|
1858
|
+
result.properties = Object.fromEntries(Object.entries(result.properties).map(([key, value]) => [key, mergeOneOfAnyOf(value)]));
|
|
1859
|
+
}
|
|
1860
|
+
if (result.items) {
|
|
1861
|
+
result.items = mergeOneOfAnyOf(result.items);
|
|
1862
|
+
}
|
|
1863
|
+
if (result.allOf) {
|
|
1864
|
+
result.allOf = result.allOf.map((item) => mergeOneOfAnyOf(item));
|
|
1865
|
+
}
|
|
1866
|
+
delete result.oneOf;
|
|
1867
|
+
delete result.anyOf;
|
|
1868
|
+
return result;
|
|
1869
|
+
};
|
|
1776
1870
|
const useGenerateExampleFromMediaTypeContent = (mediaTypeContent, chosenExampleIndex, { skipReadOnly, skipWriteOnly, skipNonRequired, ticks } = {}) => {
|
|
1777
1871
|
const document = useDocument();
|
|
1778
1872
|
return React.useMemo(() => generateExampleFromMediaTypeContent(mediaTypeContent, document, chosenExampleIndex, {
|
|
@@ -1791,7 +1885,9 @@ const generateExampleFromMediaTypeContent = (mediaTypeContent, document, chosenE
|
|
|
1791
1885
|
return ((_a = json.safeStringify(textRequestBodyExamples === null || textRequestBodyExamples === void 0 ? void 0 : textRequestBodyExamples[chosenExampleIndex]['value'], undefined, 2)) !== null && _a !== void 0 ? _a : '');
|
|
1792
1886
|
}
|
|
1793
1887
|
else if (textRequestBodySchema) {
|
|
1794
|
-
|
|
1888
|
+
let unwrappedSchema = getResolvedObject(textRequestBodySchema);
|
|
1889
|
+
unwrappedSchema = mergeOneOfAnyOf(unwrappedSchema);
|
|
1890
|
+
const generated = Sampler__namespace.sample(unwrappedSchema, options, document);
|
|
1795
1891
|
return generated !== null ? (_b = json.safeStringify(generated, undefined, 2)) !== null && _b !== void 0 ? _b : '' : '';
|
|
1796
1892
|
}
|
|
1797
1893
|
}
|
|
@@ -1828,7 +1924,9 @@ const generateExamplesFromJsonSchema = (schema) => {
|
|
|
1828
1924
|
return examples;
|
|
1829
1925
|
}
|
|
1830
1926
|
try {
|
|
1831
|
-
|
|
1927
|
+
let resolvedSchema = getResolvedObject(schema);
|
|
1928
|
+
resolvedSchema = mergeOneOfAnyOf(resolvedSchema);
|
|
1929
|
+
const generated = Sampler__namespace.sample(resolvedSchema, {
|
|
1832
1930
|
maxSampleDepth: 4,
|
|
1833
1931
|
ticks: 6000,
|
|
1834
1932
|
});
|
package/index.mjs
CHANGED
|
@@ -112,6 +112,71 @@ const recursivelyCreateResolvedObject = (currentObject, rootCurrentObject, prope
|
|
|
112
112
|
const isResolvedObjectProxy = (someObject) => {
|
|
113
113
|
return !!someObject[originalObjectSymbol];
|
|
114
114
|
};
|
|
115
|
+
const getResolvedObject = (obj, cache = new WeakMap()) => {
|
|
116
|
+
if (!isPlainObject(obj) && !isArray(obj)) {
|
|
117
|
+
return obj;
|
|
118
|
+
}
|
|
119
|
+
if (cache.has(obj)) {
|
|
120
|
+
return cache.get(obj);
|
|
121
|
+
}
|
|
122
|
+
if (isArray(obj)) {
|
|
123
|
+
const result = [];
|
|
124
|
+
cache.set(obj, result);
|
|
125
|
+
for (let i = 0; i < obj.length; i++) {
|
|
126
|
+
result[i] = getResolvedObject(obj[i], cache);
|
|
127
|
+
}
|
|
128
|
+
return result;
|
|
129
|
+
}
|
|
130
|
+
const result = {};
|
|
131
|
+
cache.set(obj, result);
|
|
132
|
+
for (const key in obj) {
|
|
133
|
+
if (!Object.prototype.hasOwnProperty.call(obj, key))
|
|
134
|
+
continue;
|
|
135
|
+
const value = obj[key];
|
|
136
|
+
if (isArray(value)) {
|
|
137
|
+
result[key] = getResolvedObject(value, cache);
|
|
138
|
+
}
|
|
139
|
+
else if (isPlainObject(value)) {
|
|
140
|
+
result[key] = getResolvedObject(value, cache);
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
result[key] = value;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return result;
|
|
147
|
+
};
|
|
148
|
+
const deepUnwrapObject = (obj, cache = new WeakMap()) => {
|
|
149
|
+
const unwrapped = (obj === null || obj === void 0 ? void 0 : obj[originalObjectSymbol]) || obj;
|
|
150
|
+
if (!isPlainObject(unwrapped)) {
|
|
151
|
+
return unwrapped;
|
|
152
|
+
}
|
|
153
|
+
if (cache.has(obj)) {
|
|
154
|
+
return cache.get(obj);
|
|
155
|
+
}
|
|
156
|
+
const hasComposition = Object.prototype.hasOwnProperty.call(unwrapped, 'oneOf') ||
|
|
157
|
+
Object.prototype.hasOwnProperty.call(unwrapped, 'anyOf') ||
|
|
158
|
+
Object.prototype.hasOwnProperty.call(unwrapped, 'allOf');
|
|
159
|
+
if (!hasComposition && unwrapped === obj) {
|
|
160
|
+
return unwrapped;
|
|
161
|
+
}
|
|
162
|
+
const result = {};
|
|
163
|
+
cache.set(obj, result);
|
|
164
|
+
for (const key in unwrapped) {
|
|
165
|
+
if (!Object.prototype.hasOwnProperty.call(unwrapped, key))
|
|
166
|
+
continue;
|
|
167
|
+
const value = unwrapped[key];
|
|
168
|
+
if (isArray(value)) {
|
|
169
|
+
result[key] = value.map(item => (isPlainObject(item) || isArray(item) ? deepUnwrapObject(item, cache) : item));
|
|
170
|
+
}
|
|
171
|
+
else if (isPlainObject(value)) {
|
|
172
|
+
result[key] = deepUnwrapObject(value, cache);
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
result[key] = value;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return result;
|
|
179
|
+
};
|
|
115
180
|
const getOriginalObject = (resolvedObject) => {
|
|
116
181
|
const originalObject = resolvedObject[originalObjectSymbol] || resolvedObject;
|
|
117
182
|
if (!originalObject) {
|
|
@@ -120,21 +185,22 @@ const getOriginalObject = (resolvedObject) => {
|
|
|
120
185
|
const hasAllSchemaErrors = (array) => {
|
|
121
186
|
return array.every(item => item['x-sl-error-message'] !== undefined);
|
|
122
187
|
};
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
188
|
+
const deepUnwrapped = deepUnwrapObject(originalObject);
|
|
189
|
+
if (deepUnwrapped.anyOf) {
|
|
190
|
+
if (hasAllSchemaErrors(deepUnwrapped.anyOf)) {
|
|
191
|
+
return Object.assign(Object.assign({}, deepUnwrapped), { anyOf: [deepUnwrapped.anyOf] });
|
|
126
192
|
}
|
|
127
|
-
const filteredArray =
|
|
128
|
-
return Object.assign(Object.assign({},
|
|
193
|
+
const filteredArray = deepUnwrapped.anyOf.filter((item) => !item['x-sl-error-message']);
|
|
194
|
+
return Object.assign(Object.assign({}, deepUnwrapped), { anyOf: filteredArray });
|
|
129
195
|
}
|
|
130
|
-
else if (
|
|
131
|
-
if (hasAllSchemaErrors(
|
|
132
|
-
return Object.assign(Object.assign({},
|
|
196
|
+
else if (deepUnwrapped.oneOf) {
|
|
197
|
+
if (hasAllSchemaErrors(deepUnwrapped.oneOf)) {
|
|
198
|
+
return Object.assign(Object.assign({}, deepUnwrapped), { oneOf: [deepUnwrapped.oneOf] });
|
|
133
199
|
}
|
|
134
|
-
const filteredArray =
|
|
135
|
-
return Object.assign(Object.assign({},
|
|
200
|
+
const filteredArray = deepUnwrapped.oneOf.filter((item) => !item['x-sl-error-message']);
|
|
201
|
+
return Object.assign(Object.assign({}, deepUnwrapped), { oneOf: filteredArray });
|
|
136
202
|
}
|
|
137
|
-
return
|
|
203
|
+
return deepUnwrapped;
|
|
138
204
|
};
|
|
139
205
|
const isReference = hasRef;
|
|
140
206
|
|
|
@@ -1752,6 +1818,34 @@ function ExampleMenu({ examples, requestBody, onChange }) {
|
|
|
1752
1818
|
return (React.createElement(Menu, { "aria-label": "Examples", items: menuItems, renderTrigger: ({ isOpen }) => (React.createElement(Button, { appearance: "minimal", size: "sm", iconRight: ['fas', 'sort'], active: isOpen }, "Examples")) }));
|
|
1753
1819
|
}
|
|
1754
1820
|
|
|
1821
|
+
const mergeOneOfAnyOf = (schema) => {
|
|
1822
|
+
if (!isPlainObject$1(schema)) {
|
|
1823
|
+
return schema;
|
|
1824
|
+
}
|
|
1825
|
+
let result = Object.assign({}, schema);
|
|
1826
|
+
if (result.oneOf && result.oneOf.length > 0) {
|
|
1827
|
+
const firstOption = result.oneOf[0];
|
|
1828
|
+
const { oneOf } = result, rest = __rest(result, ["oneOf"]);
|
|
1829
|
+
result = Object.assign(Object.assign({}, rest), firstOption);
|
|
1830
|
+
}
|
|
1831
|
+
else if (result.anyOf && result.anyOf.length > 0) {
|
|
1832
|
+
const firstOption = result.anyOf[0];
|
|
1833
|
+
const { anyOf } = result, rest = __rest(result, ["anyOf"]);
|
|
1834
|
+
result = Object.assign(Object.assign({}, rest), firstOption);
|
|
1835
|
+
}
|
|
1836
|
+
if (result.properties) {
|
|
1837
|
+
result.properties = Object.fromEntries(Object.entries(result.properties).map(([key, value]) => [key, mergeOneOfAnyOf(value)]));
|
|
1838
|
+
}
|
|
1839
|
+
if (result.items) {
|
|
1840
|
+
result.items = mergeOneOfAnyOf(result.items);
|
|
1841
|
+
}
|
|
1842
|
+
if (result.allOf) {
|
|
1843
|
+
result.allOf = result.allOf.map((item) => mergeOneOfAnyOf(item));
|
|
1844
|
+
}
|
|
1845
|
+
delete result.oneOf;
|
|
1846
|
+
delete result.anyOf;
|
|
1847
|
+
return result;
|
|
1848
|
+
};
|
|
1755
1849
|
const useGenerateExampleFromMediaTypeContent = (mediaTypeContent, chosenExampleIndex, { skipReadOnly, skipWriteOnly, skipNonRequired, ticks } = {}) => {
|
|
1756
1850
|
const document = useDocument();
|
|
1757
1851
|
return React__default.useMemo(() => generateExampleFromMediaTypeContent(mediaTypeContent, document, chosenExampleIndex, {
|
|
@@ -1770,7 +1864,9 @@ const generateExampleFromMediaTypeContent = (mediaTypeContent, document, chosenE
|
|
|
1770
1864
|
return ((_a = safeStringify(textRequestBodyExamples === null || textRequestBodyExamples === void 0 ? void 0 : textRequestBodyExamples[chosenExampleIndex]['value'], undefined, 2)) !== null && _a !== void 0 ? _a : '');
|
|
1771
1865
|
}
|
|
1772
1866
|
else if (textRequestBodySchema) {
|
|
1773
|
-
|
|
1867
|
+
let unwrappedSchema = getResolvedObject(textRequestBodySchema);
|
|
1868
|
+
unwrappedSchema = mergeOneOfAnyOf(unwrappedSchema);
|
|
1869
|
+
const generated = Sampler.sample(unwrappedSchema, options, document);
|
|
1774
1870
|
return generated !== null ? (_b = safeStringify(generated, undefined, 2)) !== null && _b !== void 0 ? _b : '' : '';
|
|
1775
1871
|
}
|
|
1776
1872
|
}
|
|
@@ -1807,7 +1903,9 @@ const generateExamplesFromJsonSchema = (schema) => {
|
|
|
1807
1903
|
return examples;
|
|
1808
1904
|
}
|
|
1809
1905
|
try {
|
|
1810
|
-
|
|
1906
|
+
let resolvedSchema = getResolvedObject(schema);
|
|
1907
|
+
resolvedSchema = mergeOneOfAnyOf(resolvedSchema);
|
|
1908
|
+
const generated = Sampler.sample(resolvedSchema, {
|
|
1811
1909
|
maxSampleDepth: 4,
|
|
1812
1910
|
ticks: 6000,
|
|
1813
1911
|
});
|
package/package.json
CHANGED
|
@@ -5,6 +5,7 @@ interface CreateResolvedObjectOptions {
|
|
|
5
5
|
}
|
|
6
6
|
export declare const createResolvedObject: (currentObject: object, options?: CreateResolvedObjectOptions) => object;
|
|
7
7
|
export declare const isResolvedObjectProxy: (someObject: object) => boolean;
|
|
8
|
+
export declare const getResolvedObject: (obj: any, cache?: WeakMap<object, any>) => any;
|
|
8
9
|
export declare const getOriginalObject: (resolvedObject: object) => object;
|
|
9
10
|
export declare const isReference: (obj: unknown) => obj is Record<string, unknown> & {
|
|
10
11
|
$ref: string;
|