Hi everyone.
Most Symfony API validation patterns feel over-engineered to me. Too many layers, too much boilerplate, and endless desync between validation logic and OpenAPI docs. I got tired of SOLID-pattern hell and built a pragmatic solution for my own projects.
The approach: I use JSON Schema as the Single Source of Truth. It handles request validation, maps data to DTOs, and automatically keeps Nelmio/Swagger documentation in sync.
What it looks like in a controller:
#[Route('/api/products/search', methods: ['GET'])]
public function search(#[MapRequest('product-search.json')] ProductSearchDto $dto): JsonResponse
{
// Documentation and validation are already handled.
// $dto is populated and valid.
}
Why it’s better than standard "best practices":
If you’re tired of infinite abstractions and just want to ship working code, check it out:
Cheers ))
No responses yet.