Type-Safe Validation
Strong typing with ValidatedDtoInterface ensures your data is always valid and properly structured.
Type-safe JSON Schema validation with automatic OpenAPI documentation generation
Install the bundle via Composer:
composer require outcomer/symfony-json-schema-validationCreate a JSON schema:
{
"type": "object",
"properties": {
"body": {
"type": "object",
"properties": {
"name": { "type": "string", "minLength": 3 },
"email": { "type": "string", "format": "email" }
},
"required": ["name", "email"]
}
}
}Use it in your controller:
#[Route('/api/users', methods: ['POST'])]
public function createUser(#[MapRequest('user-create.json')] ValidatedRequest $request): JsonResponse
{
$data = $request->getPayload()->getBody();
// $data is guaranteed to be valid!
return $this->json(['message' => 'User created']);
}