@kubb/adapter-oas 5.0.0-alpha.53 → 5.0.0-alpha.55

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
@@ -1070,6 +1070,26 @@ function buildSchemaNode(schema, name, nullable, defaultValue) {
1070
1070
  example: schema.example
1071
1071
  };
1072
1072
  }
1073
+ /**
1074
+ * Returns all request body content type keys for an operation.
1075
+ *
1076
+ * The requestBody is dereferenced **in-place** when it is a `$ref` — the same mutation
1077
+ * that `getRequestSchema` already performs — so that the returned list accurately reflects
1078
+ * the available content types even for referenced bodies.
1079
+ *
1080
+ * @example
1081
+ * ```ts
1082
+ * getRequestBodyContentTypes(document, operation)
1083
+ * // ['application/json', 'multipart/form-data']
1084
+ * ```
1085
+ */
1086
+ function getRequestBodyContentTypes(document, operation) {
1087
+ if (operation.schema.requestBody) operation.schema.requestBody = dereferenceWithRef(document, operation.schema.requestBody);
1088
+ const body = operation.schema.requestBody;
1089
+ if (!body || isReference(body)) return [];
1090
+ const inline = body;
1091
+ return inline.content ? Object.keys(inline.content) : [];
1092
+ }
1073
1093
  //#endregion
1074
1094
  //#region src/parser.ts
1075
1095
  /**
@@ -1657,7 +1677,7 @@ function createSchemaParser(ctx) {
1657
1677
  });
1658
1678
  }
1659
1679
  /**
1660
- * Reads the inline `requestBody` metadata (description / required / contentType) that OAS exposes
1680
+ * Reads the inline `requestBody` metadata (description / required) that OAS exposes
1661
1681
  * outside the schema itself. Returns an empty object when the request body is missing or a `$ref`.
1662
1682
  */
1663
1683
  function getRequestBodyMeta(operation) {
@@ -1666,8 +1686,7 @@ function createSchemaParser(ctx) {
1666
1686
  const inline = body;
1667
1687
  return {
1668
1688
  description: inline.description,
1669
- required: inline.required === true,
1670
- contentType: inline.content ? Object.keys(inline.content)[0] : void 0
1689
+ required: inline.required === true
1671
1690
  };
1672
1691
  }
1673
1692
  /**
@@ -1699,15 +1718,21 @@ function createSchemaParser(ctx) {
1699
1718
  */
1700
1719
  function parseOperation(options, operation) {
1701
1720
  const parameters = getParameters(document, operation).map((param) => parseParameter(options, param));
1702
- const requestBodySchema = getRequestSchema(document, operation, { contentType: ctx.contentType });
1703
- const requestBodySchemaNode = requestBodySchema ? parseSchema({ schema: requestBodySchema }, options) : void 0;
1721
+ const allContentTypes = ctx.contentType ? [ctx.contentType] : getRequestBodyContentTypes(document, operation);
1704
1722
  const requestBodyMeta = getRequestBodyMeta(operation);
1705
- const requestBody = requestBodySchemaNode ? {
1723
+ const content = allContentTypes.flatMap((ct) => {
1724
+ const schema = getRequestSchema(document, operation, { contentType: ct });
1725
+ if (!schema) return [];
1726
+ return [{
1727
+ contentType: ct,
1728
+ schema: _kubb_core.ast.syncOptionality(parseSchema({ schema }, options), requestBodyMeta.required),
1729
+ keysToOmit: collectPropertyKeysByFlag(schema, "readOnly")
1730
+ }];
1731
+ });
1732
+ const requestBody = content.length > 0 || requestBodyMeta.description ? {
1706
1733
  description: requestBodyMeta.description,
1707
- schema: _kubb_core.ast.syncOptionality(requestBodySchemaNode, requestBodyMeta.required),
1708
- keysToOmit: collectPropertyKeysByFlag(requestBodySchema, "readOnly"),
1709
1734
  required: requestBodyMeta.required || void 0,
1710
- contentType: requestBodyMeta.contentType
1735
+ content: content.length > 0 ? content : void 0
1711
1736
  } : void 0;
1712
1737
  const responses = operation.getResponseStatusCodes().map((statusCode) => {
1713
1738
  const responseObj = operation.getResponseByStatusCode(statusCode);