koas-parameters
Version:
Koas parameters attempts to coerce path and query parameters to the type specified in their respective JSON schema.
69 lines (68 loc) • 2.1 kB
TypeScript
import { Plugin } from 'koas-core';
/**
* This interface may be augmented to define path parameter types.
*/
export interface PathParams {
}
/**
* This interface may be augmented to define query parameter types.
*/
export interface QueryParams {
}
declare module 'koa' {
interface DefaultContext {
/**
* The path parameters coerced according to the type defined in their JSON schema in the OpenAPI
* document.
*/
pathParams: PathParams;
/**
* The query parameters coerced according to the type defined in their JSON schema in the
* OpenAPI document.
*/
queryParams: QueryParams;
}
}
export interface ParameterParsers {
/**
* A function to convert a raw string parameter to a boolean.
*
* @param value - The raw string value to process.
* @returns The processed boolean value.
*/
boolean?: (value: string) => boolean | string;
/**
* A function to convert a raw string parameter to an integer.
*
* @param value - The raw string value to process.
* @returns The processed integer value.
*/
integer?: (value: string) => number | string;
/**
* A function to convert a raw string parameter to number.
*
* @param value - The raw string value to process.
* @returns The processed number value.
*/
number?: (value: string) => number | string;
/**
* A function to convert a raw string parameter to a processed string.
*
* @param value - The raw string value to process.
* @returns The processed string value.
*/
string?: (value: string) => string;
}
export interface KoasParametersOptions {
/**
* The parsers for converting raw values to strings.
*/
parsers?: ParameterParsers;
}
/**
* Create a Koas plugin for parsing path and query parameters.
*
* @param options - The options for parsing the parameters.
* @returns A Koas plugin for parsing path and query parameters.
*/
export declare function parameters({ parsers }?: KoasParametersOptions): Plugin;