@kubb/adapter-oas 5.2.0 → 5.2.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.
package/dist/index.cjs CHANGED
@@ -617,6 +617,19 @@ function isBinary(schema) {
617
617
  return schema.type === "string" && schema.contentMediaType === "application/octet-stream";
618
618
  }
619
619
  /**
620
+ * Returns the binary schema for an `application/octet-stream` entry the OAS 3.1 upgrade emptied
621
+ * out, or `undefined` when the entry carries a schema of its own. Without the fallback such a
622
+ * body resolves to the empty schema type instead of a blob.
623
+ */
624
+ function getBinaryFallbackSchema(mediaType, schema) {
625
+ if (mediaType !== "application/octet-stream") return void 0;
626
+ if (schema && Object.keys(schema).length > 0) return void 0;
627
+ return {
628
+ type: "string",
629
+ contentMediaType: "application/octet-stream"
630
+ };
631
+ }
632
+ /**
620
633
  * MIME type fragments that mark a media type as JSON-like.
621
634
  *
622
635
  * A content type is JSON when it contains any of these substrings. The `+json` entry catches
@@ -1381,10 +1394,7 @@ function convertUnion({ schema, name, nullable, defaultValue, rawOptions, parse,
1381
1394
  };
1382
1395
  const unionMembers = [...schema.oneOf ?? [], ...schema.anyOf ?? []];
1383
1396
  const strategy = schema.oneOf ? "one" : "any";
1384
- const unionExtras = {
1385
- discriminatorPropertyName: isDiscriminator(schema) ? schema.discriminator.propertyName : void 0,
1386
- strategy
1387
- };
1397
+ const explicitDiscriminatorPropertyName = isDiscriminator(schema) ? schema.discriminator.propertyName : void 0;
1388
1398
  const discriminator = isDiscriminator(schema) ? schema.discriminator : void 0;
1389
1399
  const { oneOf: _o, anyOf: _a, discriminator: _d, ...memberBaseSchema } = schema;
1390
1400
  const sharedPropertiesNode = schema.properties ? parse({
@@ -1403,8 +1413,9 @@ function convertUnion({ schema, name, nullable, defaultValue, rawOptions, parse,
1403
1413
  });
1404
1414
  const unionNode = createNode(ctx, {
1405
1415
  type: "union",
1406
- ...unionExtras,
1407
- members
1416
+ strategy,
1417
+ members,
1418
+ discriminatorPropertyName: explicitDiscriminatorPropertyName ?? _kubb_ast.ast.inferDiscriminatorPropertyName(members)
1408
1419
  });
1409
1420
  if (!sharedPropertiesNode) return unionNode;
1410
1421
  return createNode(ctx, {
@@ -1412,13 +1423,15 @@ function convertUnion({ schema, name, nullable, defaultValue, rawOptions, parse,
1412
1423
  members: [unionNode, sharedPropertiesNode]
1413
1424
  });
1414
1425
  }
1426
+ const members = unionMembers.map((s) => parse({
1427
+ schema: s,
1428
+ name
1429
+ }, rawOptions));
1415
1430
  const unionNode = createNode(ctx, {
1416
1431
  type: "union",
1417
- ...unionExtras,
1418
- members: unionMembers.map((s) => parse({
1419
- schema: s,
1420
- name
1421
- }, rawOptions))
1432
+ strategy,
1433
+ members,
1434
+ discriminatorPropertyName: explicitDiscriminatorPropertyName ?? _kubb_ast.ast.inferDiscriminatorPropertyName(members)
1422
1435
  });
1423
1436
  return _kubb_ast.ast.applyMacros(unionNode, [_kubb_kit.macroSimplifyUnion], { depth: "shallow" });
1424
1437
  }
@@ -2085,9 +2098,8 @@ function getResponseBody(responseBody, contentType) {
2085
2098
  if (isReference(responseBody)) return false;
2086
2099
  const body = responseBody;
2087
2100
  if (!body.content) return false;
2088
- if (contentType) return contentType in body.content ? body.content[contentType] : false;
2089
- const picked = pickContentEntry(body.content);
2090
- return picked ? picked[1] : false;
2101
+ if (contentType) return contentType in body.content ? [contentType, body.content[contentType]] : false;
2102
+ return pickContentEntry(body.content);
2091
2103
  }
2092
2104
  /**
2093
2105
  * Returns the response schema for a given operation and HTTP status code.
@@ -2107,7 +2119,10 @@ function getResponseSchema({ document, operation, refs, statusCode, options = {}
2107
2119
  statusCode
2108
2120
  }), options.contentType);
2109
2121
  if (responseBody === false) return {};
2110
- const schema = responseBody.schema;
2122
+ const [mediaType, entry] = responseBody;
2123
+ const schema = entry.schema;
2124
+ const binary = getBinaryFallbackSchema(mediaType, schema);
2125
+ if (binary) return binary;
2111
2126
  if (!schema) return {};
2112
2127
  return dereferenceWithRef(document, schema);
2113
2128
  }
@@ -2128,10 +2143,8 @@ function getRequestSchema({ document, operation, refs, options = {} }) {
2128
2143
  if (requestBody === false) return null;
2129
2144
  const mediaType = Array.isArray(requestBody) ? requestBody[0] : options.contentType;
2130
2145
  const schema = Array.isArray(requestBody) ? requestBody[1].schema : requestBody.schema;
2131
- if (mediaType === "application/octet-stream" && (!schema || Object.keys(schema).length === 0)) return {
2132
- type: "string",
2133
- contentMediaType: "application/octet-stream"
2134
- };
2146
+ const binary = getBinaryFallbackSchema(mediaType, schema);
2147
+ if (binary) return binary;
2135
2148
  if (!schema) return null;
2136
2149
  return dereferenceWithRef(document, schema);
2137
2150
  }