@skmtc/core 0.32.1 → 0.32.2

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 (113) hide show
  1. package/esm/parse/v3-1/_merge-all-of/check-array-item-type-conflicts.d.ts +2 -1
  2. package/esm/parse/v3-1/_merge-all-of/check-array-item-type-conflicts.js +7 -3
  3. package/esm/parse/v3-1/_merge-all-of/generic-merge.d.ts +2 -2
  4. package/esm/parse/v3-1/_merge-all-of/generic-merge.js +2 -2
  5. package/esm/parse/v3-1/_merge-all-of/merge-array-constraints.d.ts +2 -2
  6. package/esm/parse/v3-1/_merge-all-of/merge-array-constraints.js +8 -12
  7. package/esm/parse/v3-1/_merge-all-of/merge-boolean-constraints.d.ts +2 -2
  8. package/esm/parse/v3-1/_merge-all-of/merge-boolean-constraints.js +2 -2
  9. package/esm/parse/v3-1/_merge-all-of/merge-integer-constraints.d.ts +2 -2
  10. package/esm/parse/v3-1/_merge-all-of/merge-integer-constraints.js +2 -2
  11. package/esm/parse/v3-1/_merge-all-of/merge-intersection.d.ts +3 -2
  12. package/esm/parse/v3-1/_merge-all-of/merge-intersection.js +2 -2
  13. package/esm/parse/v3-1/_merge-all-of/merge-number-constraints.d.ts +2 -2
  14. package/esm/parse/v3-1/_merge-all-of/merge-number-constraints.js +2 -2
  15. package/esm/parse/v3-1/_merge-all-of/merge-object-constraints.d.ts +2 -2
  16. package/esm/parse/v3-1/_merge-all-of/merge-object-constraints.js +3 -3
  17. package/esm/parse/v3-1/_merge-all-of/merge-properties.d.ts +2 -2
  18. package/esm/parse/v3-1/_merge-all-of/merge-properties.js +2 -2
  19. package/esm/parse/v3-1/_merge-all-of/merge-string-constraints.d.ts +2 -2
  20. package/esm/parse/v3-1/_merge-all-of/merge-string-constraints.js +3 -3
  21. package/esm/parse/v3-1/_merge-all-of/merge-union.d.ts +5 -3
  22. package/esm/parse/v3-1/_merge-all-of/merge-union.js +31 -7
  23. package/esm/parse/v3-1/_merge-all-of/merge.d.ts +2 -2
  24. package/esm/parse/v3-1/_merge-all-of/merge.js +28 -23
  25. package/esm/parse/v3-1/_merge-all-of/types.d.ts +6 -0
  26. package/esm/parse/v3-1/schema/normalize-schema-shape.d.ts +24 -0
  27. package/esm/parse/v3-1/schema/normalize-schema-shape.js +213 -0
  28. package/esm/parse/v3-1/schema/toSchemasV3.js +7 -195
  29. package/esm/parse/v3-2/_merge-all-of/check-array-item-type-conflicts.d.ts +2 -1
  30. package/esm/parse/v3-2/_merge-all-of/check-array-item-type-conflicts.js +7 -3
  31. package/esm/parse/v3-2/_merge-all-of/generic-merge.d.ts +2 -2
  32. package/esm/parse/v3-2/_merge-all-of/generic-merge.js +2 -2
  33. package/esm/parse/v3-2/_merge-all-of/merge-array-constraints.d.ts +2 -2
  34. package/esm/parse/v3-2/_merge-all-of/merge-array-constraints.js +8 -12
  35. package/esm/parse/v3-2/_merge-all-of/merge-boolean-constraints.d.ts +2 -2
  36. package/esm/parse/v3-2/_merge-all-of/merge-boolean-constraints.js +2 -2
  37. package/esm/parse/v3-2/_merge-all-of/merge-integer-constraints.d.ts +2 -2
  38. package/esm/parse/v3-2/_merge-all-of/merge-integer-constraints.js +2 -2
  39. package/esm/parse/v3-2/_merge-all-of/merge-intersection.d.ts +3 -2
  40. package/esm/parse/v3-2/_merge-all-of/merge-intersection.js +2 -2
  41. package/esm/parse/v3-2/_merge-all-of/merge-number-constraints.d.ts +2 -2
  42. package/esm/parse/v3-2/_merge-all-of/merge-number-constraints.js +2 -2
  43. package/esm/parse/v3-2/_merge-all-of/merge-object-constraints.d.ts +2 -2
  44. package/esm/parse/v3-2/_merge-all-of/merge-object-constraints.js +3 -3
  45. package/esm/parse/v3-2/_merge-all-of/merge-properties.d.ts +2 -2
  46. package/esm/parse/v3-2/_merge-all-of/merge-properties.js +2 -2
  47. package/esm/parse/v3-2/_merge-all-of/merge-string-constraints.d.ts +2 -2
  48. package/esm/parse/v3-2/_merge-all-of/merge-string-constraints.js +3 -3
  49. package/esm/parse/v3-2/_merge-all-of/merge-union.d.ts +5 -3
  50. package/esm/parse/v3-2/_merge-all-of/merge-union.js +31 -7
  51. package/esm/parse/v3-2/_merge-all-of/merge.d.ts +2 -2
  52. package/esm/parse/v3-2/_merge-all-of/merge.js +28 -23
  53. package/esm/parse/v3-2/_merge-all-of/types.d.ts +6 -0
  54. package/esm/parse/v3-2/schema/normalize-schema-shape.d.ts +24 -0
  55. package/esm/parse/v3-2/schema/normalize-schema-shape.js +213 -0
  56. package/esm/parse/v3-2/schema/toSchemasV3.js +7 -195
  57. package/package.json +1 -1
  58. package/script/parse/v3-1/_merge-all-of/check-array-item-type-conflicts.d.ts +2 -1
  59. package/script/parse/v3-1/_merge-all-of/check-array-item-type-conflicts.js +7 -3
  60. package/script/parse/v3-1/_merge-all-of/generic-merge.d.ts +2 -2
  61. package/script/parse/v3-1/_merge-all-of/generic-merge.js +2 -2
  62. package/script/parse/v3-1/_merge-all-of/merge-array-constraints.d.ts +2 -2
  63. package/script/parse/v3-1/_merge-all-of/merge-array-constraints.js +8 -12
  64. package/script/parse/v3-1/_merge-all-of/merge-boolean-constraints.d.ts +2 -2
  65. package/script/parse/v3-1/_merge-all-of/merge-boolean-constraints.js +2 -2
  66. package/script/parse/v3-1/_merge-all-of/merge-integer-constraints.d.ts +2 -2
  67. package/script/parse/v3-1/_merge-all-of/merge-integer-constraints.js +2 -2
  68. package/script/parse/v3-1/_merge-all-of/merge-intersection.d.ts +3 -2
  69. package/script/parse/v3-1/_merge-all-of/merge-intersection.js +2 -2
  70. package/script/parse/v3-1/_merge-all-of/merge-number-constraints.d.ts +2 -2
  71. package/script/parse/v3-1/_merge-all-of/merge-number-constraints.js +2 -2
  72. package/script/parse/v3-1/_merge-all-of/merge-object-constraints.d.ts +2 -2
  73. package/script/parse/v3-1/_merge-all-of/merge-object-constraints.js +3 -3
  74. package/script/parse/v3-1/_merge-all-of/merge-properties.d.ts +2 -2
  75. package/script/parse/v3-1/_merge-all-of/merge-properties.js +2 -2
  76. package/script/parse/v3-1/_merge-all-of/merge-string-constraints.d.ts +2 -2
  77. package/script/parse/v3-1/_merge-all-of/merge-string-constraints.js +3 -3
  78. package/script/parse/v3-1/_merge-all-of/merge-union.d.ts +5 -3
  79. package/script/parse/v3-1/_merge-all-of/merge-union.js +31 -7
  80. package/script/parse/v3-1/_merge-all-of/merge.d.ts +2 -2
  81. package/script/parse/v3-1/_merge-all-of/merge.js +28 -23
  82. package/script/parse/v3-1/_merge-all-of/types.d.ts +6 -0
  83. package/script/parse/v3-1/schema/normalize-schema-shape.d.ts +24 -0
  84. package/script/parse/v3-1/schema/normalize-schema-shape.js +219 -0
  85. package/script/parse/v3-1/schema/toSchemasV3.js +8 -196
  86. package/script/parse/v3-2/_merge-all-of/check-array-item-type-conflicts.d.ts +2 -1
  87. package/script/parse/v3-2/_merge-all-of/check-array-item-type-conflicts.js +7 -3
  88. package/script/parse/v3-2/_merge-all-of/generic-merge.d.ts +2 -2
  89. package/script/parse/v3-2/_merge-all-of/generic-merge.js +2 -2
  90. package/script/parse/v3-2/_merge-all-of/merge-array-constraints.d.ts +2 -2
  91. package/script/parse/v3-2/_merge-all-of/merge-array-constraints.js +8 -12
  92. package/script/parse/v3-2/_merge-all-of/merge-boolean-constraints.d.ts +2 -2
  93. package/script/parse/v3-2/_merge-all-of/merge-boolean-constraints.js +2 -2
  94. package/script/parse/v3-2/_merge-all-of/merge-integer-constraints.d.ts +2 -2
  95. package/script/parse/v3-2/_merge-all-of/merge-integer-constraints.js +2 -2
  96. package/script/parse/v3-2/_merge-all-of/merge-intersection.d.ts +3 -2
  97. package/script/parse/v3-2/_merge-all-of/merge-intersection.js +2 -2
  98. package/script/parse/v3-2/_merge-all-of/merge-number-constraints.d.ts +2 -2
  99. package/script/parse/v3-2/_merge-all-of/merge-number-constraints.js +2 -2
  100. package/script/parse/v3-2/_merge-all-of/merge-object-constraints.d.ts +2 -2
  101. package/script/parse/v3-2/_merge-all-of/merge-object-constraints.js +3 -3
  102. package/script/parse/v3-2/_merge-all-of/merge-properties.d.ts +2 -2
  103. package/script/parse/v3-2/_merge-all-of/merge-properties.js +2 -2
  104. package/script/parse/v3-2/_merge-all-of/merge-string-constraints.d.ts +2 -2
  105. package/script/parse/v3-2/_merge-all-of/merge-string-constraints.js +3 -3
  106. package/script/parse/v3-2/_merge-all-of/merge-union.d.ts +5 -3
  107. package/script/parse/v3-2/_merge-all-of/merge-union.js +31 -7
  108. package/script/parse/v3-2/_merge-all-of/merge.d.ts +2 -2
  109. package/script/parse/v3-2/_merge-all-of/merge.js +28 -23
  110. package/script/parse/v3-2/_merge-all-of/types.d.ts +6 -0
  111. package/script/parse/v3-2/schema/normalize-schema-shape.d.ts +24 -0
  112. package/script/parse/v3-2/schema/normalize-schema-shape.js +219 -0
  113. package/script/parse/v3-2/schema/toSchemasV3.js +8 -196
