koas-operations
Version:
Koas operations maps operation IDs to Koa controller functions.
37 lines (36 loc) • 1.22 kB
TypeScript
import { Middleware } from 'koa';
import { Plugin } from 'koas-core';
export interface KoasOperationsOptions {
/**
* A mapping of OpenAPI operation IDs to controller functions.
*
* Controllers are normal Koa middleware, but typically these don’t have to call `next()`.
*/
controllers?: Record<string, Middleware>;
/**
* The middleware to call in case the operation has no operation ID or no controller has been
* registered for the operation.
*
* By default this is middleware that returns a status code of `501 Not Implemented`.
*/
fallback?: Middleware;
/**
* Throw an error if a handler is passed that doesn’t match an operation.
*
* @default true
*/
throwOnExtraneous?: boolean;
/**
* Throw an error if an operation hasn’t been implemented.
*
* @default true
*/
throwOnNotImplemented?: boolean;
}
/**
* Map OpenAPI operation IDs to controllers.
*
* @param options - The for controlling how operation IDs are handled.
* @returns Koas middleware.
*/
export declare function operations({ controllers, fallback, throwOnExtraneous, throwOnNotImplemented, }?: KoasOperationsOptions): Plugin;