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