@kubb/plugin-ts 5.5.0-canary.20261109T173716 → 5.5.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 +51 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +51 -3
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -829,6 +829,37 @@ function Enum({ node, enum: enumOptions, resolver }) {
|
|
|
829
829
|
})] });
|
|
830
830
|
}
|
|
831
831
|
// ../../internals/shared/src/operation.ts
|
|
832
|
+
function baseContentType(contentType) {
|
|
833
|
+
return contentType.split(";")[0].trim().toLowerCase();
|
|
834
|
+
}
|
|
835
|
+
/**
|
|
836
|
+
* Whether a content entry is a sequence of JSON values the adapter marks as a stream, such as `application/jsonl`,
|
|
837
|
+
* `application/x-ndjson`, `application/json-seq`, or any media type with an OpenAPI 3.2 `itemSchema`.
|
|
838
|
+
*/
|
|
839
|
+
function isJsonLines(entry) {
|
|
840
|
+
const baseType = baseContentType(entry.contentType);
|
|
841
|
+
return Boolean(entry.stream) && baseType !== "text/event-stream" && !baseType.startsWith("multipart/");
|
|
842
|
+
}
|
|
843
|
+
function isJsonContentType(baseType) {
|
|
844
|
+
return baseType === "application/json" || baseType.endsWith("+json") || baseType === "text/json";
|
|
845
|
+
}
|
|
846
|
+
/**
|
|
847
|
+
* Parser for one response content entry.
|
|
848
|
+
*
|
|
849
|
+
* JSON stays unset so the runtime detects it. `text/event-stream` and JSON Lines are streams. A binary schema
|
|
850
|
+
* (`format: binary` / `contentMediaType`) is a blob even when the media type is not a well-known
|
|
851
|
+
* binary type. Other `text/*` is text, and `application/octet-stream`, `application/pdf`,
|
|
852
|
+
* `image/*`, `audio/*`, and `video/*` are blobs.
|
|
853
|
+
*/
|
|
854
|
+
function responseTypeForContent(entry) {
|
|
855
|
+
const baseType = baseContentType(entry.contentType);
|
|
856
|
+
if (!baseType) return void 0;
|
|
857
|
+
if (baseType === "text/event-stream" || isJsonLines(entry)) return "stream";
|
|
858
|
+
if (isJsonContentType(baseType)) return void 0;
|
|
859
|
+
if (entry.schema?.type === "blob") return "blob";
|
|
860
|
+
if (baseType.startsWith("text/")) return "text";
|
|
861
|
+
if (baseType === "application/octet-stream" || baseType === "application/pdf" || /^(image|audio|video)\//.test(baseType)) return "blob";
|
|
862
|
+
}
|
|
832
863
|
/**
|
|
833
864
|
* Maps a content type to the PascalCase suffix used to name per-content-type variants
|
|
834
865
|
* (e.g. `application/json` → `Json`, `application/xml` → `Xml`, `multipart/form-data` → `FormData`).
|
|
@@ -851,6 +882,22 @@ function getPerContentTypeName(baseName, suffix) {
|
|
|
851
882
|
return baseName + suffix;
|
|
852
883
|
}
|
|
853
884
|
/**
|
|
885
|
+
* Returns the entry with a `string` schema when the client runtime reads its body as text, such as `Pet` on `application/xml`.
|
|
886
|
+
* 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
|
|
887
|
+
* parser from the server's `Content-Type`. `text/*` reads as text.
|
|
888
|
+
*/
|
|
889
|
+
function toResponseContent(entry) {
|
|
890
|
+
const { contentType, schema } = entry;
|
|
891
|
+
if (!schema || entry.stream || ast.resolveRef(schema).primitive === "string") return entry;
|
|
892
|
+
const baseType = baseContentType(contentType);
|
|
893
|
+
const responseType = responseTypeForContent(entry);
|
|
894
|
+
return responseType === "text" || !responseType && Boolean(baseType) && !isJsonContentType(baseType) && !baseType.includes("*") ? {
|
|
895
|
+
...entry,
|
|
896
|
+
schema: ast.factory.createSchema({ type: "string" }),
|
|
897
|
+
keysToOmit: null
|
|
898
|
+
} : entry;
|
|
899
|
+
}
|
|
900
|
+
/**
|
|
854
901
|
* Resolves per-content-type variant names for a set of content entries, deduplicating suffix
|
|
855
902
|
* collisions with a numeric counter. Entries without a schema are skipped. The returned `suffix` is
|
|
856
903
|
* the final (possibly counter-augmented) value, so callers can derive parallel names in another
|
|
@@ -1879,9 +1926,10 @@ const typeGenerator = defineGenerator({
|
|
|
1879
1926
|
}
|
|
1880
1927
|
const requestType = buildRequestType();
|
|
1881
1928
|
const responseTypes = node.responses.map((res) => {
|
|
1882
|
-
const
|
|
1929
|
+
const content = (res.content ?? []).map(toResponseContent);
|
|
1930
|
+
const variants = content.filter((entry) => entry.schema);
|
|
1883
1931
|
if (variants.length > 1) return buildContentTypeVariants(variants, resolver.response.status(node, res.statusCode), res.pointer);
|
|
1884
|
-
const primary = variants[0] ??
|
|
1932
|
+
const primary = variants[0] ?? content[0];
|
|
1885
1933
|
return renderSchemaType({
|
|
1886
1934
|
schema: primary?.schema ? {
|
|
1887
1935
|
...primary.schema,
|
|
@@ -1950,7 +1998,7 @@ var compatibility = {
|
|
|
1950
1998
|
"node": ">=22.22"
|
|
1951
1999
|
};
|
|
1952
2000
|
// package.json
|
|
1953
|
-
var version = "5.5.0-canary.
|
|
2001
|
+
var version = "5.5.0-canary.20261109T175348";
|
|
1954
2002
|
// src/resolvers/resolverTs.ts
|
|
1955
2003
|
/**
|
|
1956
2004
|
* Default resolver used by `@kubb/plugin-ts`. Decides the names and file paths
|