@skmtc/core 0.32.1 → 0.32.3

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 (131) hide show
  1. package/esm/parse/v3-0/operation/toOperationsV3.js +1 -2
  2. package/esm/parse/v3-0/server/toServerV3.js +16 -2
  3. package/esm/parse/v3-0/webhook/toWebhooksV3.js +1 -2
  4. package/esm/parse/v3-1/_merge-all-of/check-array-item-type-conflicts.d.ts +2 -1
  5. package/esm/parse/v3-1/_merge-all-of/check-array-item-type-conflicts.js +7 -3
  6. package/esm/parse/v3-1/_merge-all-of/generic-merge.d.ts +2 -2
  7. package/esm/parse/v3-1/_merge-all-of/generic-merge.js +2 -2
  8. package/esm/parse/v3-1/_merge-all-of/merge-array-constraints.d.ts +2 -2
  9. package/esm/parse/v3-1/_merge-all-of/merge-array-constraints.js +8 -12
  10. package/esm/parse/v3-1/_merge-all-of/merge-boolean-constraints.d.ts +2 -2
  11. package/esm/parse/v3-1/_merge-all-of/merge-boolean-constraints.js +2 -2
  12. package/esm/parse/v3-1/_merge-all-of/merge-integer-constraints.d.ts +2 -2
  13. package/esm/parse/v3-1/_merge-all-of/merge-integer-constraints.js +2 -2
  14. package/esm/parse/v3-1/_merge-all-of/merge-intersection.d.ts +3 -2
  15. package/esm/parse/v3-1/_merge-all-of/merge-intersection.js +2 -2
  16. package/esm/parse/v3-1/_merge-all-of/merge-number-constraints.d.ts +2 -2
  17. package/esm/parse/v3-1/_merge-all-of/merge-number-constraints.js +2 -2
  18. package/esm/parse/v3-1/_merge-all-of/merge-object-constraints.d.ts +2 -2
  19. package/esm/parse/v3-1/_merge-all-of/merge-object-constraints.js +3 -3
  20. package/esm/parse/v3-1/_merge-all-of/merge-properties.d.ts +2 -2
  21. package/esm/parse/v3-1/_merge-all-of/merge-properties.js +2 -2
  22. package/esm/parse/v3-1/_merge-all-of/merge-string-constraints.d.ts +2 -2
  23. package/esm/parse/v3-1/_merge-all-of/merge-string-constraints.js +3 -3
  24. package/esm/parse/v3-1/_merge-all-of/merge-union.d.ts +5 -3
  25. package/esm/parse/v3-1/_merge-all-of/merge-union.js +31 -7
  26. package/esm/parse/v3-1/_merge-all-of/merge.d.ts +2 -2
  27. package/esm/parse/v3-1/_merge-all-of/merge.js +28 -23
  28. package/esm/parse/v3-1/_merge-all-of/types.d.ts +6 -0
  29. package/esm/parse/v3-1/operation/toOperationsV3.js +1 -2
  30. package/esm/parse/v3-1/schema/normalize-schema-shape.d.ts +24 -0
  31. package/esm/parse/v3-1/schema/normalize-schema-shape.js +213 -0
  32. package/esm/parse/v3-1/schema/toSchemasV3.js +7 -195
  33. package/esm/parse/v3-1/server/toServerV3.js +16 -2
  34. package/esm/parse/v3-1/webhook/toWebhooksV3.js +1 -2
  35. package/esm/parse/v3-2/_merge-all-of/check-array-item-type-conflicts.d.ts +2 -1
  36. package/esm/parse/v3-2/_merge-all-of/check-array-item-type-conflicts.js +7 -3
  37. package/esm/parse/v3-2/_merge-all-of/generic-merge.d.ts +2 -2
  38. package/esm/parse/v3-2/_merge-all-of/generic-merge.js +2 -2
  39. package/esm/parse/v3-2/_merge-all-of/merge-array-constraints.d.ts +2 -2
  40. package/esm/parse/v3-2/_merge-all-of/merge-array-constraints.js +8 -12
  41. package/esm/parse/v3-2/_merge-all-of/merge-boolean-constraints.d.ts +2 -2
  42. package/esm/parse/v3-2/_merge-all-of/merge-boolean-constraints.js +2 -2
  43. package/esm/parse/v3-2/_merge-all-of/merge-integer-constraints.d.ts +2 -2
  44. package/esm/parse/v3-2/_merge-all-of/merge-integer-constraints.js +2 -2
  45. package/esm/parse/v3-2/_merge-all-of/merge-intersection.d.ts +3 -2
  46. package/esm/parse/v3-2/_merge-all-of/merge-intersection.js +2 -2
  47. package/esm/parse/v3-2/_merge-all-of/merge-number-constraints.d.ts +2 -2
  48. package/esm/parse/v3-2/_merge-all-of/merge-number-constraints.js +2 -2
  49. package/esm/parse/v3-2/_merge-all-of/merge-object-constraints.d.ts +2 -2
  50. package/esm/parse/v3-2/_merge-all-of/merge-object-constraints.js +3 -3
  51. package/esm/parse/v3-2/_merge-all-of/merge-properties.d.ts +2 -2
  52. package/esm/parse/v3-2/_merge-all-of/merge-properties.js +2 -2
  53. package/esm/parse/v3-2/_merge-all-of/merge-string-constraints.d.ts +2 -2
  54. package/esm/parse/v3-2/_merge-all-of/merge-string-constraints.js +3 -3
  55. package/esm/parse/v3-2/_merge-all-of/merge-union.d.ts +5 -3
  56. package/esm/parse/v3-2/_merge-all-of/merge-union.js +31 -7
  57. package/esm/parse/v3-2/_merge-all-of/merge.d.ts +2 -2
  58. package/esm/parse/v3-2/_merge-all-of/merge.js +28 -23
  59. package/esm/parse/v3-2/_merge-all-of/types.d.ts +6 -0
  60. package/esm/parse/v3-2/operation/toOperationsV3.js +1 -2
  61. package/esm/parse/v3-2/schema/normalize-schema-shape.d.ts +24 -0
  62. package/esm/parse/v3-2/schema/normalize-schema-shape.js +213 -0
  63. package/esm/parse/v3-2/schema/toSchemasV3.js +7 -195
  64. package/esm/parse/v3-2/server/toServerV3.js +16 -2
  65. package/esm/parse/v3-2/webhook/toWebhooksV3.js +1 -2
  66. package/package.json +1 -1
  67. package/script/parse/v3-0/operation/toOperationsV3.js +1 -2
  68. package/script/parse/v3-0/server/toServerV3.js +16 -2
  69. package/script/parse/v3-0/webhook/toWebhooksV3.js +1 -2
  70. package/script/parse/v3-1/_merge-all-of/check-array-item-type-conflicts.d.ts +2 -1
  71. package/script/parse/v3-1/_merge-all-of/check-array-item-type-conflicts.js +7 -3
  72. package/script/parse/v3-1/_merge-all-of/generic-merge.d.ts +2 -2
  73. package/script/parse/v3-1/_merge-all-of/generic-merge.js +2 -2
  74. package/script/parse/v3-1/_merge-all-of/merge-array-constraints.d.ts +2 -2
  75. package/script/parse/v3-1/_merge-all-of/merge-array-constraints.js +8 -12
  76. package/script/parse/v3-1/_merge-all-of/merge-boolean-constraints.d.ts +2 -2
  77. package/script/parse/v3-1/_merge-all-of/merge-boolean-constraints.js +2 -2
  78. package/script/parse/v3-1/_merge-all-of/merge-integer-constraints.d.ts +2 -2
  79. package/script/parse/v3-1/_merge-all-of/merge-integer-constraints.js +2 -2
  80. package/script/parse/v3-1/_merge-all-of/merge-intersection.d.ts +3 -2
  81. package/script/parse/v3-1/_merge-all-of/merge-intersection.js +2 -2
  82. package/script/parse/v3-1/_merge-all-of/merge-number-constraints.d.ts +2 -2
  83. package/script/parse/v3-1/_merge-all-of/merge-number-constraints.js +2 -2
  84. package/script/parse/v3-1/_merge-all-of/merge-object-constraints.d.ts +2 -2
  85. package/script/parse/v3-1/_merge-all-of/merge-object-constraints.js +3 -3
  86. package/script/parse/v3-1/_merge-all-of/merge-properties.d.ts +2 -2
  87. package/script/parse/v3-1/_merge-all-of/merge-properties.js +2 -2
  88. package/script/parse/v3-1/_merge-all-of/merge-string-constraints.d.ts +2 -2
  89. package/script/parse/v3-1/_merge-all-of/merge-string-constraints.js +3 -3
  90. package/script/parse/v3-1/_merge-all-of/merge-union.d.ts +5 -3
  91. package/script/parse/v3-1/_merge-all-of/merge-union.js +31 -7
  92. package/script/parse/v3-1/_merge-all-of/merge.d.ts +2 -2
  93. package/script/parse/v3-1/_merge-all-of/merge.js +28 -23
  94. package/script/parse/v3-1/_merge-all-of/types.d.ts +6 -0
  95. package/script/parse/v3-1/operation/toOperationsV3.js +1 -2
  96. package/script/parse/v3-1/schema/normalize-schema-shape.d.ts +24 -0
  97. package/script/parse/v3-1/schema/normalize-schema-shape.js +219 -0
  98. package/script/parse/v3-1/schema/toSchemasV3.js +8 -196
  99. package/script/parse/v3-1/server/toServerV3.js +16 -2
  100. package/script/parse/v3-1/webhook/toWebhooksV3.js +1 -2
  101. package/script/parse/v3-2/_merge-all-of/check-array-item-type-conflicts.d.ts +2 -1
  102. package/script/parse/v3-2/_merge-all-of/check-array-item-type-conflicts.js +7 -3
  103. package/script/parse/v3-2/_merge-all-of/generic-merge.d.ts +2 -2
  104. package/script/parse/v3-2/_merge-all-of/generic-merge.js +2 -2
  105. package/script/parse/v3-2/_merge-all-of/merge-array-constraints.d.ts +2 -2
  106. package/script/parse/v3-2/_merge-all-of/merge-array-constraints.js +8 -12
  107. package/script/parse/v3-2/_merge-all-of/merge-boolean-constraints.d.ts +2 -2
  108. package/script/parse/v3-2/_merge-all-of/merge-boolean-constraints.js +2 -2
  109. package/script/parse/v3-2/_merge-all-of/merge-integer-constraints.d.ts +2 -2
  110. package/script/parse/v3-2/_merge-all-of/merge-integer-constraints.js +2 -2
  111. package/script/parse/v3-2/_merge-all-of/merge-intersection.d.ts +3 -2
  112. package/script/parse/v3-2/_merge-all-of/merge-intersection.js +2 -2
  113. package/script/parse/v3-2/_merge-all-of/merge-number-constraints.d.ts +2 -2
  114. package/script/parse/v3-2/_merge-all-of/merge-number-constraints.js +2 -2
  115. package/script/parse/v3-2/_merge-all-of/merge-object-constraints.d.ts +2 -2
  116. package/script/parse/v3-2/_merge-all-of/merge-object-constraints.js +3 -3
  117. package/script/parse/v3-2/_merge-all-of/merge-properties.d.ts +2 -2
  118. package/script/parse/v3-2/_merge-all-of/merge-properties.js +2 -2
  119. package/script/parse/v3-2/_merge-all-of/merge-string-constraints.d.ts +2 -2
  120. package/script/parse/v3-2/_merge-all-of/merge-string-constraints.js +3 -3
  121. package/script/parse/v3-2/_merge-all-of/merge-union.d.ts +5 -3
  122. package/script/parse/v3-2/_merge-all-of/merge-union.js +31 -7
  123. package/script/parse/v3-2/_merge-all-of/merge.d.ts +2 -2
  124. package/script/parse/v3-2/_merge-all-of/merge.js +28 -23
  125. package/script/parse/v3-2/_merge-all-of/types.d.ts +6 -0
  126. package/script/parse/v3-2/operation/toOperationsV3.js +1 -2
  127. package/script/parse/v3-2/schema/normalize-schema-shape.d.ts +24 -0
  128. package/script/parse/v3-2/schema/normalize-schema-shape.js +219 -0
  129. package/script/parse/v3-2/schema/toSchemasV3.js +8 -196
  130. package/script/parse/v3-2/server/toServerV3.js +16 -2
  131. package/script/parse/v3-2/webhook/toWebhooksV3.js +1 -2
