@kubb/adapter-oas 5.27.1 → 5.28.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -17,7 +17,7 @@ var compatibility = {
17
17
  "node": ">=22.22"
18
18
  };
19
19
  // package.json
20
- var version = "5.27.1";
20
+ var version = "5.28.1";
21
21
  // src/constants.ts
22
22
  /**
23
23
  * Default parser options applied when no explicit options are provided.
@@ -2021,6 +2021,13 @@ function extractExamples(schema) {
2021
2021
  if (Array.isArray(schema.examples)) return schema.examples;
2022
2022
  return schema.example !== void 0 ? [schema.example] : void 0;
2023
2023
  }
2024
+ /**
2025
+ * Whether the schema and its inline `allOf` members hold more than one distinct `pattern`. A value must match every one.
2026
+ */
2027
+ function hasSeveralPatterns(schema) {
2028
+ const patterns = [schema, ...schema.allOf ?? []].map((item) => isReference(item) ? void 0 : item.pattern).filter((pattern) => pattern !== void 0);
2029
+ return new Set(patterns).size > 1;
2030
+ }
2024
2031
  function hasStructuralKeywords(fragment) {
2025
2032
  return Object.keys(fragment).some((key) => structuralKeys.has(key));
2026
2033
  }
@@ -2044,6 +2051,7 @@ function flattenSchema(schema) {
2044
2051
  const allOfFragments = schema.allOf;
2045
2052
  if (allOfFragments.some((item) => isReference(item))) return schema;
2046
2053
  if (allOfFragments.some(hasStructuralKeywords)) return schema;
2054
+ if (hasSeveralPatterns(schema)) return schema;
2047
2055
  const { allOf: _allOf, ...rest } = schema;
2048
2056
  const merged = rest;
2049
2057
  for (const fragment of allOfFragments) for (const [key, value] of Object.entries(fragment)) merged[key] ??= value;
@@ -3191,11 +3199,26 @@ function mergeAnnotations(schema) {
3191
3199
  } : schema;
3192
3200
  }
3193
3201
  /**
3202
+ * Whether the parent's own keywords become an intersection member: always beside `properties`, and
3203
+ * beside several patterns when the parent holds more than its type and annotations, such as `minLength`.
3204
+ */
3205
+ function keepsOwnKeywords(schema) {
3206
+ if (schema.properties) return true;
3207
+ if (!hasSeveralPatterns(schema)) return false;
3208
+ return Object.keys(schema).some((key) => key !== "allOf" && key !== "type" && key !== "nullable" && !annotationKeys.has(key));
3209
+ }
3210
+ /**
3211
+ * Whether a one-member `allOf` adds nothing but annotations, so it parses as that member.
3212
+ */
3213
+ function isSingleMemberAllOf(schema) {
3214
+ return schema.allOf.length === 1 && !schema.properties && !(Array.isArray(schema.required) && schema.required.length) && schema.additionalProperties === void 0 && !hasSeveralPatterns(schema);
3215
+ }
3216
+ /**
3194
3217
  * Converts an `allOf` schema into a flattened node or an `IntersectionSchemaNode`.
3195
3218
  */
3196
3219
  function convertAllOf({ schema: original, name, nullable, defaultValue, parse, refs }) {
3197
3220
  const schema = mergeAnnotations(original);
3198
- if (schema.allOf.length === 1 && !schema.properties && !(Array.isArray(schema.required) && schema.required.length) && schema.additionalProperties === void 0) {
3221
+ if (isSingleMemberAllOf(schema)) {
3199
3222
  const [memberSchema] = schema.allOf;
3200
3223
  const memberNode = parse({
3201
3224
  schema: memberSchema,
@@ -3268,7 +3291,7 @@ function convertAllOf({ schema: original, name, nullable, defaultValue, parse, r
3268
3291
  }
3269
3292
  }
3270
3293
  }
3271
- if (schema.properties) {
3294
+ if (keepsOwnKeywords(schema)) {
3272
3295
  const { allOf: _allOf, ...schemaWithoutAllOf } = schema;
3273
3296
  allOfMembers.push(parse({ schema: schemaWithoutAllOf }));
3274
3297
  }