import express from 'express'; import { InfoObject, OpenAPIObject } from 'openapi3-ts'; import { SwaggerUiOptions } from 'swagger-ui-express'; import { z } from 'zod'; import { EndpointProps, EndpointHandler } from './typings'; export type CustomInfo = Partial & { /** Add custom schemas to the API definition */ schemas?: Record; }; export type JsonRouterProps = { info: CustomInfo; bodySize: string | number; /** The path under which all endpoints of this router will reside */ basePath: string; }; type Serve = { /** * Display the swagger express page to query the API directly */ swagger?: { enabled: boolean; /** * The URL where the swagger interface will be displayed * @default / */ url?: string; } & SwaggerUiOptions; /** * Serve the OpenAPI JSON file for the active router */ openApi?: { enabled: boolean; /** * URL of the OpenAPI Json Definition * @default /openapi.json */ url?: string; /** * Method to edit the API Object before returning it to the user (ex: change an header value for another one) */ editDoc?: (doc: OpenAPIObject) => OpenAPIObject; /** * Provides a clean documentation generated from the OpenAPI JSON file */ redoc?: { enabled: boolean; /** * URL where redoc will be available. It is feeded from the openApi previously configured. * @default /redoc */ url?: string; }; }; }; export declare class JsonRouter { private _endpoints; private _router; private _props; private _basePath; children: JsonRouter[]; constructor(props?: Partial); get basePath(): string; /** Adds a child router. The path is defined when you create the router. */ addRouter(subRouter: JsonRouter): void; /** * Provide a list of routes to copy to the current router (ex: same logic but different version of an API) * If no paths are provided, all routes from this router will be copied to the target router, except if they already exist * */ copyRoutesFromRouter(router: JsonRouter, paths?: { path: string; method: string; }[]): void; /** * Serves the various routers. * - Swagger can only be enabled once (ideally at the root router). * - OpenAPI can be enabled to have an individual openapi.json file per router. Child routes will be displayed on the parent even if this is not enabled * */ serve({ swagger, openApi }: Serve): void; /** Access the underlying Express router. Avoid if not necessary */ get inner(): express.IRouter; get openapi(): import("openapi3-ts").OpenApiBuilder; get cliDoc(): string; get>(info: EndpointProps, ...handlers: Array>): express.IRouter; put>(info: EndpointProps, ...handlers: Array>): express.IRouter; post>(info: EndpointProps, ...handlers: Array>): express.IRouter; delete>(info: EndpointProps, ...handlers: Array>): express.IRouter; /** Adds an error handle. Must be added last on your router */ addErrorHandler(handler: express.ErrorRequestHandler): void; /** Adds an endpoint to the router. This is used when copying method across routers */ private _addEndpoint; /** This middleware registers the endpoint and simply validate the input based on schemas */ private _validationMw; private _wrapHandlers; /** Returns all the endpoints of the specified router, including its children, with the correct path */ private _getAllEndpoints; private _setupOpenApiRouter; } export {};