@sdk-it/typescript 0.46.9 → 0.46.10

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
@@ -12,6 +12,7 @@ import {
12
12
  } from "@sdk-it/core/file-system.js";
13
13
  import {
14
14
  cleanFiles,
15
+ forEachOperation as forEachOperation6,
15
16
  readWriteMetadata,
16
17
  sanitizeTag as sanitizeTag4,
17
18
  toIR
@@ -502,7 +503,7 @@ import { join } from "node:path";
502
503
  import { camelcase as camelcase4, spinalcase as spinalcase2 } from "stringcase";
503
504
  import {
504
505
  followRef as followRef3,
505
- isEmpty as isEmpty4,
506
+ isEmpty as isEmpty3,
506
507
  isRef as isRef3,
507
508
  resolveRef as resolveRef2,
508
509
  sortArray
@@ -795,16 +796,8 @@ function appendDefault(defaultValue) {
795
796
 
796
797
  // packages/typescript/src/lib/sdk.ts
797
798
  import { camelcase as camelcase3 } from "stringcase";
799
+ import { pascalcase as pascalcase3 } from "@sdk-it/core";
798
800
  import {
799
- isEmpty as isEmpty3,
800
- pascalcase as pascalcase3
801
- } from "@sdk-it/core";
802
- import {
803
- isBinaryContentType,
804
- isSseContentType,
805
- isStreamingContentType,
806
- isTextContentType,
807
- parseJsonContentType,
808
801
  sanitizeTag as sanitizeTag3
809
802
  } from "@sdk-it/spec";
810
803
 
@@ -903,18 +896,13 @@ var status_map_default = {
903
896
  };
904
897
 
905
898
  // packages/typescript/src/lib/sdk.ts
906
- function toEndpoint(groupName, spec, specOperation, operation) {
899
+ function toEndpoint(groupName, specOperation, operation) {
907
900
  const schemaName = camelcase3(`${specOperation.operationId} schema`);
908
901
  const schemaRef = `${camelcase3(groupName)}.${schemaName}`;
909
902
  const schemas = [];
910
903
  specOperation.responses ??= {};
911
- const outputs = Object.keys(specOperation.responses).flatMap(
912
- (status) => toHttpOutput(
913
- spec,
914
- specOperation.operationId,
915
- status,
916
- specOperation.responses[status]
917
- )
904
+ const outputs = Object.keys(specOperation.responses).map(
905
+ (status) => toHttpOutput(status, specOperation.responses[status])
918
906
  );
919
907
  const addTypeParser = Object.keys(operation.schemas).length > 1;
920
908
  for (const type in operation.schemas ?? {}) {
@@ -952,87 +940,44 @@ function normalOperation() {
952
940
  },
953
941
  }`;
954
942
  }
955
- function toHttpOutput(spec, operationName, status, response, withGenerics = true) {
956
- const typeScriptDeserialzer = new TypeScriptEmitter(spec);
957
- const interfaceName = pascalcase3(sanitizeTag3(response["x-response-name"]));
958
- if (!isEmpty3(response.content)) {
959
- const contentTypeResult = fromContentType(typeScriptDeserialzer, response);
960
- if (!contentTypeResult) {
961
- throw new Error(
962
- `No recognizable content type for response ${status} in operation ${operationName}`
963
- );
964
- }
965
- const parser = contentTypeResult.parser || "buffered";
966
- const outputs = [];
967
- const statusName = `http.${status_map_default[status] || "APIResponse"}`;
968
- const statusCode = +status;
969
- if (statusCode === 204) {
970
- outputs.push(statusName);
971
- } else {
972
- const generic = withGenerics ? `<outputs.${interfaceName}>` : "";
973
- if (status.endsWith("XX")) {
974
- outputs.push(`http.APIError${generic}`);
975
- } else {
976
- if (parser !== "buffered") {
977
- outputs.push(`{type: ${statusName}${generic}, parser: ${parser}}`);
978
- } else {
979
- outputs.push(`${statusName}${generic}`);
980
- }
981
- }
982
- }
983
- return outputs;
984
- }
985
- return [];
943
+ var bodyParser = {
944
+ json: "buffered",
945
+ text: "buffered",
946
+ binary: "buffered",
947
+ empty: "bodyless",
948
+ stream: "chunked",
949
+ sse: "sse"
950
+ };
951
+ function toHttpOutput(status, response) {
952
+ const body = response["x-body"];
953
+ const type = status.endsWith("XX") ? "http.APIError" : `http.${status_map_default[status] || "APIResponse"}`;
954
+ if (status === "204") {
955
+ return type;
956
+ }
957
+ const data = dataType(status, response);
958
+ const parser = bodyParser[body];
959
+ return parser === "buffered" ? `${type}<${data}>` : `{type: ${type}<${data}>, parser: ${parser}}`;
986
960
  }
987
- function fromContentType(typeScriptDeserialzer, response) {
988
- if ((response.headers ?? {})["Transfer-Encoding"]) {
989
- return streamedOutput();
990
- }
991
- const hasContentDisposition = hasHeader(response, "Content-Disposition");
992
- for (const type in response.content) {
993
- const isStreaming = isStreamingContentType(type);
994
- const isBinary = isBinaryContentType(type) || isStreaming && hasContentDisposition;
995
- if (isStreaming && !hasContentDisposition) {
996
- return streamedOutput();
997
- }
998
- if (isBinary) {
999
- return {
1000
- parser: "buffered",
1001
- responseSchema: response.content[type].schema ? typeScriptDeserialzer.handle(response.content[type].schema, true) : "Blob"
1002
- };
1003
- }
1004
- if (parseJsonContentType(type)) {
1005
- const schema = response.content[type].schema;
1006
- return {
1007
- parser: "buffered",
1008
- responseSchema: schema ? typeScriptDeserialzer.handle(schema, true) : "void"
1009
- };
1010
- }
1011
- if (isSseContentType(type)) {
1012
- return {
1013
- parser: "sse",
1014
- responseSchema: "SSEListener"
1015
- };
1016
- }
1017
- if (isTextContentType(type)) {
1018
- return {
1019
- parser: "buffered",
1020
- responseSchema: response.content[type].schema ? typeScriptDeserialzer.handle(response.content[type].schema, true) : "void"
1021
- };
1022
- }
961
+ function dataType(status, response) {
962
+ switch (response["x-body"]) {
963
+ case "empty":
964
+ return "null";
965
+ case "stream":
966
+ return "ReadableStream";
967
+ case "sse":
968
+ return "SSEListener";
969
+ default:
970
+ return `outputs.${pascalcase3(sanitizeTag3(outputName(status, response)))}`;
1023
971
  }
1024
- return streamedOutput();
1025
972
  }
1026
- function hasHeader(response, name) {
1027
- const headers = response.headers ?? {};
1028
- const target = name.toLowerCase();
1029
- return Object.keys(headers).some((key) => key.toLowerCase() === target);
1030
- }
1031
- function streamedOutput() {
1032
- return {
1033
- parser: "chunked",
1034
- responseSchema: "ReadableStream"
1035
- };
973
+ function outputName(status, response) {
974
+ const name = response["x-response-name"];
975
+ if (!name) {
976
+ throw new Error(
977
+ `Response ${status} has a ${response["x-body"]} body but no output name; generate with responses.flattenErrorResponses so every response is normalized`
978
+ );
979
+ }
980
+ return name;
1036
981
  }
1037
982
  function inputToPath(operation, inputs) {
1038
983
  const inputHeaders = [];
@@ -1078,7 +1023,7 @@ function coearceRequestInput(spec, operation, type) {
1078
1023
  if (type === "application/empty") {
1079
1024
  objectSchema = {
1080
1025
  type: "object",
1081
- additionalProperties: isEmpty4(xProperties)
1026
+ additionalProperties: isEmpty3(xProperties)
1082
1027
  };
1083
1028
  } else {
1084
1029
  if (objectSchema.type !== "object") {
@@ -1135,7 +1080,7 @@ function generateCode(config) {
1135
1080
  );
1136
1081
  }
1137
1082
  const details = buildInput(config.spec, operation);
1138
- const endpoint = toEndpoint(entry.tag, config.spec, operation, {
1083
+ const endpoint = toEndpoint(entry.tag, operation, {
1139
1084
  method: entry.method,
1140
1085
  path: entry.path,
1141
1086
  operationId: operation.operationId,
@@ -1180,25 +1125,26 @@ ${allSchemas.map((it) => it.use).join(",\n")}
1180
1125
  `.trim(),
1181
1126
  ...Object.fromEntries(
1182
1127
  Object.entries(endpoints).map(([name, endpoint]) => {
1128
+ const operations = endpoint.flatMap((it) => it.schemas).join(",\n");
1183
1129
  return [
1184
1130
  [
1185
1131
  join("api", `${spinalcase2(name)}.ts`),
1186
1132
  `${[
1187
1133
  `import z from 'zod';`,
1188
1134
  `import * as http from '${config.makeImport("../http/response")}';`,
1189
- `import * as outputs from '${config.makeImport("../outputs/index")}';`,
1135
+ ...operations.includes("outputs.") ? [
1136
+ `import * as outputs from '${config.makeImport("../outputs/index")}';`
1137
+ ] : [],
1190
1138
  `import { toRequest, json, urlencoded, empty, formdata, type HeadersInit } from '${config.makeImport("../http/request")}';`,
1191
- `import { chunked, buffered } from "${config.makeImport("../http/parse-response")}";`,
1192
- `import { sse } from "${config.makeImport("../http/sse")}";`,
1139
+ `import { chunked, buffered, bodyless } from "${config.makeImport("../http/parse-response")}";`,
1140
+ `import { sse, type SSEListener } from "${config.makeImport("../http/sse")}";`,
1193
1141
  `import * as ${camelcase4(name)} from '../inputs/${config.makeImport(spinalcase2(name))}';`,
1194
1142
  `import { createBaseUrlInterceptor, createHeadersInterceptor, type Interceptor } from '${config.makeImport("../http/interceptors")}';`,
1195
1143
  `import { Dispatcher, fetchType, type InstanceType } from '${config.makeImport("../http/dispatcher")}';`,
1196
1144
  `import { Pagination, OffsetPagination, CursorPagination } from "${config.makeImport("../pagination/index")}";`
1197
- ].join(
1198
- "\n"
1199
- )}
1145
+ ].join("\n")}
1200
1146
  export default {
1201
- ${endpoint.flatMap((it) => it.schemas).join(",\n")}
1147
+ ${operations}
1202
1148
  }`
1203
1149
  ]
1204
1150
  ];
@@ -1324,7 +1270,7 @@ var dispatcher_default = "export type Unionize<T> = T extends [infer Single exte
1324
1270
  var interceptors_default = "export interface Interceptor {\n before?: (config: RequestConfig) => Promise<RequestConfig> | RequestConfig;\n after?: (response: Response) => Promise<Response> | Response;\n}\n\nexport const createHeadersInterceptor = (\n headers: Record<string, string | undefined>,\n requestHeaders: HeadersInit,\n):Interceptor => {\n return {\n before({init, url}) {\n // Priority Levels\n // 1. Headers Input\n // 2. Request Headers\n // 3. Default Headers\n\n for (const [key, value] of new Headers(requestHeaders)) {\n // Only set the header if it doesn't already exist and has a value\n // even though these headers are passed at operation level\n // still they are lower priority compared to the headers input\n if (value !== undefined && !init.headers.has(key)) {\n init.headers.set(key, value);\n }\n }\n\n for (const [key, value] of Object.entries(headers)) {\n // Only set the header if it doesn't already exist and has a value\n if (value !== undefined && !init.headers.has(key)) {\n init.headers.set(key, value);\n }\n }\n\n return {init, url};\n },\n };\n};\n\nexport const createBaseUrlInterceptor = (baseUrl: string): Interceptor => {\n return {\n before({ init, url }) {\n if (url.protocol === 'local:') {\n return {\n init,\n url: new URL(url.href.replace('local://', baseUrl))\n };\n }\n return { init, url };\n },\n };\n};\n";
1325
1271
 
1326
1272
  // packages/typescript/src/lib/http/parse-response.txt
1327
- var parse_response_default = 'import { parse } from "fast-content-type-parse";\n\nfunction isBinaryContentType(contentType: string) {\n const type = contentType.toLowerCase();\n if (type.startsWith("image/")) {\n return true;\n }\n if (type.startsWith("audio/")) {\n return true;\n }\n if (type.startsWith("video/")) {\n return true;\n }\n switch (type) {\n case "application/pdf":\n case "application/zip":\n case "application/gzip":\n case "application/x-7z-compressed":\n case "application/x-tar":\n case "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":\n case "application/vnd.openxmlformats-officedocument.wordprocessingml.document":\n case "application/vnd.openxmlformats-officedocument.presentationml.presentation":\n case "application/vnd.ms-excel":\n case "application/vnd.ms-powerpoint":\n case "application/msword":\n case "application/octet-stream":\n return true;\n default:\n return false;\n }\n}\n\nfunction isAttachment(response: Response) {\n const contentDisposition = response.headers.get("Content-Disposition");\n const dispositionType = contentDisposition?.split(";", 1)[0];\n return dispositionType?.trim().toLowerCase() === "attachment";\n}\n\nasync function handleChunkedResponse(response: Response, contentType: string) {\n const { type } = parse(contentType);\n\n switch (type) {\n case "application/json": {\n let buffer = "";\n const reader = response.body!.getReader();\n const decoder = new TextDecoder();\n while (true) {\n const { value, done } = await reader.read();\n if (done) break;\n buffer += decoder.decode(value);\n }\n return JSON.parse(buffer);\n }\n case "text/html":\n case "text/plain": {\n let buffer = "";\n const reader = response.body!.getReader();\n const decoder = new TextDecoder();\n while (true) {\n const { value, done } = await reader.read();\n if (done) break;\n buffer += decoder.decode(value);\n }\n return buffer;\n }\n default:\n return response.body;\n }\n}\n\nexport function chunked(response: Response) {\n return response.body!;\n}\n\nexport async function buffered(response: Response) {\n // Statuses that, per the HTTP spec, carry no message body. These responses\n // usually omit Content-Type entirely, so this must run before the guard below.\n if (\n response.status === 204 ||\n response.status === 205 ||\n response.status === 304\n ) {\n return null;\n }\n if (isAttachment(response)) {\n return response.blob();\n }\n\n const contentType = response.headers.get("Content-Type");\n if (!contentType) {\n throw new Error("Content-Type header is missing");\n }\n\n const { type } = parse(contentType);\n if (isBinaryContentType(type)) {\n return response.blob();\n }\n if (type.startsWith("text/")) {\n return response.text();\n }\n switch (type) {\n case "application/json":\n return response.json();\n case "application/xml":\n return response.text();\n case "application/x-www-form-urlencoded": {\n const text = await response.text();\n return Object.fromEntries(new URLSearchParams(text));\n }\n case "multipart/form-data":\n return response.formData();\n default:\n throw new Error(`Unsupported content type: ${contentType}`);\n }\n}\n';
1273
+ var parse_response_default = 'import { parse } from "fast-content-type-parse";\n\nfunction isBinaryContentType(contentType: string) {\n const type = contentType.toLowerCase();\n if (type.startsWith("image/")) {\n return true;\n }\n if (type.startsWith("audio/")) {\n return true;\n }\n if (type.startsWith("video/")) {\n return true;\n }\n switch (type) {\n case "application/pdf":\n case "application/zip":\n case "application/gzip":\n case "application/x-7z-compressed":\n case "application/x-tar":\n case "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":\n case "application/vnd.openxmlformats-officedocument.wordprocessingml.document":\n case "application/vnd.openxmlformats-officedocument.presentationml.presentation":\n case "application/vnd.ms-excel":\n case "application/vnd.ms-powerpoint":\n case "application/msword":\n case "application/octet-stream":\n return true;\n default:\n return false;\n }\n}\n\nfunction isAttachment(response: Response) {\n const contentDisposition = response.headers.get("Content-Disposition");\n const dispositionType = contentDisposition?.split(";", 1)[0];\n return dispositionType?.trim().toLowerCase() === "attachment";\n}\n\nexport function chunked(response: Response) {\n return response.body!;\n}\n\n// The operation declares no body; release the unread stream so the\n// connection is not held until garbage collection.\nexport async function bodyless(response: Response) {\n await response.body?.cancel();\n return null;\n}\n\nexport async function buffered(response: Response) {\n // Statuses that, per the HTTP spec, carry no message body. These responses\n // usually omit Content-Type entirely, so this must run before the guard below.\n if (\n response.status === 204 ||\n response.status === 205 ||\n response.status === 304\n ) {\n return null;\n }\n if (isAttachment(response)) {\n return response.blob();\n }\n\n const contentType = response.headers.get("Content-Type");\n if (!contentType) {\n throw new Error("Content-Type header is missing");\n }\n\n const { type } = parse(contentType);\n if (isBinaryContentType(type)) {\n return response.blob();\n }\n if (type.startsWith("text/")) {\n return response.text();\n }\n switch (type) {\n case "application/json":\n return response.json();\n case "application/xml":\n return response.text();\n case "application/x-www-form-urlencoded": {\n const text = await response.text();\n return Object.fromEntries(new URLSearchParams(text));\n }\n case "multipart/form-data":\n return response.formData();\n default:\n throw new Error(`Unsupported content type: ${contentType}`);\n }\n}\n';
1328
1274
 
1329
1275
  // packages/typescript/src/lib/http/parser.txt
1330
1276
  var parser_default = "import { z } from 'zod';\n\nexport class ParseError<T extends z.ZodType> extends Error {\n public data: z.core.$ZodFlattenedError<z.output<T>, z.core.$ZodIssue>;\n constructor(\n data: z.core.$ZodFlattenedError<z.output<T>, z.core.$ZodIssue>,\n ) {\n super('Validation failed');\n this.name = 'ParseError';\n this.data = data;\n }\n}\n\nexport function parseInput<T extends z.ZodType>(\n schema: T,\n input: unknown,\n): z.infer<T> {\n const result = schema.safeParse(input);\n if (!result.success) {\n const error = z.flattenError(result.error, (issue) => issue);\n throw new ParseError<T>(error);\n }\n return result.data as z.infer<T>;\n}\n";
@@ -1348,7 +1294,7 @@ var offset_pagination_default = "type OffsetPaginationParams = {\n offset: numb
1348
1294
  var page_pagination_default = "type InferPage<T> = T extends Page<infer U> ? U : never;\ntype PaginationParams<P extends number | bigint | null, S extends number | bigint | null> = {\n page?: P;\n pageSize?: S;\n};\n\ninterface Metadata {\n hasMore?: boolean;\n}\n\ntype PaginationRequestOptions = {\n signal?: AbortSignal;\n};\n\ntype PaginationResult<T, M extends Metadata> = {\n data: T[];\n meta: M;\n};\n\ntype FetchFn<\n T,\n M extends Metadata,\n P extends number | bigint | null,\n S extends number | bigint | null,\n> = (\n input: Partial<PaginationParams<P, S>>,\n requestOptions?: PaginationRequestOptions,\n) => Promise<PaginationResult<T, M>>;\n\n/**\n * @experimental\n */\nexport class Pagination<\n T,\n M extends Metadata,\n P extends number | bigint | null,\n S extends number | bigint | null,\n> {\n #meta: PaginationResult<T, M>['meta'] | null = null;\n #params: PaginationParams<P, S>;\n #currentPage: Page<T> | null = null;\n readonly #fetchFn: FetchFn<T, M, P, S>;\n readonly #requestOptions: PaginationRequestOptions;\n\n constructor(\n initialParams: { page?: P | undefined; pageSize?: S | undefined },\n fetchFn: FetchFn<T, M, P, S>,\n requestOptions: PaginationRequestOptions = {},\n ) {\n this.#fetchFn = fetchFn;\n this.#requestOptions = requestOptions;\n this.#params = {\n ...(initialParams.page === undefined ? {} : { page: initialParams.page }),\n ...(initialParams.pageSize === undefined ? {} : { pageSize: initialParams.pageSize }),\n };\n }\n\n async getNextPage(requestOptions?: PaginationRequestOptions) {\n const result = await this.#fetchFn(this.#params, {\n ...this.#requestOptions,\n ...requestOptions,\n });\n this.#currentPage = new Page(result.data);\n this.#meta = result.meta;\n this.#params = {\n ...this.#params,\n page: (((this.#params.page as number) || 0) + 1) as never,\n };\n return this;\n }\n\n getCurrentPage() {\n if (!this.#currentPage) {\n throw new Error(\n 'No page data available. Please call getNextPage() first.',\n );\n }\n return this.#currentPage;\n }\n\n get hasMore() {\n if (!this.#meta) {\n throw new Error(\n 'No meta data available. Please call getNextPage() first.',\n );\n }\n return this.#meta.hasMore;\n }\n\n async *[Symbol.asyncIterator]() {\n for await (const page of this.iter()) {\n yield page.getCurrentPage();\n }\n }\n\n async *iter(requestOptions?: PaginationRequestOptions) {\n if (!this.#currentPage) {\n yield await this.getNextPage(requestOptions);\n }\n\n while (this.hasMore) {\n yield await this.getNextPage(requestOptions);\n }\n }\n\n get metadata() {\n if (!this.#meta) {\n throw new Error(\n 'No meta data available. Please call getNextPage() first.',\n );\n }\n return this.#meta;\n }\n}\n\nclass Page<T> {\n data: T[];\n constructor(data: T[]) {\n this.data = data;\n }\n}\n";
1349
1295
 
1350
1296
  // packages/typescript/src/lib/readme/readme.ts
1351
- import { isEmpty as isEmpty5 } from "@sdk-it/core";
1297
+ import { isEmpty as isEmpty4 } from "@sdk-it/core";
1352
1298
  import { forEachOperation as forEachOperation4 } from "@sdk-it/spec";
1353
1299
 
1354
1300
  // packages/typescript/src/lib/readme/prop.emitter.ts
@@ -1676,7 +1622,7 @@ function toReadme(spec, generator) {
1676
1622
  markdown.push(`#### Output`);
1677
1623
  for (const status in operation.responses) {
1678
1624
  const response = operation.responses[status];
1679
- if (!isEmpty5(response.content)) {
1625
+ if (!isEmpty4(response.content)) {
1680
1626
  const contentEntries = Object.entries(response.content);
1681
1627
  if (contentEntries.length === 1) {
1682
1628
  const [contentType, mediaType] = contentEntries[0];
@@ -1955,7 +1901,7 @@ function expandServerUrls(servers) {
1955
1901
  // packages/typescript/src/lib/typescript-snippet.ts
1956
1902
  import { camelcase as camelcase5, spinalcase as spinalcase3 } from "stringcase";
1957
1903
  import {
1958
- isEmpty as isEmpty6,
1904
+ isEmpty as isEmpty5,
1959
1905
  pascalcase as pascalcase4,
1960
1906
  resolveRef as resolveRef4
1961
1907
  } from "@sdk-it/core";
@@ -2168,7 +2114,7 @@ var TypeScriptSnippet = class {
2168
2114
  }
2169
2115
  succinct(entry, operation, values) {
2170
2116
  let payload = "{}";
2171
- if (!isEmpty6(operation.requestBody)) {
2117
+ if (!isEmpty5(operation.requestBody)) {
2172
2118
  const contentTypes = Object.keys(operation.requestBody.content || {});
2173
2119
  const schema = resolveRef4(
2174
2120
  this.#spec,
@@ -2225,7 +2171,7 @@ var TypeScriptSnippet = class {
2225
2171
  return this.#streamDownload(entry, payload);
2226
2172
  }
2227
2173
  }
2228
- if (!isEmpty6(operation["x-pagination"])) {
2174
+ if (!isEmpty5(operation["x-pagination"])) {
2229
2175
  return this.#pagination(operation, entry, payload);
2230
2176
  }
2231
2177
  return this.#normal(entry, payload);
@@ -2335,7 +2281,7 @@ const result = await ${camelcase5(this.#clientName)}.request('${entry.method.toU
2335
2281
  options.baseUrl = servers[0] ?? "http://localhost:3000";
2336
2282
  }
2337
2283
  const authOptions = this.#authentication();
2338
- if (!isEmpty6(authOptions)) {
2284
+ if (!isEmpty5(authOptions)) {
2339
2285
  const [firstAuth] = authOptions;
2340
2286
  options.credentials = {
2341
2287
  [firstAuth.name]: this.#credentialExample(firstAuth.scheme)
@@ -2376,7 +2322,7 @@ ${client.use}`;
2376
2322
  );
2377
2323
  const baseUrl = expandServerUrls(this.#spec.servers ?? [])[0] || "https://api.example.com";
2378
2324
  const authOptions = this.#authentication();
2379
- const hasApiKey = !isEmpty6(authOptions);
2325
+ const hasApiKey = !isEmpty5(authOptions);
2380
2326
  sections.push("### Configuration Options");
2381
2327
  sections.push("");
2382
2328
  sections.push("| Option | Type | Required | Description |");
@@ -2761,7 +2707,7 @@ ${client.use}`;
2761
2707
  }
2762
2708
  authenticationDocs() {
2763
2709
  const authOptions = this.#authentication();
2764
- if (isEmpty6(authOptions)) {
2710
+ if (isEmpty5(authOptions)) {
2765
2711
  return "";
2766
2712
  }
2767
2713
  const only = authOptions.length === 1;
@@ -2804,7 +2750,7 @@ ${client.use}`;
2804
2750
  const initialClientOptions = {
2805
2751
  baseUrl: "https://api.production-service.com"
2806
2752
  };
2807
- if (!isEmpty6(authOptions)) {
2753
+ if (!isEmpty5(authOptions)) {
2808
2754
  const [primaryAuth] = authOptions;
2809
2755
  initialClientOptions.credentials = {
2810
2756
  [primaryAuth.name]: this.#credentialExample(primaryAuth.scheme)
@@ -2819,7 +2765,7 @@ ${client.use}`;
2819
2765
  "client.setOptions({",
2820
2766
  " baseUrl: 'https://api.staging-service.com',"
2821
2767
  ];
2822
- if (!isEmpty6(authOptions)) {
2768
+ if (!isEmpty5(authOptions)) {
2823
2769
  const [primaryAuth] = authOptions;
2824
2770
  configurationUpdateCode.push(
2825
2771
  ` credentials: ${JSON.stringify({
@@ -3127,23 +3073,34 @@ ${utils_default}`
3127
3073
  function serializeModels(spec) {
3128
3074
  const filesMap = {};
3129
3075
  const files = {};
3076
+ const responseBodies = /* @__PURE__ */ new Map();
3077
+ forEachOperation6(spec, (_, operation) => {
3078
+ for (const response of Object.values(operation.responses)) {
3079
+ const name = response["x-response-name"];
3080
+ if (name) {
3081
+ responseBodies.set(name, response["x-body"]);
3082
+ }
3083
+ }
3084
+ });
3130
3085
  for (const [name, schema] of Object.entries(spec.components.schemas)) {
3131
3086
  const isResponseBody = schema["x-responsebody"];
3132
3087
  const isRequestBody = schema["x-requestbody"];
3133
3088
  const responseGroup = schema["x-response-group"];
3134
- const stream = schema["x-stream"];
3089
+ const body = responseGroup ? responseBodies.get(name) : void 0;
3135
3090
  if (isRequestBody) {
3136
3091
  continue;
3137
3092
  }
3138
3093
  const folder = isResponseBody ? "outputs" : "models";
3139
- const isSse = schema["x-sse"];
3140
- let typeContent = isSse ? "SSEListener" : "ReadableStream";
3141
- if (!stream) {
3142
- const serializer = new TypeScriptEmitter(spec);
3143
- typeContent = serializer.handle(schema, true);
3094
+ let typeContent;
3095
+ if (body === "sse") {
3096
+ typeContent = "SSEListener";
3097
+ } else if (body === "stream") {
3098
+ typeContent = "ReadableStream";
3099
+ } else {
3100
+ typeContent = new TypeScriptEmitter(spec).handle(schema, true);
3144
3101
  }
3145
3102
  const imports = [];
3146
- if (isSse) {
3103
+ if (body === "sse") {
3147
3104
  imports.push(`import type { SSEListener } from '../http/sse.ts';`);
3148
3105
  }
3149
3106
  const fileContent = [