@kubb/plugin-ts 5.3.0-canary.20261025T201031 → 5.4.0-canary.20261025T213930

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
@@ -105,6 +105,7 @@ function screamingSnakeCase(text, { prefix = "", suffix = "" } = {}) {
105
105
  const reservedWords = /* @__PURE__ */ new Set([
106
106
  "abstract",
107
107
  "arguments",
108
+ "await",
108
109
  "boolean",
109
110
  "break",
110
111
  "byte",
@@ -950,7 +951,10 @@ function getOperationParameters(node) {
950
951
  * shape from the same inputs. `primitive: 'object'` is a no-op for the TS printer and tells the Zod
951
952
  * printer to emit `z.object(…)` rather than a record.
952
953
  */
953
- function buildOptionsSchema(node, resolver) {
954
+ function hasRequestContentTypeChoice(node) {
955
+ return (node.requestBody?.content ?? []).filter((entry) => entry.schema).length > 1;
956
+ }
957
+ function buildOptionsSchema(node, resolver, { pairContentTypes = false } = {}) {
954
958
  const { path, query, header } = getOperationParameters(node);
955
959
  const hasBody = Boolean(node.requestBody?.content?.[0]?.schema);
956
960
  const createNever = () => kubb_kit.ast.factory.createSchema({
@@ -975,29 +979,57 @@ function buildOptionsSchema(node, resolver) {
975
979
  resolve: resolver.param.headers
976
980
  }
977
981
  ];
978
- return kubb_kit.ast.factory.createSchema({
982
+ const createOptions = (body, extra = []) => kubb_kit.ast.factory.createSchema({
979
983
  type: "object",
980
984
  primitive: "object",
981
985
  deprecated: node.deprecated,
982
- properties: [kubb_kit.ast.factory.createProperty({
983
- name: "body",
984
- required: hasBody,
985
- schema: hasBody ? kubb_kit.ast.factory.createSchema({
986
- type: "ref",
987
- name: resolver.response.body(node)
988
- }) : createNever()
989
- }), ...groups.map(({ name, params, resolve }) => {
990
- const required = params.some((param) => param.required);
991
- return kubb_kit.ast.factory.createProperty({
992
- name,
993
- required,
994
- schema: params.length > 0 ? kubb_kit.ast.factory.createSchema({
995
- type: "ref",
996
- name: resolve.call(resolver.param, node, params[0]),
997
- optional: !required
998
- }) : createNever()
999
- });
1000
- })]
986
+ properties: [
987
+ kubb_kit.ast.factory.createProperty({
988
+ name: "body",
989
+ required: hasBody,
990
+ schema: body
991
+ }),
992
+ ...groups.map(({ name, params, resolve }) => {
993
+ const required = params.some((param) => param.required);
994
+ return kubb_kit.ast.factory.createProperty({
995
+ name,
996
+ required,
997
+ schema: params.length > 0 ? kubb_kit.ast.factory.createSchema({
998
+ type: "ref",
999
+ name: resolve.call(resolver.param, node, params[0]),
1000
+ optional: !required
1001
+ }) : createNever()
1002
+ });
1003
+ }),
1004
+ ...extra
1005
+ ]
1006
+ });
1007
+ const variants = pairContentTypes && hasRequestContentTypeChoice(node) ? resolveContentTypeVariants(node.requestBody?.content ?? [], resolver.response.body(node)) : [];
1008
+ if (variants.length < 2) return createOptions(hasBody ? kubb_kit.ast.factory.createSchema({
1009
+ type: "ref",
1010
+ name: resolver.response.body(node)
1011
+ }) : createNever());
1012
+ return kubb_kit.ast.factory.createSchema({
1013
+ type: "union",
1014
+ members: variants.map((variant, index) => createOptions(kubb_kit.ast.factory.createSchema({
1015
+ type: "ref",
1016
+ name: variant.name
1017
+ }), [kubb_kit.ast.factory.createProperty({
1018
+ name: "contentType",
1019
+ required: index > 0,
1020
+ schema: kubb_kit.ast.factory.createSchema({
1021
+ type: "object",
1022
+ primitive: "object",
1023
+ properties: [kubb_kit.ast.factory.createProperty({
1024
+ name: "request",
1025
+ required: true,
1026
+ schema: kubb_kit.ast.factory.createSchema({
1027
+ type: "enum",
1028
+ enumValues: [variant.contentType]
1029
+ })
1030
+ })]
1031
+ })
1032
+ })]))
1001
1033
  });
1002
1034
  }
1003
1035
  /**
@@ -1740,7 +1772,7 @@ const typeGenerator = (0, kubb_kit.defineGenerator)({
1740
1772
  });
1741
1773
  });
1742
1774
  const optionsType = renderSchemaType({
1743
- schema: buildOptionsSchema(node, resolver),
1775
+ schema: buildOptionsSchema(node, resolver, { pairContentTypes: true }),
1744
1776
  name: resolver.response.options(node)
1745
1777
  });
1746
1778
  const responsesType = renderSchemaType({
@@ -1801,7 +1833,7 @@ var compatibility = {
1801
1833
  };
1802
1834
  //#endregion
1803
1835
  //#region package.json
1804
- var version = "5.3.0-canary.20261025T201031";
1836
+ var version = "5.4.0-canary.20261025T213930";
1805
1837
  //#endregion
1806
1838
  //#region src/resolvers/resolverTs.ts
1807
1839
  /**