Page Contents

Home > @loopback/rest > validateRequestBody

validateRequestBody() function

Check whether the request body is valid according to the provided OpenAPI schema. The JSON schema is generated from the OpenAPI schema which is typically defined by @requestBody(). The validation leverages AJV schema validator.

Signature:

export declare function validateRequestBody(body: RequestBody, requestBodySpec?: RequestBodyObject, globalSchemas?: SchemasObject, options?: ValidationOptions): Promise<void>;

Parameters

Parameter Type Description
body RequestBody The request body parsed from an HTTP request.
requestBodySpec RequestBodyObject (Optional) The OpenAPI requestBody specification defined in @requestBody().
globalSchemas SchemasObject (Optional) The referenced schemas generated from OpenAPISpec.components.schemas.
options ValidationOptions (Optional) Request body validation options for AJV

Returns:

Promise<void>