public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next)
{
$value = $request->getParsedBody();
if (!is_object($value)) {
return $this->invalidateResponse($response, sprintf('Parsed body must be an object. Type %s is invalid.', gettype($value)));
}
$validator = new Validator();
$validator->check($value, $this->schema);
if (!$validator->isValid()) {
return $this->invalidateResponse($response, 'Unprocessable Entity', ['Content-Type' => 'application/json'], json_encode($validator->getErrors(), JSON_UNESCAPED_SLASHES));
}
return $next($request, $response);
}