hono-openapi 0.5.0-rc.2 → 0.5.0-rc.4

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.d.cts CHANGED
@@ -2,176 +2,10 @@ import * as openapi_types from 'openapi-types';
2
2
  import { OpenAPIV3_1 } from 'openapi-types';
3
3
  import { Env, Input, Context, Next, MiddlewareHandler, ValidationTargets, Hono } from 'hono';
4
4
  import { BlankInput, TypedResponse, ValidationTargets as ValidationTargets$1, RouterRoute, BlankEnv, Input as Input$1, Schema, BlankSchema, MiddlewareHandler as MiddlewareHandler$1 } from 'hono/types';
5
+ import * as json_schema from 'json-schema';
5
6
  import { Hook } from '@hono/standard-validator';
6
7
  import { StatusCode } from 'hono/utils/http-status';
7
8
 
8
- // ==================================================================================================
9
- // JSON Schema Draft 07
10
- // ==================================================================================================
11
- // https://tools.ietf.org/html/draft-handrews-json-schema-validation-01
12
- // --------------------------------------------------------------------------------------------------
13
-
14
- /**
15
- * Primitive type
16
- * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.1.1
17
- */
18
- type JSONSchema7TypeName =
19
- | "string" //
20
- | "number"
21
- | "integer"
22
- | "boolean"
23
- | "object"
24
- | "array"
25
- | "null";
26
-
27
- /**
28
- * Primitive type
29
- * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.1.1
30
- */
31
- type JSONSchema7Type =
32
- | string //
33
- | number
34
- | boolean
35
- | JSONSchema7Object
36
- | JSONSchema7Array
37
- | null;
38
-
39
- // Workaround for infinite type recursion
40
- interface JSONSchema7Object {
41
- [key: string]: JSONSchema7Type;
42
- }
43
-
44
- // Workaround for infinite type recursion
45
- // https://github.com/Microsoft/TypeScript/issues/3496#issuecomment-128553540
46
- interface JSONSchema7Array extends Array<JSONSchema7Type> {}
47
-
48
- /**
49
- * Meta schema
50
- *
51
- * Recommended values:
52
- * - 'http://json-schema.org/schema#'
53
- * - 'http://json-schema.org/hyper-schema#'
54
- * - 'http://json-schema.org/draft-07/schema#'
55
- * - 'http://json-schema.org/draft-07/hyper-schema#'
56
- *
57
- * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-5
58
- */
59
- type JSONSchema7Version = string;
60
-
61
- /**
62
- * JSON Schema v7
63
- * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01
64
- */
65
- type JSONSchema7Definition = JSONSchema7 | boolean;
66
- interface JSONSchema7 {
67
- $id?: string | undefined;
68
- $ref?: string | undefined;
69
- $schema?: JSONSchema7Version | undefined;
70
- $comment?: string | undefined;
71
-
72
- /**
73
- * @see https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-00#section-8.2.4
74
- * @see https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-validation-00#appendix-A
75
- */
76
- $defs?: {
77
- [key: string]: JSONSchema7Definition;
78
- } | undefined;
79
-
80
- /**
81
- * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.1
82
- */
83
- type?: JSONSchema7TypeName | JSONSchema7TypeName[] | undefined;
84
- enum?: JSONSchema7Type[] | undefined;
85
- const?: JSONSchema7Type | undefined;
86
-
87
- /**
88
- * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.2
89
- */
90
- multipleOf?: number | undefined;
91
- maximum?: number | undefined;
92
- exclusiveMaximum?: number | undefined;
93
- minimum?: number | undefined;
94
- exclusiveMinimum?: number | undefined;
95
-
96
- /**
97
- * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.3
98
- */
99
- maxLength?: number | undefined;
100
- minLength?: number | undefined;
101
- pattern?: string | undefined;
102
-
103
- /**
104
- * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.4
105
- */
106
- items?: JSONSchema7Definition | JSONSchema7Definition[] | undefined;
107
- additionalItems?: JSONSchema7Definition | undefined;
108
- maxItems?: number | undefined;
109
- minItems?: number | undefined;
110
- uniqueItems?: boolean | undefined;
111
- contains?: JSONSchema7Definition | undefined;
112
-
113
- /**
114
- * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.5
115
- */
116
- maxProperties?: number | undefined;
117
- minProperties?: number | undefined;
118
- required?: string[] | undefined;
119
- properties?: {
120
- [key: string]: JSONSchema7Definition;
121
- } | undefined;
122
- patternProperties?: {
123
- [key: string]: JSONSchema7Definition;
124
- } | undefined;
125
- additionalProperties?: JSONSchema7Definition | undefined;
126
- dependencies?: {
127
- [key: string]: JSONSchema7Definition | string[];
128
- } | undefined;
129
- propertyNames?: JSONSchema7Definition | undefined;
130
-
131
- /**
132
- * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.6
133
- */
134
- if?: JSONSchema7Definition | undefined;
135
- then?: JSONSchema7Definition | undefined;
136
- else?: JSONSchema7Definition | undefined;
137
-
138
- /**
139
- * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.7
140
- */
141
- allOf?: JSONSchema7Definition[] | undefined;
142
- anyOf?: JSONSchema7Definition[] | undefined;
143
- oneOf?: JSONSchema7Definition[] | undefined;
144
- not?: JSONSchema7Definition | undefined;
145
-
146
- /**
147
- * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-7
148
- */
149
- format?: string | undefined;
150
-
151
- /**
152
- * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-8
153
- */
154
- contentMediaType?: string | undefined;
155
- contentEncoding?: string | undefined;
156
-
157
- /**
158
- * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-9
159
- */
160
- definitions?: {
161
- [key: string]: JSONSchema7Definition;
162
- } | undefined;
163
-
164
- /**
165
- * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-10
166
- */
167
- title?: string | undefined;
168
- description?: string | undefined;
169
- default?: JSONSchema7Type | undefined;
170
- readOnly?: boolean | undefined;
171
- writeOnly?: boolean | undefined;
172
- examples?: JSONSchema7Type | undefined;
173
- }
174
-
175
9
  /** The Standard Schema interface. */
