You can validate a \Psr\Http\Message\ServerRequestInterface instance using the ValidatorBuilder. The builder supports loading specifications from YAML files, YAML strings, JSON files, JSON strings, or a pre-generated \cebe\openapi\spec\OpenApi schema object.
If you already have routing information and know the specific operation (path and method) that should match the request, use getRoutedRequestValidator with an OperationAddress. This is more performant as it avoids searching the entire specification for a match.
$yamlFile = "api.yaml";
$validator = (new \League\OpenAPIValidation\PSR7\ValidatorBuilder)->fromYamlFile($yamlFile)->getServerRequestValidator();
// Standard validation (returns OperationAddress match)
$match = $validator->validate($request);
// Optimized validation using known routing
$address = new \League\OpenAPIValidation\PSR7\OperationAddress('/some/operation', 'post');
$validator = (new \League\OpenAPIValidation\PSR7\ValidatorBuilder)->fromSchema($schema)->getRoutedRequestValidator();
$validator->validate($address, $request);