outcomer/symfony-json-schema-validation
最新稳定版本:v3.0.0
Composer 安装命令:
composer require outcomer/symfony-json-schema-validation
包简介
JSON Schema validation bundle for Symfony with OPIS integration
README 文档
README
A powerful and flexible JSON Schema validation solution for Symfony applications with automatic OpenAPI documentation generation.
📚 Why
Read the story behind this bundle on Hashnode
🚀 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 7.4+ and 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.2+ features and Symfony 7.4+/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
统计信息
- 总下载量: 19
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 11
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-15