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
Requires
- php: >=8.4
- symfony/config: ^8.0
- symfony/dependency-injection: ^8.0
- symfony/framework-bundle: ^8.0
- symfony/http-foundation: ^8.0
- symfony/http-kernel: ^8.0
Requires (Dev)
- escapestudios/symfony2-coding-standard: ^3.16
- nelmio/api-doc-bundle: ^5.9
- opis/json-schema: ^2.6
- phpunit/phpunit: ^12.5
- squizlabs/php_codesniffer: ^3.13
- symfony/phpunit-bridge: ^8.0
- symfony/var-dumper: ^8.0
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.
🚀 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
- 🔗 How It Works
- 🔗 Installation Guide
- 🔗 Quick Start Tutorial
- 🔗 Schema Basics
- 🔗 Configuration Options
- 🔗 DTO Injection
- 🔗 OpenAPI Integration
- 🔗 Examples
- 🔗 API Reference
⚡ 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?
- 📖 Check our documentation
- 🐛 Report issues
- 💬 Join discussions