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?: RequestBodyValidationOptions): void;

Parameters

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

Returns:

void