oas 32.1.9 → 32.1.11

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.
Files changed (37) hide show
  1. package/dist/analyzer/index.cjs +6 -6
  2. package/dist/analyzer/index.js +4 -4
  3. package/dist/{chunk-WRZUJO3I.js → chunk-2J4VKLIT.js} +4 -4
  4. package/dist/{chunk-YPR7YTHM.cjs → chunk-3MTU2ESP.cjs} +1 -1
  5. package/dist/{chunk-YPR7YTHM.cjs.map → chunk-3MTU2ESP.cjs.map} +1 -1
  6. package/dist/{chunk-NG4A45EE.cjs → chunk-DNLCD3K6.cjs} +153 -141
  7. package/dist/chunk-DNLCD3K6.cjs.map +1 -0
  8. package/dist/{chunk-Q6ABRA4U.cjs → chunk-FGPV2UXT.cjs} +28 -28
  9. package/dist/{chunk-Q6ABRA4U.cjs.map → chunk-FGPV2UXT.cjs.map} +1 -1
  10. package/dist/{chunk-55H65L6J.js → chunk-JCBISKOK.js} +37 -25
  11. package/dist/chunk-JCBISKOK.js.map +1 -0
  12. package/dist/{chunk-MNOEMVCF.js → chunk-PSNTODZL.js} +1 -1
  13. package/dist/{chunk-MNOEMVCF.js.map → chunk-PSNTODZL.js.map} +1 -1
  14. package/dist/{chunk-7BR3G6FM.js → chunk-QINBUHP2.js} +179 -48
  15. package/dist/chunk-QINBUHP2.js.map +1 -0
  16. package/dist/{chunk-KZCEPS4J.cjs → chunk-X7KOY66H.cjs} +206 -75
  17. package/dist/chunk-X7KOY66H.cjs.map +1 -0
  18. package/dist/index.cjs +5 -5
  19. package/dist/index.js +4 -4
  20. package/dist/operation/index.cjs +4 -4
  21. package/dist/operation/index.js +3 -3
  22. package/dist/reducer/index.cjs +49 -28
  23. package/dist/reducer/index.cjs.map +1 -1
  24. package/dist/reducer/index.js +23 -2
  25. package/dist/reducer/index.js.map +1 -1
  26. package/dist/types.cjs +2 -2
  27. package/dist/types.d.cts +3 -0
  28. package/dist/types.d.ts +3 -0
  29. package/dist/types.js +1 -1
  30. package/dist/utils.cjs +3 -3
  31. package/dist/utils.js +2 -2
  32. package/package.json +2 -2
  33. package/dist/chunk-55H65L6J.js.map +0 -1
  34. package/dist/chunk-7BR3G6FM.js.map +0 -1
  35. package/dist/chunk-KZCEPS4J.cjs.map +0 -1
  36. package/dist/chunk-NG4A45EE.cjs.map +0 -1
  37. /package/dist/{chunk-WRZUJO3I.js.map → chunk-2J4VKLIT.js.map} +0 -0
@@ -6,7 +6,7 @@ import {
6
6
  isOpenAPI30,
7
7
  isRef,
8
8
  isSchema
9
- } from "./chunk-MNOEMVCF.js";
9
+ } from "./chunk-PSNTODZL.js";
10
10
 
11
11
  // src/lib/matches-mimetype.ts
12
12
  function matchesMediaType(types2, mediaType) {
@@ -141,6 +141,24 @@ function dereferenceRef(value, definition, seenRefs = /* @__PURE__ */ new Set())
141
141
  }
142
142
  return value;
143
143
  }