@@ -12,6 +12,7 @@ import { toGetRef } from '../../../helpers/refFns.js';
12
12
  import { mergeIntersection } from '../_merge-all-of/merge-intersection.js';
13
13
  import { mergeUnion } from '../_merge-all-of/merge-union.js';
14
14
  import { tryParseAt } from '../../../context/tryParseAt.js';
15
+ import { isNullOnlyType, normalizeMergeMember, normalizeSchemaShape } from './normalize-schema-shape.js';
15
16
  export const toSchemasV3 = ({ schemas, stackTrail, context }) => {
16
17
  const output = {};
17
18
  const entries = Object.entries(schemas);
@@ -36,185 +37,6 @@ export const toOptionalSchemasV3 = ({ schemas, stackTrail, context }) => {
36
37
  }
37
38
  return toSchemasV3({ schemas, stackTrail, context });
38
39
  };
39
- /**
40
- * OpenAPI 3.1 lets a schema's `type` be an ARRAY (e.g. `['string', 'null']`),
41
- * which the shared IR — modelling a single `type` plus a `nullable` flag —
42
- * does not. Normalize the array form into shapes the rest of the dispatcher
43
- * already understands:
44
- *
45
- * - `['T', 'null']` (one non-null type) → `{ type: 'T', nullable: true }`
46
- * - `['T1', 'T2', …]` (several non-null) → a `oneOf` of the bare types,
47
- * i.e. the 3.1 multi-type union. 3.0 cannot express this — it is the
48
- * CASE-2 gap where the v3-0 parser degrades to OasUnknown.
49
- * - `['null']` (only null) → left unchanged → OasUnknown,
50
- * since there is no first-class OasNull IR node yet (a documented gap).
51
- *
52
- * The hoisted `nullable` flag is the IR's representation of nullability; the
53
- * leaf parsers read it via `parseNullable`. A non-array `type` passes through.
54
- */
55
- const normalizeTypeArray = (schema) => {
56
- const rawType = schema.type;
57
- if (!Array.isArray(rawType)) {
58
- return schema;
59
- }
60
- const members = rawType.filter(member => member !== 'null');
61
- const nullable = rawType.length !== members.length || schema.nullable;
62
- // Only `null` (`type: ['null']`): no OasNull node yet — fall through.
63
- if (members.length === 0) {
64
- return schema;
65
- }
66
- // Several non-null types: a 3.1 multi-type union. Model it as a `oneOf`
67
- // of the bare types and let the oneOf branch build the OasUnion.
68
- if (members.length > 1) {
69
- const { type: _type, ...rest } = schema;
70
- return { ...rest, nullable, oneOf: members.map(member => ({ type: member })) };
71
- }
72
- // Exactly one non-null type: dispatch as that type, carrying nullability.
73
- switch (members[0]) {
74
- case 'object':
75
- case 'integer':
76
- case 'number':
77
- case 'boolean':
78
- case 'string':
79
- return { ...schema, type: members[0], nullable };
80
- case 'array':
81
- return 'items' in schema ? { ...schema, type: members[0], nullable } : schema;
82
- default:
83
- return schema;
84
- }
85
- };
86
- /**
87
- * OpenAPI 3.1 `const: X` is the single-value form of `enum` (3.0 expresses a
88
- * literal as a one-element `enum`). Rewrite it so the existing enum-aware leaf
89
- * parsers handle it; matches down-convert's `convertConstToEnum`, so a 3.0
90
- * `enum:[X]` and a 3.1 `const:X` land on the same IR.
91
- */
92
- const normalizeConst = (schema) => {
93
- if (!('const' in schema)) {
94
- return schema;
95
- }
96
- // `const` is a 3.1 keyword the 3.0-typed SchemaObject does not model; read
97
- // it via an annotated destructure rather than a cast.
98
- const { const: constValue, ...rest } = schema;
99
- return { ...rest, enum: [constValue] };
100
- };
101
- /**
102
- * OpenAPI 3.1 schemas carry `examples` (an array, JSON Schema 2020-12); 3.0
103
- * and the IR use a single `example`. Adopt the first array element as the IR
104
- * `example` when no singular `example` is set, and drop the array. Matches
105
- * down-convert's `convertJsonSchemaExamples`.
106
- */
107
- const normalizeExamples = (schema) => {
108
- if ('example' in schema || !('examples' in schema)) {
109
- return schema;
110
- }
111
- // `examples` is a 3.1 keyword the 3.0-typed SchemaObject does not model.
112
- const { examples, ...rest } = schema;
113
- if (!Array.isArray(examples) || examples.length === 0) {
114
- return rest;
115
- }
116
- return { ...rest, example: examples[0] };
117
- };
118
- /**
119
- * OpenAPI 3.1 expresses exclusive bounds as NUMBERS (`exclusiveMinimum: 5`
120
- * means "> 5"); the shared IR (and 3.0) model them as a boolean flag paired
121
- * with `minimum`/`maximum`. Convert the numeric form so the number/integer
122
- * leaves validate. Matches down-convert's `convertExclusiveMinMax`, so a 3.0
123
- * `{minimum:5, exclusiveMinimum:true}` and a 3.1 `{exclusiveMinimum:5}` land
124
- * on the same IR.
125
- */
126
- const normalizeExclusiveBounds = (schema) => {
127
- // `exclusiveMinimum`/`exclusiveMaximum` are 3.0-typed boolean here; in 3.1
128
- // they arrive as numbers, so read them loosely.
129
- const exclusiveMinimum = schema.exclusiveMinimum;
130
- const exclusiveMaximum = schema.exclusiveMaximum;
131
- if (typeof exclusiveMinimum !== 'number' && typeof exclusiveMaximum !== 'number') {
132
- return schema;
133
- }
134
- const next = { ...schema };
135
- if (typeof exclusiveMinimum === 'number') {
136
- next.minimum = exclusiveMinimum;
137
- next.exclusiveMinimum = true;
138
- }
139
- if (typeof exclusiveMaximum === 'number') {
140
- next.maximum = exclusiveMaximum;
141
- next.exclusiveMaximum = true;
142
- }
143
- return next;
144
- };
145
- /**
146
- * OpenAPI 3.1 / JSON Schema 2020-12 expresses a binary string payload with
147
- * `contentMediaType: 'application/octet-stream'` and base64 with
148
- * `contentEncoding: 'base64'`; the shared IR (and 3.0) carry these as a string
149
- * `format` (`binary` / `byte`, both in the format allow-list). Map them so the
150
- * format reaches the IR. Mirrors down-convert's
151
- * `convertJsonSchemaContentMediaType` / `convertJsonSchemaContentEncoding`:
152
- * string schemas only, and a pre-existing (conflicting) `format` wins — the
153
- * content keyword is dropped, not overwritten. Without this, retiring
154
- * down-convert would silently lose the `format` signal on 3.1 binary uploads.
155
- */
156
- const normalizeContentFormat = (schema) => {
157
- if (schema.type !== 'string') {
158
- return schema;
159
- }
160
- // `contentMediaType`/`contentEncoding` are 3.1 keywords the 3.0-typed
161
- // SchemaObject does not model; read them loosely.
162
- const view = schema;
163
- const derivedFormat = view.contentMediaType === 'application/octet-stream'
164
- ? 'binary'
165
- : view.contentEncoding === 'base64'
166
- ? 'byte'
167
- : undefined;
168
- if (derivedFormat === undefined) {
169
- return schema;
170
- }
171
- const { contentMediaType: _contentMediaType, contentEncoding: _contentEncoding, ...rest } = view;
172
- return 'format' in rest ? rest : { ...rest, format: derivedFormat };
173
- };
174
- /**
175
- * In-place applicators that evaluate keys `unevaluatedProperties` would
176
- * otherwise see. `$ref` and `not` never reach `normalizeSchemaShape`.
177
- */
178
- const inPlaceApplicators = [
179
- 'allOf',
180
- 'oneOf',
181
- 'anyOf',
182
- 'if',
183
- 'then',
184
- 'else',
185
- 'dependentSchemas',
186
- '$dynamicRef'
187
- ];
188
- /**
189
- * With no in-place applicator on the same schema, `unevaluatedProperties`
190
- * means the same as `additionalProperties` (JSON Schema 2020-12 §11.3,
191
- * §10.3.2.3), so rename it. When `additionalProperties` is also present it
192
- * evaluates every remaining key, so `unevaluatedProperties` is dropped.
193
- */
194
- const normalizeUnevaluatedProperties = (schema) => {
195
- if (!('unevaluatedProperties' in schema)) {
196
- return schema;
197
- }
198
- if (inPlaceApplicators.some(keyword => keyword in schema)) {
199
- return schema;
200
- }
201
- // `unevaluatedProperties` is a 3.1 keyword the 3.0-typed SchemaObject does
202
- // not model; read it via an annotated destructure.
203
- const { unevaluatedProperties, ...rest } = schema;
204
- if ('additionalProperties' in rest) {
205
- return rest;
206
- }
207
- if (!isAdditionalPropertiesValue(unevaluatedProperties)) {
208
- return schema;
209
- }
210
- return { ...rest, additionalProperties: unevaluatedProperties };
211
- };
212
- /**
213
- * Is this a value `additionalProperties` accepts: a boolean, or a schema or
214
- * `$ref` object?
215
- */
216
- const isAdditionalPropertiesValue = (value) => typeof value === 'boolean' ||
217
- (typeof value === 'object' && value !== null && !Array.isArray(value));
218
40
  /**
219
41
  * Remove `unevaluatedProperties` from an `allOf`/`oneOf`/`anyOf` wrapper and
220
42
  * log it as skipped. Left in place, it would be renamed to
@@ -235,26 +57,13 @@ const withoutWrapperUnevaluatedProperties = ({ schema, parentType, stackTrail, c
235
57
  return rest;
236
58
  };
237
59
  /**
238
- * Map the 3.1-only schema-shape encodings onto the shared IR shape before
239
- * dispatching: `unevaluatedProperties`, type arrays, `const`, `examples[]`,
240
- * numeric exclusive bounds, and binary/base64 content keywords. Each step
241
- * returns its input unchanged when it does not apply, so the composed result
242
- * is referentially equal to `schema` when nothing matched — letting the
243
- * dispatcher re-dispatch only when needed.
244
- */
245
- const normalizeSchemaShape = (schema) => {
246
- return normalizeExclusiveBounds(normalizeExamples(normalizeConst(normalizeContentFormat(normalizeTypeArray(normalizeUnevaluatedProperties(schema))))));
247
- };
248
- /**
249
- * Is this a 3.1 `{ type: 'null' }` schema member? (`'null'` is a 3.1 type
250
- * literal the 3.0-typed SchemaObject does not model, so read it loosely.)
60
+ * Is this a 3.1 null-only schema member (`type: 'null'` or `['null']`)?
251
61
  */
