outcomer/symfony-json-schema-validation

JSON Schema validation bundle for Symfony with OPIS integration

Installs: 5

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

Type:symfony-bundle

pkg:composer/outcomer/symfony-json-schema-validation

v2.0.0 2026-01-28 08:40 UTC

This package is auto-updated.

Last update: 2026-02-28 08:49:19 UTC


README

A powerful and flexible JSON Schema validation solution for Symfony applications with automatic OpenAPI documentation generation.

GitHub Actions Latest Stable Version PHP Version Symfony Version License

🚀 Features

  • Complete Request Validation: Validate request body, query parameters, path variables, and headers
  • Automatic OpenAPI Documentation: Generate API documentation with nelmio/api-doc-bundle integration
  • Priority-Based Validation: Control validation order with MapRequest priority system
  • Type-Safe Results: Strongly typed validated data with ValidatedDtoInterface support
  • Comprehensive Error Handling: Detailed validation errors with JSON Schema feedback
  • Modern Symfony Integration: Full support for Symfony 8.0+ with attribute-based configuration

📖 Documentation

📚 Complete Documentation - Visit our comprehensive documentation website

Quick Links

⚡ Quick Start

Installation

composer require outcomer/symfony-json-schema-validation

Basic Usage

use Outcomer\Bundle\SymfonyJsonSchemaValidation\Attribute\MapRequest;

class UserController
{
    #[Route('/api/users', methods: ['POST'])]
    public function create(
        #[MapRequest(
            schemaPath: 'schemas/user-create.json',
            validationGroups: ['create']
        )]
        UserCreateDto $user
    ): JsonResponse {
        // $user contains validated data from request body, query, path, and headers
        return new JsonResponse(['id' => $userService->create($user)]);
    }
}

JSON Schema Example

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "body": {
      "type": "object", 
      "properties": {
        "name": {"type": "string", "minLength": 1},
        "email": {"type": "string", "format": "email"}
      },
      "required": ["name", "email"]
    },
    "query": {
      "type": "object",
      "properties": {
        "locale": {"type": "string", "enum": ["en", "de", "fr"]}
      }
    },
    "headers": {
      "type": "object",
      "properties": {
        "x-api-version": {"type": "string", "pattern": "^v[1-9]$"}
      }
    }
  }
}

🎯 Key Benefits

  • Developer Experience: Intuitive attribute-based validation with full IDE support
  • API Documentation: Automatic OpenAPI spec generation with zero configuration
  • Production Ready: Battle-tested with comprehensive error handling and logging
  • Flexible Schema: Support for complex validation scenarios across all request components
  • Modern PHP: Takes advantage of PHP 8.4+ features and Symfony 8.0+ improvements

🤝 Contributing

We welcome contributions! Please see our Contributing Guide for details.

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

Need Help?