@kubb/ast 5.0.0-alpha.52 → 5.0.0-alpha.54

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.d.ts CHANGED
@@ -1740,26 +1740,41 @@ type OperationNode = BaseNode & {
1740
1740
  * Human-readable request body description.
1741
1741
  */
1742
1742
  description?: string;
1743
- /**
1744
- * Request body schema.
1745
- * For OpenAPI, this is the schema from the first `content` entry.
1746
- */
1747
- schema?: SchemaNode;
1748
- /**
1749
- * Property keys to exclude from the generated request body type via `Omit<Type, Keys>`.
1750
- * Set when a referenced schema has `readOnly` fields that should be omitted in request types.
1751
- */
1752
- keysToOmit?: Array<string>;
1753
1743
  /**
1754
1744
  * Whether the request body is required (`requestBody.required: true` in the spec).
1755
1745
  * When `false` or absent, the generated `data` parameter should be optional.
1756
1746
  */
1757
1747
  required?: boolean;
1758
1748
  /**
1759
- * Media type of the request body (e.g. `'application/json'`, `'multipart/form-data'`).
1760
- * Extracted from the first `content` entry of the OpenAPI `requestBody`.
1749
+ * All available content type entries for this request body.
1750
+ *
1751
+ * When the adapter `contentType` option is set, this array contains exactly one entry for
1752
+ * that content type. Otherwise it contains one entry per content type declared in the spec,
1753
+ * so that plugins can generate code for every variant (e.g. separate hooks for
1754
+ * `application/json` and `multipart/form-data`).
1755
+ *
1756
+ * @example
1757
+ * ```ts
1758
+ * // spec has both application/json and multipart/form-data
1759
+ * requestBody.content[0].contentType // 'application/json'
1760
+ * requestBody.content[1].contentType // 'multipart/form-data'
1761
+ * ```
1761
1762
  */
1762
- contentType?: string;
1763
+ content?: Array<{
1764
+ /**
1765
+ * The content type for this entry (e.g. `'application/json'`).
1766
+ */
1767
+ contentType: string;
1768
+ /**
1769
+ * Request body schema for this content type.
1770
+ */
1771
+ schema?: SchemaNode;
1772
+ /**
1773
+ * Property keys to exclude from the generated request body type via `Omit<Type, Keys>`.
1774
+ * Set when a referenced schema has `readOnly` fields that should be omitted in request types.
1775
+ */
1776
+ keysToOmit?: Array<string>;
1777
+ }>;
1763
1778
  };
1764
1779
  /**
1765
1780
  * Operation responses.
package/dist/index.js CHANGED
@@ -431,7 +431,7 @@ function createOperationParams(node, options) {
431
431
  const pathParams = casedParams.filter((p) => p.in === "path");
432
432
  const queryParams = casedParams.filter((p) => p.in === "query");
433
433
  const headerParams = casedParams.filter((p) => p.in === "header");
434
- const bodyType = node.requestBody?.schema ? wrapType(resolver?.resolveDataName(node) ?? "unknown") : void 0;
434
+ const bodyType = node.requestBody?.content?.[0]?.schema ? wrapType(resolver?.resolveDataName(node) ?? "unknown") : void 0;
435
435
  const bodyRequired = node.requestBody?.required ?? false;
436
436
  const queryGroupType = resolver ? resolveGroupType({
437
437
  node,
@@ -1513,7 +1513,7 @@ function getChildren(node, recurse) {
1513
1513
  case "Output": return [];
1514
1514
  case "Operation": return [
1515
1515
  ...node.parameters,
1516
- ...node.requestBody?.schema ? [node.requestBody.schema] : [],
1516
+ ...node.requestBody?.content?.flatMap((c) => c.schema ? [c.schema] : []) ?? [],
1517
1517
  ...node.responses
1518
1518
  ];
1519
1519
  case "Schema": {
@@ -1626,10 +1626,13 @@ function transform(node, options) {
1626
1626
  })),
1627
1627
  requestBody: op.requestBody ? {
1628
1628
  ...op.requestBody,
1629
- schema: op.requestBody.schema ? transform(op.requestBody.schema, {
1630
- ...options,
1631
- parent: op
1632
- }) : void 0
1629
+ content: op.requestBody.content?.map((c) => ({
1630
+ ...c,
1631
+ schema: c.schema ? transform(c.schema, {
1632
+ ...options,
1633
+ parent: op
1634
+ }) : void 0
1635
+ }))
1633
1636
  } : void 0,
1634
1637
  responses: op.responses.map((r) => transform(r, {
1635
1638
  ...options,