Skip to content

Conversation

CodeWithKyrian
Copy link
Contributor

This PR adds type-safe Schema attributes for JSON Schema validation and enhances the DocBlock parser to support rich array type definitions.

New Features

Schema Attribute System

  • Added #[Schema] attribute to define precise JSON Schema constraints for parameters
  • Created supporting classes:
    • Format: Constants for common string formats (EMAIL, DATE_TIME, etc.)
    • ArrayItems: For array item constraints
    • Property: For object property constraints
  • Implemented constraint handling for strings, numbers, arrays, and objects
  • Set up clear precedence: Schema attributes > DocBlock annotations > PHP type hints

Enhanced DocBlock Array Type Parsing

  • Improved array type inference from DocBlocks with support for:
    • Simple array syntax: string[], int[], bool[]
    • Generic array syntax: array<string>, array<int>
    • Nested arrays: array<array<string>>, string[][]
    • Object-like arrays: array{name: string, age: int}
  • Added detection for complex nested structures
  • Updated the parser to correctly identify object-like arrays vs regular arrays

Testing

  • Created test stubs demonstrating all array type scenarios
  • Added tests verifying that constraints are correctly applied
  • Ensured precedence is properly respected

Documentation

  • Updated README with new Schema attribute information
  • Added examples of DocBlock array type usage
  • Documented precedence rules

…arsing

- Implement Schema attribute system for type-safe JSON Schema validation
- Enhance DocBlock array type parsing for various notations:
  - string[], int[] (basic arrays)
  - array<T> (generic arrays)
  - array<array<T>> (nested arrays)
  - array{key: type} (object-like arrays)
- Update SchemaGenerator to respect precedence: Schema > DocBlock > PHP types
- Add comprehensive tests for new functionality
@CodeWithKyrian CodeWithKyrian merged commit c8840af into main May 17, 2025
8 checks passed
@CodeWithKyrian CodeWithKyrian deleted the feature/schema-attributes-and-array-types branch May 17, 2025 16:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant