@kubb/plugin-zod 5.8.1 → 5.8.3

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
@@ -56,6 +56,22 @@ function resolveContentTypeVariants(entries, baseName) {
56
56
  }
57
57
  const operationParameterGroupsByNode = /* @__PURE__ */ new WeakMap();
58
58
  /**
59
+ * An OpenAPI 3.2 `querystring` parameter is the whole query string, so a form-encoded object becomes one query parameter
60
+ * per property, typed and serialized like any other.
61
+ * Another content type, such as JSON, stays one parameter named after it, and the runtime sends its value as the whole query string.
62
+ */
63
+ function spreadQuerystring(param) {
64
+ const schema = param.schema.type === "ref" ? param.schema.schema : param.schema;
65
+ const formEncoded = !param.contentType || param.contentType.split(";")[0].trim().toLowerCase() === "application/x-www-form-urlencoded";
66
+ if (schema?.type !== "object" || !formEncoded) return [param];
67
+ return schema.properties.map((property) => _kubb_kit.ast.factory.createParameter({
68
+ name: property.name,
69
+ in: "query",
70
+ schema: property.schema,
71
+ required: param.required && property.required
72
+ }));
73
+ }
74
+ /**
59
75
  * Groups an operation's parameters by location (`path`/`query`/`header`/`cookie`), deduping each
60
76
  * group by name. Every plugin generator visiting the same `OperationNode` shares one AST instance
61
77
  * (see `KubbDriver`), so the result is cached per node to avoid re-filtering and re-deduping the
@@ -64,17 +80,18 @@ const operationParameterGroupsByNode = /* @__PURE__ */ new WeakMap();
64
80
  function getOperationParameters(node) {
65
81
  const cached = operationParameterGroupsByNode.get(node);
66
82
  if (cached) return cached;
67
- const group = (location) => {
83
+ const dedupe = (params) => {
68
84
  const seen = /* @__PURE__ */ new Set();
69
- return node.parameters.filter((param) => {
70
- if (param.in !== location || seen.has(param.name)) return false;
85
+ return params.filter((param) => {
86
+ if (seen.has(param.name)) return false;
71
87
  seen.add(param.name);
72
88
  return true;
73
89
  });
74
90
  };
91
+ const group = (location) => dedupe(node.parameters.filter((param) => param.in === location));
75
92
  const groups = {
76
93
  path: group("path"),
77
- query: group("query"),
94
+ query: dedupe([...group("query"), ...group("querystring").flatMap(spreadQuerystring)]),
78
95
  header: group("header"),
79
96
  cookie: group("cookie")
80
97
  };
@@ -123,7 +140,7 @@ function buildOptionsSchema(node, resolver, { pairContentTypes = false } = {}) {
123
140
  properties: [
124
141
  _kubb_kit.ast.factory.createProperty({
125
142
  name: "body",
126
- required: hasBody,
143
+ required: hasBody && node.requestBody?.required === true,
127
144
  schema: body
128
145
  }),
129
146
  ...groups.map(({ name, params, resolve }) => {
@@ -1349,7 +1366,7 @@ function buildScalarNodes(dialect) {
1349
1366
  },
1350
1367
  ipv4: () => "z.ipv4()",
1351
1368
  ipv6: () => "z.ipv6()",
1352
- blob: () => "z.instanceof(File)",
1369
+ blob: () => "z.instanceof(Blob)",
1353
1370
  enum(node) {
1354
1371
  const nonNullValues = (node.namedEnumValues?.map((v) => v.value) ?? node.enumValues ?? []).filter((v) => v !== null);
1355
1372
  if (node.namedEnumValues?.length) {
@@ -2168,11 +2185,11 @@ const zodGenerator = (0, _kubb_kit.defineGenerator)({
2168
2185
  });
2169
2186
  // kubb-extension.json
2170
2187
  var compatibility = {
2171
- "kubb": ">=5.14.6",
2188
+ "kubb": ">=5.16.0",
2172
2189
  "node": ">=22.22"
2173
2190
  };
2174
2191
  // package.json
2175
- var version = "5.8.1";
2192
+ var version = "5.8.3";
2176
2193
  // src/resolvers/resolverZod.ts
2177
2194
  /**
2178
2195
  * Default resolver used by `@kubb/plugin-zod`. Decides the names and file