@kaito-http/core 4.0.0-beta.30 → 4.0.0-beta.32

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
@@ -1263,8 +1263,7 @@ var Router = class _Router {
1263
1263
  params: rawParams
1264
1264
  });
1265
1265
  if (result instanceof KaitoSSEResponse) {
1266
- const body2 = route.openapi?.body;
1267
- const schema = body2 && "schema" in body2 ? body2.schema : void 0;
1266
+ const schema = route.openapi && "schema" in route.openapi ? route.openapi.schema : void 0;
1268
1267
  const stringStream = result.events.pipeThrough(
1269
1268
  new TransformStream({
1270
1269
  transform(event, controller) {
@@ -1296,8 +1295,8 @@ var Router = class _Router {
1296
1295
  }
1297
1296
  return result;
1298
1297
  }
1299
- if (route.openapi && "schema" in route.openapi.body && route.openapi.body.schema) {
1300
- const parsed = route.openapi.body.schema.serialize(result);
1298
+ if (route.openapi && "schema" in route.openapi && route.openapi.schema) {
1299
+ const parsed = route.openapi.schema.serialize(result);
1301
1300
  return head.toResponse(parsed);
1302
1301
  }
1303
1302
  if (result === void 0) {
@@ -1417,7 +1416,7 @@ var Router = class _Router {
1417
1416
  paths[pathWithColonParamsReplaceWithCurlyBraces] = {};
1418
1417
  }
1419
1418
  let contentType;
1420
- const type = route.openapi.body.type;
1419
+ const type = route.openapi.type;
1421
1420
  switch (type) {
1422
1421
  case "json":
1423
1422
  contentType = "application/json";
@@ -1431,15 +1430,15 @@ var Router = class _Router {
1431
1430
  default:
1432
1431
  throw new Error(`Unknown output type in route ${route.method} ${route.path}: ${type}`);
1433
1432
  }
1434
- if ("schema" in route.openapi.body && route.openapi.body.schema) visit(route.openapi.body.schema);
1433
+ if ("schema" in route.openapi && route.openapi.schema) visit(route.openapi.schema);
1435
1434
  if (route.body) visit(route.body);
1436
- const responseSchema = "schema" in route.openapi.body && route.openapi.body.schema ? route.openapi.body.schema.toOpenAPI() : { type: "string" };
1435
+ const responseSchema = "schema" in route.openapi && route.openapi.schema ? route.openapi.schema.toOpenAPI() : { type: "string" };
1437
1436
  const item = {
1438
1437
  ...route.openapi.summary ? { summary: route.openapi.summary } : {},
1439
1438
  description: route.openapi?.description ?? "Successful response",
1440
1439
  responses: {
1441
1440
  200: {
1442
- description: route.openapi.body.description ?? "Successful response",
1441
+ description: route.openapi.description ?? "Successful response",
1443
1442
  content: {
1444
1443
  [contentType]: {
1445
1444
  schema: responseSchema
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { JSONValue, BaseSchema, AnySchemaFor } from './schema/schema.cjs';
2
- export { ArrayChecks, ArrayDef, BaseSchemaDef, BooleanDef, Issue, JSONPrimitive, KArray, KBoolean, KLazy, KLiteral, KNativeEnum, KNull, KNumber, KObject, KObjectFromURLSearchParams, KRecord, KRef, KScalar, KString, KUnion, LazyDef, LiteralDef, NativeEnumDef, NullDef, NumberChecks, NumberDef, NumberFormat, ObjectDef, ParseContext, ParseResult, RecordDef, RefDef, STRING_FORMAT_REGEXES, ScalarDef, ScalarOptions, SchemaError, StringChecks, StringDef, StringFormat, UnionDef, isPrimitiveJSONValue, k } from './schema/schema.cjs';
1
+ import { JSONValue, BaseSchema, BaseSchemaDef, AnySchemaFor } from './schema/schema.cjs';
2
+ export { ArrayChecks, ArrayDef, BooleanDef, Issue, JSONPrimitive, KArray, KBoolean, KLazy, KLiteral, KNativeEnum, KNull, KNumber, KObject, KObjectFromURLSearchParams, KRecord, KRef, KScalar, KString, KUnion, LazyDef, LiteralDef, NativeEnumDef, NullDef, NumberChecks, NumberDef, NumberFormat, ObjectDef, ParseContext, ParseResult, RecordDef, RefDef, STRING_FORMAT_REGEXES, ScalarDef, ScalarOptions, SchemaError, StringChecks, StringDef, StringFormat, UnionDef, isPrimitiveJSONValue, k } from './schema/schema.cjs';
3
3
  import * as OpenAPI from 'openapi3-ts/oas31';
4
4
  import { KaitoSSEResponse, SSEEvent } from './stream/stream.cjs';
5
5
 
@@ -74,7 +74,7 @@ declare class KaitoHead {
74
74
  get touched(): boolean;
75
75
  }
76
76
 
77
- type PrefixRoutesPathInner<R extends AnyRoute, Prefix extends `/${string}`> = R extends Route<infer ContextFrom, infer ContextTo, infer RouterInput, infer ResultOutput, infer Path, infer AdditionalParams, infer Method, infer Query, infer BodyOutput> ? Route<ContextFrom, ContextTo, RouterInput, ResultOutput, `${Prefix}${Path extends '/' ? '' : Path}`, AdditionalParams, Method, Query, BodyOutput> : never;
77
+ type PrefixRoutesPathInner<R extends AnyRoute, Prefix extends `/${string}`> = R extends Route<infer ContextFrom, infer ContextTo, infer RouterInput, infer ResultOutput, infer Path, infer AdditionalParams, infer Method, infer Query, infer BodyInput, infer BodyOutput> ? Route<ContextFrom, ContextTo, RouterInput, ResultOutput, `${Prefix}${Path extends '/' ? '' : Path}`, AdditionalParams, Method, Query, BodyInput, BodyOutput> : never;
78
78
  type PrefixRoutesPath<Prefix extends `/${string}`, R extends AnyRoute> = R extends R ? PrefixRoutesPathInner<R, Prefix> : never;
79
79
  type RouterState<ContextFrom, ContextTo, RequiredParams extends string, Routes extends AnyRoute, Input extends readonly unknown[]> = {
80
80
  routes: Set<Routes>;
@@ -121,29 +121,29 @@ declare class Router<ContextFrom, ContextTo, RequiredParams extends string, Rout
121
121
  openapi: ({ info, servers, }: {
122
122
  info: OpenAPI.InfoObject;
123
123
  servers?: Partial<Record<(`https://` | `http://`) | ({} & string), string>>;
124
- }) => Router<ContextFrom, ContextTo, RequiredParams, Routes | Route<ContextFrom, ContextTo, Input, Response, "/openapi.json", RequiredParams, "GET", {}, never>, Input>;
124
+ }) => Router<ContextFrom, ContextTo, RequiredParams, Routes | Route<ContextFrom, ContextTo, Input, Response, "/openapi.json", RequiredParams, "GET", {}, never, never>, Input>;
125
125
  private readonly method;
126
- readonly get: <Path extends string, ResultOutput = never, Query extends AnyQuery = {}, Body extends JSONValue = never>(path: Path, route: ((data: RouteRunData<RequiredParams | ExtractRouteParams<Path>, ContextTo, Query, Body>) => ResultOutput | Promise<ResultOutput>) | (Omit<Route<ContextFrom, ContextTo, Input, ResultOutput, Path, RequiredParams, "GET", Query, Body>, "body" | "path" | "method" | "router" | "openapi"> & {
126
+ readonly get: <Path extends string, ResultOutput = never, Query extends AnyQuery = {}, BodyInput extends JSONValue = never, BodyOutput = never>(path: Path, route: ((data: RouteRunData<RequiredParams | ExtractRouteParams<Path>, ContextTo, Query, BodyOutput>) => ResultOutput | Promise<ResultOutput>) | (Omit<Route<ContextFrom, ContextTo, Input, ResultOutput, Path, RequiredParams, "GET", Query, BodyInput, BodyOutput>, "body" | "path" | "method" | "router" | "openapi"> & {
127
127
  openapi?: OpenAPISpecFor<ResultOutput>;
128
- })) => Router<ContextFrom, ContextTo, RequiredParams, Routes | Route<ContextFrom, ContextTo, Input, ResultOutput, Path, RequiredParams, "GET", Query, Body>, Input>;
129
- readonly post: <Path extends string, ResultOutput = never, Query extends AnyQuery = {}, Body extends JSONValue = never>(path: Path, route: ((data: RouteRunData<RequiredParams | ExtractRouteParams<Path>, ContextTo, Query, Body>) => ResultOutput | Promise<ResultOutput>) | (Omit<Route<ContextFrom, ContextTo, Input, ResultOutput, Path, RequiredParams, "POST", Query, Body>, "path" | "method" | "router" | "openapi"> & {
128
+ })) => Router<ContextFrom, ContextTo, RequiredParams, Routes | Route<ContextFrom, ContextTo, Input, ResultOutput, Path, RequiredParams, "GET", Query, BodyInput, BodyOutput>, Input>;
129
+ readonly post: <Path extends string, ResultOutput = never, Query extends AnyQuery = {}, BodyInput extends JSONValue = never, BodyOutput = never>(path: Path, route: ((data: RouteRunData<RequiredParams | ExtractRouteParams<Path>, ContextTo, Query, BodyOutput>) => ResultOutput | Promise<ResultOutput>) | (Omit<Route<ContextFrom, ContextTo, Input, ResultOutput, Path, RequiredParams, "POST", Query, BodyInput, BodyOutput>, "path" | "method" | "router" | "openapi"> & {
130
130
  openapi?: OpenAPISpecFor<ResultOutput>;
131
- })) => Router<ContextFrom, ContextTo, RequiredParams, Routes | Route<ContextFrom, ContextTo, Input, ResultOutput, Path, RequiredParams, "POST", Query, Body>, Input>;
132
- readonly put: <Path extends string, ResultOutput = never, Query extends AnyQuery = {}, Body extends JSONValue = never>(path: Path, route: ((data: RouteRunData<RequiredParams | ExtractRouteParams<Path>, ContextTo, Query, Body>) => ResultOutput | Promise<ResultOutput>) | (Omit<Route<ContextFrom, ContextTo, Input, ResultOutput, Path, RequiredParams, "PUT", Query, Body>, "path" | "method" | "router" | "openapi"> & {
131
+ })) => Router<ContextFrom, ContextTo, RequiredParams, Routes | Route<ContextFrom, ContextTo, Input, ResultOutput, Path, RequiredParams, "POST", Query, BodyInput, BodyOutput>, Input>;
132
+ readonly put: <Path extends string, ResultOutput = never, Query extends AnyQuery = {}, BodyInput extends JSONValue = never, BodyOutput = never>(path: Path, route: ((data: RouteRunData<RequiredParams | ExtractRouteParams<Path>, ContextTo, Query, BodyOutput>) => ResultOutput | Promise<ResultOutput>) | (Omit<Route<ContextFrom, ContextTo, Input, ResultOutput, Path, RequiredParams, "PUT", Query, BodyInput, BodyOutput>, "path" | "method" | "router" | "openapi"> & {
133
133
  openapi?: OpenAPISpecFor<ResultOutput>;
134
- })) => Router<ContextFrom, ContextTo, RequiredParams, Routes | Route<ContextFrom, ContextTo, Input, ResultOutput, Path, RequiredParams, "PUT", Query, Body>, Input>;
135
- readonly patch: <Path extends string, ResultOutput = never, Query extends AnyQuery = {}, Body extends JSONValue = never>(path: Path, route: ((data: RouteRunData<RequiredParams | ExtractRouteParams<Path>, ContextTo, Query, Body>) => ResultOutput | Promise<ResultOutput>) | (Omit<Route<ContextFrom, ContextTo, Input, ResultOutput, Path, RequiredParams, "PATCH", Query, Body>, "path" | "method" | "router" | "openapi"> & {
134
+ })) => Router<ContextFrom, ContextTo, RequiredParams, Routes | Route<ContextFrom, ContextTo, Input, ResultOutput, Path, RequiredParams, "PUT", Query, BodyInput, BodyOutput>, Input>;
135
+ readonly patch: <Path extends string, ResultOutput = never, Query extends AnyQuery = {}, BodyInput extends JSONValue = never, BodyOutput = never>(path: Path, route: ((data: RouteRunData<RequiredParams | ExtractRouteParams<Path>, ContextTo, Query, BodyOutput>) => ResultOutput | Promise<ResultOutput>) | (Omit<Route<ContextFrom, ContextTo, Input, ResultOutput, Path, RequiredParams, "PATCH", Query, BodyInput, BodyOutput>, "path" | "method" | "router" | "openapi"> & {
136
136
  openapi?: OpenAPISpecFor<ResultOutput>;
137
- })) => Router<ContextFrom, ContextTo, RequiredParams, Routes | Route<ContextFrom, ContextTo, Input, ResultOutput, Path, RequiredParams, "PATCH", Query, Body>, Input>;
138
- readonly delete: <Path extends string, ResultOutput = never, Query extends AnyQuery = {}, Body extends JSONValue = never>(path: Path, route: ((data: RouteRunData<RequiredParams | ExtractRouteParams<Path>, ContextTo, Query, Body>) => ResultOutput | Promise<ResultOutput>) | (Omit<Route<ContextFrom, ContextTo, Input, ResultOutput, Path, RequiredParams, "DELETE", Query, Body>, "path" | "method" | "router" | "openapi"> & {
137
+ })) => Router<ContextFrom, ContextTo, RequiredParams, Routes | Route<ContextFrom, ContextTo, Input, ResultOutput, Path, RequiredParams, "PATCH", Query, BodyInput, BodyOutput>, Input>;
138
+ readonly delete: <Path extends string, ResultOutput = never, Query extends AnyQuery = {}, BodyInput extends JSONValue = never, BodyOutput = never>(path: Path, route: ((data: RouteRunData<RequiredParams | ExtractRouteParams<Path>, ContextTo, Query, BodyOutput>) => ResultOutput | Promise<ResultOutput>) | (Omit<Route<ContextFrom, ContextTo, Input, ResultOutput, Path, RequiredParams, "DELETE", Query, BodyInput, BodyOutput>, "path" | "method" | "router" | "openapi"> & {
139
139
  openapi?: OpenAPISpecFor<ResultOutput>;
140
- })) => Router<ContextFrom, ContextTo, RequiredParams, Routes | Route<ContextFrom, ContextTo, Input, ResultOutput, Path, RequiredParams, "DELETE", Query, Body>, Input>;
141
- readonly head: <Path extends string, ResultOutput = never, Query extends AnyQuery = {}, Body extends JSONValue = never>(path: Path, route: ((data: RouteRunData<RequiredParams | ExtractRouteParams<Path>, ContextTo, Query, Body>) => ResultOutput | Promise<ResultOutput>) | (Omit<Route<ContextFrom, ContextTo, Input, ResultOutput, Path, RequiredParams, "HEAD", Query, Body>, "path" | "method" | "router" | "openapi"> & {
140
+ })) => Router<ContextFrom, ContextTo, RequiredParams, Routes | Route<ContextFrom, ContextTo, Input, ResultOutput, Path, RequiredParams, "DELETE", Query, BodyInput, BodyOutput>, Input>;
141
+ readonly head: <Path extends string, ResultOutput = never, Query extends AnyQuery = {}, BodyInput extends JSONValue = never, BodyOutput = never>(path: Path, route: ((data: RouteRunData<RequiredParams | ExtractRouteParams<Path>, ContextTo, Query, BodyOutput>) => ResultOutput | Promise<ResultOutput>) | (Omit<Route<ContextFrom, ContextTo, Input, ResultOutput, Path, RequiredParams, "HEAD", Query, BodyInput, BodyOutput>, "path" | "method" | "router" | "openapi"> & {
142
142
  openapi?: OpenAPISpecFor<ResultOutput>;
143
- })) => Router<ContextFrom, ContextTo, RequiredParams, Routes | Route<ContextFrom, ContextTo, Input, ResultOutput, Path, RequiredParams, "HEAD", Query, Body>, Input>;
144
- readonly options: <Path extends string, ResultOutput = never, Query extends AnyQuery = {}, Body extends JSONValue = never>(path: Path, route: ((data: RouteRunData<RequiredParams | ExtractRouteParams<Path>, ContextTo, Query, Body>) => ResultOutput | Promise<ResultOutput>) | (Omit<Route<ContextFrom, ContextTo, Input, ResultOutput, Path, RequiredParams, "OPTIONS", Query, Body>, "path" | "method" | "router" | "openapi"> & {
143
+ })) => Router<ContextFrom, ContextTo, RequiredParams, Routes | Route<ContextFrom, ContextTo, Input, ResultOutput, Path, RequiredParams, "HEAD", Query, BodyInput, BodyOutput>, Input>;
144
+ readonly options: <Path extends string, ResultOutput = never, Query extends AnyQuery = {}, BodyInput extends JSONValue = never, BodyOutput = never>(path: Path, route: ((data: RouteRunData<RequiredParams | ExtractRouteParams<Path>, ContextTo, Query, BodyOutput>) => ResultOutput | Promise<ResultOutput>) | (Omit<Route<ContextFrom, ContextTo, Input, ResultOutput, Path, RequiredParams, "OPTIONS", Query, BodyInput, BodyOutput>, "path" | "method" | "router" | "openapi"> & {
145
145
  openapi?: OpenAPISpecFor<ResultOutput>;
146
- })) => Router<ContextFrom, ContextTo, RequiredParams, Routes | Route<ContextFrom, ContextTo, Input, ResultOutput, Path, RequiredParams, "OPTIONS", Query, Body>, Input>;
146
+ })) => Router<ContextFrom, ContextTo, RequiredParams, Routes | Route<ContextFrom, ContextTo, Input, ResultOutput, Path, RequiredParams, "OPTIONS", Query, BodyInput, BodyOutput>, Input>;
147
147
  through: <NextContext>(through: (context: ContextTo, params: Record<RequiredParams, string>) => MaybePromise<NextContext>) => Router<ContextFrom, NextContext, RequiredParams, Routes, Input>;
148
148
  }
149
149
 
@@ -157,45 +157,57 @@ type AnyQuery = {
157
157
  [key in string]: any;
158
158
  };
159
159
  type Through<From, To, RequiredParams extends string> = (context: From, params: Record<RequiredParams, string>) => Promise<To>;
160
- type SSEOutputSpecWithSchema = {
160
+ /**
161
+ * Wraps BaseSchema to prevent the schema from participating in inference for `Output`.
162
+ *
163
+ * BaseSchema's `_output` is covariant (readonly), which means when both `run()` and the schema
164
+ * compete to infer `ResultOutput`, TypeScript widens to the less specific type (e.g. `string`
165
+ * instead of `"us-east-1"`). `NoInfer` ensures `Output` is only inferred from
166
+ * `run()`, and the schema only checks against it via the contravariant `serialize` property.
167
+ *
168
+ * @see https://github.com/microsoft/TypeScript/issues/51756
169
+ */
170
+ type OutputSchema<Output> = BaseSchema<any, any, any> & {
171
+ serialize: (value: NoInfer<Output>) => JSONValue;
172
+ };
173
+ type SSEOutputSpecWithSchema<Output> = {
161
174
  type: 'sse';
162
- schema: BaseSchema<any, any, any>;
175
+ schema: OutputSchema<Output>;
176
+ summary?: string | undefined;
163
177
  description?: string | undefined;
164
178
  };
165
179
  type SSEOutputSpecWithoutSchema = {
166
180
  type: 'sse';
167
181
  schema?: undefined;
182
+ summary?: string | undefined;
168
183
  description?: string | undefined;
169
184
  };
170
- type SSEOutputSpec = SSEOutputSpecWithSchema | SSEOutputSpecWithoutSchema;
171
- type JSONOutputSpec = {
185
+ type SSEOutputSpec<Output> = SSEOutputSpecWithSchema<Output> | SSEOutputSpecWithoutSchema;
186
+ type JSONOutputSpec<Output> = {
172
187
  type: 'json';
173
- schema: BaseSchema<any, any, any>;
188
+ schema: OutputSchema<Output>;
189
+ summary?: string | undefined;
174
190
  description?: string | undefined;
175
191
  };
176
192
  type ResponseOutputSpec = {
177
193
  type: 'response';
194
+ summary?: string | undefined;
178
195
  description?: string | undefined;
179
196
  };
180
- type OutputSpec = SSEOutputSpec | JSONOutputSpec | ResponseOutputSpec;
181
- type OpenAPISpec<Body extends OutputSpec = OutputSpec> = {
182
- summary?: string;
183
- description?: string;
184
- body: Body;
185
- };
186
- type OpenAPISpecFor<ResultOutput> = 0 extends 1 & ResultOutput ? OpenAPISpec : [ResultOutput] extends [never] ? OpenAPISpec : [ResultOutput] extends [KaitoSSEResponse<any>] ? [ResultOutput extends KaitoSSEResponse<SSEEvent<infer U, any>> ? U : never] extends [JSONValue] ? OpenAPISpec<SSEOutputSpec> : OpenAPISpec<SSEOutputSpecWithSchema> : [ResultOutput] extends [Response] ? OpenAPISpec<ResponseOutputSpec> : OpenAPISpec<JSONOutputSpec>;
187
- type Route<ContextFrom, ContextTo, RouterInput extends readonly unknown[], ResultOutput, Path extends string, AdditionalParams extends string, Method extends KaitoMethod, Query extends Record<string, JSONValue>, Body extends JSONValue> = {
188
- body?: AnySchemaFor<Body>;
197
+ type AnyOutputSpec = SSEOutputSpec<any> | JSONOutputSpec<any> | ResponseOutputSpec;
198
+ type OpenAPISpecFor<ResultOutput> = [ResultOutput] extends [never] ? AnyOutputSpec : [ResultOutput] extends [KaitoSSEResponse<infer Event>] ? Event extends SSEEvent<infer U, any> ? [U] extends [JSONValue] ? SSEOutputSpec<Event> : SSEOutputSpecWithSchema<Event> : SSEOutputSpec<any> : [ResultOutput] extends [Response] ? ResponseOutputSpec : JSONOutputSpec<ResultOutput>;
199
+ type Route<ContextFrom, ContextTo, RouterInput extends readonly unknown[], ResultOutput, Path extends string, AdditionalParams extends string, Method extends KaitoMethod, Query extends Record<string, JSONValue>, BodyInput extends JSONValue, BodyOutput> = {
200
+ body?: BaseSchema<BodyInput, BodyOutput, BaseSchemaDef<BodyInput>>;
189
201
  query?: {
190
202
  [Key in keyof Query]: AnySchemaFor<Query[Key]>;
191
203
  };
192
204
  path: Path;
193
205
  method: Method;
194
- openapi?: OpenAPISpec;
206
+ openapi?: AnyOutputSpec;
195
207
  router: Router<ContextFrom, ContextTo, AdditionalParams, AnyRoute, RouterInput>;
196
- run(data: RouteRunData<ExtractRouteParams<Path> | AdditionalParams, ContextTo, Query, Body>): Promise<ResultOutput> | ResultOutput;
208
+ run(data: RouteRunData<ExtractRouteParams<Path> | AdditionalParams, ContextTo, Query, BodyOutput>): Promise<ResultOutput> | ResultOutput;
197
209
  };
198
- type AnyRoute = Route<any, any, any, unknown, any, any, any, any, any>;
210
+ type AnyRoute = Route<any, any, any, unknown, any, any, any, any, any, any>;
199
211
 
200
212
  /**
201
213
  * A helper to check if the environment is Node.js-like and the `NODE_ENV` environment variable is set to `'development'`
@@ -297,4 +309,4 @@ interface KaitoConfig<ContextFrom, Input extends readonly unknown[]> {
297
309
  */
298
310
  declare const create: <Context = null, Input extends readonly unknown[] = []>(config?: KaitoConfig<Context, Input>) => Router<Context, Context, never, never, Input>;
299
311
 
300
- export { type AnyQuery, type AnyRoute, AnySchemaFor, BaseSchema, type ExtractRouteParams, type GetContext, type InferRoutes, type JSONOutputSpec, JSONValue, type KaitoConfig, KaitoError, KaitoHead, type KaitoMethod, KaitoRequest, type MaybePromise, type OpenAPISpec, type OpenAPISpecFor, type OutputSpec, type ResponseOutputSpec, type Route, type RouteRunData, Router, type RouterState, type SSEOutputSpec, type SSEOutputSpecWithSchema, type SSEOutputSpecWithoutSchema, type Through, WrappedError, create, isNodeLikeDev };
312
+ export { type AnyOutputSpec, type AnyQuery, type AnyRoute, AnySchemaFor, BaseSchema, BaseSchemaDef, type ExtractRouteParams, type GetContext, type InferRoutes, type JSONOutputSpec, JSONValue, type KaitoConfig, KaitoError, KaitoHead, type KaitoMethod, KaitoRequest, type MaybePromise, type OpenAPISpecFor, type ResponseOutputSpec, type Route, type RouteRunData, Router, type RouterState, type SSEOutputSpec, type SSEOutputSpecWithSchema, type SSEOutputSpecWithoutSchema, type Through, WrappedError, create, isNodeLikeDev };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { JSONValue, BaseSchema, AnySchemaFor } from './schema/schema.js';
2
- export { ArrayChecks, ArrayDef, BaseSchemaDef, BooleanDef, Issue, JSONPrimitive, KArray, KBoolean, KLazy, KLiteral, KNativeEnum, KNull, KNumber, KObject, KObjectFromURLSearchParams, KRecord, KRef, KScalar, KString, KUnion, LazyDef, LiteralDef, NativeEnumDef, NullDef, NumberChecks, NumberDef, NumberFormat, ObjectDef, ParseContext, ParseResult, RecordDef, RefDef, STRING_FORMAT_REGEXES, ScalarDef, ScalarOptions, SchemaError, StringChecks, StringDef, StringFormat, UnionDef, isPrimitiveJSONValue, k } from './schema/schema.js';
1
+ import { JSONValue, BaseSchema, BaseSchemaDef, AnySchemaFor } from './schema/schema.js';
2
+ export { ArrayChecks, ArrayDef, BooleanDef, Issue, JSONPrimitive, KArray, KBoolean, KLazy, KLiteral, KNativeEnum, KNull, KNumber, KObject, KObjectFromURLSearchParams, KRecord, KRef, KScalar, KString, KUnion, LazyDef, LiteralDef, NativeEnumDef, NullDef, NumberChecks, NumberDef, NumberFormat, ObjectDef, ParseContext, ParseResult, RecordDef, RefDef, STRING_FORMAT_REGEXES, ScalarDef, ScalarOptions, SchemaError, StringChecks, StringDef, StringFormat, UnionDef, isPrimitiveJSONValue, k } from './schema/schema.js';
3
3
  import * as OpenAPI from 'openapi3-ts/oas31';
4
4
  import { KaitoSSEResponse, SSEEvent } from './stream/stream.js';
5
5
 
@@ -74,7 +74,7 @@ declare class KaitoHead {
74
74
  get touched(): boolean;
75
75
  }
76
76
 
77
- type PrefixRoutesPathInner<R extends AnyRoute, Prefix extends `/${string}`> = R extends Route<infer ContextFrom, infer ContextTo, infer RouterInput, infer ResultOutput, infer Path, infer AdditionalParams, infer Method, infer Query, infer BodyOutput> ? Route<ContextFrom, ContextTo, RouterInput, ResultOutput, `${Prefix}${Path extends '/' ? '' : Path}`, AdditionalParams, Method, Query, BodyOutput> : never;
77
+ type PrefixRoutesPathInner<R extends AnyRoute, Prefix extends `/${string}`> = R extends Route<infer ContextFrom, infer ContextTo, infer RouterInput, infer ResultOutput, infer Path, infer AdditionalParams, infer Method, infer Query, infer BodyInput, infer BodyOutput> ? Route<ContextFrom, ContextTo, RouterInput, ResultOutput, `${Prefix}${Path extends '/' ? '' : Path}`, AdditionalParams, Method, Query, BodyInput, BodyOutput> : never;
78
78
  type PrefixRoutesPath<Prefix extends `/${string}`, R extends AnyRoute> = R extends R ? PrefixRoutesPathInner<R, Prefix> : never;
79
79
  type RouterState<ContextFrom, ContextTo, RequiredParams extends string, Routes extends AnyRoute, Input extends readonly unknown[]> = {
80
80
  routes: Set<Routes>;
@@ -121,29 +121,29 @@ declare class Router<ContextFrom, ContextTo, RequiredParams extends string, Rout
121
121
  openapi: ({ info, servers, }: {
122
122
  info: OpenAPI.InfoObject;
123
123
  servers?: Partial<Record<(`https://` | `http://`) | ({} & string), string>>;
124
- }) => Router<ContextFrom, ContextTo, RequiredParams, Routes | Route<ContextFrom, ContextTo, Input, Response, "/openapi.json", RequiredParams, "GET", {}, never>, Input>;
124
+ }) => Router<ContextFrom, ContextTo, RequiredParams, Routes | Route<ContextFrom, ContextTo, Input, Response, "/openapi.json", RequiredParams, "GET", {}, never, never>, Input>;
125
125
  private readonly method;
126
- readonly get: <Path extends string, ResultOutput = never, Query extends AnyQuery = {}, Body extends JSONValue = never>(path: Path, route: ((data: RouteRunData<RequiredParams | ExtractRouteParams<Path>, ContextTo, Query, Body>) => ResultOutput | Promise<ResultOutput>) | (Omit<Route<ContextFrom, ContextTo, Input, ResultOutput, Path, RequiredParams, "GET", Query, Body>, "body" | "path" | "method" | "router" | "openapi"> & {
126
+ readonly get: <Path extends string, ResultOutput = never, Query extends AnyQuery = {}, BodyInput extends JSONValue = never, BodyOutput = never>(path: Path, route: ((data: RouteRunData<RequiredParams | ExtractRouteParams<Path>, ContextTo, Query, BodyOutput>) => ResultOutput | Promise<ResultOutput>) | (Omit<Route<ContextFrom, ContextTo, Input, ResultOutput, Path, RequiredParams, "GET", Query, BodyInput, BodyOutput>, "body" | "path" | "method" | "router" | "openapi"> & {
127
127
  openapi?: OpenAPISpecFor<ResultOutput>;
128
- })) => Router<ContextFrom, ContextTo, RequiredParams, Routes | Route<ContextFrom, ContextTo, Input, ResultOutput, Path, RequiredParams, "GET", Query, Body>, Input>;
129
- readonly post: <Path extends string, ResultOutput = never, Query extends AnyQuery = {}, Body extends JSONValue = never>(path: Path, route: ((data: RouteRunData<RequiredParams | ExtractRouteParams<Path>, ContextTo, Query, Body>) => ResultOutput | Promise<ResultOutput>) | (Omit<Route<ContextFrom, ContextTo, Input, ResultOutput, Path, RequiredParams, "POST", Query, Body>, "path" | "method" | "router" | "openapi"> & {
128
+ })) => Router<ContextFrom, ContextTo, RequiredParams, Routes | Route<ContextFrom, ContextTo, Input, ResultOutput, Path, RequiredParams, "GET", Query, BodyInput, BodyOutput>, Input>;
129
+ readonly post: <Path extends string, ResultOutput = never, Query extends AnyQuery = {}, BodyInput extends JSONValue = never, BodyOutput = never>(path: Path, route: ((data: RouteRunData<RequiredParams | ExtractRouteParams<Path>, ContextTo, Query, BodyOutput>) => ResultOutput | Promise<ResultOutput>) | (Omit<Route<ContextFrom, ContextTo, Input, ResultOutput, Path, RequiredParams, "POST", Query, BodyInput, BodyOutput>, "path" | "method" | "router" | "openapi"> & {
130
130
  openapi?: OpenAPISpecFor<ResultOutput>;
131
- })) => Router<ContextFrom, ContextTo, RequiredParams, Routes | Route<ContextFrom, ContextTo, Input, ResultOutput, Path, RequiredParams, "POST", Query, Body>, Input>;
132
- readonly put: <Path extends string, ResultOutput = never, Query extends AnyQuery = {}, Body extends JSONValue = never>(path: Path, route: ((data: RouteRunData<RequiredParams | ExtractRouteParams<Path>, ContextTo, Query, Body>) => ResultOutput | Promise<ResultOutput>) | (Omit<Route<ContextFrom, ContextTo, Input, ResultOutput, Path, RequiredParams, "PUT", Query, Body>, "path" | "method" | "router" | "openapi"> & {
131
+ })) => Router<ContextFrom, ContextTo, RequiredParams, Routes | Route<ContextFrom, ContextTo, Input, ResultOutput, Path, RequiredParams, "POST", Query, BodyInput, BodyOutput>, Input>;
132
+ readonly put: <Path extends string, ResultOutput = never, Query extends AnyQuery = {}, BodyInput extends JSONValue = never, BodyOutput = never>(path: Path, route: ((data: RouteRunData<RequiredParams | ExtractRouteParams<Path>, ContextTo, Query, BodyOutput>) => ResultOutput | Promise<ResultOutput>) | (Omit<Route<ContextFrom, ContextTo, Input, ResultOutput, Path, RequiredParams, "PUT", Query, BodyInput, BodyOutput>, "path" | "method" | "router" | "openapi"> & {
133
133
  openapi?: OpenAPISpecFor<ResultOutput>;
134
- })) => Router<ContextFrom, ContextTo, RequiredParams, Routes | Route<ContextFrom, ContextTo, Input, ResultOutput, Path, RequiredParams, "PUT", Query, Body>, Input>;
135
- readonly patch: <Path extends string, ResultOutput = never, Query extends AnyQuery = {}, Body extends JSONValue = never>(path: Path, route: ((data: RouteRunData<RequiredParams | ExtractRouteParams<Path>, ContextTo, Query, Body>) => ResultOutput | Promise<ResultOutput>) | (Omit<Route<ContextFrom, ContextTo, Input, ResultOutput, Path, RequiredParams, "PATCH", Query, Body>, "path" | "method" | "router" | "openapi"> & {
134
+ })) => Router<ContextFrom, ContextTo, RequiredParams, Routes | Route<ContextFrom, ContextTo, Input, ResultOutput, Path, RequiredParams, "PUT", Query, BodyInput, BodyOutput>, Input>;
135
+ readonly patch: <Path extends string, ResultOutput = never, Query extends AnyQuery = {}, BodyInput extends JSONValue = never, BodyOutput = never>(path: Path, route: ((data: RouteRunData<RequiredParams | ExtractRouteParams<Path>, ContextTo, Query, BodyOutput>) => ResultOutput | Promise<ResultOutput>) | (Omit<Route<ContextFrom, ContextTo, Input, ResultOutput, Path, RequiredParams, "PATCH", Query, BodyInput, BodyOutput>, "path" | "method" | "router" | "openapi"> & {
136
136
  openapi?: OpenAPISpecFor<ResultOutput>;
137
- })) => Router<ContextFrom, ContextTo, RequiredParams, Routes | Route<ContextFrom, ContextTo, Input, ResultOutput, Path, RequiredParams, "PATCH", Query, Body>, Input>;
138
- readonly delete: <Path extends string, ResultOutput = never, Query extends AnyQuery = {}, Body extends JSONValue = never>(path: Path, route: ((data: RouteRunData<RequiredParams | ExtractRouteParams<Path>, ContextTo, Query, Body>) => ResultOutput | Promise<ResultOutput>) | (Omit<Route<ContextFrom, ContextTo, Input, ResultOutput, Path, RequiredParams, "DELETE", Query, Body>, "path" | "method" | "router" | "openapi"> & {
137
+ })) => Router<ContextFrom, ContextTo, RequiredParams, Routes | Route<ContextFrom, ContextTo, Input, ResultOutput, Path, RequiredParams, "PATCH", Query, BodyInput, BodyOutput>, Input>;
138
+ readonly delete: <Path extends string, ResultOutput = never, Query extends AnyQuery = {}, BodyInput extends JSONValue = never, BodyOutput = never>(path: Path, route: ((data: RouteRunData<RequiredParams | ExtractRouteParams<Path>, ContextTo, Query, BodyOutput>) => ResultOutput | Promise<ResultOutput>) | (Omit<Route<ContextFrom, ContextTo, Input, ResultOutput, Path, RequiredParams, "DELETE", Query, BodyInput, BodyOutput>, "path" | "method" | "router" | "openapi"> & {
139
139
  openapi?: OpenAPISpecFor<ResultOutput>;
140
- })) => Router<ContextFrom, ContextTo, RequiredParams, Routes | Route<ContextFrom, ContextTo, Input, ResultOutput, Path, RequiredParams, "DELETE", Query, Body>, Input>;
141
- readonly head: <Path extends string, ResultOutput = never, Query extends AnyQuery = {}, Body extends JSONValue = never>(path: Path, route: ((data: RouteRunData<RequiredParams | ExtractRouteParams<Path>, ContextTo, Query, Body>) => ResultOutput | Promise<ResultOutput>) | (Omit<Route<ContextFrom, ContextTo, Input, ResultOutput, Path, RequiredParams, "HEAD", Query, Body>, "path" | "method" | "router" | "openapi"> & {
140
+ })) => Router<ContextFrom, ContextTo, RequiredParams, Routes | Route<ContextFrom, ContextTo, Input, ResultOutput, Path, RequiredParams, "DELETE", Query, BodyInput, BodyOutput>, Input>;
141
+ readonly head: <Path extends string, ResultOutput = never, Query extends AnyQuery = {}, BodyInput extends JSONValue = never, BodyOutput = never>(path: Path, route: ((data: RouteRunData<RequiredParams | ExtractRouteParams<Path>, ContextTo, Query, BodyOutput>) => ResultOutput | Promise<ResultOutput>) | (Omit<Route<ContextFrom, ContextTo, Input, ResultOutput, Path, RequiredParams, "HEAD", Query, BodyInput, BodyOutput>, "path" | "method" | "router" | "openapi"> & {
142
142
  openapi?: OpenAPISpecFor<ResultOutput>;
143
- })) => Router<ContextFrom, ContextTo, RequiredParams, Routes | Route<ContextFrom, ContextTo, Input, ResultOutput, Path, RequiredParams, "HEAD", Query, Body>, Input>;
144
- readonly options: <Path extends string, ResultOutput = never, Query extends AnyQuery = {}, Body extends JSONValue = never>(path: Path, route: ((data: RouteRunData<RequiredParams | ExtractRouteParams<Path>, ContextTo, Query, Body>) => ResultOutput | Promise<ResultOutput>) | (Omit<Route<ContextFrom, ContextTo, Input, ResultOutput, Path, RequiredParams, "OPTIONS", Query, Body>, "path" | "method" | "router" | "openapi"> & {
143
+ })) => Router<ContextFrom, ContextTo, RequiredParams, Routes | Route<ContextFrom, ContextTo, Input, ResultOutput, Path, RequiredParams, "HEAD", Query, BodyInput, BodyOutput>, Input>;
144
+ readonly options: <Path extends string, ResultOutput = never, Query extends AnyQuery = {}, BodyInput extends JSONValue = never, BodyOutput = never>(path: Path, route: ((data: RouteRunData<RequiredParams | ExtractRouteParams<Path>, ContextTo, Query, BodyOutput>) => ResultOutput | Promise<ResultOutput>) | (Omit<Route<ContextFrom, ContextTo, Input, ResultOutput, Path, RequiredParams, "OPTIONS", Query, BodyInput, BodyOutput>, "path" | "method" | "router" | "openapi"> & {
145
145
  openapi?: OpenAPISpecFor<ResultOutput>;
146
- })) => Router<ContextFrom, ContextTo, RequiredParams, Routes | Route<ContextFrom, ContextTo, Input, ResultOutput, Path, RequiredParams, "OPTIONS", Query, Body>, Input>;
146
+ })) => Router<ContextFrom, ContextTo, RequiredParams, Routes | Route<ContextFrom, ContextTo, Input, ResultOutput, Path, RequiredParams, "OPTIONS", Query, BodyInput, BodyOutput>, Input>;
147
147
  through: <NextContext>(through: (context: ContextTo, params: Record<RequiredParams, string>) => MaybePromise<NextContext>) => Router<ContextFrom, NextContext, RequiredParams, Routes, Input>;
148
148
  }
149
149
 
@@ -157,45 +157,57 @@ type AnyQuery = {
157
157
  [key in string]: any;
158
158
  };
159
159
  type Through<From, To, RequiredParams extends string> = (context: From, params: Record<RequiredParams, string>) => Promise<To>;
160
- type SSEOutputSpecWithSchema = {
160
+ /**
161
+ * Wraps BaseSchema to prevent the schema from participating in inference for `Output`.
162
+ *
163
+ * BaseSchema's `_output` is covariant (readonly), which means when both `run()` and the schema
164
+ * compete to infer `ResultOutput`, TypeScript widens to the less specific type (e.g. `string`
165
+ * instead of `"us-east-1"`). `NoInfer` ensures `Output` is only inferred from
166
+ * `run()`, and the schema only checks against it via the contravariant `serialize` property.
167
+ *
168
+ * @see https://github.com/microsoft/TypeScript/issues/51756
169
+ */
170
+ type OutputSchema<Output> = BaseSchema<any, any, any> & {
171
+ serialize: (value: NoInfer<Output>) => JSONValue;
172
+ };
173
+ type SSEOutputSpecWithSchema<Output> = {
161
174
  type: 'sse';
162
- schema: BaseSchema<any, any, any>;
175
+ schema: OutputSchema<Output>;
176
+ summary?: string | undefined;
163
177
  description?: string | undefined;
164
178
  };
165
179
  type SSEOutputSpecWithoutSchema = {
166
180
  type: 'sse';
167
181
  schema?: undefined;
182
+ summary?: string | undefined;
168
183
  description?: string | undefined;
169
184
  };
170
- type SSEOutputSpec = SSEOutputSpecWithSchema | SSEOutputSpecWithoutSchema;
171
- type JSONOutputSpec = {
185
+ type SSEOutputSpec<Output> = SSEOutputSpecWithSchema<Output> | SSEOutputSpecWithoutSchema;
186
+ type JSONOutputSpec<Output> = {
172
187
  type: 'json';
173
- schema: BaseSchema<any, any, any>;
188
+ schema: OutputSchema<Output>;
189
+ summary?: string | undefined;
174
190
  description?: string | undefined;
175
191
  };
176
192
  type ResponseOutputSpec = {
177
193
  type: 'response';
194
+ summary?: string | undefined;
178
195
  description?: string | undefined;
179
196
  };
180
- type OutputSpec = SSEOutputSpec | JSONOutputSpec | ResponseOutputSpec;
181
- type OpenAPISpec<Body extends OutputSpec = OutputSpec> = {
182
- summary?: string;
183
- description?: string;
184
- body: Body;
185
- };
186
- type OpenAPISpecFor<ResultOutput> = 0 extends 1 & ResultOutput ? OpenAPISpec : [ResultOutput] extends [never] ? OpenAPISpec : [ResultOutput] extends [KaitoSSEResponse<any>] ? [ResultOutput extends KaitoSSEResponse<SSEEvent<infer U, any>> ? U : never] extends [JSONValue] ? OpenAPISpec<SSEOutputSpec> : OpenAPISpec<SSEOutputSpecWithSchema> : [ResultOutput] extends [Response] ? OpenAPISpec<ResponseOutputSpec> : OpenAPISpec<JSONOutputSpec>;
187
- type Route<ContextFrom, ContextTo, RouterInput extends readonly unknown[], ResultOutput, Path extends string, AdditionalParams extends string, Method extends KaitoMethod, Query extends Record<string, JSONValue>, Body extends JSONValue> = {
188
- body?: AnySchemaFor<Body>;
197
+ type AnyOutputSpec = SSEOutputSpec<any> | JSONOutputSpec<any> | ResponseOutputSpec;
198
+ type OpenAPISpecFor<ResultOutput> = [ResultOutput] extends [never] ? AnyOutputSpec : [ResultOutput] extends [KaitoSSEResponse<infer Event>] ? Event extends SSEEvent<infer U, any> ? [U] extends [JSONValue] ? SSEOutputSpec<Event> : SSEOutputSpecWithSchema<Event> : SSEOutputSpec<any> : [ResultOutput] extends [Response] ? ResponseOutputSpec : JSONOutputSpec<ResultOutput>;
199
+ type Route<ContextFrom, ContextTo, RouterInput extends readonly unknown[], ResultOutput, Path extends string, AdditionalParams extends string, Method extends KaitoMethod, Query extends Record<string, JSONValue>, BodyInput extends JSONValue, BodyOutput> = {
200
+ body?: BaseSchema<BodyInput, BodyOutput, BaseSchemaDef<BodyInput>>;
189
201
  query?: {
190
202
  [Key in keyof Query]: AnySchemaFor<Query[Key]>;
191
203
  };
192
204
  path: Path;
193
205
  method: Method;
194
- openapi?: OpenAPISpec;
206
+ openapi?: AnyOutputSpec;
195
207
  router: Router<ContextFrom, ContextTo, AdditionalParams, AnyRoute, RouterInput>;
196
- run(data: RouteRunData<ExtractRouteParams<Path> | AdditionalParams, ContextTo, Query, Body>): Promise<ResultOutput> | ResultOutput;
208
+ run(data: RouteRunData<ExtractRouteParams<Path> | AdditionalParams, ContextTo, Query, BodyOutput>): Promise<ResultOutput> | ResultOutput;
197
209
  };
198
- type AnyRoute = Route<any, any, any, unknown, any, any, any, any, any>;
210
+ type AnyRoute = Route<any, any, any, unknown, any, any, any, any, any, any>;
199
211
 
200
212
  /**
201
213
  * A helper to check if the environment is Node.js-like and the `NODE_ENV` environment variable is set to `'development'`
@@ -297,4 +309,4 @@ interface KaitoConfig<ContextFrom, Input extends readonly unknown[]> {
297
309
  */
298
310
  declare const create: <Context = null, Input extends readonly unknown[] = []>(config?: KaitoConfig<Context, Input>) => Router<Context, Context, never, never, Input>;
299
311
 
300
- export { type AnyQuery, type AnyRoute, AnySchemaFor, BaseSchema, type ExtractRouteParams, type GetContext, type InferRoutes, type JSONOutputSpec, JSONValue, type KaitoConfig, KaitoError, KaitoHead, type KaitoMethod, KaitoRequest, type MaybePromise, type OpenAPISpec, type OpenAPISpecFor, type OutputSpec, type ResponseOutputSpec, type Route, type RouteRunData, Router, type RouterState, type SSEOutputSpec, type SSEOutputSpecWithSchema, type SSEOutputSpecWithoutSchema, type Through, WrappedError, create, isNodeLikeDev };
312
+ export { type AnyOutputSpec, type AnyQuery, type AnyRoute, AnySchemaFor, BaseSchema, BaseSchemaDef, type ExtractRouteParams, type GetContext, type InferRoutes, type JSONOutputSpec, JSONValue, type KaitoConfig, KaitoError, KaitoHead, type KaitoMethod, KaitoRequest, type MaybePromise, type OpenAPISpecFor, type ResponseOutputSpec, type Route, type RouteRunData, Router, type RouterState, type SSEOutputSpec, type SSEOutputSpecWithSchema, type SSEOutputSpecWithoutSchema, type Through, WrappedError, create, isNodeLikeDev };
package/dist/index.js CHANGED
@@ -1,7 +1,3 @@
1
- import {
2
- KaitoSSEResponse,
3
- sseEventToString
4
- } from "./chunk-HJ5HIYGW.js";
5
1
  import {
6
2
  BaseSchema,
7
3
  KArray,
@@ -24,6 +20,10 @@ import {
24
20
  isPrimitiveJSONValue,
25
21
  k
26
22
  } from "./chunk-DRJX3OJG.js";
23
+ import {
24
+ KaitoSSEResponse,
25
+ sseEventToString
26
+ } from "./chunk-HJ5HIYGW.js";
27
27
 
28
28
  // src/router/router.ts
29
29
  import "openapi3-ts/oas31";
@@ -233,8 +233,7 @@ var Router = class _Router {
233
233
  params: rawParams
234
234
  });
235
235
  if (result instanceof KaitoSSEResponse) {
236
- const body2 = route.openapi?.body;
237
- const schema = body2 && "schema" in body2 ? body2.schema : void 0;
236
+ const schema = route.openapi && "schema" in route.openapi ? route.openapi.schema : void 0;
238
237
  const stringStream = result.events.pipeThrough(
239
238
  new TransformStream({
240
239
  transform(event, controller) {
@@ -266,8 +265,8 @@ var Router = class _Router {
266
265
  }
267
266
  return result;
268
267
  }
269
- if (route.openapi && "schema" in route.openapi.body && route.openapi.body.schema) {
270
- const parsed = route.openapi.body.schema.serialize(result);
268
+ if (route.openapi && "schema" in route.openapi && route.openapi.schema) {
269
+ const parsed = route.openapi.schema.serialize(result);
271
270
  return head.toResponse(parsed);
272
271
  }
273
272
  if (result === void 0) {
@@ -387,7 +386,7 @@ var Router = class _Router {
387
386
  paths[pathWithColonParamsReplaceWithCurlyBraces] = {};
388
387
  }
389
388
  let contentType;
390
- const type = route.openapi.body.type;
389
+ const type = route.openapi.type;
391
390
  switch (type) {
392
391
  case "json":
393
392
  contentType = "application/json";
@@ -401,15 +400,15 @@ var Router = class _Router {
401
400
  default:
402
401
  throw new Error(`Unknown output type in route ${route.method} ${route.path}: ${type}`);
403
402
  }
404
- if ("schema" in route.openapi.body && route.openapi.body.schema) visit(route.openapi.body.schema);
403
+ if ("schema" in route.openapi && route.openapi.schema) visit(route.openapi.schema);
405
404
  if (route.body) visit(route.body);
406
- const responseSchema = "schema" in route.openapi.body && route.openapi.body.schema ? route.openapi.body.schema.toOpenAPI() : { type: "string" };
405
+ const responseSchema = "schema" in route.openapi && route.openapi.schema ? route.openapi.schema.toOpenAPI() : { type: "string" };
407
406
  const item = {
408
407
  ...route.openapi.summary ? { summary: route.openapi.summary } : {},
409
408
  description: route.openapi?.description ?? "Successful response",
410
409
  responses: {
411
410
  200: {
412
- description: route.openapi.body.description ?? "Successful response",
411
+ description: route.openapi.description ?? "Successful response",
413
412
  content: {
414
413
  [contentType]: {
415
414
  schema: responseSchema
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kaito-http/core",
3
3
  "type": "module",
4
- "version": "4.0.0-beta.30",
4
+ "version": "4.0.0-beta.32",
5
5
  "author": "Alistair Smith <hi@alistair.sh>",
6
6
  "repository": "https://github.com/kaito-http/kaito",
7
7
  "dependencies": {