@kubb/plugin-zod 5.9.0-canary.20261109T173716 → 5.9.0-canary.20261109T175348
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 +52 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +52 -4
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/dist/index.cjs
CHANGED
|
@@ -6,6 +6,37 @@ let _kubb_kit = require("@kubb/kit");
|
|
|
6
6
|
let _kubb_renderer_jsx = require("@kubb/renderer-jsx");
|
|
7
7
|
let _kubb_renderer_jsx_jsx_runtime = require("@kubb/renderer-jsx/jsx-runtime");
|
|
8
8
|
// ../../internals/shared/src/operation.ts
|
|
9
|
+
function baseContentType(contentType) {
|
|
10
|
+
return contentType.split(";")[0].trim().toLowerCase();
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Whether a content entry is a sequence of JSON values the adapter marks as a stream, such as `application/jsonl`,
|
|
14
|
+
* `application/x-ndjson`, `application/json-seq`, or any media type with an OpenAPI 3.2 `itemSchema`.
|
|
15
|
+
*/
|
|
16
|
+
function isJsonLines(entry) {
|
|
17
|
+
const baseType = baseContentType(entry.contentType);
|
|
18
|
+
return Boolean(entry.stream) && baseType !== "text/event-stream" && !baseType.startsWith("multipart/");
|
|
19
|
+
}
|
|
20
|
+
function isJsonContentType(baseType) {
|
|
21
|
+
return baseType === "application/json" || baseType.endsWith("+json") || baseType === "text/json";
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Parser for one response content entry.
|
|
25
|
+
*
|
|
26
|
+
* JSON stays unset so the runtime detects it. `text/event-stream` and JSON Lines are streams. A binary schema
|
|
27
|
+
* (`format: binary` / `contentMediaType`) is a blob even when the media type is not a well-known
|
|
28
|
+
* binary type. Other `text/*` is text, and `application/octet-stream`, `application/pdf`,
|
|
29
|
+
* `image/*`, `audio/*`, and `video/*` are blobs.
|
|
30
|
+
*/
|
|
31
|
+
function responseTypeForContent(entry) {
|
|
32
|
+
const baseType = baseContentType(entry.contentType);
|
|
33
|
+
if (!baseType) return void 0;
|
|
34
|
+
if (baseType === "text/event-stream" || isJsonLines(entry)) return "stream";
|
|
35
|
+
if (isJsonContentType(baseType)) return void 0;
|
|
36
|
+
if (entry.schema?.type === "blob") return "blob";
|
|
37
|
+
if (baseType.startsWith("text/")) return "text";
|
|
38
|
+
if (baseType === "application/octet-stream" || baseType === "application/pdf" || /^(image|audio|video)\//.test(baseType)) return "blob";
|
|
39
|
+
}
|
|
9
40
|
/**
|
|
10
41
|
* Maps a content type to the PascalCase suffix used to name per-content-type variants
|
|
11
42
|
* (e.g. `application/json` → `Json`, `application/xml` → `Xml`, `multipart/form-data` → `FormData`).
|
|
@@ -28,6 +59,22 @@ function getPerContentTypeName(baseName, suffix) {
|
|
|
28
59
|
return baseName + suffix;
|
|
29
60
|
}
|
|
30
61
|
/**
|
|
62
|
+
* Returns the entry with a `string` schema when the client runtime reads its body as text, such as `Pet` on `application/xml`.
|
|
63
|
+
* JSON, binary, and stream entries keep their schema, and so do wildcards such as `application/*` and the any-type `*`, so the runtime can pick the
|
|
64
|
+
* parser from the server's `Content-Type`. `text/*` reads as text.
|
|
65
|
+
*/
|
|
66
|
+
function toResponseContent(entry) {
|
|
67
|
+
const { contentType, schema } = entry;
|
|
68
|
+
if (!schema || entry.stream || _kubb_kit.ast.resolveRef(schema).primitive === "string") return entry;
|
|
69
|
+
const baseType = baseContentType(contentType);
|
|
70
|
+
const responseType = responseTypeForContent(entry);
|
|
71
|
+
return responseType === "text" || !responseType && Boolean(baseType) && !isJsonContentType(baseType) && !baseType.includes("*") ? {
|
|
72
|
+
...entry,
|
|
73
|
+
schema: _kubb_kit.ast.factory.createSchema({ type: "string" }),
|
|
74
|
+
keysToOmit: null
|
|
75
|
+
} : entry;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
31
78
|
* Resolves per-content-type variant names for a set of content entries, deduplicating suffix
|
|
32
79
|
* collisions with a numeric counter. Entries without a schema are skipped. The returned `suffix` is
|
|
33
80
|
* the final (possibly counter-augmented) value, so callers can derive parallel names in another
|
|
@@ -2088,9 +2135,10 @@ const zodGenerator = (0, _kubb_kit.defineGenerator)({
|
|
|
2088
2135
|
direction: "encode"
|
|
2089
2136
|
}));
|
|
2090
2137
|
const responseSchemas = node.responses.map((res) => {
|
|
2091
|
-
const
|
|
2092
|
-
|
|
2093
|
-
|
|
2138
|
+
const content = (res.content ?? []).map(toResponseContent);
|
|
2139
|
+
const variants = content.filter((entry) => entry.schema);
|
|
2140
|
+
if (variants.length > 1) return buildContentTypeVariants(content, resolver.response.status(node, res.statusCode));
|
|
2141
|
+
const primary = variants[0] ?? content[0];
|
|
2094
2142
|
return renderSchemaEntry({
|
|
2095
2143
|
schema: primary?.schema ?? null,
|
|
2096
2144
|
name: resolver.response.status(node, res.statusCode),
|
|
@@ -2215,7 +2263,7 @@ var compatibility = {
|
|
|
2215
2263
|
"node": ">=22.22"
|
|
2216
2264
|
};
|
|
2217
2265
|
// package.json
|
|
2218
|
-
var version = "5.9.0-canary.
|
|
2266
|
+
var version = "5.9.0-canary.20261109T175348";
|
|
2219
2267
|
// src/resolvers/resolverZod.ts
|
|
2220
2268
|
/**
|
|
2221
2269
|
* Default resolver used by `@kubb/plugin-zod`. Decides the names and file
|