Closed
Description
Description
#[MapRequestPayload]
attribute, introduced in Symfony 6.3, is an awesome feature for APIs that use JSON for requests. The attribute works with Serializer and Validator components, and returns 422 Unprocessable Entity
status code on Validator returned any violation(s). However, in API development, sometimes we want 400 Bad Request
instead of 422. So it would be great if we can customise the status code that MapRequestPayload returns on validation error.
Example
Option 1. Use attribute to customise for each endpoint
#[Route('/pets', methods: ['POST'])]
public function createPet(
#[MapRequestPayload(statusOnError: Response::HTTP_BAD_REQUEST) PetDto $pet,
): Response;
Option 2. Use config to customise globally
framework:
map_request_payload:
default_status_code_on_error: 400