@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 +25 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +25 -8
- package/dist/index.js.map +1 -1
- package/kubb-extension.json +1 -1
- package/package.json +3 -3
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
|
|
79
|
+
const dedupe = (params) => {
|
|
64
80
|
const seen = /* @__PURE__ */ new Set();
|
|
65
|
-
return
|
|
66
|
-
if (
|
|
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
|
};
|
|
@@ -119,7 +136,7 @@ function buildOptionsSchema(node, resolver, { pairContentTypes = false } = {}) {
|
|
|
119
136
|
properties: [
|
|
120
137
|
ast.factory.createProperty({
|
|
121
138
|
name: "body",
|
|
122
|
-
required: hasBody,
|
|
139
|
+
required: hasBody && node.requestBody?.required === true,
|
|
123
140
|
schema: body
|
|
124
141
|
}),
|
|
125
142
|
...groups.map(({ name, params, resolve }) => {
|
|
@@ -1345,7 +1362,7 @@ function buildScalarNodes(dialect) {
|
|
|
1345
1362
|
},
|
|
1346
1363
|
ipv4: () => "z.ipv4()",
|
|
1347
1364
|
ipv6: () => "z.ipv6()",
|
|
1348
|
-
blob: () => "z.instanceof(
|
|
1365
|
+
blob: () => "z.instanceof(Blob)",
|
|
1349
1366
|
enum(node) {
|
|
1350
1367
|
const nonNullValues = (node.namedEnumValues?.map((v) => v.value) ?? node.enumValues ?? []).filter((v) => v !== null);
|
|
1351
1368
|
if (node.namedEnumValues?.length) {
|
|
@@ -2164,11 +2181,11 @@ const zodGenerator = defineGenerator({
|
|
|
2164
2181
|
});
|
|
2165
2182
|
// kubb-extension.json
|
|
2166
2183
|
var compatibility = {
|
|
2167
|
-
"kubb": ">=5.
|
|
2184
|
+
"kubb": ">=5.16.0",
|
|
2168
2185
|
"node": ">=22.22"
|
|
2169
2186
|
};
|
|
2170
2187
|
// package.json
|
|
2171
|
-
var version = "5.8.
|
|
2188
|
+
var version = "5.8.3";
|
|
2172
2189
|
// src/resolvers/resolverZod.ts
|
|
2173
2190
|
/**
|
|
2174
2191
|
* Default resolver used by `@kubb/plugin-zod`. Decides the names and file
|