I have put a callback inside Assert\Optional but it is not being called when I put outside the Optional It does get called but I get field missed error in case that option parameter is not in request. What I want if that parameter is in the request it should be passed to callback for custom validation and if it is not it should not generate missing field error.
Below is the code that I am trying but it is not working as expected.
"list_id"=>[
new Assert\Optional(
new Assert\NotBlank(
['message'=>$this->translator->trans("required")
]
),
new Assert\Type(['integer',
'message' => $this->translator->trans("integer")
]),
new Assert\Callback([$this, 'validateList']),
),
],
I tried to add optional field validation with custom validation callback
If I remove other validations the callback works and I don't get missing field error in case the field is not in the request data.