outcomer / symfony-json-schema-validation
JSON Schema validation bundle for Symfony with OPIS integration
Package info
github.com/outcomer/symfony-json-schema-validation
Type:symfony-bundle
pkg:composer/outcomer/symfony-json-schema-validation
Requires
- php: >=8.2
- symfony/config: ^7.4|^8.0
- symfony/dependency-injection: ^7.4|^8.0
- symfony/framework-bundle: ^7.4|^8.0
- symfony/http-foundation: ^7.4|^8.0
- symfony/http-kernel: ^7.4|^8.0
Requires (Dev)
- escapestudios/symfony2-coding-standard: ^3.16
- nelmio/api-doc-bundle: ^5.9
- opis/json-schema: ^2.6
- phpunit/phpunit: ^11.0|^12.0
- squizlabs/php_codesniffer: ^3.13
- symfony/phpunit-bridge: ^7.4|^8.0
- symfony/var-dumper: ^7.4|^8.0
This package is auto-updated.
Last update: 2026-05-28 17:18:36 UTC
README
Before
Typical Symfony API endpoint:
- Request DTO
- Symfony Validator constraints
- OpenAPI annotations
- Mapping logic
Same field described multiple times.
class CreateUserRequest { #[Assert\NotBlank] #[Assert\Email] public string $email; }
Plus OpenAPI annotations and mapping.
This logic is repeated in 3 different places in real projects.
After
One schema:
{
"type": "object",
"required": ["email"],
"properties": {
"email": {
"type": "string",
"format": "email"
}
}
}
Used for:
- validation
- request mapping
- OpenAPI generation
One schema replaces all of this duplication.
⚡ 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('schemas/user-create.json')] 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]$"}
}
}
}
}
📚 Why
Read the story behind this bundle on Hashnode
📖 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
🚀 Features
- Single source of truth for API validation
- No serializer groups
- Automatic OpenAPI generation
When NOT to use this
Use API Platform if you need:
- full CRUD automation
- admin panels
- heavy framework magic
Incremental adoption
You can use this bundle:
- on a single endpoint
- together with Symfony Validator
- together with API Platform
- without rewriting your application
No migration is required.
FAQ
Does this replace Symfony Validator?
No. You can use both together.
Does this work with API Platform?
Yes. The bundle can coexist with API Platform.
Is this all-or-nothing?
No. You can adopt it endpoint-by-endpoint.
Why use JSON Schema?
To avoid duplication between validation, request mapping and OpenAPI.
Is there vendor lock-in?
No. Your schemas remain standard JSON Schema documents.
🤝 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