@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.js CHANGED
@@ -594,6 +594,19 @@ function isBinary(schema) {
594
594
  return schema.type === "string" && schema.contentMediaType === "application/octet-stream";
595
595
  }
596
596
  /**
597
+ * Returns the binary schema for an `application/octet-stream` entry the OAS 3.1 upgrade emptied
598
+ * out, or `undefined` when the entry carries a schema of its own. Without the fallback such a
599
+ * body resolves to the empty schema type instead of a blob.
600
+ */
601
+ function getBinaryFallbackSchema(mediaType, schema) {
602
+ if (mediaType !== "application/octet-stream") return void 0;
603
+ if (schema && Object.keys(schema).length > 0) return void 0;
604
+ return {
605
+ type: "string",
606
+ contentMediaType: "application/octet-stream"
607
+ };
608
+ }
609
+ /**
597
610
  * MIME type fragments that mark a media type as JSON-like.
598
611
  *
599
612
  * A content type is JSON when it contains any of these substrings. The `+json` entry catches
@@ -1358,10 +1371,7 @@ function convertUnion({ schema, name, nullable, defaultValue, rawOptions, parse,
1358
1371
  };
1359
1372
  const unionMembers = [...schema.oneOf ?? [], ...schema.anyOf ?? []];
1360
1373
  const strategy = schema.oneOf ? "one" : "any";
1361
- const unionExtras = {
1362
- discriminatorPropertyName: isDiscriminator(schema) ? schema.discriminator.propertyName : void 0,
1363
- strategy
1364
- };
1374
+ const explicitDiscriminatorPropertyName = isDiscriminator(schema) ? schema.discriminator.propertyName : void 0;
1365
1375
  const discriminator = isDiscriminator(schema) ? schema.discriminator : void 0;
1366
1376
  const { oneOf: _o, anyOf: _a, discriminator: _d, ...memberBaseSchema } = schema;
1367
1377
  const sharedPropertiesNode = schema.properties ? parse({
@@ -1380,8 +1390,9 @@ function convertUnion({ schema, name, nullable, defaultValue, rawOptions, parse,
1380
1390
  });
1381
1391
  const unionNode = createNode(ctx, {
1382
1392
  type: "union",
1383
- ...unionExtras,
1384
- members
1393
+ strategy,
1394
+ members,
1395
+ discriminatorPropertyName: explicitDiscriminatorPropertyName ?? ast.inferDiscriminatorPropertyName(members)
1385
1396
  });
1386
1397
  if (!sharedPropertiesNode) return unionNode;
1387
1398
  return createNode(ctx, {
@@ -1389,13 +1400,15 @@ function convertUnion({ schema, name, nullable, defaultValue, rawOptions, parse,
1389
1400
  members: [unionNode, sharedPropertiesNode]
1390
1401
  });
1391
1402
  }
1403
+ const members = unionMembers.map((s) => parse({
1404
+ schema: s,
1405
+ name
1406
+ }, rawOptions));
1392
1407
  const unionNode = createNode(ctx, {
1393
1408
  type: "union",
1394
- ...unionExtras,
1395
- members: unionMembers.map((s) => parse({
1396
- schema: s,
1397
- name
1398
- }, rawOptions))
1409
+ strategy,
1410
+ members,
1411
+ discriminatorPropertyName: explicitDiscriminatorPropertyName ?? ast.inferDiscriminatorPropertyName(members)
1399
1412
  });
1400
1413
  return ast.applyMacros(unionNode, [macroSimplifyUnion], { depth: "shallow" });
1401
1414
  }
@@ -2062,9 +2075,8 @@ function getResponseBody(responseBody, contentType) {
2062
2075
  if (isReference(responseBody)) return false;
2063
2076
  const body = responseBody;
2064
2077
  if (!body.content) return false;
2065
- if (contentType) return contentType in body.content ? body.content[contentType] : false;
2066
- const picked = pickContentEntry(body.content);
2067
- return picked ? picked[1] : false;
2078
+ if (contentType) return contentType in body.content ? [contentType, body.content[contentType]] : false;
2079
+ return pickContentEntry(body.content);
2068
2080
  }
2069
2081
  /**
2070
2082
  * Returns the response schema for a given operation and HTTP status code.
@@ -2084,7 +2096,10 @@ function getResponseSchema({ document, operation, refs, statusCode, options = {}
2084
2096
  statusCode
2085
2097
  }), options.contentType);
2086
2098
  if (responseBody === false) return {};
2087
- const schema = responseBody.schema;
2099
+ const [mediaType, entry] = responseBody;
2100
+ const schema = entry.schema;
2101
+ const binary = getBinaryFallbackSchema(mediaType, schema);
2102
+ if (binary) return binary;
2088
2103
  if (!schema) return {};
2089
2104
  return dereferenceWithRef(document, schema);
2090
2105
  }
@@ -2105,10 +2120,8 @@ function getRequestSchema({ document, operation, refs, options = {} }) {
2105
2120
  if (requestBody === false) return null;
2106
2121
  const mediaType = Array.isArray(requestBody) ? requestBody[0] : options.contentType;
2107
2122
  const schema = Array.isArray(requestBody) ? requestBody[1].schema : requestBody.schema;
2108
- if (mediaType === "application/octet-stream" && (!schema || Object.keys(schema).length === 0)) return {
2109
- type: "string",
2110
- contentMediaType: "application/octet-stream"
2111
- };
2123
+ const binary = getBinaryFallbackSchema(mediaType, schema);
2124
+ if (binary) return binary;
2112
2125
  if (!schema) return null;
2113
2126
  return dereferenceWithRef(document, schema);
2114
2127
  }