176
10
  interface StandardSchemaV1<Input = unknown, Output = Input> {
177
11
  /** The Standard Schema properties. */
@@ -234,11 +68,11 @@ declare namespace StandardSchemaV1 {
234
68
  * @param schema Validation schema
235
69
  * @returns Resolver result
236
70
  */
237
- declare function resolver<Schema extends StandardSchemaV1>(schema: Schema): {
71
+ declare function resolver<Schema extends StandardSchemaV1>(schema: Schema, options?: Record<string, unknown>): {
238
72
  vendor: string;
239
73
  validate: (value: unknown) => StandardSchemaV1.Result<unknown> | Promise<StandardSchemaV1.Result<unknown>>;
240
- toJSONSchema: (options?: Record<string, unknown>) => Promise<JSONSchema7>;
241
- toOpenAPISchema: (options?: Record<string, unknown>) => Promise<{
74
+ toJSONSchema: () => Promise<json_schema.JSONSchema7>;
75
+ toOpenAPISchema: () => Promise<{
242
76
  schema: OpenAPIV3_1.SchemaObject;
243
77
  components: OpenAPIV3_1.ComponentsObject | undefined;
244
78
  }>;
@@ -264,7 +98,7 @@ declare function validator<Schema extends StandardSchemaV1, Target extends keyof
264
98
  out: {
265
99
  [K in Target]: Out;
266
100
  };
267
- }, V extends I = I>(target: Target, schema: Schema, hook?: Hook<StandardSchemaV1.InferOutput<Schema>, E, P, Target>, options?: Record<string, unknown>): MiddlewareHandler<E, P, V>;
101
+ }, V extends I = I>(target: Target, schema: Schema, hook?: Hook<StandardSchemaV1.InferOutput<Schema>, E, P, Target>, options?: ResolverReturnType["options"]): MiddlewareHandler<E, P, V>;
268
102
  /**
269
103
  * Describe a route with OpenAPI specs.
270
104
  * @param spec Options for describing a route
@@ -285,7 +119,7 @@ type HandlerResponse<T extends Partial<Record<StatusCode, StandardSchemaV1>> = P
285
119
  [K in keyof T]: T[K] extends StandardSchemaV1 ? PromiseOr<TypedResponse<StandardSchemaV1.InferOutput<T[K]>, Num<K> extends StatusCode ? Num<K> : never>> : never;
286
120
  }[keyof T];
287
121
  type Handler<E extends Env = any, P extends string = any, I extends Input = BlankInput, T extends Partial<Record<StatusCode, StandardSchemaV1>> = Partial<Record<StatusCode, StandardSchemaV1>>> = (c: Context<E, P, I>, next: Next) => HandlerResponse<T>;
288
- declare function describeResponse<E extends Env = any, P extends string = any, I extends Input = BlankInput, T extends Partial<Record<StatusCode, StandardSchemaV1>> = Partial<Record<StatusCode, StandardSchemaV1>>>(handler: Handler<E, P, I, T>, responses: ResponseObject<T>): Handler<E, P, I, T>;
122
+ declare function describeResponse<E extends Env = any, P extends string = any, I extends Input = BlankInput, T extends Partial<Record<StatusCode, StandardSchemaV1>> = Partial<Record<StatusCode, StandardSchemaV1>>>(handler: Handler<E, P, I, T>, responses: ResponseObject<T>, options?: Record<string, unknown>): Handler<E, P, I, T>;
289
123
 
290
124
  /**
291
125
  * The unique symbol for the middlewares, which makes it easier to identify them. Not meant to be used directly, unless you're creating a custom middleware.
@@ -294,15 +128,21 @@ declare const uniqueSymbol: unique symbol;
294
128
  declare const ALLOWED_METHODS: readonly ["GET", "PUT", "POST", "DELETE", "OPTIONS", "HEAD", "PATCH", "TRACE"];
295
129
  type AllowedMethods = (typeof ALLOWED_METHODS)[number];
296
130
  declare function registerSchemaPath({ route, specs, paths, }: RegisterSchemaPathOptions): void;
297
- declare function removeExcludedPaths(paths: OpenAPIV3_1.PathsObject, ctx: {
298
- options: SanitizedGenerateSpecOptions;
299
- }): OpenAPIV3_1.PathsObject<{}, {}>;
131
+ declare function removeExcludedPaths(paths: OpenAPIV3_1.PathsObject, ctx: SpecContext): OpenAPIV3_1.PathsObject<{}, {}>;
300
132
 
301
133
  type PromiseOr<T> = T | Promise<T>;
302
- type ResolverReturnType = ReturnType<typeof resolver>;
134
+ type ResolverReturnType = ReturnType<typeof resolver> & {
135
+ options?: {
136
+ /**
137
+ * Override the media type of the request body, if not specified, it will be `application/json` for `json` target and `multipart/form-data` for `form` target.
138
+ */
139
+ media?: string;
140
+ } & {
141
+ [key: string]: unknown;
142
+ };
143
+ };
303
144
  type HandlerUniqueProperty = (ResolverReturnType & {
304
145
  target: keyof ValidationTargets$1;
305
- options?: Record<string, unknown>;
306
146
  }) | {
307
147
  spec: DescribeRouteOptions;
308
148
  };
@@ -344,13 +184,15 @@ type GenerateSpecOptions = {
344
184
  */
345
185
  defaultOptions: Partial<Record<AllowedMethods | "ALL", DescribeRouteOptions>>;
346
186
  };
347
- type HaveDefaultValues = "documentation" | "excludeStaticFile" | "exclude" | "excludeMethods" | "excludeTags";
348
- type SanitizedGenerateSpecOptions = Pick<GenerateSpecOptions, HaveDefaultValues> & Omit<Partial<GenerateSpecOptions>, HaveDefaultValues>;
349
187
  type DescribeRouteOptions = Omit<OpenAPIV3_1.OperationObject, "responses" | "parameters"> & {
350
188
  /**
351
189
  * Pass `true` to hide route from OpenAPI/swagger document
352
190
  */
353
- hide?: boolean | ((c: Context) => boolean);
191
+ hide?: boolean | ((props: {
192
+ c?: Context;
193
+ method: string;
194
+ path: string;
195
+ }) => boolean);
354
196
  /**
355
197
  * Responses of the request
356
198
  */
@@ -366,9 +208,17 @@ type DescribeRouteOptions = Omit<OpenAPIV3_1.OperationObject, "responses" | "par
366
208
  };
367
209
  type RegisterSchemaPathOptions = {
368
210
  route: RouterRoute;
369
- specs?: DescribeRouteOptions | Pick<OpenAPIV3_1.OperationObject, "parameters" | "requestBody">;
211
+ specs?: DescribeRouteOptions & {
212
+ operationId?: string | ((route: RouterRoute) => string);
213
+ };
370
214
  paths: Partial<OpenAPIV3_1.PathsObject>;
371
215
  };
216
+ type HaveDefaultValues = "documentation" | "excludeStaticFile" | "exclude" | "excludeMethods" | "excludeTags";
217
+ type SanitizedGenerateSpecOptions = Pick<GenerateSpecOptions, HaveDefaultValues> & Omit<Partial<GenerateSpecOptions>, HaveDefaultValues>;
218
+ type SpecContext = {
219
+ components: OpenAPIV3_1.ComponentsObject;
220
+ options: SanitizedGenerateSpecOptions;
221
+ };
372
222
 
373
223
  /**
374
224
  * Route handler for OpenAPI specs
@@ -411,20 +261,7 @@ declare function generateSpecs<E extends Env = BlankEnv, P extends string = stri
411
261
  trace?: OpenAPIV3_1.OperationObject<{}>;
412
262
  };
413
263
  };
414
- components: {
415
- schemas: {
416
- [x: string]: OpenAPIV3_1.SchemaObject;
417
- };
418
- responses?: Record<string, OpenAPIV3_1.ReferenceObject | OpenAPIV3_1.ResponseObject>;
419
- parameters?: Record<string, OpenAPIV3_1.ReferenceObject | OpenAPIV3_1.ParameterObject>;
420
- examples?: Record<string, OpenAPIV3_1.ReferenceObject | OpenAPIV3_1.ExampleObject>;
421
- requestBodies?: Record<string, OpenAPIV3_1.ReferenceObject | OpenAPIV3_1.RequestBodyObject>;
422
- headers?: Record<string, OpenAPIV3_1.ReferenceObject | OpenAPIV3_1.HeaderObject>;
423
- securitySchemes?: Record<string, OpenAPIV3_1.ReferenceObject | OpenAPIV3_1.SecuritySchemeObject>;
424
- links?: Record<string, OpenAPIV3_1.ReferenceObject | OpenAPIV3_1.LinkObject>;
425
- callbacks?: Record<string, OpenAPIV3_1.ReferenceObject | OpenAPIV3_1.CallbackObject>;
426
- pathItems?: Record<string, OpenAPIV3_1.ReferenceObject | OpenAPIV3_1.PathItemObject>;
427
- };
264
+ components: OpenAPIV3_1.ComponentsObject;
428
265
  openapi: string;
429
266
  externalDocs?: openapi_types.OpenAPIV3.ExternalDocumentationObject;
430
267
  security?: openapi_types.OpenAPIV3.SecurityRequirementObject[];
@@ -433,4 +270,4 @@ declare function generateSpecs<E extends Env = BlankEnv, P extends string = stri
433
270
  jsonSchemaDialect?: string;
434
271
  }>;
435
272
 
436
- export { ALLOWED_METHODS, type AllowedMethods, type DescribeRouteOptions, type GenerateSpecOptions, type HandlerUniqueProperty, type PromiseOr, type RegisterSchemaPathOptions, type ResolverReturnType, type SanitizedGenerateSpecOptions, describeResponse, describeRoute, generateSpecs, openAPIRouteHandler, registerSchemaPath, removeExcludedPaths, resolver, uniqueSymbol, validator };
273
+ export { ALLOWED_METHODS, type AllowedMethods, type DescribeRouteOptions, type GenerateSpecOptions, type HandlerUniqueProperty, type PromiseOr, type RegisterSchemaPathOptions, type ResolverReturnType, type SpecContext, describeResponse, describeRoute, generateSpecs, openAPIRouteHandler, registerSchemaPath, removeExcludedPaths, resolver, uniqueSymbol, validator };
package/dist/index.d.ts CHANGED
@@ -2,176 +2,10 @@ import * as openapi_types from 'openapi-types';
2
2
  import { OpenAPIV3_1 } from 'openapi-types';
3
3
  import { Env, Input, Context, Next, MiddlewareHandler, ValidationTargets, Hono } from 'hono';
4
4
  import { BlankInput, TypedResponse, ValidationTargets as ValidationTargets$1, RouterRoute, BlankEnv, Input as Input$1, Schema, BlankSchema, MiddlewareHandler as MiddlewareHandler$1 } from 'hono/types';
5
+ import * as json_schema from 'json-schema';
5
6
  import { Hook } from '@hono/standard-validator';
6
7
  import { StatusCode } from 'hono/utils/http-status';
7
8
 
8
- // ==================================================================================================
9
- // JSON Schema Draft 07
10
- // ==================================================================================================
11
- // https://tools.ietf.org/html/draft-handrews-json-schema-validation-01
12
- // --------------------------------------------------------------------------------------------------
13
-
14
- /**
15
- * Primitive type
16
- * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.1.1
17
- */
18
- type JSONSchema7TypeName =
19
- | "string" //
20
- | "number"
21
- | "integer"
22
- | "boolean"
23
- | "object"
24
- | "array"
25
- | "null";
26
-
27
- /**
28
- * Primitive type
29
- * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.1.1
30
- */
31
- type JSONSchema7Type =
32
- | string //
33
- | number
34
- | boolean
35
- | JSONSchema7Object
36
- | JSONSchema7Array
37
- | null;
38
-
39
- // Workaround for infinite type recursion
40
- interface JSONSchema7Object {
41
- [key: string]: JSONSchema7Type;
42
- }
43
-
44
- // Workaround for infinite type recursion
45
- // https://github.com/Microsoft/TypeScript/issues/3496#issuecomment-128553540
46
- interface JSONSchema7Array extends Array<JSONSchema7Type> {}
47
-
48
- /**
49
- * Meta schema
50
- *
51
- * Recommended values:
52
- * - 'http://json-schema.org/schema#'
53
- * - 'http://json-schema.org/hyper-schema#'
54
- * - 'http://json-schema.org/draft-07/schema#'
55
- * - 'http://json-schema.org/draft-07/hyper-schema#'
56
- *
57
- * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-5
58
- */
59
- type JSONSchema7Version = string;
60
-
61
- /**
62
- * JSON Schema v7
63
- * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01
64
- */
65
- type JSONSchema7Definition = JSONSchema7 | boolean;
66
- interface JSONSchema7 {
67
- $id?: string | undefined;
68
- $ref?: string | undefined;
69
- $schema?: JSONSchema7Version | undefined;
70
- $comment?: string | undefined;
71
-
72
- /**
73
- * @see https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-00#section-8.2.4
74
- * @see https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-validation-00#appendix-A
75
- */
76
- $defs?: {
77
- [key: string]: JSONSchema7Definition;
78
- } | undefined;
79
-
80
- /**
81
- * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.1
82
- */
83
- type?: JSONSchema7TypeName | JSONSchema7TypeName[] | undefined;
84
- enum?: JSONSchema7Type[] | undefined;
85
- const?: JSONSchema7Type | undefined;
86
-
87
- /**
88
- * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.2
89
- */
90
- multipleOf?: number | undefined;
91
- maximum?: number | undefined;
92
- exclusiveMaximum?: number | undefined;
93
- minimum?: number | undefined;
94
- exclusiveMinimum?: number | undefined;
95
-
96
- /**
97
- * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.3
98
- */
99
- maxLength?: number | undefined;
100
- minLength?: number | undefined;
101
- pattern?: string | undefined;
102
-
103
- /**
104
- * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.4
105
- */
106
- items?: JSONSchema7Definition | JSONSchema7Definition[] | undefined;
107
- additionalItems?: JSONSchema7Definition | undefined;
108
- maxItems?: number | undefined;
109
- minItems?: number | undefined;
110
- uniqueItems?: boolean | undefined;
111
- contains?: JSONSchema7Definition | undefined;
112
-
113
- /**
114
- * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.5
115
- */
116
- maxProperties?: number | undefined;
117
- minProperties?: number | undefined;
118
- required?: string[] | undefined;
119
- properties?: {
120
- [key: string]: JSONSchema7Definition;
121
- } | undefined;
122
- patternProperties?: {
123
- [key: string]: JSONSchema7Definition;
124
- } | undefined;
125
- additionalProperties?: JSONSchema7Definition | undefined;
126
- dependencies?: {
127
- [key: string]: JSONSchema7Definition | string[];
128
- } | undefined;
129
- propertyNames?: JSONSchema7Definition | undefined;
130
-
131
- /**
132
- * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.6
133
- */
134
- if?: JSONSchema7Definition | undefined;
135
- then?: JSONSchema7Definition | undefined;
136
- else?: JSONSchema7Definition | undefined;
137
-
138
- /**
139
- * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.7
140
- */
141
- allOf?: JSONSchema7Definition[] | undefined;
142
- anyOf?: JSONSchema7Definition[] | undefined;
143
- oneOf?: JSONSchema7Definition[] | undefined;
144
- not?: JSONSchema7Definition | undefined;
145
-
146
- /**
147
- * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-7
148
- */
149
- format?: string | undefined;
150
-
151
- /**
152
- * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-8
153
- */
154
- contentMediaType?: string | undefined;
155
- contentEncoding?: string | undefined;
156
-
157
- /**
158
- * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-9
159
- */
160
- definitions?: {
161
- [key: string]: JSONSchema7Definition;
162
- } | undefined;
163
-
164
- /**
165
- * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-10
166
- */
167
- title?: string | undefined;
168
- description?: string | undefined;
169
- default?: JSONSchema7Type | undefined;
170
- readOnly?: boolean | undefined;
171
- writeOnly?: boolean | undefined;
172
- examples?: JSONSchema7Type | undefined;
173
- }
174
-
175
9
  /** The Standard Schema interface. */
176
10
  interface StandardSchemaV1<Input = unknown, Output = Input> {
177
11
  /** The Standard Schema properties. */
@@ -234,11 +68,11 @@ declare namespace StandardSchemaV1 {
234
68
  * @param schema Validation schema
235
69
  * @returns Resolver result
236
70
  */
237
- declare function resolver<Schema extends StandardSchemaV1>(schema: Schema): {
71
+ declare function resolver<Schema extends StandardSchemaV1>(schema: Schema, options?: Record<string, unknown>): {
238
72
  vendor: string;
239
73
  validate: (value: unknown) => StandardSchemaV1.Result<unknown> | Promise<StandardSchemaV1.Result<unknown>>;
240
- toJSONSchema: (options?: Record<string, unknown>) => Promise<JSONSchema7>;
241
- toOpenAPISchema: (options?: Record<string, unknown>) => Promise<{
74
+ toJSONSchema: () => Promise<json_schema.JSONSchema7>;
75
+ toOpenAPISchema: () => Promise<{
242
76
  schema: OpenAPIV3_1.SchemaObject;
243
77
  components: OpenAPIV3_1.ComponentsObject | undefined;
244
78
  }>;
@@ -264,7 +98,7 @@ declare function validator<Schema extends StandardSchemaV1, Target extends keyof
264
98
  out: {
265
99
  [K in Target]: Out;
266
100
  };
267
- }, V extends I = I>(target: Target, schema: Schema, hook?: Hook<StandardSchemaV1.InferOutput<Schema>, E, P, Target>, options?: Record<string, unknown>): MiddlewareHandler<E, P, V>;
101
+ }, V extends I = I>(target: Target, schema: Schema, hook?: Hook<StandardSchemaV1.InferOutput<Schema>, E, P, Target>, options?: ResolverReturnType["options"]): MiddlewareHandler<E, P, V>;
268
102
  /**
269
103
  * Describe a route with OpenAPI specs.
270
104
  * @param spec Options for describing a route
@@ -285,7 +119,7 @@ type HandlerResponse<T extends Partial<Record<StatusCode, StandardSchemaV1>> = P
285
119
  [K in keyof T]: T[K] extends StandardSchemaV1 ? PromiseOr<TypedResponse<StandardSchemaV1.InferOutput<T[K]>, Num<K> extends StatusCode ? Num<K> : never>> : never;
286
120
  }[keyof T];
287
121
  type Handler<E extends Env = any, P extends string = any, I extends Input = BlankInput, T extends Partial<Record<StatusCode, StandardSchemaV1>> = Partial<Record<StatusCode, StandardSchemaV1>>> = (c: Context<E, P, I>, next: Next) => HandlerResponse<T>;
288
- declare function describeResponse<E extends Env = any, P extends string = any, I extends Input = BlankInput, T extends Partial<Record<StatusCode, StandardSchemaV1>> = Partial<Record<StatusCode, StandardSchemaV1>>>(handler: Handler<E, P, I, T>, responses: ResponseObject<T>): Handler<E, P, I, T>;
122
+ declare function describeResponse<E extends Env = any, P extends string = any, I extends Input = BlankInput, T extends Partial<Record<StatusCode, StandardSchemaV1>> = Partial<Record<StatusCode, StandardSchemaV1>>>(handler: Handler<E, P, I, T>, responses: ResponseObject<T>, options?: Record<string, unknown>): Handler<E, P, I, T>;
289
123
 
290
124
  /**
291
125
  * The unique symbol for the middlewares, which makes it easier to identify them. Not meant to be used directly, unless you're creating a custom middleware.
@@ -294,15 +128,21 @@ declare const uniqueSymbol: unique symbol;
294
128
  declare const ALLOWED_METHODS: readonly ["GET", "PUT", "POST", "DELETE", "OPTIONS", "HEAD", "PATCH", "TRACE"];
295
129
  type AllowedMethods = (typeof ALLOWED_METHODS)[number];
296
130
  declare function registerSchemaPath({ route, specs, paths, }: RegisterSchemaPathOptions): void;
297
- declare function removeExcludedPaths(paths: OpenAPIV3_1.PathsObject, ctx: {
298
- options: SanitizedGenerateSpecOptions;
299
- }): OpenAPIV3_1.PathsObject<{}, {}>;
131
+ declare function removeExcludedPaths(paths: OpenAPIV3_1.PathsObject, ctx: SpecContext): OpenAPIV3_1.PathsObject<{}, {}>;
300
132
 
301
133
  type PromiseOr<T> = T | Promise<T>;
302
- type ResolverReturnType = ReturnType<typeof resolver>;
134
+ type ResolverReturnType = ReturnType<typeof resolver> & {
135
+ options?: {
136
+ /**
137
+ * Override the media type of the request body, if not specified, it will be `application/json` for `json` target and `multipart/form-data` for `form` target.
138
+ */
139
+ media?: string;
140
+ } & {
141
+ [key: string]: unknown;
142
+ };
143
+ };
303
144
  type HandlerUniqueProperty = (ResolverReturnType & {
304
145
  target: keyof ValidationTargets$1;
305
- options?: Record<string, unknown>;
306
146
  }) | {
307
147
  spec: DescribeRouteOptions;
308
148
  };
@@ -344,13 +184,15 @@ type GenerateSpecOptions = {
344
184
  */
345
185
  defaultOptions: Partial<Record<AllowedMethods | "ALL", DescribeRouteOptions>>;
346
186
  };
347
- type HaveDefaultValues = "documentation" | "excludeStaticFile" | "exclude" | "excludeMethods" | "excludeTags";
348
- type SanitizedGenerateSpecOptions = Pick<GenerateSpecOptions, HaveDefaultValues> & Omit<Partial<GenerateSpecOptions>, HaveDefaultValues>;
349
187
  type DescribeRouteOptions = Omit<OpenAPIV3_1.OperationObject, "responses" | "parameters"> & {
350
188
  /**
351
189
  * Pass `true` to hide route from OpenAPI/swagger document
352
190
  */
353
- hide?: boolean | ((c: Context) => boolean);
191
+ hide?: boolean | ((props: {
192
+ c?: Context;
193
+ method: string;
194
+ path: string;
195
+ }) => boolean);
354
196
  /**
355
197
  * Responses of the request
356
198
  */
@@ -366,9 +208,17 @@ type DescribeRouteOptions = Omit<OpenAPIV3_1.OperationObject, "responses" | "par
366
208
  };
367
209
  type RegisterSchemaPathOptions = {
368
210
  route: RouterRoute;
369
- specs?: DescribeRouteOptions | Pick<OpenAPIV3_1.OperationObject, "parameters" | "requestBody">;
211
+ specs?: DescribeRouteOptions & {
212
+ operationId?: string | ((route: RouterRoute) => string);
213
+ };
370
214
  paths: Partial<OpenAPIV3_1.PathsObject>;
371
215
  };
216
+ type HaveDefaultValues = "documentation" | "excludeStaticFile" | "exclude" | "excludeMethods" | "excludeTags";
217
+ type SanitizedGenerateSpecOptions = Pick<GenerateSpecOptions, HaveDefaultValues> & Omit<Partial<GenerateSpecOptions>, HaveDefaultValues>;
218
+ type SpecContext = {
219
+ components: OpenAPIV3_1.ComponentsObject;
220
+ options: SanitizedGenerateSpecOptions;
221
+ };
372
222
 
373
223
  /**
374
224
  * Route handler for OpenAPI specs
@@ -411,20 +261,7 @@ declare function generateSpecs<E extends Env = BlankEnv, P extends string = stri
411
261
  trace?: OpenAPIV3_1.OperationObject<{}>;
412
262
  };
413
263
  };
414
- components: {
415
- schemas: {
416
- [x: string]: OpenAPIV3_1.SchemaObject;
417
- };
418
- responses?: Record<string, OpenAPIV3_1.ReferenceObject | OpenAPIV3_1.ResponseObject>;
419
- parameters?: Record<string, OpenAPIV3_1.ReferenceObject | OpenAPIV3_1.ParameterObject>;
420
- examples?: Record<string, OpenAPIV3_1.ReferenceObject | OpenAPIV3_1.ExampleObject>;
421
- requestBodies?: Record<string, OpenAPIV3_1.ReferenceObject | OpenAPIV3_1.RequestBodyObject>;
422
- headers?: Record<string, OpenAPIV3_1.ReferenceObject | OpenAPIV3_1.HeaderObject>;
423
- securitySchemes?: Record<string, OpenAPIV3_1.ReferenceObject | OpenAPIV3_1.SecuritySchemeObject>;
424
- links?: Record<string, OpenAPIV3_1.ReferenceObject | OpenAPIV3_1.LinkObject>;
425
- callbacks?: Record<string, OpenAPIV3_1.ReferenceObject | OpenAPIV3_1.CallbackObject>;
426
- pathItems?: Record<string, OpenAPIV3_1.ReferenceObject | OpenAPIV3_1.PathItemObject>;
427
- };
264
+ components: OpenAPIV3_1.ComponentsObject;
428
265
  openapi: string;
429
266
  externalDocs?: openapi_types.OpenAPIV3.ExternalDocumentationObject;
430
267
  security?: openapi_types.OpenAPIV3.SecurityRequirementObject[];
@@ -433,4 +270,4 @@ declare function generateSpecs<E extends Env = BlankEnv, P extends string = stri
433
270
  jsonSchemaDialect?: string;
434
271
  }>;
435
272
 
436
- export { ALLOWED_METHODS, type AllowedMethods, type DescribeRouteOptions, type GenerateSpecOptions, type HandlerUniqueProperty, type PromiseOr, type RegisterSchemaPathOptions, type ResolverReturnType, type SanitizedGenerateSpecOptions, describeResponse, describeRoute, generateSpecs, openAPIRouteHandler, registerSchemaPath, removeExcludedPaths, resolver, uniqueSymbol, validator };
273
+ export { ALLOWED_METHODS, type AllowedMethods, type DescribeRouteOptions, type GenerateSpecOptions, type HandlerUniqueProperty, type PromiseOr, type RegisterSchemaPathOptions, type ResolverReturnType, type SpecContext, describeResponse, describeRoute, generateSpecs, openAPIRouteHandler, registerSchemaPath, removeExcludedPaths, resolver, uniqueSymbol, validator };