import * as openapi_types from 'openapi-types';
import { OpenAPIV3_1 } from 'openapi-types';
import { Env, Input, Context, Next, MiddlewareHandler, ValidationTargets, Hono } from 'hono';
import { TypedResponse, RouterRoute, ValidationTargets as ValidationTargets$1, BlankEnv, Input as Input$1, BlankInput, Schema, BlankSchema, MiddlewareHandler as MiddlewareHandler$1 } from 'hono/types';
import { loadVendor as loadVendor$2, ToOpenAPISchemaContext } from '@standard-community/standard-openapi';
import { Hook } from '@hono/standard-validator';
import { loadVendor as loadVendor$1 } from '@standard-community/standard-json';
import { StatusCode } from 'hono/utils/http-status';
import { JSONParsed } from 'hono/utils/types';
import { JSONSchema7 } from 'json-schema';
/** The Standard Schema interface. */
interface StandardSchemaV1 {
/** The Standard Schema properties. */
readonly "~standard": StandardSchemaV1.Props ;
}
declare namespace StandardSchemaV1 {
/** The Standard Schema properties interface. */
export interface Props {
/** The version number of the standard. */
readonly version: 1;
/** The vendor name of the schema library. */
readonly vendor: string;
/** Validates unknown input values. */
readonly validate: (value: unknown) => Result | Promise>;
/** Inferred types associated with the schema. */
readonly types?: Types | undefined;
}
/** The result interface of the validate function. */
export type Result = SuccessResult | FailureResult;
/** The result interface if validation succeeds. */
export interface SuccessResult {
/** The typed output value. */
readonly value: Output;
/** The non-existent issues. */
readonly issues?: undefined;
}
/** The result interface if validation fails. */
export interface FailureResult {
/** The issues of failed validation. */
readonly issues: ReadonlyArray;
}
/** The issue interface of the failure output. */
export interface Issue {
/** The error message of the issue. */
readonly message: string;
/** The path of the issue, if any. */
readonly path?: ReadonlyArray | undefined;
}
/** The path segment interface of the issue. */
export interface PathSegment {
/** The key representing a path segment. */
readonly key: PropertyKey;
}
/** The Standard Schema types interface. */
export interface Types {
/** The input type of the schema. */
readonly input: Input;
/** The output type of the schema. */
readonly output: Output;
}
/** Infers the input type of a Standard Schema. */
export type InferInput = NonNullable["input"];
/** Infers the output type of a Standard Schema. */
export type InferOutput = NonNullable["output"];
export { };
}
declare function loadVendor(vendor: string, fn: {
toJSONSchema?: Parameters[1];
toOpenAPISchema?: Parameters[1];
}): void;
/**
* Generate a resolver for a validation schema
* @param schema Validation schema
* @returns Resolver result
*/
declare function resolver(schema: Schema, userDefinedOptions?: Record): {
vendor: string;
validate: (value: unknown) => StandardSchemaV1.Result | Promise>;
toJSONSchema: (customOptions?: Record) => JSONSchema7 | Promise;
toOpenAPISchema: (customOptions?: Record) => Promise<{
schema: OpenAPIV3_1.SchemaObject;
components: OpenAPIV3_1.ComponentsObject | undefined;
}>;
};
type HasUndefined = undefined extends T ? true : false;
/**
* Create a validator middleware
* @param target Target for validation
* @param schema Validation schema
* @param hook Hook for validation
* @returns Middleware handler
*/
declare function validator, Out = StandardSchemaV1.InferOutput, I extends Input = {
in: HasUndefined extends true ? {
[K in Target]?: In extends ValidationTargets[K] ? In : {
[K2 in keyof In]?: ValidationTargets[K][K2];
};
} : {
[K in Target]: In extends ValidationTargets[K] ? In : {
[K2 in keyof In]: ValidationTargets[K][K2];
};
};
out: {
[K in Target]: Out;
};
}, V extends I = I>(target: Target, schema: Schema, hook?: Hook, E, P, Target>, options?: ResolverReturnType["options"]): MiddlewareHandler;
/**
* Describe a route with OpenAPI specs.
* @param spec Options for describing a route
* @returns Middleware handler
*/
declare function describeRoute(spec: DescribeRouteOptions): MiddlewareHandler;
type ResponseObject>> = {
[K in keyof T]: OpenAPIV3_1.ReferenceObject | (OpenAPIV3_1.ResponseObject & {
content?: {
[media: string]: OpenAPIV3_1.MediaTypeObject & {
vSchema?: T[K];
};
};
});
};
type Num = T extends `${infer N extends number}` ? N : T;
type HandlerResponse> = Partial>> = PromiseOr<{
[K in keyof T]: T[K] extends StandardSchemaV1 ? TypedResponse>, Num extends StatusCode ? Num : never> : never;
}[keyof T]>;
type Handler> = Partial>> = (c: Context, next: Next) => HandlerResponse;
declare function describeResponse> = Partial>>(handler: Handler, responses: ResponseObject, options?: Record): Handler;
/**
* 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.
*/
declare const uniqueSymbol: unique symbol;
declare const ALLOWED_METHODS: readonly ["GET", "PUT", "POST", "DELETE", "OPTIONS", "HEAD", "PATCH", "TRACE"];
type AllowedMethods = (typeof ALLOWED_METHODS)[number];
declare function clearSpecsContext(): void;
declare function registerSchemaPath({ route, specs, paths, }: RegisterSchemaPathOptions): void;
declare function removeExcludedPaths(paths: OpenAPIV3_1.PathsObject, ctx: SpecContext): OpenAPIV3_1.PathsObject<{}, {}>;
type PromiseOr = T | Promise;
type ResolverReturnType = ReturnType & {
options?: {
/**
* 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.
*/
media?: string;
} & Partial;
};
type HandlerUniqueProperty = (ResolverReturnType & {
target: keyof ValidationTargets$1;
}) | {
spec: DescribeRouteOptions;
};
/**
* A media type object that accepts resolver() output in addition to standard schema types.
*/
type MediaTypeObjectWithResolver = Omit & {
schema?: OpenAPIV3_1.ReferenceObject | OpenAPIV3_1.SchemaObject | ResolverReturnType;
};
/**
* A response object that accepts resolver() output in schema positions.
*/
type ResponseObjectWithResolver = (Omit & {
content?: {
[media: string]: MediaTypeObjectWithResolver;
};
}) | OpenAPIV3_1.ReferenceObject;
/**
* A responses map that accepts resolver() output in schema positions.
*/
type ResponsesWithResolver = {
[key: string]: ResponseObjectWithResolver;
};
/**
* Extended document type that allows resolver() in documentation.components.responses
*/
type DocumentWithResolver = Omit, "x-express-openapi-additional-middleware" | "x-express-openapi-validation-strict" | "components"> & {
components?: Omit & {
responses?: ResponsesWithResolver;
};
};
type GenerateSpecOptions = {
/**
* Customize OpenAPI config, refers to Swagger 2.0 config
*
* @see https://swagger.io/specification/v2/
*/
documentation: DocumentWithResolver;
/**
* Include paths which don't have the handlers.
* This is useful when you want to document the
* API without implementing it or index all the paths.
*/
includeEmptyPaths: boolean;
/**
* Determine if Swagger should exclude static files (by checking if the last path segment contains a period).
*
* @default true
*/
excludeStaticFile: boolean;
/**
* Paths to exclude from OpenAPI endpoint
*
* @default []
*/
exclude: string | RegExp | Array;
/**
* Exclude methods from the specs
*/
excludeMethods: AllowedMethods[];
/**
* Exclude tags from OpenAPI
*/
excludeTags: string[];
/**
* Default options for `describeRoute` method
*/
defaultOptions: Partial>;
};
type OperationId = string | ((route: RouterRoute) => string);
type DescribeRouteOptions = Omit & {
operationId?: OperationId;
/**
* Pass `true` to hide route from OpenAPI/swagger document
*/
hide?: boolean | ((props: {
c?: Context;
method: string;
path: string;
}) => boolean);
/**
* Responses of the request
*/
responses?: ResponsesWithResolver;
};
type RegisterSchemaPathOptions = {
route: RouterRoute;
specs?: DescribeRouteOptions & {
operationId?: OperationId;
};
paths: Partial;
};
type HaveDefaultValues = "documentation" | "excludeStaticFile" | "exclude" | "excludeMethods" | "excludeTags";
type SanitizedGenerateSpecOptions = Pick & Omit, HaveDefaultValues>;
type SpecContext = {
components: OpenAPIV3_1.ComponentsObject;
options: SanitizedGenerateSpecOptions;
};
/**
* Route handler for OpenAPI specs
* @param hono Instance of Hono
* @param options Options for generating OpenAPI specs
* @returns Middleware handler for OpenAPI specs
*/
declare function openAPIRouteHandler(hono: Hono, options?: Partial): MiddlewareHandler$1;
/**
* Generate OpenAPI specs for the given Hono instance
* @param hono Instance of Hono
* @param options Options for generating OpenAPI specs
* @param config Configuration for OpenAPI route handler
* @param Context Route context for hiding routes
* @returns OpenAPI specs
*/
declare function generateSpecs(hono: Hono, options?: Partial, c?: Context): Promise<{
tags: openapi_types.OpenAPIV3.TagObject[];
info: {
description: string;
title: string;
termsOfService?: string;
contact?: openapi_types.OpenAPIV3.ContactObject;
version: string;
summary?: string;
license?: OpenAPIV3_1.LicenseObject;
};
paths: {
[x: string]: Omit, "parameters" | "servers"> & {
servers?: OpenAPIV3_1.ServerObject[];
parameters?: (OpenAPIV3_1.ReferenceObject | OpenAPIV3_1.ParameterObject)[];
} & {
get?: OpenAPIV3_1.OperationObject<{}>;
put?: OpenAPIV3_1.OperationObject<{}>;
post?: OpenAPIV3_1.OperationObject<{}>;
delete?: OpenAPIV3_1.OperationObject<{}>;
options?: OpenAPIV3_1.OperationObject<{}>;
head?: OpenAPIV3_1.OperationObject<{}>;
patch?: OpenAPIV3_1.OperationObject<{}>;
trace?: OpenAPIV3_1.OperationObject<{}>;
};
};
components: OpenAPIV3_1.ComponentsObject;
openapi: string;
externalDocs?: openapi_types.OpenAPIV3.ExternalDocumentationObject;
security?: openapi_types.OpenAPIV3.SecurityRequirementObject[];
servers?: OpenAPIV3_1.ServerObject[];
webhooks?: Record;
jsonSchemaDialect?: string;
}>;
export { ALLOWED_METHODS, type AllowedMethods, type DescribeRouteOptions, type GenerateSpecOptions, type HandlerUniqueProperty, type PromiseOr, type RegisterSchemaPathOptions, type ResolverReturnType, type ResponsesWithResolver, type SpecContext, clearSpecsContext, describeResponse, describeRoute, generateSpecs, loadVendor, openAPIRouteHandler, registerSchemaPath, removeExcludedPaths, resolver, uniqueSymbol, validator };