I created a contoller in Symfony that will be handle API requests. I want to validate action request. Parameter 'type' of the request must be integer. There is controller action code:
public function store(ValidatorInterface $validator, Request $request): JsonResponse
{
$collection = new Collection([
'type' => [
new Assert\Type('int'),
new Assert\Range(['min' => 1, 'max' => 2])
]
]);
$errors = $validator->validate($request->request->all(), $collection);
if ($errors->count()) {
dd($errors);
}
return new JsonResponse('OK');
}
But when I tested this action via Postman, validation is failed with error "This value should be of type int." event if I send response with int value:
What is the right way to validate int param or string param as int in Symfony?

You can use
digittype for the type validator. Then the validator will check type via ctype_digit function