144
+ function dereferenceRefDeep(value, definition, seenRefs = /* @__PURE__ */ new Set()) {
145
+ if (value === null || value === void 0) return value;
146
+ if (typeof value !== "object") return value;
147
+ if (isRef(value)) {
148
+ if (!definition) return value;
149
+ const resolved = dereferenceRef(value, definition, seenRefs);
150
+ if (isRef(resolved)) return resolved;
151
+ return dereferenceRefDeep(resolved, definition, seenRefs);
152
+ }
153
+ if (Array.isArray(value)) {
154
+ return value.map((entry) => dereferenceRefDeep(entry, definition, seenRefs));
155
+ }
156
+ const out = {};
157
+ for (const key of Object.keys(value)) {
158
+ out[key] = dereferenceRefDeep(value[key], definition, seenRefs);
159
+ }
160
+ return out;
161
+ }
144
162
  function getDereferencingOptions(circularRefs) {
145
163
  return {
146
164
  resolve: {
@@ -209,6 +227,15 @@ function getRefPathSegments(ref) {
209
227
  }
210
228
  return path;
211
229
  }
230
+ function isArrayIndexSegment(seg) {
231
+ return /^\d+$/.test(seg);
232
+ }
233
+ function childShouldBeSchemaArray(parentKey, childSeg) {
234
+ if (!childSeg || !isArrayIndexSegment(childSeg)) {
235
+ return false;
236
+ }
237
+ return parentKey === "allOf" || parentKey === "anyOf" || parentKey === "oneOf";
238
+ }
212
239
  function mergeReferencedSchemasIntoRoot(root, refToSchema) {
213
240
  for (const [ref, schema] of refToSchema) {
214
241
  const segments = getRefPathSegments(ref);
@@ -216,16 +243,57 @@ function mergeReferencedSchemasIntoRoot(root, refToSchema) {
216
243
  continue;
217
244
  }
218
245
  let current = root;
246
+ let pathInvalid = false;
219
247
  for (let i = 0; i < segments.length - 1; i++) {
220
248
  const seg = segments[i];
221
- let next = current[seg];
222
- if (!next || typeof next !== "object" || Array.isArray(next)) {
249
+ const nextSeg = segments[i + 1];
250
+ if (Array.isArray(current)) {
251
+ const idx = Number(seg);
252
+ if (!Number.isInteger(idx) || idx < 0) {
253
+ pathInvalid = true;
254
+ break;
255
+ }
256
+ const slot = current[idx];
257
+ if (slot === void 0 || slot === null || typeof slot !== "object" || Array.isArray(slot)) {
258
+ const nextObj = {};
259
+ current[idx] = nextObj;
260
+ current = nextObj;
261
+ } else {
262
+ current = slot;
263
+ }
264
+ continue;
265
+ }
266
+ const cur = current;
267
+ const existing = cur[seg];
268
+ if (childShouldBeSchemaArray(seg, nextSeg)) {
269
+ if (!Array.isArray(existing)) {
270
+ cur[seg] = [];
271
+ }
272
+ current = cur[seg];
273
+ continue;
274
+ }
275
+ let next;
276
+ if (existing !== void 0 && existing !== null && typeof existing === "object" && !Array.isArray(existing)) {
277
+ next = existing;
278
+ } else {
223
279
  next = {};
224
- current[seg] = next;
280
+ cur[seg] = next;
225
281
  }
226
282
  current = next;
227
283
  }
228
- current[segments[segments.length - 1]] = schema;
284
+ if (pathInvalid) {
285
+ continue;
286
+ }
287
+ const lastSeg = segments[segments.length - 1];
288
+ if (Array.isArray(current)) {
289
+ const idx = Number(lastSeg);
290
+ if (!Number.isInteger(idx) || idx < 0) {
291
+ continue;
292
+ }
293
+ current[idx] = schema;
294
+ } else {
295
+ current[lastSeg] = schema;
296
+ }
229
297
  }
230
298
  }
231
299
 
@@ -350,6 +418,35 @@ var UNSUPPORTED_SCHEMA_PROPS = [
350
418
  "externalDocs",
351
419
  "xml"
352
420
  ];
421
+ var mergeAllOfSchemasOptions = {
422
+ ignoreAdditionalProperties: true,
423
+ resolvers: {
424
+ // `merge-json-schema-allof` by default takes the first `description` when you're merging an
425
+ // `allOf` but because generally when you're merging two schemas together with an `allOf` you
426
+ // want data in the subsequent schemas to be applied to the first and `description` should be a
427
+ // part of that.
428
+ description: (obj) => {
429
+ return obj.slice(-1)[0];
430
+ },
431
+ // `merge-json-schema-allof` doesn't support merging enum arrays but since that's a safe and
432
+ // simple operation as enums always contain primitives we can handle it ourselves with a custom
433
+ // resolver. We intersect the arrays so that child schemas can narrow a parent's broad enum
434
+ // (e.g. [1,2,20,50] ∩ [1] = [1]).
435
+ //
436
+ // We unfortunately need to cast our return value as `any[]` because the internal types of
437
+ // `merge-json-schema-allof`'s `enum` resolver are not portable.
438
+ enum: (obj) => {
439
+ const arrays = obj;
440
+ const intersection = arrays.reduce((acc, e) => acc.filter((v) => e.includes(v)));
441
+ return intersection.length > 0 ? intersection : arrays.reduce((acc, e) => acc.concat(e), []);
442
+ },
443
+ // For any unknown keywords (e.g., `example`, `format`, `x-readme-ref-name`), we fallback to
444
+ // using the `title` resolver (which uses the first value found).
445
+ // https://github.com/mokkabonna/json-schema-merge-allof/blob/ea2e48ee34415022de5a50c236eb4793a943ad11/src/index.js#L292
446
+ // https://github.com/mokkabonna/json-schema-merge-allof/blob/ea2e48ee34415022de5a50c236eb4793a943ad11/README.md?plain=1#L147
447
+ defaultResolver: mergeJSONSchemaAllOf.options.resolvers.title
448
+ }
449
+ };
353
450
  var PENDING_SCHEMA = { __pending: true };
354
451
  function isPendingSchema(s) {
355
452
  return isObject(s) && "__pending" in s && s.__pending === true;
@@ -369,6 +466,14 @@ function getSchemaVersionString(schema, api) {
369
466
  function isPolymorphicSchema(schema) {
370
467
  return "allOf" in schema || "anyOf" in schema || "oneOf" in schema;
371
468
  }
469
+ function shouldFoldParentItemsIntoPolymorphBranch(item) {
470
+ if (!isObject(item)) return false;
471
+ if (isRef(item)) return true;
472
+ const branch = item;
473
+ if (!("type" in branch) || branch.type === void 0) return true;
474
+ if (!hasSchemaType(branch, "array")) return false;
475
+ return !("items" in branch) || branch.items === void 0;
476
+ }
372
477
  function isEmptyPolymorphicSchema(list) {
373
478
  if (!Array.isArray(list)) return false;
374
479
  if (!list.length) return true;
@@ -378,7 +483,7 @@ function isEmptyPolymorphicSchema(list) {
378
483
  return Array.isArray(branch) ? !branch.length : !Object.keys(branch).length;
379
484
  });
380
485
  }
381
- function inlinePropertyRefsForMerge(schema, usedSchemas) {
486
+ function inlinePropertyRefsForMerge(schema, usedSchemas, refLogger) {
382
487
  const out = structuredClone(schema);
383
488
  if (!("properties" in out) || typeof out.properties !== "object" || out.properties === null) {
384
489
  return out;
@@ -386,6 +491,10 @@ function inlinePropertyRefsForMerge(schema, usedSchemas) {
386
491
  for (const key of Object.keys(out.properties)) {
387
492
  const val = out.properties[key];
388
493
  if (isRef(val)) {
494
+ if (val.$ref.startsWith("#/paths/")) {
495
+ refLogger(val.$ref, "ref");
496
+ continue;
497
+ }
389
498
  const resolved = usedSchemas.get(val.$ref);
390
499
  if (resolved !== void 0 && !isPendingSchema(resolved)) {
391
500
  out.properties[key] = {
@@ -590,7 +699,7 @@ function toJSONSchema(data, opts) {
590
699
  returnMode: "ref",
591
700
  refLogger
592
701
  });
593
- const { $ref: _$ref, ...siblings } = schema;
702
+ const { $ref: _$ref, properties: _propertiesWithRef, ...siblings } = schema;
594
703
  if (Object.keys(siblings).length > 0) {
595
704
  return { ...resolved, ...siblings };
596
705
  }
@@ -601,14 +710,43 @@ function toJSONSchema(data, opts) {
601
710
  }
602
711
  if (isSchema(schema, isPolymorphicAllOfChild)) {
603
712
  if ("allOf" in schema && Array.isArray(schema.allOf)) {
713
+ if ("properties" in schema && schema.properties !== void 0 && typeof schema.properties === "object" && schema.properties !== null && !Array.isArray(schema.properties)) {
714
+ const preprocessed = {};
715
+ for (const prop of Object.keys(schema.properties)) {
716
+ const val = schema.properties[prop];
717
+ if (Array.isArray(val) || typeof val === "object" && val !== null) {
718
+ preprocessed[prop] = toJSONSchema(val, {
719
+ ...polyOptions,
720
+ currentLocation: `${currentLocation}/${encodePointer(prop)}`,
721
+ prevDefaultSchemas,
722
+ prevExampleSchemas
723
+ });
724
+ } else {
725
+ preprocessed[prop] = val;
726
+ }
727
+ }
728
+ schema = { ...schema, properties: preprocessed };
729
+ }
604
730
  let allOfSchemas = schema.allOf;
605
731
  if (definition && usedSchemas) {
606
- const allOfOptions = schema.allOf.length > 1 ? { ...polyOptions, refLogger: () => {
732
+ const allOfOptions = allOfSchemas.length > 1 ? { ...polyOptions, refLogger: () => {
607
733
  } } : polyOptions;
608
- allOfSchemas = schema.allOf.map((item) => {
734
+ allOfSchemas = allOfSchemas.map((item) => {
609
735
  if (isRef(item)) {
610
- return resolveAndCacheRefSchema({
611
- schema: item,
736
+ if (Object.keys(item).length === 1) {
737
+ return resolveAndCacheRefSchema({
738
+ schema: item,
739
+ definition,
740
+ usedSchemas,
741
+ seenRefs,
742
+ conversionOptions: allOfOptions,
743
+ returnMode: "converted",
744
+ refLogger
745
+ });
746
+ }
747
+ const { $ref, ...siblings } = item;
748
+ const resolved = resolveAndCacheRefSchema({
749
+ schema: { $ref },
612
750
  definition,
613
751
  usedSchemas,
614
752
  seenRefs,
@@ -616,44 +754,28 @@ function toJSONSchema(data, opts) {
616
754
  returnMode: "converted",
617
755
  refLogger
618
756
  });
757
+ if (!Object.keys(siblings).length) {
758
+ return resolved;
759
+ }
760
+ const siblingSchema = toJSONSchema(siblings, allOfOptions);
761
+ try {
762
+ return mergeJSONSchemaAllOf(
763
+ { allOf: [resolved, siblingSchema] },
764
+ mergeAllOfSchemasOptions
765
+ );
766
+ } catch {
767
+ return resolved;
768
+ }
619
769
  }
620
770
  return toJSONSchema(item, allOfOptions);
621
771
  });
622
772
  schema = {
623
773
  ...schema,
624
- allOf: allOfSchemas.map((s) => inlinePropertyRefsForMerge(s, usedSchemas))
774
+ allOf: allOfSchemas.map((s) => inlinePropertyRefsForMerge(s, usedSchemas, refLogger))
625
775
  };
626
776
  }
627
777
  try {
628
- schema = mergeJSONSchemaAllOf(schema, {
629
- ignoreAdditionalProperties: true,
630
- resolvers: {
631
- // `merge-json-schema-allof` by default takes the first `description` when you're
632
- // merging an `allOf` but because generally when you're merging two schemas together
633
- // with an `allOf` you want data in the subsequent schemas to be applied to the first
634
- // and `description` should be a part of that.
635
- description: (obj) => {
636
- return obj.slice(-1)[0];
637
- },
638
- // `merge-json-schema-allof` doesn't support merging enum arrays but since that's a
639
- // safe and simple operation as enums always contain primitives we can handle it
640
- // ourselves with a custom resolver. We intersect the arrays so that child schemas
641
- // can narrow a parent's broad enum (e.g. [1,2,20,50] ∩ [1] = [1]).
642
- //
643
- // We unfortunately need to cast our return value as `any[]` because the internal types
644
- // of `merge-json-schema-allof`'s `enum` resolver are not portable.
645
- enum: (obj) => {
646
- const arrays = obj;
647
- const intersection = arrays.reduce((acc, e) => acc.filter((v) => e.includes(v)));
648
- return intersection.length > 0 ? intersection : arrays.reduce((acc, e) => acc.concat(e), []);
649
- },
650
- // for any unknown keywords (e.g., `example`, `format`, `x-readme-ref-name`),
651
- // we fallback to using the title resolver (which uses the first value found).
652
- // https://github.com/mokkabonna/json-schema-merge-allof/blob/ea2e48ee34415022de5a50c236eb4793a943ad11/src/index.js#L292
653
- // https://github.com/mokkabonna/json-schema-merge-allof/blob/ea2e48ee34415022de5a50c236eb4793a943ad11/README.md?plain=1#L147
654
- defaultResolver: mergeJSONSchemaAllOf.options.resolvers.title
655
- }
656
- });
778
+ schema = mergeJSONSchemaAllOf(schema, mergeAllOfSchemasOptions);
657
779
  } catch {
658
780
  const { ...schemaWithoutAllOf } = schema;
659
781
  schema = schemaWithoutAllOf;
@@ -687,12 +809,16 @@ function toJSONSchema(data, opts) {
687
809
  itemOptions
688
810
  );
689
811
  } else if ("items" in schema) {
690
- schema[polyType][idx] = toJSONSchema(
691
- {
692
- allOf: [item, { items: schema.items }]
693
- },
694
- itemOptions
695
- );
812
+ if (shouldFoldParentItemsIntoPolymorphBranch(item)) {
813
+ schema[polyType][idx] = toJSONSchema(
814
+ {
815
+ allOf: [item, { items: schema.items }]
816
+ },
817
+ itemOptions
818
+ );
819
+ } else {
820
+ schema[polyType][idx] = toJSONSchema(item, itemOptions);
821
+ }
696
822
  } else {
697
823
  schema[polyType][idx] = toJSONSchema(item, itemOptions);
698
824
  }
@@ -1037,6 +1163,9 @@ ${enums}`;
1037
1163
  }
1038
1164
  if ("items" in schema) {
1039
1165
  delete schema.items;
1166
+ if ("type" in schema && schema.type === "array") {
1167
+ delete schema.type;
1168
+ }
1040
1169
  }
1041
1170
  }
1042
1171
  }
@@ -1268,7 +1397,9 @@ export {
1268
1397
  decorateComponentSchemasWithRefName,
1269
1398
  decodePointer,
1270
1399
  dereferenceRef,
1400
+ dereferenceRefDeep,
1271
1401
  getDereferencingOptions,
1402
+ collectRefsInSchema,
1272
1403
  filterRequiredRefsToReferenced,
1273
1404
  mergeReferencedSchemasIntoRoot,
1274
1405
  matches_mimetype_default,
@@ -1282,4 +1413,4 @@ export {
1282
1413
  supportedMethods,
1283
1414
  SERVER_VARIABLE_REGEX
1284
1415
  };
1285
- //# sourceMappingURL=chunk-7BR3G6FM.js.map
1416
+ //# sourceMappingURL=chunk-QINBUHP2.js.map