252
62
  const isNullTypeSchema = (member) => {
253
63
  if (isRef(member)) {
254
64
  return false;
255
65
  }
256
- const type = member.type;
257
- return type === 'null';
66
+ return isNullOnlyType(member.type);
258
67
  };
259
68
  /**
260
69
  * Split `oneOf`/`anyOf` members into the non-null members plus whether a
@@ -351,7 +160,8 @@ export const toSchemaV3 = ({ schema, stackTrail, context }) => {
351
160
  }
352
161
  const merged = mergeIntersection({
353
162
  schema: wrapper,
354
- getRef: toGetRef(context.documentObject)
163
+ getRef: toGetRef(context.documentObject),
164
+ normalize: normalizeMergeMember
355
165
  });
356
166
  return toSchemaV3({ schema: merged, stackTrail: st, context });
357
167
  });
@@ -373,6 +183,7 @@ export const toSchemaV3 = ({ schema, stackTrail, context }) => {
373
183
  const merged = mergeUnion({
374
184
  schema: withoutNull,
375
185
  getRef: toGetRef(context.documentObject),
186
+ normalize: normalizeMergeMember,
376
187
  groupType: 'oneOf'
377
188
  });
378
189
  if (!('oneOf' in merged) || !Array.isArray(merged.oneOf)) {
@@ -434,6 +245,7 @@ export const toSchemaV3 = ({ schema, stackTrail, context }) => {
434
245
  const merged = mergeUnion({
435
246
  schema: withoutNull,
436
247
  getRef: toGetRef(context.documentObject),
248
+ normalize: normalizeMergeMember,
437
249
  groupType: 'anyOf'
438
250
  });
439
251
  if (!('anyOf' in merged) || !Array.isArray(merged.anyOf)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skmtc/core",
3
- "version": "0.32.1",
3
+ "version": "0.32.2",
4
4
  "description": "Skmtc is a declarative code generation framework",
5
5
  "keywords": [
6
6
  "openapi",
@@ -1,2 +1,3 @@
1
1
  import type { OpenAPIV3 } from 'openapi-types';
2
- export declare const checkArrayItemTypeConflicts: (a: OpenAPIV3.SchemaObject, b: OpenAPIV3.SchemaObject) => void;
2
+ import type { NormalizeFn } from './types.js';
3
+ export declare const checkArrayItemTypeConflicts: (a: OpenAPIV3.SchemaObject, b: OpenAPIV3.SchemaObject, normalize: NormalizeFn) => void;
@@ -1,10 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.checkArrayItemTypeConflicts = void 0;
4
- const checkArrayItemTypeConflicts = (a, b) => {
4
+ const refFns_js_1 = require("../../../helpers/refFns.js");
5
+ const checkArrayItemTypeConflicts = (a, b, normalize) => {
5
6
  if (a.type === 'array' && b.type === 'array' && 'items' in a && 'items' in b) {
6
- const aItems = a.items;
7
- const bItems = b.items;
7
+ if ((0, refFns_js_1.isRef)(a.items) || (0, refFns_js_1.isRef)(b.items)) {
8
+ return;
9
+ }
10
+ const aItems = normalize(a.items);
11
+ const bItems = normalize(b.items);
8
12
  if (aItems.type && bItems.type && aItems.type !== bItems.type) {
9
13
  throw new Error(`Cannot merge schemas: array items have conflicting types '${aItems.type}' and '${bItems.type}'`);
10
14
  }
@@ -1,3 +1,3 @@
1
- import type { SchemaObject, GetRefFn } from './types.js';
1
+ import type { SchemaObject, GetRefFn, NormalizeFn } from './types.js';
2
2
  import type * as v from 'valibot';
3
- export declare const genericMerge: <T>(first: SchemaObject, second: SchemaObject, getRef: GetRefFn, typeCheck?: v.GenericSchema<T>) => SchemaObject;
3
+ export declare const genericMerge: <T>(first: SchemaObject, second: SchemaObject, getRef: GetRefFn, normalize: NormalizeFn, typeCheck?: v.GenericSchema<T>) => SchemaObject;
@@ -4,11 +4,11 @@ exports.genericMerge = void 0;
4
4
  const merge_enum_values_js_1 = require("./merge-enum-values.js");
5
5
  const merge_properties_js_1 = require("./merge-properties.js");
6
6
  const merge_required_js_1 = require("./merge-required.js");
7
- const genericMerge = (first, second, getRef, typeCheck) => {
7
+ const genericMerge = (first, second, getRef, normalize, typeCheck) => {
8
8
  return {
9
9
  ...first,
10
10
  ...second,
11
- ...(0, merge_properties_js_1.mergeProperties)(first, second, getRef),
11
+ ...(0, merge_properties_js_1.mergeProperties)(first, second, getRef, normalize),
12
12
  ...(0, merge_required_js_1.mergeRequired)(first, second),
13
13
  ...(0, merge_enum_values_js_1.mergeEnumValues)(first, second, typeCheck)
14
14
  };
@@ -1,2 +1,2 @@
1
- import type { ArraySchemaObject, GetRefFn, SchemaObject } from './types.js';
2
- export declare function mergeArrayConstraints(first: ArraySchemaObject | SchemaObject, second: ArraySchemaObject | SchemaObject, getRef: GetRefFn): ArraySchemaObject;
1
+ import type { ArraySchemaObject, GetRefFn, NormalizeFn, SchemaObject } from './types.js';
2
+ export declare function mergeArrayConstraints(first: ArraySchemaObject | SchemaObject, second: ArraySchemaObject | SchemaObject, getRef: GetRefFn, normalize: NormalizeFn): SchemaObject;
@@ -38,16 +38,12 @@ const merge_js_1 = require("./merge.js");
38
38
  const generic_merge_js_1 = require("./generic-merge.js");
39
39
  const v = __importStar(require("valibot"));
40
40
  const check_type_conflicts_js_1 = require("./check-type-conflicts.js");
41
- function mergeArrayConstraints(first, second, getRef) {
41
+ function mergeArrayConstraints(first, second, getRef, normalize) {
42
42
  (0, check_type_conflicts_js_1.checkTypeConflicts)(first, second);
43
- if (!('items' in first) && !('items' in second)) {
44
- throw new Error('Cannot merge array constraints: no items found');
45
- }
46
- const result = {
47
- ...(0, generic_merge_js_1.genericMerge)(first, second, getRef, v.array(v.any())),
48
- type: 'array',
49
- items: mergeItems(first, second, getRef)
50
- };
43
+ const merged = (0, generic_merge_js_1.genericMerge)(first, second, getRef, normalize, v.array(v.any()));
44
+ const items = mergeItems(first, second, getRef, normalize);
45
+ // With no `items` on either side, `items` stays absent (unknown items).
46
+ const result = items === undefined ? merged : { ...merged, type: 'array', items };
51
47
  // Merge minItems
52
48
  if (first.minItems !== undefined || second.minItems !== undefined) {
53
49
  const minA = first.minItems ?? 0;
@@ -66,9 +62,9 @@ function mergeArrayConstraints(first, second, getRef) {
66
62
  }
67
63
  return result;
68
64
  }
69
- const mergeItems = (first, second, getRef) => {
65
+ const mergeItems = (first, second, getRef, normalize) => {
70
66
  if ('items' in first && 'items' in second && first.items && second.items) {
71
- return (0, merge_js_1.mergeSchemasOrRefs)(first.items, second.items, getRef);
67
+ return (0, merge_js_1.mergeSchemasOrRefs)(first.items, second.items, getRef, normalize);
72
68
  }
73
69
  if ('items' in first && first.items) {
74
70
  return first.items;
@@ -76,5 +72,5 @@ const mergeItems = (first, second, getRef) => {
76
72
  if ('items' in second && second.items) {
77
73
  return second.items;
78
74
  }
79
- throw new Error('Cannot merge array constraints: no items found');
75
+ return undefined;
80
76
  };
@@ -1,3 +1,3 @@
1
1
  import type { OpenAPIV3 } from 'openapi-types';
2
- import type { GetRefFn } from './types.js';
3
- export declare function mergeBooleanConstraints(first: OpenAPIV3.SchemaObject, second: OpenAPIV3.SchemaObject, getRef: GetRefFn): OpenAPIV3.SchemaObject;
2
+ import type { GetRefFn, NormalizeFn } from './types.js';
3
+ export declare function mergeBooleanConstraints(first: OpenAPIV3.SchemaObject, second: OpenAPIV3.SchemaObject, getRef: GetRefFn, normalize: NormalizeFn): OpenAPIV3.SchemaObject;
@@ -37,7 +37,7 @@ exports.mergeBooleanConstraints = mergeBooleanConstraints;
37
37
  const generic_merge_js_1 = require("./generic-merge.js");
38
38
  const v = __importStar(require("valibot"));
39
39
  const check_type_conflicts_js_1 = require("./check-type-conflicts.js");
40
- function mergeBooleanConstraints(first, second, getRef) {
40
+ function mergeBooleanConstraints(first, second, getRef, normalize) {
41
41
  (0, check_type_conflicts_js_1.checkTypeConflicts)(first, second);
42
- return (0, generic_merge_js_1.genericMerge)(first, second, getRef, v.boolean());
42
+ return (0, generic_merge_js_1.genericMerge)(first, second, getRef, normalize, v.boolean());
43
43
  }
@@ -1,3 +1,3 @@
1
1
  import type { OpenAPIV3 } from 'openapi-types';
2
- import type { GetRefFn } from './types.js';
3
- export declare function mergeIntegerConstraints(first: OpenAPIV3.SchemaObject, second: OpenAPIV3.SchemaObject, getRef: GetRefFn): OpenAPIV3.SchemaObject;
2
+ import type { GetRefFn, NormalizeFn } from './types.js';
3
+ export declare function mergeIntegerConstraints(first: OpenAPIV3.SchemaObject, second: OpenAPIV3.SchemaObject, getRef: GetRefFn, normalize: NormalizeFn): OpenAPIV3.SchemaObject;
@@ -37,10 +37,10 @@ exports.mergeIntegerConstraints = mergeIntegerConstraints;
37
37
  const generic_merge_js_1 = require("./generic-merge.js");
38
38
  const v = __importStar(require("valibot"));
39
39
  const check_type_conflicts_js_1 = require("./check-type-conflicts.js");
40
- function mergeIntegerConstraints(first, second, getRef) {
40
+ function mergeIntegerConstraints(first, second, getRef, normalize) {
41
41
  (0, check_type_conflicts_js_1.checkTypeConflicts)(first, second);
42
42
  // First merge enum values if present
43
- const result = (0, generic_merge_js_1.genericMerge)(first, second, getRef, v.number());
43
+ const result = (0, generic_merge_js_1.genericMerge)(first, second, getRef, normalize, v.number());
44
44
  // Then merge other constraints
45
45
  result.type = 'integer';
46
46
  // Merge minimum and exclusiveMinimum
@@ -1,8 +1,9 @@
1
- import type { GetRefFn, SchemaOrReference, SchemaObject } from './types.js';
1
+ import type { GetRefFn, NormalizeFn, SchemaOrReference, SchemaObject } from './types.js';
2
2
  type MergeIntersectionArgs = {
3
3
  schema: SchemaObject;
4
4
  getRef: GetRefFn;
5
+ normalize: NormalizeFn;
5
6
  throwOnConflict?: boolean;
6
7
  };
7
- export declare const mergeIntersection: ({ schema, getRef }: MergeIntersectionArgs) => SchemaOrReference;
8
+ export declare const mergeIntersection: ({ schema, getRef, normalize }: MergeIntersectionArgs) => SchemaOrReference;
8
9
  export {};
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.mergeIntersection = void 0;
4
4
  const decompose_intersection_js_1 = require("./decompose-intersection.js");
5
5
  const merge_js_1 = require("./merge.js");
6
- const mergeIntersection = ({ schema, getRef }) => {
6
+ const mergeIntersection = ({ schema, getRef, normalize }) => {
7
7
  const decomposed = (0, decompose_intersection_js_1.decomposeIntersection)({ schema });
8
8
  if (decomposed.length === 1) {
9
9
  return decomposed[0];
@@ -12,7 +12,7 @@ const mergeIntersection = ({ schema, getRef }) => {
12
12
  return '$ref' in decomposed ? getRef(decomposed) : decomposed;
13
13
  });
14
14
  const result = dereffed.reduce((acc, decomposed) => {
15
- const merged = (0, merge_js_1.mergeSchemasOrRefs)(acc, decomposed, getRef);
15
+ const merged = (0, merge_js_1.mergeSchemasOrRefs)(acc, decomposed, getRef, normalize);
16
16
  return merged;
17
17
  }, {});
18
18
  return result;
@@ -1,3 +1,3 @@
1
1
  import type { OpenAPIV3 } from 'openapi-types';
2
- import type { GetRefFn } from './types.js';
3
- export declare function mergeNumberConstraints(first: OpenAPIV3.SchemaObject, second: OpenAPIV3.SchemaObject, getRef: GetRefFn): OpenAPIV3.SchemaObject;
2
+ import type { GetRefFn, NormalizeFn } from './types.js';
3
+ export declare function mergeNumberConstraints(first: OpenAPIV3.SchemaObject, second: OpenAPIV3.SchemaObject, getRef: GetRefFn, normalize: NormalizeFn): OpenAPIV3.SchemaObject;
@@ -37,10 +37,10 @@ exports.mergeNumberConstraints = mergeNumberConstraints;
37
37
  const generic_merge_js_1 = require("./generic-merge.js");
38
38
  const v = __importStar(require("valibot"));
39
39
  const check_type_conflicts_js_1 = require("./check-type-conflicts.js");
40
- function mergeNumberConstraints(first, second, getRef) {
40
+ function mergeNumberConstraints(first, second, getRef, normalize) {
41
41
  (0, check_type_conflicts_js_1.checkTypeConflicts)(first, second);
42
42
  // First merge enum values if present
43
- const result = (0, generic_merge_js_1.genericMerge)(first, second, getRef, v.number());
43
+ const result = (0, generic_merge_js_1.genericMerge)(first, second, getRef, normalize, v.number());
44
44
  // Then merge other constraints
45
45
  result.type = 'number';
46
46
  // Merge minimum and exclusiveMinimum
@@ -1,5 +1,5 @@
1
1
  import type { OpenAPIV3 } from 'openapi-types';
2
+ import type { GetRefFn, NormalizeFn } from './types.js';
2
3
  type SchemaObject = OpenAPIV3.SchemaObject;
3
- type ReferenceObject = OpenAPIV3.ReferenceObject;
4
- export declare const mergeObjectConstraints: (first: SchemaObject, second: SchemaObject, getRef: (ref: ReferenceObject) => SchemaObject) => SchemaObject;
4
+ export declare const mergeObjectConstraints: (first: SchemaObject, second: SchemaObject, getRef: GetRefFn, normalize: NormalizeFn) => SchemaObject;
5
5
  export {};
@@ -38,14 +38,14 @@ const merge_js_1 = require("./merge.js");
38
38
  const generic_merge_js_1 = require("./generic-merge.js");
39
39
  const v = __importStar(require("valibot"));
40
40
  const check_type_conflicts_js_1 = require("./check-type-conflicts.js");
41
- const mergeObjectConstraints = (first, second, getRef) => {
41
+ const mergeObjectConstraints = (first, second, getRef, normalize) => {
42
42
  // Check for type conflicts
43
43
  (0, check_type_conflicts_js_1.checkTypeConflicts)(first, second);
44
- const result = (0, generic_merge_js_1.genericMerge)(first, second, getRef, v.record(v.string(), v.any()));
44
+ const result = (0, generic_merge_js_1.genericMerge)(first, second, getRef, normalize, v.record(v.string(), v.any()));
45
45
  if (typeof second.additionalProperties === 'object' &&
46
46
  typeof first.additionalProperties === 'object') {
47
47
  // If both have additionalProperties as schemas, merge them
48
- result.additionalProperties = (0, merge_js_1.mergeSchemasOrRefs)(first.additionalProperties, second.additionalProperties, getRef);
48
+ result.additionalProperties = (0, merge_js_1.mergeSchemasOrRefs)(first.additionalProperties, second.additionalProperties, getRef, normalize);
49
49
  }
50
50
  else if (second.additionalProperties !== undefined) {
51
51
  result.additionalProperties = second.additionalProperties;
@@ -1,2 +1,2 @@
1
- import type { SchemaObject, GetRefFn } from './types.js';
2
- export declare const mergeProperties: (first: SchemaObject, second: SchemaObject, getRef: GetRefFn) => SchemaObject | undefined;
1
+ import type { SchemaObject, GetRefFn, NormalizeFn } from './types.js';
2
+ export declare const mergeProperties: (first: SchemaObject, second: SchemaObject, getRef: GetRefFn, normalize: NormalizeFn) => SchemaObject | undefined;
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.mergeProperties = void 0;
4
4
  const merge_js_1 = require("./merge.js");
5
- const mergeProperties = (first, second, getRef) => {
5
+ const mergeProperties = (first, second, getRef, normalize) => {
6
6
  if (containsProperties(first, second)) {
7
7
  const properties = { ...first.properties };
8
8
  if (!properties) {
@@ -12,7 +12,7 @@ const mergeProperties = (first, second, getRef) => {
12
12
  }
13
13
  for (const key in second.properties) {
14
14
  if (key in properties) {
15
- properties[key] = (0, merge_js_1.mergeSchemasOrRefs)(properties[key], second.properties[key], getRef);
15
+ properties[key] = (0, merge_js_1.mergeSchemasOrRefs)(properties[key], second.properties[key], getRef, normalize);
16
16
  }
17
17
  else {
18
18
  properties[key] = second.properties[key];
@@ -1,3 +1,3 @@
1
1
  import type { OpenAPIV3 } from 'openapi-types';
2
- import type { GetRefFn } from './types.js';
3
- export declare function mergeStringConstraints(first: OpenAPIV3.SchemaObject, second: OpenAPIV3.SchemaObject, getRef: GetRefFn): OpenAPIV3.SchemaObject;
2
+ import type { GetRefFn, NormalizeFn } from './types.js';
3
+ export declare function mergeStringConstraints(first: OpenAPIV3.SchemaObject, second: OpenAPIV3.SchemaObject, getRef: GetRefFn, normalize: NormalizeFn): OpenAPIV3.SchemaObject;
@@ -38,13 +38,13 @@ const generic_merge_js_1 = require("./generic-merge.js");
38
38
  const v = __importStar(require("valibot"));
39
39
  const check_type_conflicts_js_1 = require("./check-type-conflicts.js");
40
40
  const check_at_least_one_type_match_js_1 = require("./check-at-least-one-type-match.js");
41
- function mergeStringConstraints(first, second, getRef) {
41
+ function mergeStringConstraints(first, second, getRef, normalize) {
42
42
  (0, check_type_conflicts_js_1.checkTypeConflicts)(first, second);
43
43
  if (!(0, check_at_least_one_type_match_js_1.checkAtLeastOneTypeMatch)(first, second, 'string')) {
44
- return (0, generic_merge_js_1.genericMerge)(first, second, getRef);
44
+ return (0, generic_merge_js_1.genericMerge)(first, second, getRef, normalize);
45
45
  }
46
46
  // First merge enum values if present
47
- const result = (0, generic_merge_js_1.genericMerge)(first, second, getRef, v.string());
47
+ const result = (0, generic_merge_js_1.genericMerge)(first, second, getRef, normalize, v.string());
48
48
  // Then merge other constraints
49
49
  result.type = 'string';
50
50
  // Merge minLength
@@ -1,15 +1,17 @@
1
- import type { GetRefFn, SchemaOrReference, SchemaObject } from './types.js';
1
+ import type { GetRefFn, NormalizeFn, SchemaOrReference, SchemaObject } from './types.js';
2
2
  type MergeUnionArgs = {
3
3
  schema: SchemaObject;
4
4
  getRef: GetRefFn;
5
+ normalize: NormalizeFn;
5
6
  groupType: 'oneOf' | 'anyOf';
6
7
  };
7
- export declare const mergeUnion: ({ schema, getRef, groupType }: MergeUnionArgs) => SchemaOrReference;
8
+ export declare const mergeUnion: ({ schema, getRef, normalize, groupType }: MergeUnionArgs) => SchemaOrReference;
8
9
  type MergeCrossProductArgs = {
9
10
  first: SchemaObject;
10
11
  second: SchemaObject;
11
12
  getRef: GetRefFn;
13
+ normalize: NormalizeFn;
12
14
  groupType: 'oneOf' | 'anyOf';
13
15
  };
14
- export declare const mergeCrossProduct: ({ first, second, getRef, groupType }: MergeCrossProductArgs) => SchemaObject;
16
+ export declare const mergeCrossProduct: ({ first, second, getRef, normalize, groupType }: MergeCrossProductArgs) => SchemaObject;
15
17
  export {};
@@ -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;