@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
@@ -0,0 +1,213 @@
1
+ /**
2
+ * OpenAPI 3.1 lets a schema's `type` be an ARRAY (e.g. `['string', 'null']`),
3
+ * which the shared IR — modelling a single `type` plus a `nullable` flag —
4
+ * does not. Normalize the array form into shapes the rest of the dispatcher
5
+ * already understands:
6
+ *
7
+ * - `['T', 'null']` (one non-null type) → `{ type: 'T', nullable: true }`.
8
+ * An array type without `items` keeps `items` absent (unknown items).
9
+ * - `['T1', 'T2', …]` (several non-null) → a `oneOf` of the bare types,
10
+ * i.e. the 3.1 multi-type union. 3.0 cannot express this — it is the
11
+ * CASE-2 gap where the v3-0 parser degrades to OasUnknown.
12
+ * - `['null']` (only null) → left unchanged → OasUnknown,
13
+ * since there is no first-class OasNull IR node yet (a documented gap).
14
+ * Inside a merge, {@link normalizeMergeMember} handles it.
15
+ *
16
+ * The hoisted `nullable` flag is the IR's representation of nullability; the
17
+ * leaf parsers read it via `parseNullable`. A non-array `type` passes through.
18
+ */
19
+ const normalizeTypeArray = (schema) => {
20
+ const rawType = schema.type;
21
+ if (!Array.isArray(rawType)) {
22
+ return schema;
23
+ }
24
+ const members = rawType.filter(member => member !== 'null');
25
+ const nullable = rawType.length !== members.length || schema.nullable;
26
+ // Only `null` (`type: ['null']`): no OasNull node yet — fall through.
27
+ if (members.length === 0) {
28
+ return schema;
29
+ }
30
+ // Several non-null types: a 3.1 multi-type union. Model it as a `oneOf`
31
+ // of the bare types and let the oneOf branch build the OasUnion.
32
+ if (members.length > 1) {
33
+ const { type: _type, ...rest } = schema;
34
+ return { ...rest, nullable, oneOf: members.map(member => ({ type: member })) };
35
+ }
36
+ // Exactly one non-null type: dispatch as that type, carrying nullability.
37
+ switch (members[0]) {
38
+ case 'object':
39
+ case 'integer':
40
+ case 'number':
41
+ case 'boolean':
42
+ case 'string':
43
+ case 'array':
44
+ return { ...schema, type: members[0], nullable };
45
+ default:
46
+ return schema;
47
+ }
48
+ };
49
+ /**
50
+ * OpenAPI 3.1 `const: X` is the single-value form of `enum` (3.0 expresses a
51
+ * literal as a one-element `enum`). Rewrite it so the existing enum-aware leaf
52
+ * parsers handle it; matches down-convert's `convertConstToEnum`, so a 3.0
53
+ * `enum:[X]` and a 3.1 `const:X` land on the same IR.
54
+ */
55
+ const normalizeConst = (schema) => {
56
+ if (!('const' in schema)) {
57
+ return schema;
58
+ }
59
+ // `const` is a 3.1 keyword the 3.0-typed SchemaObject does not model; read
60
+ // it via an annotated destructure rather than a cast.
61
+ const { const: constValue, ...rest } = schema;
62
+ return { ...rest, enum: [constValue] };
63
+ };
64
+ /**
65
+ * OpenAPI 3.1 schemas carry `examples` (an array, JSON Schema 2020-12); 3.0
66
+ * and the IR use a single `example`. Adopt the first array element as the IR
67
+ * `example` when no singular `example` is set, and drop the array. Matches
68
+ * down-convert's `convertJsonSchemaExamples`.
69
+ */
70
+ const normalizeExamples = (schema) => {
71
+ if ('example' in schema || !('examples' in schema)) {
72
+ return schema;
73
+ }
74
+ // `examples` is a 3.1 keyword the 3.0-typed SchemaObject does not model.
75
+ const { examples, ...rest } = schema;
76
+ if (!Array.isArray(examples) || examples.length === 0) {
77
+ return rest;
78
+ }
79
+ return { ...rest, example: examples[0] };
80
+ };
81
+ /**
82
+ * OpenAPI 3.1 expresses exclusive bounds as NUMBERS (`exclusiveMinimum: 5`
83
+ * means "> 5"); the shared IR (and 3.0) model them as a boolean flag paired
84
+ * with `minimum`/`maximum`. Convert the numeric form so the number/integer
85
+ * leaves validate. Matches down-convert's `convertExclusiveMinMax`, so a 3.0
86
+ * `{minimum:5, exclusiveMinimum:true}` and a 3.1 `{exclusiveMinimum:5}` land
87
+ * on the same IR.
88
+ */
89
+ const normalizeExclusiveBounds = (schema) => {
90
+ // `exclusiveMinimum`/`exclusiveMaximum` are 3.0-typed boolean here; in 3.1
91
+ // they arrive as numbers, so read them loosely.
92
+ const exclusiveMinimum = schema.exclusiveMinimum;
93
+ const exclusiveMaximum = schema.exclusiveMaximum;
94
+ if (typeof exclusiveMinimum !== 'number' && typeof exclusiveMaximum !== 'number') {
95
+ return schema;
96
+ }
97
+ const next = { ...schema };
98
+ if (typeof exclusiveMinimum === 'number') {
99
+ next.minimum = exclusiveMinimum;
100
+ next.exclusiveMinimum = true;
101
+ }
102
+ if (typeof exclusiveMaximum === 'number') {
103
+ next.maximum = exclusiveMaximum;
104
+ next.exclusiveMaximum = true;
105
+ }
106
+ return next;
107
+ };
108
+ /**
109
+ * OpenAPI 3.1 / JSON Schema 2020-12 expresses a binary string payload with
110
+ * `contentMediaType: 'application/octet-stream'` and base64 with
111
+ * `contentEncoding: 'base64'`; the shared IR (and 3.0) carry these as a string
112
+ * `format` (`binary` / `byte`, both in the format allow-list). Map them so the
113
+ * format reaches the IR. Mirrors down-convert's
114
+ * `convertJsonSchemaContentMediaType` / `convertJsonSchemaContentEncoding`:
115
+ * string schemas only, and a pre-existing (conflicting) `format` wins — the
116
+ * content keyword is dropped, not overwritten. Without this, retiring
117
+ * down-convert would silently lose the `format` signal on 3.1 binary uploads.
118
+ */
119
+ const normalizeContentFormat = (schema) => {
120
+ if (schema.type !== 'string') {
121
+ return schema;
122
+ }
123
+ // `contentMediaType`/`contentEncoding` are 3.1 keywords the 3.0-typed
124
+ // SchemaObject does not model; read them loosely.
125
+ const view = schema;
126
+ const derivedFormat = view.contentMediaType === 'application/octet-stream'
127
+ ? 'binary'
128
+ : view.contentEncoding === 'base64'
129
+ ? 'byte'
130
+ : undefined;
131
+ if (derivedFormat === undefined) {
132
+ return schema;
133
+ }
134
+ const { contentMediaType: _contentMediaType, contentEncoding: _contentEncoding, ...rest } = view;
135
+ return 'format' in rest ? rest : { ...rest, format: derivedFormat };
136
+ };
137
+ /**
138
+ * In-place applicators that evaluate keys `unevaluatedProperties` would
139
+ * otherwise see. `$ref` never reaches `normalizeSchemaShape`, and both the
140
+ * dispatcher and the merge refuse a schema with `not`.
141
+ */
142
+ const inPlaceApplicators = [
143
+ 'allOf',
144
+ 'oneOf',
145
+ 'anyOf',
146
+ 'if',
147
+ 'then',
148
+ 'else',
149
+ 'dependentSchemas',
150
+ '$dynamicRef'
151
+ ];
152
+ /**
153
+ * With no in-place applicator on the same schema, `unevaluatedProperties`
154
+ * means the same as `additionalProperties` (JSON Schema 2020-12 §11.3,
155
+ * §10.3.2.3), so rename it. When `additionalProperties` is also present it
156
+ * evaluates every remaining key, so `unevaluatedProperties` is dropped.
157
+ */
158
+ const normalizeUnevaluatedProperties = (schema) => {
159
+ if (!('unevaluatedProperties' in schema)) {
160
+ return schema;
161
+ }
162
+ if (inPlaceApplicators.some(keyword => keyword in schema)) {
163
+ return schema;
164
+ }
165
+ // `unevaluatedProperties` is a 3.1 keyword the 3.0-typed SchemaObject does
166
+ // not model; read it via an annotated destructure.
167
+ const { unevaluatedProperties, ...rest } = schema;
168
+ if ('additionalProperties' in rest) {
169
+ return rest;
170
+ }
171
+ if (!isAdditionalPropertiesValue(unevaluatedProperties)) {
172
+ return schema;
173
+ }
174
+ return { ...rest, additionalProperties: unevaluatedProperties };
175
+ };
176
+ /**
177
+ * Is this a value `additionalProperties` accepts: a boolean, or a schema or
178
+ * `$ref` object?
179
+ */
180
+ const isAdditionalPropertiesValue = (value) => typeof value === 'boolean' ||
181
+ (typeof value === 'object' && value !== null && !Array.isArray(value));
182
+ /**
183
+ * Map the 3.1-only schema-shape encodings onto the shared IR shape before
184
+ * dispatching: `unevaluatedProperties`, type arrays, `const`, `examples[]`,
185
+ * numeric exclusive bounds, and binary/base64 content keywords. Each step
186
+ * returns its input unchanged when it does not apply, so the composed result
187
+ * is referentially equal to `schema` when nothing matched — letting the
188
+ * dispatcher re-dispatch only when needed. Idempotent: a normalized schema
189
+ * comes back as the same object.
190
+ */
191
+ export const normalizeSchemaShape = (schema) => {
192
+ return normalizeExclusiveBounds(normalizeExamples(normalizeConst(normalizeContentFormat(normalizeTypeArray(normalizeUnevaluatedProperties(schema))))));
193
+ };
194
+ /**
195
+ * Is `type` only `null` (`'null'` or `['null']`)? `'null'` is a 3.1 type the
196
+ * 3.0-typed SchemaObject does not model, so read it loosely.
197
+ */
198
+ export const isNullOnlyType = (type) => type === 'null' || (Array.isArray(type) && type.length > 0 && type.every(item => item === 'null'));
199
+ /**
200
+ * Normalize a schema as it enters the `allOf`/`oneOf`/`anyOf` merge: the
201
+ * {@link normalizeSchemaShape} rules, plus a null-only member (`type: 'null'`
202
+ * or `['null']`) becomes `{ nullable: true }` with no `type`, so it adds
203
+ * nullability instead of conflicting with the other members' types.
204
+ * Idempotent, like `normalizeSchemaShape`.
205
+ */
206
+ export const normalizeMergeMember = (schema) => {
207
+ const normalized = normalizeSchemaShape(schema);
208
+ if (!isNullOnlyType(normalized.type)) {
209
+ return normalized;
210
+ }
211
+ const { type: _type, ...rest } = normalized;
212
+ return { ...rest, nullable: true };
213
+ };
@@ -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)) {
@@ -1,9 +1,23 @@
1
1
  import { OasServer } from '../../../oas/server/Server.js';
2
2
  import { toSpecificationExtensionsV3 } from '../specificationExtensions/toSpecificationExtensionsV3.js';
3
3
  import { toOptionalServerVariablesV3 } from '../serverVariable/toServerVariableV3.js';
4
+ import { tryParseAt } from '../../../context/tryParseAt.js';
4
5
  export const toServersV3 = ({ servers, stackTrail, context }) => {
5
- return servers.map((server, index) => {
6
- return stackTrail.trace(server.url ?? index, st => toServerV3({ server, stackTrail: st, context }));
6
+ return servers.flatMap((server, index) => {
7
+ const parsed = tryParseAt({
8
+ stackTrail,
9
+ key: `${index}`,
10
+ context,
11
+ type: 'INVALID_OPERATION',
12
+ parent: servers,
13
+ fn: st => {
14
+ if (typeof server?.url !== 'string') {
15
+ throw new Error(`Expected a Server Object with a string url, got: ${JSON.stringify(server)}`);
16
+ }
17
+ return toServerV3({ server, stackTrail: st, context });
18
+ }
19
+ });
20
+ return parsed ? [parsed] : [];
7
21
  });
8
22
  };
9
23
  export const toOptionalServersV3 = ({ servers, stackTrail, context }) => {
@@ -111,8 +111,7 @@ export const toWebhooksV3 = ({ webhooks, stackTrail, context }) => {
111
111
  }
112
112
  catch (error) {
113
113
  const normalized = error instanceof Error ? error : new Error(String(error));
114
- context.logIssue({
115
- key: method,
114
+ context.logIssueNoKey({
116
115
  parent: operation,
117
116
  level: 'error',
118
117
  message: normalized.message,
@@ -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,7 +1,11 @@
1
- export const checkArrayItemTypeConflicts = (a, b) => {
1
+ import { isRef } from '../../../helpers/refFns.js';
2
+ export const checkArrayItemTypeConflicts = (a, b, normalize) => {
2
3
  if (a.type === 'array' && b.type === 'array' && 'items' in a && 'items' in b) {
3
- const aItems = a.items;
4
- const bItems = b.items;
4
+ if (isRef(a.items) || isRef(b.items)) {
5
+ return;
6
+ }
7
+ const aItems = normalize(a.items);
8
+ const bItems = normalize(b.items);
5
9
  if (aItems.type && bItems.type && aItems.type !== bItems.type) {
6
10
  throw new Error(`Cannot merge schemas: array items have conflicting types '${aItems.type}' and '${bItems.type}'`);
7
11
  }
@@ -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;
@@ -1,11 +1,11 @@
1
1
  import { mergeEnumValues } from './merge-enum-values.js';
2
2
  import { mergeProperties } from './merge-properties.js';
3
3
  import { mergeRequired } from './merge-required.js';
4
- export const genericMerge = (first, second, getRef, typeCheck) => {
4
+ export const genericMerge = (first, second, getRef, normalize, typeCheck) => {
5
5
  return {
6
6
  ...first,
7
7
  ...second,
8
- ...mergeProperties(first, second, getRef),
8
+ ...mergeProperties(first, second, getRef, normalize),
9
9
  ...mergeRequired(first, second),
10
10
  ...mergeEnumValues(first, second, typeCheck)
11
11
  };
@@ -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;
@@ -2,16 +2,12 @@ import { mergeSchemasOrRefs } from './merge.js';
2
2
  import { genericMerge } from './generic-merge.js';
3
3
  import * as v from 'valibot';
4
4
  import { checkTypeConflicts } from './check-type-conflicts.js';
5
- export function mergeArrayConstraints(first, second, getRef) {
5
+ export function mergeArrayConstraints(first, second, getRef, normalize) {
6
6
  checkTypeConflicts(first, second);
7
- if (!('items' in first) && !('items' in second)) {
8
- throw new Error('Cannot merge array constraints: no items found');
9
- }
10
- const result = {
11
- ...genericMerge(first, second, getRef, v.array(v.any())),
12
- type: 'array',
13
- items: mergeItems(first, second, getRef)
14
- };
7
+ const merged = genericMerge(first, second, getRef, normalize, v.array(v.any()));
8
+ const items = mergeItems(first, second, getRef, normalize);
9
+ // With no `items` on either side, `items` stays absent (unknown items).
10
+ const result = items === undefined ? merged : { ...merged, type: 'array', items };
15
11
  // Merge minItems
16
12
  if (first.minItems !== undefined || second.minItems !== undefined) {
17
13
  const minA = first.minItems ?? 0;
@@ -30,9 +26,9 @@ export function mergeArrayConstraints(first, second, getRef) {
30
26
  }
31
27
  return result;
32
28
  }
33
- const mergeItems = (first, second, getRef) => {
29
+ const mergeItems = (first, second, getRef, normalize) => {
34
30
  if ('items' in first && 'items' in second && first.items && second.items) {
35
- return mergeSchemasOrRefs(first.items, second.items, getRef);
31
+ return mergeSchemasOrRefs(first.items, second.items, getRef, normalize);
36
32
  }
37
33
  if ('items' in first && first.items) {
38
34
  return first.items;
@@ -40,5 +36,5 @@ const mergeItems = (first, second, getRef) => {
40
36
  if ('items' in second && second.items) {
41
37
  return second.items;
42
38
  }
43
- throw new Error('Cannot merge array constraints: no items found');
39
+ return undefined;
44
40
  };
@@ -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;
@@ -1,7 +1,7 @@
1
1
  import { genericMerge } from './generic-merge.js';
2
2
  import * as v from 'valibot';
3
3
  import { checkTypeConflicts } from './check-type-conflicts.js';
4
- export function mergeBooleanConstraints(first, second, getRef) {
4
+ export function mergeBooleanConstraints(first, second, getRef, normalize) {
5
5
  checkTypeConflicts(first, second);
6
- return genericMerge(first, second, getRef, v.boolean());
6
+ return genericMerge(first, second, getRef, normalize, v.boolean());
7
7
  }
@@ -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;
@@ -1,10 +1,10 @@
1
1
  import { genericMerge } from './generic-merge.js';
2
2
  import * as v from 'valibot';
3
3
  import { checkTypeConflicts } from './check-type-conflicts.js';
4
- export function mergeIntegerConstraints(first, second, getRef) {
4
+ export function mergeIntegerConstraints(first, second, getRef, normalize) {
5
5
  checkTypeConflicts(first, second);
6
6
  // First merge enum values if present
7
- const result = genericMerge(first, second, getRef, v.number());
7
+ const result = genericMerge(first, second, getRef, normalize, v.number());
8
8
  // Then merge other constraints
9
9
  result.type = 'integer';
10
10
  // 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 {};
@@ -1,6 +1,6 @@
1
1
  import { decomposeIntersection } from './decompose-intersection.js';
2
2
  import { mergeSchemasOrRefs } from './merge.js';
3
- export const mergeIntersection = ({ schema, getRef }) => {
3
+ export const mergeIntersection = ({ schema, getRef, normalize }) => {
4
4
  const decomposed = decomposeIntersection({ schema });
5
5
  if (decomposed.length === 1) {
6
6
  return decomposed[0];
@@ -9,7 +9,7 @@ export const mergeIntersection = ({ schema, getRef }) => {
9
9
  return '$ref' in decomposed ? getRef(decomposed) : decomposed;
10
10
  });
11
11
  const result = dereffed.reduce((acc, decomposed) => {
12
- const merged = mergeSchemasOrRefs(acc, decomposed, getRef);
12
+ const merged = mergeSchemasOrRefs(acc, decomposed, getRef, normalize);
13
13
  return merged;
14
14
  }, {});
15
15
  return result;