Add Dedicated Constraint Attributes for JSON Schema Validation #19
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR implements dedicated constraint attributes that work alongside the existing
Fieldattribute to provide modular, composable JSON Schema validation. Instead of bloating theFieldattribute with validation concerns, this creates focused, single-purpose attributes that can be combined for powerful validation rules.🚀 Features
New Constraint Attributes
#[Pattern(regex)]- String pattern validation with regex#[Length(min, max)]- String/array length constraints#[Range(min, max, exclusiveMin, exclusiveMax)]- Numeric range validation#[MultipleOf(value)]- Numeric multiple validation#[Items(min, max, unique)]- Array item constraints#[Enum(values)]- Enumeration validation💡 Usage Examples
Basic Constraints
Array and Enum Constraints
Mixed with PHPDoc Constraints
📊 Generated JSON Schema
The above examples generate clean, standards-compliant JSON Schema:
{ "type": "object", "properties": { "name": { "title": "Full Name", "type": "string", "pattern": "^[A-Z][a-z]+(?: [A-Z][a-z]+)*$", "minLength": 2, "maxLength": 100 }, "tags": { "title": "Tags", "type": "array", "minItems": 1, "maxItems": 10, "uniqueItems": true }, "status": { "title": "Status", "type": "string", "enum": ["draft", "published", "archived"] } }, "required": ["name", "tags", "status"] }