@kubb/plugin-zod 5.8.1 → 5.8.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
@@ -52,6 +52,22 @@ function resolveContentTypeVariants(entries, baseName) {
52
52
  }
53
53
  const operationParameterGroupsByNode = /* @__PURE__ */ new WeakMap();
54
54
  /**
55
+ * An OpenAPI 3.2 `querystring` parameter is the whole query string, so a form-encoded object becomes one query parameter
56
+ * per property, typed and serialized like any other.
57
+ * Another content type, such as JSON, stays one parameter named after it, and the runtime sends its value as the whole query string.
58
+ */
59
+ function spreadQuerystring(param) {
60
+ const schema = param.schema.type === "ref" ? param.schema.schema : param.schema;
61
+ const formEncoded = !param.contentType || param.contentType.split(";")[0].trim().toLowerCase() === "application/x-www-form-urlencoded";
62
+ if (schema?.type !== "object" || !formEncoded) return [param];
63
+ return schema.properties.map((property) => ast.factory.createParameter({
64
+ name: property.name,
65
+ in: "query",
66
+ schema: property.schema,
67
+ required: param.required && property.required
68
+ }));
69
+ }
70
+ /**
55
71
  * Groups an operation's parameters by location (`path`/`query`/`header`/`cookie`), deduping each
56
72
  * group by name. Every plugin generator visiting the same `OperationNode` shares one AST instance
57
73
  * (see `KubbDriver`), so the result is cached per node to avoid re-filtering and re-deduping the
@@ -60,17 +76,18 @@ const operationParameterGroupsByNode = /* @__PURE__ */ new WeakMap();
60
76
  function getOperationParameters(node) {
61
77
  const cached = operationParameterGroupsByNode.get(node);
62
78
  if (cached) return cached;
63
- const group = (location) => {
79
+ const dedupe = (params) => {
64
80
  const seen = /* @__PURE__ */ new Set();
65
- return node.parameters.filter((param) => {
66
- if (param.in !== location || seen.has(param.name)) return false;
81
+ return params.filter((param) => {
82
+ if (seen.has(param.name)) return false;
67
83
  seen.add(param.name);
68
84
  return true;
69
85
  });
70
86
  };
87
+ const group = (location) => dedupe(node.parameters.filter((param) => param.in === location));
71
88
  const groups = {
72
89
  path: group("path"),
73
- query: group("query"),
90
+ query: dedupe([...group("query"), ...group("querystring").flatMap(spreadQuerystring)]),
74
91
  header: group("header"),
75
92
  cookie: group("cookie")
76
93
  };
@@ -2164,11 +2181,11 @@ const zodGenerator = defineGenerator({
2164
2181
  });
2165
2182
  // kubb-extension.json
2166
2183
  var compatibility = {
2167
- "kubb": ">=5.14.6",
2184
+ "kubb": ">=5.16.0",
2168
2185
  "node": ">=22.22"
2169
2186
  };
2170
2187
  // package.json
2171
- var version = "5.8.1";
2188
+ var version = "5.8.2";
2172
2189
  // src/resolvers/resolverZod.ts
2173
2190
  /**
2174
2191
  * Default resolver used by `@kubb/plugin-zod`. Decides the names and file