Skip to content

Symfony JSON Schema ValidationPowerful request validation for modern Symfony applications

Type-safe JSON Schema validation with automatic OpenAPI documentation generation

Symfony JSON Schema Validation

Quick Start

Install the bundle via Composer:

bash
composer require outcomer/symfony-json-schema-validation

Create a JSON schema:

json
{
  "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:

php
#[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']);
}

What's Next?

Released under the MIT License. Built with Opis JSON Schema.