/**
* This file is part of the @egodigital/egoose distribution.
* Copyright (c) e.GO Digital GmbH, Aachen, Germany (https://www.e-go-digital.com/)
*
* @egodigital/egoose is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, version 3.
*
* @egodigital/egoose is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*/
import * as express from 'express';
import * as joi from 'joi';
import { OptionsJson } from 'body-parser';
/**
* Options for 'jsonObject()' function.
*/
export interface JsonObjectOptions {
/**
* Indicates if input body can be (null) or not.
*/
canBeNull?: boolean;
/**
* Indicates if input body can be (undefined) or not.
*/
canBeUndefined?: boolean;
/**
* A custom function, that handles a failed validation.
*/
failedHandler?: JsonObjectValidationFailedHandler;
/**
* Custom options for the Express json() middleware.
*/
options?: OptionsJson;
/**
* The optional schema to use.
*/
schema?: joi.ObjectSchema;
}
/**
* A function that returns the response for a failed JSON validation.
*
* @param {JsonObjectValidationFailedHandlerContext} context The context.
*
* @return {express.Response|PromiseLike} The result with the (new) response context.
*/
export declare type JsonObjectValidationFailedHandler = (context: JsonObjectValidationFailedHandlerContext) => (express.Response | PromiseLike);
/**
* Context of a 'JsonValidationFailedHandler'.
*/
export interface JsonObjectValidationFailedHandlerContext {
/**
* The original value of the request body.
*/
body: any;
/**
* An object or value, whichs contains the validation error details.
*/
details: any;
/**
* An object or value, which represents an ID, that describes the reason.
*/
reason: any;
/**
* The current HTTP request context.
*/
request: express.Request;
/**
* The current HTTP response context.
*/
response: express.Response;
}
/**
* Creates Express middlewares for validating JSON input.
*
* @param {JsonObjectOptions|joi.ObjectSchema} [optsOrSchema] Custom options or schema.
*
* @return {express.RequestHandler[]} The created handler(s).
*/
export declare function jsonObject(optsOrSchema?: JsonObjectOptions | joi.ObjectSchema): express.RequestHandler[];