@@ -5,7 +5,7 @@ const decompose_union_js_1 = require("./decompose-union.js");
5
5
  const merge_js_1 = require("./merge.js");
6
6
  const cross_product_js_1 = require("./cross-product.js");
7
7
  const refFns_js_1 = require("../../../helpers/refFns.js");
8
- const mergeUnion = ({ schema, getRef, groupType }) => {
8
+ const mergeUnion = ({ schema, getRef, normalize, groupType }) => {
9
9
  const { beforeExcluded, decomposed, afterExcluded } = (0, decompose_union_js_1.decomposeUnion)({ schema, groupType });
10
10
  // if (decomposed.length === 1) {
11
11
  // console.log('DECOMPOSED', JSON.stringify(decomposed[0], null, 2))
@@ -21,7 +21,13 @@ const mergeUnion = ({ schema, getRef, groupType }) => {
21
21
  return '$ref' in decomposed ? getRef(decomposed) : decomposed;
22
22
  });
23
23
  const result = dereffed.reduce((acc, decomposed) => {
24
- const merged = (0, exports.mergeCrossProduct)({ first: acc, second: decomposed, getRef, groupType });
24
+ const merged = (0, exports.mergeCrossProduct)({
25
+ first: acc,
26
+ second: decomposed,
27
+ getRef,
28
+ normalize,
29
+ groupType
30
+ });
25
31
  return merged;
26
32
  }, {});
27
33
  const output = {
@@ -32,13 +38,21 @@ const mergeUnion = ({ schema, getRef, groupType }) => {
32
38
  return output;
33
39
  };
34
40
  exports.mergeUnion = mergeUnion;
35
- const mergeCrossProduct = ({ first, second, getRef, groupType }) => {
36
- const firstGroup = Array.isArray(first[groupType]) ? first[groupType] : [first];
37
- const secondGroup = Array.isArray(second[groupType]) ? second[groupType] : [second];
41
+ const mergeCrossProduct = ({ first, second, getRef, normalize, groupType }) => {
42
+ const firstMembers = Array.isArray(first[groupType]) ? first[groupType] : [first];
43
+ const secondMembers = Array.isArray(second[groupType]) ? second[groupType] : [second];
44
+ // A member that normalizes to exactly `{ nullable: true }` is a null-only
45
+ // member: it makes the union nullable instead of joining the cross product.
46
+ const firstGroup = firstMembers.filter(member => !isNullableOnly(member, normalize));
47
+ const secondGroup = secondMembers.filter(member => !isNullableOnly(member, normalize));
48
+ const nullable = isNullableGroup(first, groupType) ||
49
+ isNullableGroup(second, groupType) ||
50
+ firstGroup.length !== firstMembers.length ||
51
+ secondGroup.length !== secondMembers.length;
38
52
  const mergedGroup = (0, cross_product_js_1.crossProduct)(firstGroup, secondGroup)
39
53
  .map(([firstItem, secondItem]) => {
40
54
  try {
41
- const result = (0, merge_js_1.mergeSchemasOrRefs)(firstItem, secondItem, getRef);
55
+ const result = (0, merge_js_1.mergeSchemasOrRefs)(firstItem, secondItem, getRef, normalize);
42
56
  return result;
43
57
  }
44
58
  catch (_error) {
@@ -52,7 +66,17 @@ const mergeCrossProduct = ({ first, second, getRef, groupType }) => {
52
66
  return item[groupType];
53
67
  }
54
68
  return [item];
55
- })
69
+ }),
70
+ ...(nullable ? { nullable: true } : {})
56
71
  };
57
72
  };
58
73
  exports.mergeCrossProduct = mergeCrossProduct;
74
+ const isNullableOnly = (member, normalize) => {
75
+ if ((0, refFns_js_1.isRef)(member)) {
76
+ return false;
77
+ }
78
+ const normalized = normalize(member);
79
+ return normalized.nullable === true && Object.keys(normalized).length === 1;
80
+ };
81
+ /** Is this a `oneOf`/`anyOf` group wrapper that already carries `nullable`? */
82
+ const isNullableGroup = (schema, groupType) => Array.isArray(schema[groupType]) && schema.nullable === true;
@@ -1,2 +1,2 @@
1
- import type { SchemaOrReference, GetRefFn } from './types.js';
2
- export declare const mergeSchemasOrRefs: (first: SchemaOrReference, second: SchemaOrReference, getRef: GetRefFn) => SchemaOrReference;
1
+ import type { SchemaOrReference, GetRefFn, NormalizeFn } from './types.js';
2
+ export declare const mergeSchemasOrRefs: (inputFirst: SchemaOrReference, inputSecond: SchemaOrReference, getRef: GetRefFn, normalize: NormalizeFn) => SchemaOrReference;
@@ -20,9 +20,11 @@ const merge_intersection_js_1 = require("./merge-intersection.js");
20
20
  const merge_union_js_1 = require("./merge-union.js");
21
21
  const isEmpty_js_1 = require("../../../helpers/isEmpty.js");
22
22
  const nullable_merge_js_1 = require("./nullable-merge.js");
23
- const mergeSchemasOrRefs = (first, second, getRef) => {
23
+ const mergeSchemasOrRefs = (inputFirst, inputSecond, getRef, normalize) => {
24
+ const first = (0, refFns_js_1.isRef)(inputFirst) ? inputFirst : normalize(inputFirst);
25
+ const second = (0, refFns_js_1.isRef)(inputSecond) ? inputSecond : normalize(inputSecond);
24
26
  if (containsRef(first, second)) {
25
- return mergeWithRef(first, second, getRef);
27
+ return mergeWithRef(first, second, getRef, normalize);
26
28
  }
27
29
  if ((0, refFns_js_1.isRef)(first)) {
28
30
  throw new Error('Ref in first');
@@ -31,17 +33,19 @@ const mergeSchemasOrRefs = (first, second, getRef) => {
31
33
  throw new Error('Ref in second');
32
34
  }
33
35
  if (containsAllOf(first) || containsAllOf(second)) {
34
- const mergedFirst = containsAllOf(first) ? (0, merge_intersection_js_1.mergeIntersection)({ schema: first, getRef }) : first;
36
+ const mergedFirst = containsAllOf(first)
37
+ ? (0, merge_intersection_js_1.mergeIntersection)({ schema: first, getRef, normalize })
38
+ : first;
35
39
  const mergedSecond = containsAllOf(second)
36
- ? (0, merge_intersection_js_1.mergeIntersection)({ schema: second, getRef })
40
+ ? (0, merge_intersection_js_1.mergeIntersection)({ schema: second, getRef, normalize })
37
41
  : second;
38
- return (0, exports.mergeSchemasOrRefs)(mergedFirst, mergedSecond, getRef);
42
+ return (0, exports.mergeSchemasOrRefs)(mergedFirst, mergedSecond, getRef, normalize);
39
43
  }
40
44
  if (containsOneOf(first, second)) {
41
- return (0, merge_union_js_1.mergeCrossProduct)({ first, second, getRef, groupType: 'oneOf' });
45
+ return (0, merge_union_js_1.mergeCrossProduct)({ first, second, getRef, normalize, groupType: 'oneOf' });
42
46
  }
43
47
  if (containsAnyOf(first, second)) {
44
- return (0, merge_union_js_1.mergeCrossProduct)({ first, second, getRef, groupType: 'anyOf' });
48
+ return (0, merge_union_js_1.mergeCrossProduct)({ first, second, getRef, normalize, groupType: 'anyOf' });
45
49
  }
46
50
  if ((0, nullable_merge_js_1.isNullOnly)(first)) {
47
51
  return (0, nullable_merge_js_1.mergeNullOnly)(second);
@@ -49,7 +53,7 @@ const mergeSchemasOrRefs = (first, second, getRef) => {
49
53
  if ((0, nullable_merge_js_1.isNullOnly)(second)) {
50
54
  return (0, nullable_merge_js_1.mergeNullOnly)(first);
51
55
  }
52
- return mergeSchemas(first, second, getRef);
56
+ return mergeSchemas(first, second, getRef, normalize);
53
57
  };
54
58
  exports.mergeSchemasOrRefs = mergeSchemasOrRefs;
55
59
  const containsAllOf = (schema) => {
@@ -94,7 +98,7 @@ const containsOneOf = (first, second) => {
94
98
  const containsRef = (first, second) => {
95
99
  return (0, refFns_js_1.isRef)(first) || (0, refFns_js_1.isRef)(second);
96
100
  };
97
- const mergeSchemas = (first, second, getRef) => {
101
+ const mergeSchemas = (first, second, getRef, normalize) => {
98
102
  try {
99
103
  (0, check_type_conflicts_js_1.checkTypeConflicts)(first, second);
100
104
  }
@@ -105,37 +109,38 @@ const mergeSchemas = (first, second, getRef) => {
105
109
  (0, check_format_conflicts_js_1.checkFormatConflicts)(first, second);
106
110
  (0, check_enum_conflicts_js_1.checkEnumConflicts)(first, second);
107
111
  (0, check_number_constraints_conflicts_js_1.checkNumberConstraintsConflicts)(first, second);
108
- (0, check_array_item_type_conflicts_js_1.checkArrayItemTypeConflicts)(first, second);
112
+ (0, check_array_item_type_conflicts_js_1.checkArrayItemTypeConflicts)(first, second, normalize);
109
113
  if (first.not || second.not) {
110
114
  throw new Error('Merging schemas with "not" keyword is not supported');
111
115
  }
112
- return typedMerge(first, second, getRef);
116
+ return typedMerge(first, second, getRef, normalize);
113
117
  };
114
- const typedMerge = (first, second, getRef) => {
118
+ const typedMerge = (first, second, getRef, normalize) => {
115
119
  if (!first.type && !second.type) {
116
- return (0, generic_merge_js_1.genericMerge)(first, second, getRef);
120
+ return (0, generic_merge_js_1.genericMerge)(first, second, getRef, normalize);
117
121
  }
118
122
  if ((0, check_at_least_one_type_match_js_1.checkAtLeastOneTypeMatch)(first, second, 'object')) {
119
- return (0, merge_object_constraints_js_1.mergeObjectConstraints)(first, second, getRef);
123
+ return (0, merge_object_constraints_js_1.mergeObjectConstraints)(first, second, getRef, normalize);
120
124
  }
121
125
  if ((0, check_at_least_one_type_match_js_1.checkAtLeastOneTypeMatch)(first, second, 'array')) {
122
- return (0, merge_array_constraints_js_1.mergeArrayConstraints)(first, second, getRef);
126
+ return (0, merge_array_constraints_js_1.mergeArrayConstraints)(first, second, getRef, normalize);
123
127
  }
124
128
  if ((0, check_at_least_one_type_match_js_1.checkAtLeastOneTypeMatch)(first, second, 'string')) {
125
- return (0, merge_string_constraints_js_1.mergeStringConstraints)(first, second, getRef);
129
+ return (0, merge_string_constraints_js_1.mergeStringConstraints)(first, second, getRef, normalize);
126
130
  }
127
131
  if ((0, check_at_least_one_type_match_js_1.checkAtLeastOneTypeMatch)(first, second, 'number')) {
128
- return (0, merge_number_constraints_js_1.mergeNumberConstraints)(first, second, getRef);
132
+ return (0, merge_number_constraints_js_1.mergeNumberConstraints)(first, second, getRef, normalize);
129
133
  }
130
134
  if ((0, check_at_least_one_type_match_js_1.checkAtLeastOneTypeMatch)(first, second, 'integer')) {
131
- return (0, merge_integer_constraints_js_1.mergeIntegerConstraints)(first, second, getRef);
135
+ return (0, merge_integer_constraints_js_1.mergeIntegerConstraints)(first, second, getRef, normalize);
132
136
  }
133
137
  if ((0, check_at_least_one_type_match_js_1.checkAtLeastOneTypeMatch)(first, second, 'boolean')) {
134
- return (0, merge_boolean_constraints_js_1.mergeBooleanConstraints)(first, second, getRef);
138
+ return (0, merge_boolean_constraints_js_1.mergeBooleanConstraints)(first, second, getRef, normalize);
135
139
  }
136
140
  throw new Error(`Cannot merge schemas with type "${first.type}" with type "${second.type}"`);
137
141
  };
138
- const mergeWithRef = (first, second, getRef) => {
142
+ const mergeWithRef = (first, second, getRef, normalize) => {
143
+ const readRef = (ref) => normalize(getRef(ref));
139
144
  if ((0, refFns_js_1.isRef)(first) && (0, refFns_js_1.isRef)(second)) {
140
145
  if (first.$ref === second.$ref) {
141
146
  return {
@@ -144,15 +149,15 @@ const mergeWithRef = (first, second, getRef) => {
144
149
  };
145
150
  }
146
151
  else {
147
- return mergeSchemas(getRef(first), getRef(second), getRef);
152
+ return mergeSchemas(readRef(first), readRef(second), getRef, normalize);
148
153
  }
149
154
  }
150
155
  if ((0, refFns_js_1.isRef)(first) && !(0, refFns_js_1.isRef)(second)) {
151
- const merged = (0, isEmpty_js_1.isEmpty)(second) ? first : mergeSchemas(getRef(first), second, getRef);
156
+ const merged = (0, isEmpty_js_1.isEmpty)(second) ? first : mergeSchemas(readRef(first), second, getRef, normalize);
152
157
  return merged;
153
158
  }
154
159
  if (!(0, refFns_js_1.isRef)(first) && (0, refFns_js_1.isRef)(second)) {
155
- const merged = (0, isEmpty_js_1.isEmpty)(first) ? second : mergeSchemas(first, getRef(second), getRef);
160
+ const merged = (0, isEmpty_js_1.isEmpty)(first) ? second : mergeSchemas(first, readRef(second), getRef, normalize);
156
161
  return merged;
157
162
  }
158
163
  throw new Error('Invalid input');
@@ -1,6 +1,12 @@
1
1
  import type { OpenAPIV3 } from 'openapi-types';
2
2
  import * as v from 'valibot';
3
3
  export type GetRefFn = (ref: OpenAPIV3.ReferenceObject) => OpenAPIV3.SchemaObject;
4
+ /**
5
+ * Maps a schema the merge reads (a member, a nested property or item schema,
6
+ * a `$ref` target) onto the shape the merge understands. The caller supplies
7
+ * it, so the merge holds no dialect rules of its own. Must be idempotent.
8
+ */
9
+ export type NormalizeFn = (schema: OpenAPIV3.SchemaObject) => OpenAPIV3.SchemaObject;
4
10
  export type OneOfObject = {
5
11
  oneOf?: (OpenAPIV3.ReferenceObject | OpenAPIV3.SchemaObject)[];
6
12
  } & OpenAPIV3.SchemaObject;
@@ -105,8 +105,7 @@ const toOperationsV3 = ({ paths, stackTrail, context }) => {
105
105
  }
106
106
  catch (error) {
107
107
  const normalized = error instanceof Error ? error : new Error(String(error));
108
- context.logIssue({
109
- key: method,
108
+ context.logIssueNoKey({
110
109
  parent: operation,
111
110
  level: 'error',
112
111
  message: normalized.message,
@@ -0,0 +1,24 @@
1
+ import type { OpenAPIV3 } from 'openapi-types';
2
+ /**
3
+ * Map the 3.1-only schema-shape encodings onto the shared IR shape before
4
+ * dispatching: `unevaluatedProperties`, type arrays, `const`, `examples[]`,
5
+ * numeric exclusive bounds, and binary/base64 content keywords. Each step
6
+ * returns its input unchanged when it does not apply, so the composed result
7
+ * is referentially equal to `schema` when nothing matched — letting the
8
+ * dispatcher re-dispatch only when needed. Idempotent: a normalized schema
9
+ * comes back as the same object.
10
+ */
11
+ export declare const normalizeSchemaShape: (schema: OpenAPIV3.SchemaObject) => OpenAPIV3.SchemaObject;
12
+ /**
13
+ * Is `type` only `null` (`'null'` or `['null']`)? `'null'` is a 3.1 type the
14
+ * 3.0-typed SchemaObject does not model, so read it loosely.
15
+ */
16
+ export declare const isNullOnlyType: (type: unknown) => boolean;
17
+ /**
18
+ * Normalize a schema as it enters the `allOf`/`oneOf`/`anyOf` merge: the
19
+ * {@link normalizeSchemaShape} rules, plus a null-only member (`type: 'null'`
20
+ * or `['null']`) becomes `{ nullable: true }` with no `type`, so it adds
21
+ * nullability instead of conflicting with the other members' types.
22
+ * Idempotent, like `normalizeSchemaShape`.
23
+ */
24
+ export declare const normalizeMergeMember: (schema: OpenAPIV3.SchemaObject) => OpenAPIV3.SchemaObject;
@@ -0,0 +1,219 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeMergeMember = exports.isNullOnlyType = exports.normalizeSchemaShape = void 0;
4
+ /**
5
+ * OpenAPI 3.1 lets a schema's `type` be an ARRAY (e.g. `['string', 'null']`),
6
+ * which the shared IR — modelling a single `type` plus a `nullable` flag —
7
+ * does not. Normalize the array form into shapes the rest of the dispatcher
8
+ * already understands:
9
+ *
10
+ * - `['T', 'null']` (one non-null type) → `{ type: 'T', nullable: true }`.
11
+ * An array type without `items` keeps `items` absent (unknown items).
12
+ * - `['T1', 'T2', …]` (several non-null) → a `oneOf` of the bare types,
13
+ * i.e. the 3.1 multi-type union. 3.0 cannot express this — it is the
14
+ * CASE-2 gap where the v3-0 parser degrades to OasUnknown.
15
+ * - `['null']` (only null) → left unchanged → OasUnknown,
16
+ * since there is no first-class OasNull IR node yet (a documented gap).
17
+ * Inside a merge, {@link normalizeMergeMember} handles it.
18
+ *
19
+ * The hoisted `nullable` flag is the IR's representation of nullability; the
20
+ * leaf parsers read it via `parseNullable`. A non-array `type` passes through.
21
+ */
22
+ const normalizeTypeArray = (schema) => {
23
+ const rawType = schema.type;
24
+ if (!Array.isArray(rawType)) {
25
+ return schema;
26
+ }
27
+ const members = rawType.filter(member => member !== 'null');
28
+ const nullable = rawType.length !== members.length || schema.nullable;
29
+ // Only `null` (`type: ['null']`): no OasNull node yet — fall through.
30
+ if (members.length === 0) {
31
+ return schema;
32
+ }
33
+ // Several non-null types: a 3.1 multi-type union. Model it as a `oneOf`
34
+ // of the bare types and let the oneOf branch build the OasUnion.
35
+ if (members.length > 1) {
36
+ const { type: _type, ...rest } = schema;
37
+ return { ...rest, nullable, oneOf: members.map(member => ({ type: member })) };
38
+ }
39
+ // Exactly one non-null type: dispatch as that type, carrying nullability.
40
+ switch (members[0]) {
41
+ case 'object':
42
+ case 'integer':
43
+ case 'number':
44
+ case 'boolean':
45
+ case 'string':
46
+ case 'array':
47
+ return { ...schema, type: members[0], nullable };
48
+ default:
49
+ return schema;
50
+ }
51
+ };
52
+ /**
53
+ * OpenAPI 3.1 `const: X` is the single-value form of `enum` (3.0 expresses a
54
+ * literal as a one-element `enum`). Rewrite it so the existing enum-aware leaf
55
+ * parsers handle it; matches down-convert's `convertConstToEnum`, so a 3.0
56
+ * `enum:[X]` and a 3.1 `const:X` land on the same IR.
57
+ */
58
+ const normalizeConst = (schema) => {
59
+ if (!('const' in schema)) {
60
+ return schema;
61
+ }
62
+ // `const` is a 3.1 keyword the 3.0-typed SchemaObject does not model; read
63
+ // it via an annotated destructure rather than a cast.
64
+ const { const: constValue, ...rest } = schema;
65
+ return { ...rest, enum: [constValue] };
66
+ };
67
+ /**
68
+ * OpenAPI 3.1 schemas carry `examples` (an array, JSON Schema 2020-12); 3.0
69
+ * and the IR use a single `example`. Adopt the first array element as the IR
70
+ * `example` when no singular `example` is set, and drop the array. Matches
71
+ * down-convert's `convertJsonSchemaExamples`.
72
+ */
73
+ const normalizeExamples = (schema) => {
74
+ if ('example' in schema || !('examples' in schema)) {
75
+ return schema;
76
+ }
77
+ // `examples` is a 3.1 keyword the 3.0-typed SchemaObject does not model.
78
+ const { examples, ...rest } = schema;
79
+ if (!Array.isArray(examples) || examples.length === 0) {
80
+ return rest;
81
+ }
82
+ return { ...rest, example: examples[0] };
83
+ };
84
+ /**
85
+ * OpenAPI 3.1 expresses exclusive bounds as NUMBERS (`exclusiveMinimum: 5`
86
+ * means "> 5"); the shared IR (and 3.0) model them as a boolean flag paired
87
+ * with `minimum`/`maximum`. Convert the numeric form so the number/integer
88
+ * leaves validate. Matches down-convert's `convertExclusiveMinMax`, so a 3.0
89
+ * `{minimum:5, exclusiveMinimum:true}` and a 3.1 `{exclusiveMinimum:5}` land
90
+ * on the same IR.
91
+ */
92
+ const normalizeExclusiveBounds = (schema) => {
93
+ // `exclusiveMinimum`/`exclusiveMaximum` are 3.0-typed boolean here; in 3.1
94
+ // they arrive as numbers, so read them loosely.
95
+ const exclusiveMinimum = schema.exclusiveMinimum;
96
+ const exclusiveMaximum = schema.exclusiveMaximum;
97
+ if (typeof exclusiveMinimum !== 'number' && typeof exclusiveMaximum !== 'number') {
98
+ return schema;
99
+ }
100
+ const next = { ...schema };
101
+ if (typeof exclusiveMinimum === 'number') {
102
+ next.minimum = exclusiveMinimum;
103
+ next.exclusiveMinimum = true;
104
+ }
105
+ if (typeof exclusiveMaximum === 'number') {
106
+ next.maximum = exclusiveMaximum;
107
+ next.exclusiveMaximum = true;
108
+ }
109
+ return next;
110
+ };
111
+ /**
112
+ * OpenAPI 3.1 / JSON Schema 2020-12 expresses a binary string payload with
113
+ * `contentMediaType: 'application/octet-stream'` and base64 with
114
+ * `contentEncoding: 'base64'`; the shared IR (and 3.0) carry these as a string
115
+ * `format` (`binary` / `byte`, both in the format allow-list). Map them so the
116
+ * format reaches the IR. Mirrors down-convert's
117
+ * `convertJsonSchemaContentMediaType` / `convertJsonSchemaContentEncoding`:
118
+ * string schemas only, and a pre-existing (conflicting) `format` wins — the
119
+ * content keyword is dropped, not overwritten. Without this, retiring
120
+ * down-convert would silently lose the `format` signal on 3.1 binary uploads.
121
+ */
122
+ const normalizeContentFormat = (schema) => {
123
+ if (schema.type !== 'string') {
124
+ return schema;
125
+ }
126
+ // `contentMediaType`/`contentEncoding` are 3.1 keywords the 3.0-typed
127
+ // SchemaObject does not model; read them loosely.
128
+ const view = schema;
129
+ const derivedFormat = view.contentMediaType === 'application/octet-stream'
130
+ ? 'binary'
131
+ : view.contentEncoding === 'base64'
132
+ ? 'byte'
133
+ : undefined;
134
+ if (derivedFormat === undefined) {
135
+ return schema;
136
+ }
137
+ const { contentMediaType: _contentMediaType, contentEncoding: _contentEncoding, ...rest } = view;
138
+ return 'format' in rest ? rest : { ...rest, format: derivedFormat };
139
+ };
140
+ /**
141
+ * In-place applicators that evaluate keys `unevaluatedProperties` would
142
+ * otherwise see. `$ref` never reaches `normalizeSchemaShape`, and both the
143
+ * dispatcher and the merge refuse a schema with `not`.
144
+ */
145
+ const inPlaceApplicators = [
146
+ 'allOf',
147
+ 'oneOf',
148
+ 'anyOf',
149
+ 'if',
150
+ 'then',
151
+ 'else',
152
+ 'dependentSchemas',
153
+ '$dynamicRef'
154
+ ];
155
+ /**
156
+ * With no in-place applicator on the same schema, `unevaluatedProperties`
157
+ * means the same as `additionalProperties` (JSON Schema 2020-12 §11.3,
158
+ * §10.3.2.3), so rename it. When `additionalProperties` is also present it
159
+ * evaluates every remaining key, so `unevaluatedProperties` is dropped.
160
+ */
161
+ const normalizeUnevaluatedProperties = (schema) => {
162
+ if (!('unevaluatedProperties' in schema)) {
163
+ return schema;
164
+ }
165
+ if (inPlaceApplicators.some(keyword => keyword in schema)) {
166
+ return schema;
167
+ }
168
+ // `unevaluatedProperties` is a 3.1 keyword the 3.0-typed SchemaObject does
169
+ // not model; read it via an annotated destructure.
170
+ const { unevaluatedProperties, ...rest } = schema;
171
+ if ('additionalProperties' in rest) {
172
+ return rest;
173
+ }
174
+ if (!isAdditionalPropertiesValue(unevaluatedProperties)) {
175
+ return schema;
176
+ }
177
+ return { ...rest, additionalProperties: unevaluatedProperties };
178
+ };
179
+ /**
180
+ * Is this a value `additionalProperties` accepts: a boolean, or a schema or
181
+ * `$ref` object?
182
+ */
183
+ const isAdditionalPropertiesValue = (value) => typeof value === 'boolean' ||
184
+ (typeof value === 'object' && value !== null && !Array.isArray(value));
185
+ /**
186
+ * Map the 3.1-only schema-shape encodings onto the shared IR shape before
187
+ * dispatching: `unevaluatedProperties`, type arrays, `const`, `examples[]`,
188
+ * numeric exclusive bounds, and binary/base64 content keywords. Each step
189
+ * returns its input unchanged when it does not apply, so the composed result
190
+ * is referentially equal to `schema` when nothing matched — letting the
191
+ * dispatcher re-dispatch only when needed. Idempotent: a normalized schema
192
+ * comes back as the same object.
193
+ */
194
+ const normalizeSchemaShape = (schema) => {
195
+ return normalizeExclusiveBounds(normalizeExamples(normalizeConst(normalizeContentFormat(normalizeTypeArray(normalizeUnevaluatedProperties(schema))))));
196
+ };
197
+ exports.normalizeSchemaShape = normalizeSchemaShape;
198
+ /**
199
+ * Is `type` only `null` (`'null'` or `['null']`)? `'null'` is a 3.1 type the
200
+ * 3.0-typed SchemaObject does not model, so read it loosely.
201
+ */
202
+ const isNullOnlyType = (type) => type === 'null' || (Array.isArray(type) && type.length > 0 && type.every(item => item === 'null'));
203
+ exports.isNullOnlyType = isNullOnlyType;
204
+ /**
205
+ * Normalize a schema as it enters the `allOf`/`oneOf`/`anyOf` merge: the
206
+ * {@link normalizeSchemaShape} rules, plus a null-only member (`type: 'null'`
207
+ * or `['null']`) becomes `{ nullable: true }` with no `type`, so it adds
208
+ * nullability instead of conflicting with the other members' types.
209
+ * Idempotent, like `normalizeSchemaShape`.
210
+ */
211
+ const normalizeMergeMember = (schema) => {
212
+ const normalized = (0, exports.normalizeSchemaShape)(schema);
213
+ if (!(0, exports.isNullOnlyType)(normalized.type)) {
214
+ return normalized;
215
+ }
216
+ const { type: _type, ...rest } = normalized;
217
+ return { ...rest, nullable: true };
218
+ };
219
+ exports.normalizeMergeMember = normalizeMergeMember;