oas 31.1.2 → 32.1.0
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/README.md +5 -0
- package/dist/analyzer/index.cjs +6 -7
- package/dist/analyzer/index.cjs.map +1 -1
- package/dist/analyzer/index.js +5 -6
- package/dist/analyzer/index.js.map +1 -1
- package/dist/{chunk-BRYRBTD7.cjs → chunk-4OCSFLJO.cjs} +537 -385
- package/dist/chunk-4OCSFLJO.cjs.map +1 -0
- package/dist/{chunk-HGVFNEKW.js → chunk-5245ZLBC.js} +476 -324
- package/dist/chunk-5245ZLBC.js.map +1 -0
- package/dist/{chunk-B5WP4BJM.cjs → chunk-7RDMAMMI.cjs} +511 -240
- package/dist/chunk-7RDMAMMI.cjs.map +1 -0
- package/dist/{chunk-LSH3X5NA.js → chunk-DVD6RE2D.js} +85 -48
- package/dist/chunk-DVD6RE2D.js.map +1 -0
- package/dist/{chunk-5EP6HY2E.js → chunk-HYH37HS2.js} +494 -223
- package/dist/chunk-HYH37HS2.js.map +1 -0
- package/dist/{chunk-7MARUOFZ.js → chunk-MNOEMVCF.js} +2 -2
- package/dist/chunk-MNOEMVCF.js.map +1 -0
- package/dist/{chunk-SYZDNSG6.cjs → chunk-WXNEGGLJ.cjs} +104 -67
- package/dist/chunk-WXNEGGLJ.cjs.map +1 -0
- package/dist/chunk-YPR7YTHM.cjs +24 -0
- package/dist/chunk-YPR7YTHM.cjs.map +1 -0
- package/dist/extensions.d.cts +3 -1
- package/dist/extensions.d.ts +3 -1
- package/dist/get-parameters-as-json-schema-BH81ZOnw.d.ts +36 -0
- package/dist/get-parameters-as-json-schema-DM1vWIEM.d.cts +36 -0
- package/dist/index.cjs +5 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +947 -7
- package/dist/index.d.ts +946 -8
- package/dist/index.js +4 -5
- package/dist/operation/index.cjs +4 -5
- package/dist/operation/index.cjs.map +1 -1
- package/dist/operation/index.d.cts +3 -1
- package/dist/operation/index.d.ts +3 -1
- package/dist/operation/index.js +3 -4
- package/dist/reducer/index.cjs +16 -18
- package/dist/reducer/index.cjs.map +1 -1
- package/dist/reducer/index.js +4 -6
- package/dist/reducer/index.js.map +1 -1
- package/dist/types.cjs +2 -2
- package/dist/types.d.cts +9 -1
- package/dist/types.d.ts +9 -1
- package/dist/types.js +1 -1
- package/dist/utils.cjs +4 -4
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +17 -3
- package/dist/utils.d.ts +17 -3
- package/dist/utils.js +5 -5
- package/package.json +3 -6
- package/dist/chunk-5EP6HY2E.js.map +0 -1
- package/dist/chunk-7MARUOFZ.js.map +0 -1
- package/dist/chunk-B5WP4BJM.cjs.map +0 -1
- package/dist/chunk-BRYRBTD7.cjs.map +0 -1
- package/dist/chunk-HGVFNEKW.js.map +0 -1
- package/dist/chunk-LSH3X5NA.js.map +0 -1
- package/dist/chunk-O3GIPZLC.cjs +0 -9
- package/dist/chunk-O3GIPZLC.cjs.map +0 -1
- package/dist/chunk-SYZDNSG6.cjs.map +0 -1
- package/dist/chunk-VA3NKXX7.js +0 -9
- package/dist/chunk-VA3NKXX7.js.map +0 -1
- package/dist/chunk-VQBEI5WI.cjs +0 -24
- package/dist/chunk-VQBEI5WI.cjs.map +0 -1
- package/dist/extensions-9XckV6aO.d.cts +0 -899
- package/dist/extensions-gq53-7Ux.d.ts +0 -899
- package/dist/operation/lib/get-parameters-as-json-schema.cjs +0 -11
- package/dist/operation/lib/get-parameters-as-json-schema.cjs.map +0 -1
- package/dist/operation/lib/get-parameters-as-json-schema.d.cts +0 -4
- package/dist/operation/lib/get-parameters-as-json-schema.d.ts +0 -4
- package/dist/operation/lib/get-parameters-as-json-schema.js +0 -11
- package/dist/operation/lib/get-parameters-as-json-schema.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
var _chunkAYA3UT4Lcjs = require('./chunk-AYA3UT4L.cjs');
|
|
@@ -6,15 +6,7 @@ var _chunkAYA3UT4Lcjs = require('./chunk-AYA3UT4L.cjs');
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
// src/lib/clone-object.ts
|
|
12
|
-
function cloneObject(obj) {
|
|
13
|
-
if (typeof obj === "undefined") {
|
|
14
|
-
return void 0;
|
|
15
|
-
}
|
|
16
|
-
return JSON.parse(JSON.stringify(obj));
|
|
17
|
-
}
|
|
9
|
+
var _chunkYPR7YTHMcjs = require('./chunk-YPR7YTHM.cjs');
|
|
18
10
|
|
|
19
11
|
// src/lib/matches-mimetype.ts
|
|
20
12
|
function matchesMediaType(types2, mediaType) {
|
|
@@ -71,6 +63,9 @@ function getParameterContentType(contentKeys) {
|
|
|
71
63
|
return contentKeys[0];
|
|
72
64
|
}
|
|
73
65
|
|
|
66
|
+
// src/lib/refs.ts
|
|
67
|
+
var _jsonpointer = require('jsonpointer'); var _jsonpointer2 = _interopRequireDefault(_jsonpointer);
|
|
68
|
+
|
|
74
69
|
// src/lib/helpers.ts
|
|
75
70
|
function hasSchemaType(schema, discriminator) {
|
|
76
71
|
if (Array.isArray(schema.type)) {
|
|
@@ -85,13 +80,18 @@ function isPrimitive(val) {
|
|
|
85
80
|
return typeof val === "string" || typeof val === "number" || typeof val === "boolean";
|
|
86
81
|
}
|
|
87
82
|
|
|
88
|
-
// src/lib/openapi-to-json-schema.ts
|
|
89
|
-
var _jsonschemamergeallof = require('json-schema-merge-allof'); var _jsonschemamergeallof2 = _interopRequireDefault(_jsonschemamergeallof);
|
|
90
|
-
var _jsonpointer = require('jsonpointer'); var _jsonpointer2 = _interopRequireDefault(_jsonpointer);
|
|
91
|
-
var _removeundefinedobjects = require('remove-undefined-objects'); var _removeundefinedobjects2 = _interopRequireDefault(_removeundefinedobjects);
|
|
92
|
-
|
|
93
83
|
// src/lib/refs.ts
|
|
94
|
-
|
|
84
|
+
function decorateComponentSchemasWithRefName(api) {
|
|
85
|
+
if (!_optionalChain([api, 'optionalAccess', _2 => _2.components, 'optionalAccess', _3 => _3.schemas]) || typeof api.components.schemas !== "object") {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
Object.keys(api.components.schemas).forEach((schemaName) => {
|
|
89
|
+
if (isPrimitive(_optionalChain([api, 'access', _4 => _4.components, 'optionalAccess', _5 => _5.schemas, 'optionalAccess', _6 => _6[schemaName]])) || Array.isArray(_optionalChain([api, 'access', _7 => _7.components, 'optionalAccess', _8 => _8.schemas, 'optionalAccess', _9 => _9[schemaName]])) || _optionalChain([api, 'access', _10 => _10.components, 'optionalAccess', _11 => _11.schemas, 'optionalAccess', _12 => _12[schemaName]]) === null) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
(_optionalChain([api, 'access', _13 => _13.components, 'optionalAccess', _14 => _14.schemas, 'optionalAccess', _15 => _15[schemaName]]))["x-readme-ref-name"] = schemaName;
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
95
|
function encodePointer(str) {
|
|
96
96
|
return str.replaceAll("~", "~0").replaceAll("/", "~1");
|
|
97
97
|
}
|
|
@@ -114,32 +114,26 @@ function findRef($ref, definition) {
|
|
|
114
114
|
}
|
|
115
115
|
return current;
|
|
116
116
|
}
|
|
117
|
-
function dereferenceRef(value, definition, seenRefs) {
|
|
117
|
+
function dereferenceRef(value, definition, seenRefs = /* @__PURE__ */ new Set()) {
|
|
118
118
|
if (value === void 0) {
|
|
119
119
|
return void 0;
|
|
120
120
|
}
|
|
121
|
-
if (
|
|
121
|
+
if (_chunkYPR7YTHMcjs.isRef.call(void 0, value)) {
|
|
122
122
|
if (!definition) {
|
|
123
123
|
return value;
|
|
124
124
|
}
|
|
125
125
|
const ref = value.$ref;
|
|
126
|
-
if (
|
|
126
|
+
if (seenRefs.has(ref)) {
|
|
127
127
|
return value;
|
|
128
128
|
}
|
|
129
|
-
|
|
130
|
-
localSeenRefs.add(ref);
|
|
129
|
+
seenRefs.add(ref);
|
|
131
130
|
try {
|
|
132
131
|
const dereferenced = findRef(ref, definition);
|
|
133
|
-
if (
|
|
134
|
-
return dereferenceRef(dereferenced, definition,
|
|
132
|
+
if (_chunkYPR7YTHMcjs.isRef.call(void 0, dereferenced)) {
|
|
133
|
+
return dereferenceRef(dereferenced, definition, seenRefs);
|
|
135
134
|
}
|
|
136
|
-
const refName = ref.split("/").pop();
|
|
137
135
|
return {
|
|
138
|
-
...dereferenced
|
|
139
|
-
// Because dereferencing will eliminate any lineage back to the original `$ref`,
|
|
140
|
-
// information that we might need at some point, we should preserve the original schema
|
|
141
|
-
// name through a custom extension.
|
|
142
|
-
"x-readme-ref-name": refName
|
|
136
|
+
...dereferenced
|
|
143
137
|
};
|
|
144
138
|
} catch (e2) {
|
|
145
139
|
return value;
|
|
@@ -164,16 +158,198 @@ function getDereferencingOptions(circularRefs) {
|
|
|
164
158
|
}
|
|
165
159
|
};
|
|
166
160
|
}
|
|
161
|
+
function collectRefsInSchema(schema) {
|
|
162
|
+
const refs = /* @__PURE__ */ new Set();
|
|
163
|
+
if (!schema || typeof schema !== "object") return refs;
|
|
164
|
+
const obj = schema;
|
|
165
|
+
if (_chunkYPR7YTHMcjs.isRef.call(void 0, obj)) {
|
|
166
|
+
refs.add(obj.$ref);
|
|
167
|
+
}
|
|
168
|
+
for (const value of Object.values(obj)) {
|
|
169
|
+
if (Array.isArray(value)) {
|
|
170
|
+
for (const item of value) {
|
|
171
|
+
for (const r of collectRefsInSchema(item)) refs.add(r);
|
|
172
|
+
}
|
|
173
|
+
} else if (value && typeof value === "object") {
|
|
174
|
+
for (const r of collectRefsInSchema(value)) refs.add(r);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return refs;
|
|
178
|
+
}
|
|
179
|
+
function filterRequiredRefsToReferenced(requiredRefs, usedSchemas) {
|
|
180
|
+
const referenced = new Set(requiredRefs);
|
|
181
|
+
let prevSize = 0;
|
|
182
|
+
while (referenced.size > prevSize) {
|
|
183
|
+
prevSize = referenced.size;
|
|
184
|
+
for (const ref of referenced) {
|
|
185
|
+
const schema = usedSchemas.get(ref);
|
|
186
|
+
if (schema) {
|
|
187
|
+
for (const r of collectRefsInSchema(schema)) {
|
|
188
|
+
referenced.add(r);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
const filtered = /* @__PURE__ */ new Map();
|
|
194
|
+
for (const ref of referenced) {
|
|
195
|
+
const s = usedSchemas.get(ref);
|
|
196
|
+
if (s !== void 0) {
|
|
197
|
+
filtered.set(ref, s);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return filtered;
|
|
201
|
+
}
|
|
202
|
+
function getRefPathSegments(ref) {
|
|
203
|
+
if (!ref.startsWith("#/")) return null;
|
|
204
|
+
const path = ref.slice(2).split("/").map((seg) => seg);
|
|
205
|
+
if (path.length < 2) {
|
|
206
|
+
return null;
|
|
207
|
+
}
|
|
208
|
+
return path;
|
|
209
|
+
}
|
|
210
|
+
function mergeReferencedSchemasIntoRoot(root, refToSchema) {
|
|
211
|
+
for (const [ref, schema] of refToSchema) {
|
|
212
|
+
const segments = getRefPathSegments(ref);
|
|
213
|
+
if (!segments || segments.length === 0) {
|
|
214
|
+
continue;
|
|
215
|
+
}
|
|
216
|
+
let current = root;
|
|
217
|
+
for (let i = 0; i < segments.length - 1; i++) {
|
|
218
|
+
const seg = segments[i];
|
|
219
|
+
let next = current[seg];
|
|
220
|
+
if (!next || typeof next !== "object" || Array.isArray(next)) {
|
|
221
|
+
next = {};
|
|
222
|
+
current[seg] = next;
|
|
223
|
+
}
|
|
224
|
+
current = next;
|
|
225
|
+
}
|
|
226
|
+
current[segments[segments.length - 1]] = schema;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// src/lib/clone-object.ts
|
|
231
|
+
function cloneObject(obj) {
|
|
232
|
+
if (typeof obj === "undefined") {
|
|
233
|
+
return void 0;
|
|
234
|
+
}
|
|
235
|
+
return JSON.parse(JSON.stringify(obj));
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// src/lib/build-discriminator-one-of.ts
|
|
239
|
+
function hasDiscriminatorWithoutPolymorphism(schema) {
|
|
240
|
+
if (!schema || typeof schema !== "object") return false;
|
|
241
|
+
if (!("discriminator" in schema)) return false;
|
|
242
|
+
if ("oneOf" in schema || "anyOf" in schema) return false;
|
|
243
|
+
return true;
|
|
244
|
+
}
|
|
245
|
+
function allOfReferencesSchema(schema, targetSchemaName) {
|
|
246
|
+
if (!schema || typeof schema !== "object") return false;
|
|
247
|
+
if (!("allOf" in schema) || !Array.isArray(schema.allOf)) return false;
|
|
248
|
+
return schema.allOf.some((item) => {
|
|
249
|
+
if (_chunkYPR7YTHMcjs.isRef.call(void 0, item)) {
|
|
250
|
+
const refParts = item.$ref.split("/");
|
|
251
|
+
const refSchemaName = refParts[refParts.length - 1];
|
|
252
|
+
return refSchemaName === targetSchemaName;
|
|
253
|
+
}
|
|
254
|
+
return false;
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
function findDiscriminatorChildren(definition) {
|
|
258
|
+
const childrenMap = /* @__PURE__ */ new Map();
|
|
259
|
+
const childrenRefMap = /* @__PURE__ */ new Map();
|
|
260
|
+
if (!_optionalChain([definition, 'optionalAccess', _16 => _16.components, 'optionalAccess', _17 => _17.schemas]) || typeof definition.components.schemas !== "object") {
|
|
261
|
+
return { children: childrenMap, refs: childrenRefMap };
|
|
262
|
+
}
|
|
263
|
+
const schemas = definition.components.schemas;
|
|
264
|
+
const schemaNames = Object.keys(schemas);
|
|
265
|
+
const discriminatorSchemas = schemaNames.filter((name) => {
|
|
266
|
+
return hasDiscriminatorWithoutPolymorphism(schemas[name]);
|
|
267
|
+
});
|
|
268
|
+
for (const baseName of discriminatorSchemas) {
|
|
269
|
+
const baseSchema = schemas[baseName];
|
|
270
|
+
const discriminator = baseSchema.discriminator;
|
|
271
|
+
let childSchemaNames = [];
|
|
272
|
+
if (discriminator.mapping && typeof discriminator.mapping === "object") {
|
|
273
|
+
const mappingRefs = Object.values(discriminator.mapping);
|
|
274
|
+
if (mappingRefs.length > 0) {
|
|
275
|
+
childSchemaNames = mappingRefs.map((ref) => ref.split("/").pop()).filter((ref) => ref !== void 0);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
if (!childSchemaNames.length) {
|
|
279
|
+
childSchemaNames = schemaNames.filter((name) => {
|
|
280
|
+
if (name === baseName) return false;
|
|
281
|
+
return allOfReferencesSchema(schemas[name], baseName);
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
if (childSchemaNames.length) {
|
|
285
|
+
for (const childName of childSchemaNames) {
|
|
286
|
+
childrenRefMap.set(childName, `#/components/schemas/${childName}`);
|
|
287
|
+
}
|
|
288
|
+
childrenMap.set(baseName, childSchemaNames);
|
|
289
|
+
childrenRefMap.set(baseName, `#/components/schemas/${baseName}`);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
return { children: childrenMap, refs: childrenRefMap };
|
|
293
|
+
}
|
|
294
|
+
function applyDiscriminatorOneOfToUsedSchemas(definition, usedSchemas, getOrAddSchema) {
|
|
295
|
+
const { children: childrenMap, refs: childrenRefMap } = findDiscriminatorChildren(definition);
|
|
296
|
+
if (!childrenMap.size) return;
|
|
297
|
+
for (const [baseName, childNames] of childrenMap) {
|
|
298
|
+
const baseRef = childrenRefMap.get(baseName);
|
|
299
|
+
if (!baseRef) continue;
|
|
300
|
+
const baseSchema = usedSchemas.get(baseRef);
|
|
301
|
+
if (!baseSchema || typeof baseSchema !== "object") continue;
|
|
302
|
+
const oneOf = [];
|
|
303
|
+
for (const childName of childNames) {
|
|
304
|
+
const childRef = childrenRefMap.get(childName);
|
|
305
|
+
if (!childRef) continue;
|
|
306
|
+
const childSchema = getOrAddSchema(childRef);
|
|
307
|
+
if (childSchema) {
|
|
308
|
+
oneOf.push({
|
|
309
|
+
$ref: childRef
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
if (oneOf.length > 0) {
|
|
314
|
+
baseSchema.oneOf = oneOf;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
for (const [parentSchemaName, childNames] of childrenMap) {
|
|
318
|
+
for (const childName of childNames) {
|
|
319
|
+
const childRef = childrenRefMap.get(childName);
|
|
320
|
+
if (!childRef) continue;
|
|
321
|
+
const childSchema = usedSchemas.get(childRef);
|
|
322
|
+
if (!childSchema || !("allOf" in childSchema) || !Array.isArray(childSchema.allOf)) {
|
|
323
|
+
continue;
|
|
324
|
+
}
|
|
325
|
+
for (let i = 0; i < childSchema.allOf.length; i++) {
|
|
326
|
+
const item = childSchema.allOf[i];
|
|
327
|
+
if (item && typeof item === "object" && "x-readme-ref-name" in item && item["x-readme-ref-name"] === parentSchemaName && "oneOf" in item) {
|
|
328
|
+
const clonedItem = cloneObject(item);
|
|
329
|
+
delete clonedItem.oneOf;
|
|
330
|
+
childSchema.allOf[i] = clonedItem;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
}
|
|
167
336
|
|
|
168
337
|
// src/lib/openapi-to-json-schema.ts
|
|
338
|
+
var _jsonschemamergeallof = require('json-schema-merge-allof'); var _jsonschemamergeallof2 = _interopRequireDefault(_jsonschemamergeallof);
|
|
339
|
+
|
|
340
|
+
var _removeundefinedobjects = require('remove-undefined-objects'); var _removeundefinedobjects2 = _interopRequireDefault(_removeundefinedobjects);
|
|
169
341
|
var UNSUPPORTED_SCHEMA_PROPS = [
|
|
170
342
|
"example",
|
|
171
343
|
// OpenAPI supports `example` but we're mapping it to `examples` in this library.
|
|
172
344
|
"externalDocs",
|
|
173
345
|
"xml"
|
|
174
346
|
];
|
|
347
|
+
var PENDING_SCHEMA = { __pending: true };
|
|
348
|
+
function isPendingSchema(s) {
|
|
349
|
+
return isObject(s) && "__pending" in s && s.__pending === true;
|
|
350
|
+
}
|
|
175
351
|
function getSchemaVersionString(schema, api) {
|
|
176
|
-
if (
|
|
352
|
+
if (_chunkYPR7YTHMcjs.isOpenAPI30.call(void 0, api)) {
|
|
177
353
|
return "http://json-schema.org/draft-04/schema#";
|
|
178
354
|
}
|
|
179
355
|
if (schema.$schema) {
|
|
@@ -187,6 +363,101 @@ function getSchemaVersionString(schema, api) {
|
|
|
187
363
|
function isPolymorphicSchema(schema) {
|
|
188
364
|
return "allOf" in schema || "anyOf" in schema || "oneOf" in schema;
|
|
189
365
|
}
|
|
366
|
+
function inlinePropertyRefsForMerge(schema, usedSchemas) {
|
|
367
|
+
const out = structuredClone(schema);
|
|
368
|
+
if (!("properties" in out) || typeof out.properties !== "object" || out.properties === null) {
|
|
369
|
+
return out;
|
|
370
|
+
}
|
|
371
|
+
for (const key of Object.keys(out.properties)) {
|
|
372
|
+
const val = out.properties[key];
|
|
373
|
+
if (_chunkYPR7YTHMcjs.isRef.call(void 0, val)) {
|
|
374
|
+
const resolved = usedSchemas.get(val.$ref);
|
|
375
|
+
if (resolved !== void 0 && !isPendingSchema(resolved)) {
|
|
376
|
+
out.properties[key] = {
|
|
377
|
+
...structuredClone(resolved)
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
return out;
|
|
383
|
+
}
|
|
384
|
+
function resolveAndCacheRefSchema({
|
|
385
|
+
schema,
|
|
386
|
+
definition,
|
|
387
|
+
usedSchemas,
|
|
388
|
+
seenRefs,
|
|
389
|
+
conversionOptions,
|
|
390
|
+
returnMode,
|
|
391
|
+
refLogger
|
|
392
|
+
}) {
|
|
393
|
+
const ref = schema.$ref;
|
|
394
|
+
const existing = usedSchemas.get(ref);
|
|
395
|
+
if (existing !== void 0 && !isPendingSchema(existing)) {
|
|
396
|
+
return returnMode === "converted" ? existing : { $ref: ref };
|
|
397
|
+
}
|
|
398
|
+
if (existing !== void 0 && isPendingSchema(existing)) {
|
|
399
|
+
return { $ref: ref };
|
|
400
|
+
}
|
|
401
|
+
usedSchemas.set(ref, PENDING_SCHEMA);
|
|
402
|
+
if (returnMode === "ref") {
|
|
403
|
+
let resolved;
|
|
404
|
+
try {
|
|
405
|
+
const dereferenced = dereferenceRef(schema, definition, seenRefs);
|
|
406
|
+
if (_chunkYPR7YTHMcjs.isRef.call(void 0, dereferenced)) {
|
|
407
|
+
refLogger(dereferenced.$ref, "ref");
|
|
408
|
+
let converted2;
|
|
409
|
+
try {
|
|
410
|
+
const pointer = ref.startsWith("#") ? decodeURIComponent(ref.substring(1)) : ref;
|
|
411
|
+
const rawSchema = _jsonpointer2.default.get(definition, pointer);
|
|
412
|
+
if (rawSchema && typeof rawSchema === "object") {
|
|
413
|
+
converted2 = toJSONSchema(structuredClone(rawSchema), { ...conversionOptions, seenRefs });
|
|
414
|
+
} else {
|
|
415
|
+
converted2 = { $ref: ref };
|
|
416
|
+
}
|
|
417
|
+
} catch (e3) {
|
|
418
|
+
converted2 = { $ref: ref };
|
|
419
|
+
}
|
|
420
|
+
usedSchemas.set(ref, converted2);
|
|
421
|
+
refLogger(ref, "ref");
|
|
422
|
+
return { $ref: ref };
|
|
423
|
+
}
|
|
424
|
+
resolved = dereferenced;
|
|
425
|
+
} catch (e4) {
|
|
426
|
+
refLogger(ref, "ref");
|
|
427
|
+
usedSchemas.set(ref, { $ref: ref });
|
|
428
|
+
return { $ref: ref };
|
|
429
|
+
}
|
|
430
|
+
const converted = toJSONSchema(structuredClone(resolved), { ...conversionOptions, seenRefs });
|
|
431
|
+
usedSchemas.set(ref, converted);
|
|
432
|
+
refLogger(ref, "ref");
|
|
433
|
+
return { $ref: ref };
|
|
434
|
+
}
|
|
435
|
+
try {
|
|
436
|
+
const dereferenced = dereferenceRef(schema, definition, seenRefs);
|
|
437
|
+
if (_chunkYPR7YTHMcjs.isRef.call(void 0, dereferenced)) {
|
|
438
|
+
let converted2;
|
|
439
|
+
try {
|
|
440
|
+
const pointer = ref.startsWith("#") ? decodeURIComponent(ref.substring(1)) : ref;
|
|
441
|
+
const rawSchema = _jsonpointer2.default.get(definition, pointer);
|
|
442
|
+
if (rawSchema && typeof rawSchema === "object") {
|
|
443
|
+
converted2 = toJSONSchema(structuredClone(rawSchema), { ...conversionOptions, seenRefs });
|
|
444
|
+
} else {
|
|
445
|
+
converted2 = { $ref: ref };
|
|
446
|
+
}
|
|
447
|
+
} catch (e5) {
|
|
448
|
+
converted2 = { $ref: ref };
|
|
449
|
+
}
|
|
450
|
+
usedSchemas.set(ref, converted2);
|
|
451
|
+
return converted2;
|
|
452
|
+
}
|
|
453
|
+
const converted = toJSONSchema(structuredClone(dereferenced), { ...conversionOptions, seenRefs });
|
|
454
|
+
usedSchemas.set(ref, converted);
|
|
455
|
+
return converted;
|
|
456
|
+
} catch (e6) {
|
|
457
|
+
usedSchemas.set(ref, { $ref: ref });
|
|
458
|
+
return { $ref: ref };
|
|
459
|
+
}
|
|
460
|
+
}
|
|
190
461
|
function isRequestBodySchema(schema) {
|
|
191
462
|
return "content" in schema;
|
|
192
463
|
}
|
|
@@ -220,7 +491,7 @@ function searchForValueByPropAndPointer(property, pointer, schemas = []) {
|
|
|
220
491
|
}
|
|
221
492
|
try {
|
|
222
493
|
foundValue = _jsonpointer2.default.get(schema, pointers[i]);
|
|
223
|
-
} catch (
|
|
494
|
+
} catch (e7) {
|
|
224
495
|
}
|
|
225
496
|
if (foundValue !== void 0) {
|
|
226
497
|
break;
|
|
@@ -232,12 +503,13 @@ function searchForValueByPropAndPointer(property, pointer, schemas = []) {
|
|
|
232
503
|
}
|
|
233
504
|
return foundValue;
|
|
234
505
|
}
|
|
235
|
-
function toJSONSchema(data, opts
|
|
506
|
+
function toJSONSchema(data, opts) {
|
|
236
507
|
let schema = data === true ? {} : { ...data };
|
|
237
|
-
const schemaAdditionalProperties =
|
|
508
|
+
const schemaAdditionalProperties = _chunkYPR7YTHMcjs.isSchema.call(void 0, schema) ? schema.additionalProperties : null;
|
|
238
509
|
const {
|
|
239
510
|
addEnumsToDescriptions,
|
|
240
511
|
currentLocation,
|
|
512
|
+
definition,
|
|
241
513
|
globalDefaults,
|
|
242
514
|
hideReadOnlyProperties,
|
|
243
515
|
hideWriteOnlyProperties,
|
|
@@ -245,7 +517,8 @@ function toJSONSchema(data, opts = {}) {
|
|
|
245
517
|
prevDefaultSchemas = [],
|
|
246
518
|
prevExampleSchemas = [],
|
|
247
519
|
refLogger,
|
|
248
|
-
|
|
520
|
+
seenRefs,
|
|
521
|
+
usedSchemas
|
|
249
522
|
} = {
|
|
250
523
|
addEnumsToDescriptions: false,
|
|
251
524
|
currentLocation: "",
|
|
@@ -256,15 +529,64 @@ function toJSONSchema(data, opts = {}) {
|
|
|
256
529
|
prevDefaultSchemas: [],
|
|
257
530
|
prevExampleSchemas: [],
|
|
258
531
|
refLogger: () => true,
|
|
259
|
-
|
|
532
|
+
seenRefs: /* @__PURE__ */ new Set(),
|
|
533
|
+
usedSchemas: /* @__PURE__ */ new Map(),
|
|
260
534
|
...opts
|
|
261
535
|
};
|
|
262
|
-
|
|
536
|
+
const polyOptions = {
|
|
537
|
+
addEnumsToDescriptions,
|
|
538
|
+
currentLocation,
|
|
539
|
+
definition,
|
|
540
|
+
globalDefaults,
|
|
541
|
+
hideReadOnlyProperties,
|
|
542
|
+
hideWriteOnlyProperties,
|
|
543
|
+
isPolymorphicAllOfChild: false,
|
|
544
|
+
prevDefaultSchemas,
|
|
545
|
+
prevExampleSchemas,
|
|
546
|
+
refLogger,
|
|
547
|
+
seenRefs,
|
|
548
|
+
usedSchemas
|
|
549
|
+
};
|
|
550
|
+
if (_chunkYPR7YTHMcjs.isRef.call(void 0, schema)) {
|
|
551
|
+
if (definition && usedSchemas) {
|
|
552
|
+
return resolveAndCacheRefSchema({
|
|
553
|
+
schema,
|
|
554
|
+
definition,
|
|
555
|
+
usedSchemas,
|
|
556
|
+
seenRefs,
|
|
557
|
+
conversionOptions: polyOptions,
|
|
558
|
+
returnMode: "ref",
|
|
559
|
+
refLogger
|
|
560
|
+
});
|
|
561
|
+
}
|
|
263
562
|
refLogger(schema.$ref, "ref");
|
|
264
|
-
return
|
|
563
|
+
return schema;
|
|
265
564
|
}
|
|
266
|
-
if (
|
|
565
|
+
if (_chunkYPR7YTHMcjs.isSchema.call(void 0, schema, isPolymorphicAllOfChild)) {
|
|
267
566
|
if ("allOf" in schema && Array.isArray(schema.allOf)) {
|
|
567
|
+
let allOfSchemas = schema.allOf;
|
|
568
|
+
if (definition && usedSchemas) {
|
|
569
|
+
const allOfOptions = schema.allOf.length > 1 ? { ...polyOptions, refLogger: () => {
|
|
570
|
+
} } : polyOptions;
|
|
571
|
+
allOfSchemas = schema.allOf.map((item) => {
|
|
572
|
+
if (_chunkYPR7YTHMcjs.isRef.call(void 0, item)) {
|
|
573
|
+
return resolveAndCacheRefSchema({
|
|
574
|
+
schema: item,
|
|
575
|
+
definition,
|
|
576
|
+
usedSchemas,
|
|
577
|
+
seenRefs,
|
|
578
|
+
conversionOptions: allOfOptions,
|
|
579
|
+
returnMode: "converted",
|
|
580
|
+
refLogger
|
|
581
|
+
});
|
|
582
|
+
}
|
|
583
|
+
return toJSONSchema(item, allOfOptions);
|
|
584
|
+
});
|
|
585
|
+
schema = {
|
|
586
|
+
...schema,
|
|
587
|
+
allOf: allOfSchemas.map((s) => inlinePropertyRefsForMerge(s, usedSchemas))
|
|
588
|
+
};
|
|
589
|
+
}
|
|
268
590
|
try {
|
|
269
591
|
schema = _jsonschemamergeallof2.default.call(void 0, schema, {
|
|
270
592
|
ignoreAdditionalProperties: true,
|
|
@@ -296,73 +618,92 @@ function toJSONSchema(data, opts = {}) {
|
|
|
296
618
|
defaultResolver: _jsonschemamergeallof2.default.options.resolvers.title
|
|
297
619
|
}
|
|
298
620
|
});
|
|
299
|
-
} catch (
|
|
621
|
+
} catch (e8) {
|
|
300
622
|
const { ...schemaWithoutAllOf } = schema;
|
|
301
623
|
schema = schemaWithoutAllOf;
|
|
302
624
|
delete schema.allOf;
|
|
303
625
|
}
|
|
304
|
-
|
|
626
|
+
collectRefsInSchema(schema).forEach((ref) => {
|
|
627
|
+
refLogger(ref, "ref");
|
|
628
|
+
});
|
|
629
|
+
if (_chunkYPR7YTHMcjs.isRef.call(void 0, schema)) {
|
|
305
630
|
refLogger(schema.$ref, "ref");
|
|
306
|
-
return
|
|
631
|
+
return schema;
|
|
307
632
|
}
|
|
308
633
|
}
|
|
309
634
|
["anyOf", "oneOf"].forEach((polyType) => {
|
|
310
635
|
if (polyType in schema && Array.isArray(schema[polyType])) {
|
|
311
636
|
const discriminatorPropertyName = "discriminator" in schema && schema.discriminator && isObject(schema.discriminator) ? schema.discriminator.propertyName : void 0;
|
|
312
637
|
schema[polyType].forEach((item, idx) => {
|
|
313
|
-
if (!_optionalChain([schema, 'access',
|
|
638
|
+
if (!_optionalChain([schema, 'access', _18 => _18[polyType], 'optionalAccess', _19 => _19[idx]])) {
|
|
314
639
|
return;
|
|
315
640
|
}
|
|
316
|
-
const
|
|
317
|
-
|
|
318
|
-
currentLocation: `${currentLocation}/${idx}
|
|
319
|
-
globalDefaults,
|
|
320
|
-
hideReadOnlyProperties,
|
|
321
|
-
hideWriteOnlyProperties,
|
|
322
|
-
isPolymorphicAllOfChild: false,
|
|
323
|
-
prevDefaultSchemas,
|
|
324
|
-
prevExampleSchemas,
|
|
325
|
-
refLogger,
|
|
326
|
-
transformer
|
|
641
|
+
const itemOptions = {
|
|
642
|
+
...polyOptions,
|
|
643
|
+
currentLocation: `${currentLocation}/${idx}`
|
|
327
644
|
};
|
|
328
645
|
if ("properties" in schema) {
|
|
329
646
|
schema[polyType][idx] = toJSONSchema(
|
|
330
|
-
{
|
|
331
|
-
|
|
647
|
+
{
|
|
648
|
+
required: schema.required,
|
|
649
|
+
allOf: [item, { properties: schema.properties }]
|
|
650
|
+
},
|
|
651
|
+
itemOptions
|
|
332
652
|
);
|
|
333
653
|
} else if ("items" in schema) {
|
|
334
654
|
schema[polyType][idx] = toJSONSchema(
|
|
335
|
-
{
|
|
336
|
-
|
|
655
|
+
{
|
|
656
|
+
allOf: [item, { items: schema.items }]
|
|
657
|
+
},
|
|
658
|
+
itemOptions
|
|
337
659
|
);
|
|
338
660
|
} else {
|
|
339
|
-
schema[polyType][idx] = toJSONSchema(item,
|
|
661
|
+
schema[polyType][idx] = toJSONSchema(item, itemOptions);
|
|
340
662
|
}
|
|
341
|
-
if (
|
|
342
|
-
|
|
663
|
+
if ("required" in schema[polyType][idx]) {
|
|
664
|
+
if (Array.isArray(schema[polyType][idx].required) && schema[polyType][idx].required.length === 0) {
|
|
665
|
+
delete schema[polyType][idx].required;
|
|
666
|
+
} else if (isObject(schema[polyType][idx]) && typeof schema[polyType][idx].required === "boolean") {
|
|
667
|
+
delete schema[polyType][idx].required;
|
|
668
|
+
}
|
|
343
669
|
}
|
|
344
|
-
if (discriminatorPropertyName
|
|
670
|
+
if (discriminatorPropertyName) {
|
|
345
671
|
const childSchema = schema[polyType][idx];
|
|
346
|
-
if (
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
672
|
+
if (isObject(childSchema)) {
|
|
673
|
+
if ("discriminator" in childSchema) {
|
|
674
|
+
delete childSchema.discriminator;
|
|
675
|
+
}
|
|
676
|
+
if ("oneOf" in childSchema) {
|
|
677
|
+
delete childSchema.oneOf;
|
|
678
|
+
}
|
|
679
|
+
if ("anyOf" in childSchema) {
|
|
680
|
+
delete childSchema.anyOf;
|
|
681
|
+
}
|
|
351
682
|
}
|
|
352
|
-
if (
|
|
353
|
-
|
|
683
|
+
if (definition && usedSchemas && _chunkYPR7YTHMcjs.isRef.call(void 0, childSchema)) {
|
|
684
|
+
const resolved = usedSchemas.get(childSchema.$ref);
|
|
685
|
+
if (resolved && typeof resolved === "object" && !isPendingSchema(resolved)) {
|
|
686
|
+
if ("discriminator" in resolved) {
|
|
687
|
+
delete resolved.discriminator;
|
|
688
|
+
}
|
|
689
|
+
if ("oneOf" in resolved) {
|
|
690
|
+
delete resolved.oneOf;
|
|
691
|
+
}
|
|
692
|
+
if ("anyOf" in resolved) {
|
|
693
|
+
delete resolved.anyOf;
|
|
694
|
+
}
|
|
695
|
+
usedSchemas.set(childSchema.$ref, resolved);
|
|
696
|
+
}
|
|
354
697
|
}
|
|
355
698
|
}
|
|
356
699
|
});
|
|
357
700
|
}
|
|
358
701
|
});
|
|
359
|
-
if (
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
});
|
|
365
|
-
}
|
|
702
|
+
if (_optionalChain([schema, 'optionalAccess', _20 => _20.discriminator, 'optionalAccess', _21 => _21.mapping]) && typeof schema.discriminator.mapping === "object") {
|
|
703
|
+
const mapping = schema.discriminator.mapping;
|
|
704
|
+
Object.keys(mapping).forEach((k) => {
|
|
705
|
+
refLogger(mapping[k], "discriminator");
|
|
706
|
+
});
|
|
366
707
|
}
|
|
367
708
|
}
|
|
368
709
|
if (!("type" in schema) && !isPolymorphicSchema(schema) && !isRequestBodySchema(schema)) {
|
|
@@ -427,7 +768,7 @@ function toJSONSchema(data, opts = {}) {
|
|
|
427
768
|
"required"
|
|
428
769
|
]
|
|
429
770
|
}).forEach(([typeKey, keywords]) => {
|
|
430
|
-
if (!_optionalChain([schema, 'access',
|
|
771
|
+
if (!_optionalChain([schema, 'access', _22 => _22.type, 'optionalAccess', _23 => _23.includes, 'call', _24 => _24(typeKey)])) {
|
|
431
772
|
return;
|
|
432
773
|
}
|
|
433
774
|
const reducedSchema = _removeundefinedobjects2.default.call(void 0, {
|
|
@@ -460,7 +801,7 @@ function toJSONSchema(data, opts = {}) {
|
|
|
460
801
|
}
|
|
461
802
|
}
|
|
462
803
|
}
|
|
463
|
-
if (
|
|
804
|
+
if (_chunkYPR7YTHMcjs.isSchema.call(void 0, schema, isPolymorphicAllOfChild)) {
|
|
464
805
|
if ("default" in schema && isObject(schema.default)) {
|
|
465
806
|
prevDefaultSchemas.push({ default: schema.default });
|
|
466
807
|
}
|
|
@@ -481,7 +822,7 @@ function toJSONSchema(data, opts = {}) {
|
|
|
481
822
|
if (typeof schema.examples === "object" && schema.examples !== null && !Array.isArray(schema.examples)) {
|
|
482
823
|
const examples = [];
|
|
483
824
|
Object.keys(schema.examples).forEach((name) => {
|
|
484
|
-
const example = _optionalChain([schema, 'access',
|
|
825
|
+
const example = _optionalChain([schema, 'access', _25 => _25.examples, 'optionalAccess', _26 => _26[name]]);
|
|
485
826
|
if ("$ref" in example) {
|
|
486
827
|
refLogger(example.$ref, "ref");
|
|
487
828
|
} else if ("value" in example) {
|
|
@@ -519,21 +860,21 @@ function toJSONSchema(data, opts = {}) {
|
|
|
519
860
|
}
|
|
520
861
|
if (hasSchemaType(schema, "array")) {
|
|
521
862
|
if ("items" in schema && schema.items !== void 0) {
|
|
522
|
-
if (!Array.isArray(schema.items) && Object.keys(schema.items).length === 1 &&
|
|
863
|
+
if (!(definition && usedSchemas) && !Array.isArray(schema.items) && Object.keys(schema.items).length === 1 && _chunkYPR7YTHMcjs.isRef.call(void 0, schema.items)) {
|
|
523
864
|
refLogger(schema.items.$ref, "ref");
|
|
524
865
|
} else if (schema.items !== true) {
|
|
525
866
|
schema.items = toJSONSchema(schema.items, {
|
|
526
|
-
|
|
867
|
+
...polyOptions,
|
|
527
868
|
currentLocation: `${currentLocation}/0`,
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
hideWriteOnlyProperties,
|
|
531
|
-
prevExampleSchemas,
|
|
532
|
-
refLogger,
|
|
533
|
-
transformer
|
|
869
|
+
prevDefaultSchemas: [],
|
|
870
|
+
prevExampleSchemas
|
|
534
871
|
});
|
|
535
|
-
if (
|
|
536
|
-
|
|
872
|
+
if ("required" in schema.items) {
|
|
873
|
+
if (Array.isArray(schema.items.required) && schema.items.required.length === 0) {
|
|
874
|
+
delete schema.items.required;
|
|
875
|
+
} else if (isObject(schema.items) && !Array.isArray(schema.items.required)) {
|
|
876
|
+
delete schema.items.required;
|
|
877
|
+
}
|
|
537
878
|
}
|
|
538
879
|
}
|
|
539
880
|
} else if ("properties" in schema || "additionalProperties" in schema) {
|
|
@@ -544,17 +885,12 @@ function toJSONSchema(data, opts = {}) {
|
|
|
544
885
|
} else if (hasSchemaType(schema, "object")) {
|
|
545
886
|
if ("properties" in schema && schema.properties !== void 0) {
|
|
546
887
|
Object.keys(schema.properties).forEach((prop) => {
|
|
547
|
-
if (Array.isArray(_optionalChain([schema, 'access',
|
|
888
|
+
if (Array.isArray(_optionalChain([schema, 'access', _27 => _27.properties, 'optionalAccess', _28 => _28[prop]])) || typeof _optionalChain([schema, 'access', _29 => _29.properties, 'optionalAccess', _30 => _30[prop]]) === "object" && _optionalChain([schema, 'access', _31 => _31.properties, 'optionalAccess', _32 => _32[prop]]) !== null) {
|
|
548
889
|
const newPropSchema = toJSONSchema(schema.properties[prop], {
|
|
549
|
-
|
|
890
|
+
...polyOptions,
|
|
550
891
|
currentLocation: `${currentLocation}/${encodePointer(prop)}`,
|
|
551
|
-
globalDefaults,
|
|
552
|
-
hideReadOnlyProperties,
|
|
553
|
-
hideWriteOnlyProperties,
|
|
554
892
|
prevDefaultSchemas,
|
|
555
|
-
prevExampleSchemas
|
|
556
|
-
refLogger,
|
|
557
|
-
transformer
|
|
893
|
+
prevExampleSchemas
|
|
558
894
|
});
|
|
559
895
|
let propShouldBeUpdated = true;
|
|
560
896
|
if ((hideReadOnlyProperties || hideWriteOnlyProperties) && !Object.keys(newPropSchema).length) {
|
|
@@ -578,7 +914,7 @@ function toJSONSchema(data, opts = {}) {
|
|
|
578
914
|
});
|
|
579
915
|
if (hideReadOnlyProperties || hideWriteOnlyProperties) {
|
|
580
916
|
if (!Object.keys(schema.properties).length) {
|
|
581
|
-
return
|
|
917
|
+
return {};
|
|
582
918
|
}
|
|
583
919
|
}
|
|
584
920
|
}
|
|
@@ -588,15 +924,10 @@ function toJSONSchema(data, opts = {}) {
|
|
|
588
924
|
schema.additionalProperties = true;
|
|
589
925
|
} else {
|
|
590
926
|
schema.additionalProperties = toJSONSchema(schemaAdditionalProperties, {
|
|
591
|
-
|
|
927
|
+
...polyOptions,
|
|
592
928
|
currentLocation,
|
|
593
|
-
globalDefaults,
|
|
594
|
-
hideReadOnlyProperties,
|
|
595
|
-
hideWriteOnlyProperties,
|
|
596
929
|
prevDefaultSchemas,
|
|
597
|
-
prevExampleSchemas
|
|
598
|
-
refLogger,
|
|
599
|
-
transformer
|
|
930
|
+
prevExampleSchemas
|
|
600
931
|
});
|
|
601
932
|
}
|
|
602
933
|
}
|
|
@@ -605,13 +936,13 @@ function toJSONSchema(data, opts = {}) {
|
|
|
605
936
|
}
|
|
606
937
|
}
|
|
607
938
|
}
|
|
608
|
-
if (
|
|
939
|
+
if (_chunkYPR7YTHMcjs.isSchema.call(void 0, schema, isPolymorphicAllOfChild) && globalDefaults && Object.keys(globalDefaults).length > 0 && currentLocation) {
|
|
609
940
|
try {
|
|
610
941
|
const userJwtDefault = _jsonpointer2.default.get(globalDefaults, currentLocation);
|
|
611
942
|
if (userJwtDefault) {
|
|
612
943
|
schema.default = userJwtDefault;
|
|
613
944
|
}
|
|
614
|
-
} catch (
|
|
945
|
+
} catch (e9) {
|
|
615
946
|
}
|
|
616
947
|
}
|
|
617
948
|
if ("default" in schema && typeof schema.default !== "undefined") {
|
|
@@ -627,7 +958,7 @@ function toJSONSchema(data, opts = {}) {
|
|
|
627
958
|
schema.default = foundDefault;
|
|
628
959
|
}
|
|
629
960
|
}
|
|
630
|
-
if (
|
|
961
|
+
if (_chunkYPR7YTHMcjs.isSchema.call(void 0, schema, isPolymorphicAllOfChild) && "enum" in schema && Array.isArray(schema.enum)) {
|
|
631
962
|
schema.enum = Array.from(new Set(schema.enum));
|
|
632
963
|
if (addEnumsToDescriptions) {
|
|
633
964
|
const enums = schema.enum.filter((v) => v !== void 0 && (typeof v !== "string" || v.trim() !== "")).map((str) => `\`${str}\``).join(" ");
|
|
@@ -658,10 +989,10 @@ ${enums}`;
|
|
|
658
989
|
} else if (hideWriteOnlyProperties && "writeOnly" in schema && schema.writeOnly === true) {
|
|
659
990
|
return {};
|
|
660
991
|
}
|
|
661
|
-
return
|
|
992
|
+
return schema;
|
|
662
993
|
}
|
|
663
994
|
|
|
664
|
-
// src/operation/
|
|
995
|
+
// src/operation/transformers/get-parameters-as-json-schema.ts
|
|
665
996
|
var types = {
|
|
666
997
|
path: "Path Params",
|
|
667
998
|
query: "Query Params",
|
|
@@ -673,54 +1004,25 @@ var types = {
|
|
|
673
1004
|
// This a special type reserved for https://npm.im/api
|
|
674
1005
|
};
|
|
675
1006
|
function getParametersAsJSONSchema(operation, api, opts) {
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
}
|
|
685
|
-
function getDeprecated(schema, type) {
|
|
686
|
-
if (_optionalChain([opts, 'optionalAccess', _17 => _17.retainDeprecatedProperties])) {
|
|
687
|
-
return null;
|
|
1007
|
+
const usedSchemas = /* @__PURE__ */ new Map();
|
|
1008
|
+
const seenRefs = /* @__PURE__ */ new Set();
|
|
1009
|
+
const refsByGroup = /* @__PURE__ */ new Map();
|
|
1010
|
+
function refLoggerForSchemaGroup(group) {
|
|
1011
|
+
let set = refsByGroup.get(group);
|
|
1012
|
+
if (!set) {
|
|
1013
|
+
set = /* @__PURE__ */ new Set();
|
|
1014
|
+
refsByGroup.set(group, set);
|
|
688
1015
|
}
|
|
689
|
-
|
|
690
|
-
const deprecatedBody = cloneObject(schema);
|
|
691
|
-
const requiredParams = schema.required || [];
|
|
692
|
-
const allDeprecatedProps = {};
|
|
693
|
-
Object.keys(deprecatedBody.properties || {}).forEach((key) => {
|
|
694
|
-
const deprecatedProp = _optionalChain([deprecatedBody, 'access', _18 => _18.properties, 'optionalAccess', _19 => _19[key]]);
|
|
695
|
-
if (deprecatedProp.deprecated && !requiredParams.includes(key) && !deprecatedProp.readOnly) {
|
|
696
|
-
allDeprecatedProps[key] = deprecatedProp;
|
|
697
|
-
}
|
|
698
|
-
});
|
|
699
|
-
deprecatedBody.properties = allDeprecatedProps;
|
|
700
|
-
const deprecatedSchema = toJSONSchema(deprecatedBody, {
|
|
701
|
-
globalDefaults: _optionalChain([opts, 'optionalAccess', _20 => _20.globalDefaults]),
|
|
702
|
-
hideReadOnlyProperties: _optionalChain([opts, 'optionalAccess', _21 => _21.hideReadOnlyProperties]),
|
|
703
|
-
hideWriteOnlyProperties: _optionalChain([opts, 'optionalAccess', _22 => _22.hideWriteOnlyProperties]),
|
|
704
|
-
prevExampleSchemas: [],
|
|
705
|
-
refLogger,
|
|
706
|
-
transformer: _optionalChain([opts, 'optionalAccess', _23 => _23.transformer])
|
|
707
|
-
});
|
|
708
|
-
if (Object.keys(deprecatedSchema).length === 0 || Object.keys(deprecatedSchema.properties || {}).length === 0) {
|
|
709
|
-
return null;
|
|
710
|
-
}
|
|
711
|
-
Object.keys(schema.properties).forEach((key) => {
|
|
712
|
-
if ((_optionalChain([schema, 'access', _24 => _24.properties, 'optionalAccess', _25 => _25[key]])).deprecated && !requiredParams.includes(key)) {
|
|
713
|
-
_optionalChainDelete([schema, 'access', _26 => _26.properties, 'optionalAccess', _27 => delete _27[key]]);
|
|
714
|
-
}
|
|
715
|
-
});
|
|
716
|
-
return {
|
|
717
|
-
type,
|
|
718
|
-
schema: isPrimitive(deprecatedSchema) ? deprecatedSchema : {
|
|
719
|
-
...deprecatedSchema,
|
|
720
|
-
$schema: getSchemaVersionString(deprecatedSchema, api)
|
|
721
|
-
}
|
|
722
|
-
};
|
|
1016
|
+
return set;
|
|
723
1017
|
}
|
|
1018
|
+
const baseSchemaOptions = {
|
|
1019
|
+
definition: api,
|
|
1020
|
+
globalDefaults: _optionalChain([opts, 'optionalAccess', _33 => _33.globalDefaults]),
|
|
1021
|
+
hideReadOnlyProperties: _optionalChain([opts, 'optionalAccess', _34 => _34.hideReadOnlyProperties]),
|
|
1022
|
+
hideWriteOnlyProperties: _optionalChain([opts, 'optionalAccess', _35 => _35.hideWriteOnlyProperties]),
|
|
1023
|
+
seenRefs,
|
|
1024
|
+
usedSchemas
|
|
1025
|
+
};
|
|
724
1026
|
function transformRequestBody() {
|
|
725
1027
|
const requestBody = operation.getRequestBody();
|
|
726
1028
|
if (!requestBody || !Array.isArray(requestBody)) return null;
|
|
@@ -734,9 +1036,12 @@ function getParametersAsJSONSchema(operation, api, opts) {
|
|
|
734
1036
|
prevExampleSchemas.push({ example: mediaTypeObject.example });
|
|
735
1037
|
} else if ("examples" in mediaTypeObject) {
|
|
736
1038
|
prevExampleSchemas.push({
|
|
737
|
-
examples: Object.values(mediaTypeObject.examples || {}).map((
|
|
738
|
-
|
|
739
|
-
|
|
1039
|
+
examples: Object.values(mediaTypeObject.examples || {}).map((ex) => {
|
|
1040
|
+
let example = ex;
|
|
1041
|
+
if (!example) return void 0;
|
|
1042
|
+
if (_chunkYPR7YTHMcjs.isRef.call(void 0, example)) {
|
|
1043
|
+
example = dereferenceRef(example, operation.api);
|
|
1044
|
+
if (!example || _chunkYPR7YTHMcjs.isRef.call(void 0, example)) return void 0;
|
|
740
1045
|
}
|
|
741
1046
|
return example.value;
|
|
742
1047
|
}).filter((item) => item !== void 0)
|
|
@@ -744,12 +1049,9 @@ function getParametersAsJSONSchema(operation, api, opts) {
|
|
|
744
1049
|
}
|
|
745
1050
|
const requestSchema = cloneObject(mediaTypeObject.schema);
|
|
746
1051
|
const cleanedSchema = toJSONSchema(requestSchema, {
|
|
747
|
-
|
|
748
|
-
hideReadOnlyProperties: _optionalChain([opts, 'optionalAccess', _29 => _29.hideReadOnlyProperties]),
|
|
749
|
-
hideWriteOnlyProperties: _optionalChain([opts, 'optionalAccess', _30 => _30.hideWriteOnlyProperties]),
|
|
1052
|
+
...baseSchemaOptions,
|
|
750
1053
|
prevExampleSchemas,
|
|
751
|
-
refLogger
|
|
752
|
-
transformer: _optionalChain([opts, 'optionalAccess', _31 => _31.transformer])
|
|
1054
|
+
refLogger: (ref) => refLoggerForSchemaGroup(type).add(ref)
|
|
753
1055
|
});
|
|
754
1056
|
if (!Object.keys(cleanedSchema).length) {
|
|
755
1057
|
return null;
|
|
@@ -761,43 +1063,9 @@ function getParametersAsJSONSchema(operation, api, opts) {
|
|
|
761
1063
|
...cleanedSchema,
|
|
762
1064
|
$schema: getSchemaVersionString(cleanedSchema, api)
|
|
763
1065
|
},
|
|
764
|
-
deprecatedProps: _nullishCoalesce(getDeprecated(cleanedSchema, type), () => ( void 0)),
|
|
765
1066
|
...description ? { description } : {}
|
|
766
1067
|
};
|
|
767
1068
|
}
|
|
768
|
-
function transformComponents() {
|
|
769
|
-
if (!("components" in api) || !api.components) {
|
|
770
|
-
return false;
|
|
771
|
-
}
|
|
772
|
-
const components2 = {
|
|
773
|
-
...Object.keys(api.components).map((componentType) => ({ [componentType]: {} })).reduce((prev, next) => Object.assign(prev, next), {})
|
|
774
|
-
};
|
|
775
|
-
Object.keys(api.components).forEach((componentType) => {
|
|
776
|
-
const cType = componentType;
|
|
777
|
-
if (typeof _optionalChain([api, 'access', _32 => _32.components, 'optionalAccess', _33 => _33[cType]]) === "object" && !Array.isArray(api.components[cType])) {
|
|
778
|
-
Object.keys(_optionalChain([api, 'access', _34 => _34.components, 'optionalAccess', _35 => _35[cType]]) || {}).forEach((schemaName) => {
|
|
779
|
-
const componentSchema = cloneObject(_optionalChain([api, 'access', _36 => _36.components, 'optionalAccess', _37 => _37[cType], 'optionalAccess', _38 => _38[schemaName]]));
|
|
780
|
-
if (!components2[cType]) {
|
|
781
|
-
components2[cType] = {};
|
|
782
|
-
}
|
|
783
|
-
components2[cType][schemaName] = toJSONSchema(componentSchema, {
|
|
784
|
-
globalDefaults: _optionalChain([opts, 'optionalAccess', _39 => _39.globalDefaults]),
|
|
785
|
-
hideReadOnlyProperties: _optionalChain([opts, 'optionalAccess', _40 => _40.hideReadOnlyProperties]),
|
|
786
|
-
hideWriteOnlyProperties: _optionalChain([opts, 'optionalAccess', _41 => _41.hideWriteOnlyProperties]),
|
|
787
|
-
refLogger,
|
|
788
|
-
transformer: _optionalChain([opts, 'optionalAccess', _42 => _42.transformer])
|
|
789
|
-
});
|
|
790
|
-
});
|
|
791
|
-
}
|
|
792
|
-
});
|
|
793
|
-
Object.keys(components2).forEach((componentType) => {
|
|
794
|
-
const cType = componentType;
|
|
795
|
-
if (!Object.keys(_optionalChain([components2, 'optionalAccess', _43 => _43[cType]]) || {}).length) {
|
|
796
|
-
_optionalChainDelete([components2, 'optionalAccess', _44 => delete _44[cType]]);
|
|
797
|
-
}
|
|
798
|
-
});
|
|
799
|
-
return components2;
|
|
800
|
-
}
|
|
801
1069
|
function transformParameters() {
|
|
802
1070
|
const operationParams = operation.getParameters();
|
|
803
1071
|
const transformed = Object.keys(types).map((type) => {
|
|
@@ -817,20 +1085,11 @@ function getParametersAsJSONSchema(operation, api, opts) {
|
|
|
817
1085
|
}
|
|
818
1086
|
if (current.deprecated) currentSchema.deprecated = current.deprecated;
|
|
819
1087
|
const interimSchema = toJSONSchema(currentSchema, {
|
|
1088
|
+
...baseSchemaOptions,
|
|
820
1089
|
currentLocation: `/${current.name}`,
|
|
821
|
-
|
|
822
|
-
hideReadOnlyProperties: _optionalChain([opts, 'optionalAccess', _46 => _46.hideReadOnlyProperties]),
|
|
823
|
-
hideWriteOnlyProperties: _optionalChain([opts, 'optionalAccess', _47 => _47.hideWriteOnlyProperties]),
|
|
824
|
-
refLogger,
|
|
825
|
-
transformer: _optionalChain([opts, 'optionalAccess', _48 => _48.transformer])
|
|
1090
|
+
refLogger: (ref) => refLoggerForSchemaGroup(type).add(ref)
|
|
826
1091
|
});
|
|
827
|
-
schema2 = isPrimitive(interimSchema) ? interimSchema : {
|
|
828
|
-
...interimSchema,
|
|
829
|
-
// Note: this applies a `$schema` version to each field in the larger schema
|
|
830
|
-
// object. It's not really **correct** but it's what we have to do because
|
|
831
|
-
// there's a chance that the end user has indicated the schemas are different.
|
|
832
|
-
$schema: getSchemaVersionString(currentSchema, api)
|
|
833
|
-
};
|
|
1092
|
+
schema2 = isPrimitive(interimSchema) ? interimSchema : { ...interimSchema };
|
|
834
1093
|
} else if ("content" in current && typeof current.content === "object") {
|
|
835
1094
|
const contentKeys = Object.keys(current.content);
|
|
836
1095
|
if (contentKeys.length) {
|
|
@@ -844,20 +1103,11 @@ function getParametersAsJSONSchema(operation, api, opts) {
|
|
|
844
1103
|
}
|
|
845
1104
|
if (current.deprecated) currentSchema.deprecated = current.deprecated;
|
|
846
1105
|
const interimSchema = toJSONSchema(currentSchema, {
|
|
1106
|
+
...baseSchemaOptions,
|
|
847
1107
|
currentLocation: `/${current.name}`,
|
|
848
|
-
|
|
849
|
-
hideReadOnlyProperties: _optionalChain([opts, 'optionalAccess', _50 => _50.hideReadOnlyProperties]),
|
|
850
|
-
hideWriteOnlyProperties: _optionalChain([opts, 'optionalAccess', _51 => _51.hideWriteOnlyProperties]),
|
|
851
|
-
refLogger,
|
|
852
|
-
transformer: _optionalChain([opts, 'optionalAccess', _52 => _52.transformer])
|
|
1108
|
+
refLogger: (ref) => refLoggerForSchemaGroup(type).add(ref)
|
|
853
1109
|
});
|
|
854
|
-
schema2 = isPrimitive(interimSchema) ? interimSchema : {
|
|
855
|
-
...interimSchema,
|
|
856
|
-
// Note: this applies a `$schema` version to each field in the larger schema
|
|
857
|
-
// object. It's not really **correct** but it's what we have to do because
|
|
858
|
-
// there's a chance that the end user has indicated the schemas are different.
|
|
859
|
-
$schema: getSchemaVersionString(currentSchema, api)
|
|
860
|
-
};
|
|
1110
|
+
schema2 = isPrimitive(interimSchema) ? interimSchema : { ...interimSchema };
|
|
861
1111
|
}
|
|
862
1112
|
}
|
|
863
1113
|
}
|
|
@@ -873,36 +1123,29 @@ function getParametersAsJSONSchema(operation, api, opts) {
|
|
|
873
1123
|
return prev;
|
|
874
1124
|
}, {});
|
|
875
1125
|
const schema = {
|
|
1126
|
+
$schema: getSchemaVersionString({}, api),
|
|
876
1127
|
type: "object",
|
|
877
1128
|
properties,
|
|
878
|
-
required
|
|
1129
|
+
...required.length > 0 ? { required } : {}
|
|
879
1130
|
};
|
|
880
1131
|
return {
|
|
881
1132
|
type,
|
|
882
1133
|
label: types[type],
|
|
883
|
-
schema
|
|
884
|
-
deprecatedProps: _nullishCoalesce(getDeprecated(schema, type), () => ( void 0))
|
|
1134
|
+
schema
|
|
885
1135
|
};
|
|
886
1136
|
}).filter((item) => item !== null);
|
|
887
|
-
if (!_optionalChain([opts, 'optionalAccess',
|
|
1137
|
+
if (!_optionalChain([opts, 'optionalAccess', _36 => _36.mergeIntoBodyAndMetadata])) {
|
|
888
1138
|
return transformed;
|
|
889
1139
|
} else if (!transformed.length) {
|
|
890
1140
|
return [];
|
|
891
1141
|
}
|
|
892
|
-
const deprecatedProps = transformed.map((r) => _optionalChain([r, 'access', _54 => _54.deprecatedProps, 'optionalAccess', _55 => _55.schema]) || null).filter(Boolean);
|
|
893
1142
|
return [
|
|
894
1143
|
{
|
|
895
1144
|
type: "metadata",
|
|
896
1145
|
label: types.metadata,
|
|
897
1146
|
schema: {
|
|
898
1147
|
allOf: transformed.map((r) => r.schema)
|
|
899
|
-
}
|
|
900
|
-
deprecatedProps: deprecatedProps.length ? {
|
|
901
|
-
type: "metadata",
|
|
902
|
-
schema: {
|
|
903
|
-
allOf: deprecatedProps
|
|
904
|
-
}
|
|
905
|
-
} : void 0
|
|
1148
|
+
}
|
|
906
1149
|
}
|
|
907
1150
|
];
|
|
908
1151
|
}
|
|
@@ -913,19 +1156,47 @@ function getParametersAsJSONSchema(operation, api, opts) {
|
|
|
913
1156
|
typeKeys[typeKeys.indexOf("form")] = "formData";
|
|
914
1157
|
typeKeys.push("metadata");
|
|
915
1158
|
const jsonSchema = [transformRequestBody()].concat(...transformParameters()).filter((item) => item !== null);
|
|
916
|
-
|
|
917
|
-
|
|
1159
|
+
applyDiscriminatorOneOfToUsedSchemas(api, usedSchemas, (ref) => {
|
|
1160
|
+
if (usedSchemas.has(ref)) {
|
|
1161
|
+
return usedSchemas.get(ref);
|
|
1162
|
+
}
|
|
1163
|
+
try {
|
|
1164
|
+
const resolved = dereferenceRef({ $ref: ref }, api, seenRefs);
|
|
1165
|
+
if (_chunkYPR7YTHMcjs.isRef.call(void 0, resolved)) return void 0;
|
|
1166
|
+
const converted = toJSONSchema(structuredClone(resolved), {
|
|
1167
|
+
...baseSchemaOptions,
|
|
1168
|
+
seenRefs
|
|
1169
|
+
});
|
|
1170
|
+
usedSchemas.set(ref, converted);
|
|
1171
|
+
return converted;
|
|
1172
|
+
} catch (e10) {
|
|
1173
|
+
return void 0;
|
|
1174
|
+
}
|
|
1175
|
+
});
|
|
918
1176
|
return jsonSchema.map((group) => {
|
|
919
|
-
if (
|
|
920
|
-
group.
|
|
1177
|
+
if (group.schema && typeof group.schema === "object") {
|
|
1178
|
+
const refsInGroup = _nullishCoalesce(refsByGroup.get(group.type), () => ( /* @__PURE__ */ new Set()));
|
|
1179
|
+
const referencedSchemas = filterRequiredRefsToReferenced(refsInGroup, usedSchemas);
|
|
1180
|
+
if (referencedSchemas.size > 0) {
|
|
1181
|
+
mergeReferencedSchemasIntoRoot(group.schema, referencedSchemas);
|
|
1182
|
+
}
|
|
921
1183
|
}
|
|
922
|
-
if (!group.deprecatedProps) delete group.deprecatedProps;
|
|
923
1184
|
return group;
|
|
924
1185
|
}).sort((a, b) => {
|
|
925
1186
|
return typeKeys.indexOf(a.type) - typeKeys.indexOf(b.type);
|
|
926
1187
|
});
|
|
927
1188
|
}
|
|
928
1189
|
|
|
1190
|
+
// src/utils.ts
|
|
1191
|
+
var supportedMethods = ["get", "put", "post", "delete", "options", "head", "patch", "trace"];
|
|
1192
|
+
var SERVER_VARIABLE_REGEX = /{([-_a-zA-Z0-9:.[\]]+)}/g;
|
|
1193
|
+
|
|
1194
|
+
|
|
1195
|
+
|
|
1196
|
+
|
|
1197
|
+
|
|
1198
|
+
|
|
1199
|
+
|
|
929
1200
|
|
|
930
1201
|
|
|
931
1202
|
|
|
@@ -939,5 +1210,5 @@ function getParametersAsJSONSchema(operation, api, opts) {
|
|
|
939
1210
|
|
|
940
1211
|
|
|
941
1212
|
|
|
942
|
-
exports.
|
|
943
|
-
//# sourceMappingURL=chunk-
|
|
1213
|
+
exports.isObject = isObject; exports.isPrimitive = isPrimitive; exports.decorateComponentSchemasWithRefName = decorateComponentSchemasWithRefName; exports.decodePointer = decodePointer; exports.dereferenceRef = dereferenceRef; exports.getDereferencingOptions = getDereferencingOptions; exports.filterRequiredRefsToReferenced = filterRequiredRefsToReferenced; exports.mergeReferencedSchemasIntoRoot = mergeReferencedSchemasIntoRoot; exports.matches_mimetype_default = matches_mimetype_default; exports.getParameterContentType = getParameterContentType; exports.cloneObject = cloneObject; exports.applyDiscriminatorOneOfToUsedSchemas = applyDiscriminatorOneOfToUsedSchemas; exports.getSchemaVersionString = getSchemaVersionString; exports.toJSONSchema = toJSONSchema; exports.types = types; exports.getParametersAsJSONSchema = getParametersAsJSONSchema; exports.supportedMethods = supportedMethods; exports.SERVER_VARIABLE_REGEX = SERVER_VARIABLE_REGEX;
|
|
1214
|
+
//# sourceMappingURL=chunk-7RDMAMMI.cjs.map
|