@@ -93,6 +93,60 @@ public function parseValidationRules(array $rules): array
9393 }
9494 }
9595
96+ // Handle min/max based on the final determined type
97+ // For strings, use minLength/maxLength; for arrays, use minItems/maxItems; for numbers, use minimum/maximum
98+ if ($ type === 'string ' ) {
99+ // Convert minimum/maximum to minLength/maxLength for strings
100+ if ($ minimum !== null ) {
101+ $ minLength = $ minimum ;
102+ $ minimum = null ;
103+ // Update description to reflect string length constraint
104+ $ description = array_map (function ($ desc ) use ($ minLength ) {
105+ return str_replace ("Minimum constraint: {$ minLength }. " , "Minimum length: {$ minLength }. " , $ desc );
106+ }, $ description );
107+ }
108+ if ($ maximum !== null ) {
109+ $ maxLength = $ maximum ;
110+ $ maximum = null ;
111+ // Update description to reflect string length constraint
112+ $ description = array_map (function ($ desc ) use ($ maxLength ) {
113+ return str_replace ("Maximum constraint: {$ maxLength }. " , "Maximum length: {$ maxLength }. " , $ desc );
114+ }, $ description );
115+ }
116+ } elseif ($ type === 'array ' ) {
117+ // For arrays, convert to minItems/maxItems
118+ $ minItems = null ;
119+ $ maxItems = null ;
120+ if ($ minimum !== null ) {
121+ $ minItems = $ minimum ;
122+ $ minimum = null ;
123+ // Update description to reflect array items constraint
124+ $ description = array_map (function ($ desc ) use ($ minItems ) {
125+ return str_replace ("Minimum constraint: {$ minItems }. " , "Minimum items: {$ minItems }. " , $ desc );
126+ }, $ description );
127+ }
128+ if ($ maximum !== null ) {
129+ $ maxItems = $ maximum ;
130+ $ maximum = null ;
131+ // Update description to reflect array items constraint
132+ $ description = array_map (function ($ desc ) use ($ maxItems ) {
133+ return str_replace ("Maximum constraint: {$ maxItems }. " , "Maximum items: {$ maxItems }. " , $ desc );
134+ }, $ description );
135+ }
136+ } else {
137+ // For numeric types, update descriptions to reflect value constraints
138+ if ($ minimum !== null ) {
139+ $ description = array_map (function ($ desc ) use ($ minimum ) {
140+ return str_replace ("Minimum constraint: {$ minimum }. " , "Minimum value: {$ minimum }. " , $ desc );
141+ }, $ description );
142+ }
143+ if ($ maximum !== null ) {
144+ $ description = array_map (function ($ desc ) use ($ maximum ) {
145+ return str_replace ("Maximum constraint: {$ maximum }. " , "Maximum value: {$ maximum }. " , $ desc );
146+ }, $ description );
147+ }
148+ }
149+
96150 // Build the result
97151 $ result = [
98152 'type ' => $ type ,
@@ -131,6 +185,14 @@ public function parseValidationRules(array $rules): array
131185 $ result ['maxLength ' ] = $ maxLength ;
132186 }
133187
188+ if (isset ($ minItems ) && $ minItems !== null ) {
189+ $ result ['minItems ' ] = $ minItems ;
190+ }
191+
192+ if (isset ($ maxItems ) && $ maxItems !== null ) {
193+ $ result ['maxItems ' ] = $ maxItems ;
194+ }
195+
134196 if ($ pattern !== null ) {
135197 $ result ['pattern ' ] = $ pattern ;
136198 }
@@ -145,6 +207,9 @@ public function parseValidationRules(array $rules): array
145207
146208 if ($ type === 'array ' && $ items !== null ) {
147209 $ result ['items ' ] = $ items ;
210+ } elseif ($ type === 'array ' && $ items === null ) {
211+ // If items is not set but type is array, set a default
212+ $ result ['items ' ] = ['type ' => 'string ' ];
148213 }
149214
150215 if (! empty ($ conditionalRequired )) {
@@ -543,7 +608,7 @@ private function processRuleName(string $ruleName, array $ruleParams): array
543608 private function processBasicRule (string $ ruleName , array $ ruleParams ): array
544609 {
545610 $ result = [
546- 'type ' => ' string ' ,
611+ 'type ' => null , // Don't set a default type - let type-specific rules set it
547612 'format ' => null ,
548613 'required ' => false ,
549614 'nullable ' => false ,
@@ -638,6 +703,27 @@ private function processBasicRule(string $ruleName, array $ruleParams): array
638703 $ result ['description ' ] = 'Must be a valid date. ' ;
639704 break ;
640705
706+ case 'date_format ' :
707+ $ result ['type ' ] = 'string ' ;
708+ $ result ['format ' ] = 'date-time ' ;
709+ if (! empty ($ ruleParams [0 ])) {
710+ $ result ['description ' ] = "Must match the format: {$ ruleParams [0 ]}. " ;
711+ $ result ['example ' ] = date ($ ruleParams [0 ]);
712+ } else {
713+ $ result ['description ' ] = 'Must match the specified date format. ' ;
714+ }
715+ break ;
716+
717+ case 'between ' :
718+ if (count ($ ruleParams ) >= 2 ) {
719+ $ min = (int ) $ ruleParams [0 ];
720+ $ max = (int ) $ ruleParams [1 ];
721+ $ result ['minimum ' ] = $ min ;
722+ $ result ['maximum ' ] = $ max ;
723+ $ result ['description ' ] = "Value between {$ min } and {$ max }. " ;
724+ }
725+ break ;
726+
641727 case 'in ' :
642728 if (! empty ($ ruleParams )) {
643729 $ result ['enum ' ] = $ ruleParams ;
@@ -647,16 +733,18 @@ private function processBasicRule(string $ruleName, array $ruleParams): array
647733 break ;
648734
649735 case 'min ' :
650- if (! empty ($ ruleParams [0 ])) {
736+ if (isset ($ ruleParams [0 ]) && $ ruleParams [ 0 ] !== '' ) {
651737 $ result ['minimum ' ] = (int ) $ ruleParams [0 ];
652- $ result ['description ' ] = "Minimum value: {$ ruleParams [0 ]}. " ;
738+ // Description will be set correctly in post-processing based on type
739+ $ result ['description ' ] = "Minimum constraint: {$ ruleParams [0 ]}. " ;
653740 }
654741 break ;
655742
656743 case 'max ' :
657- if (! empty ($ ruleParams [0 ])) {
744+ if (isset ($ ruleParams [0 ]) && $ ruleParams [ 0 ] !== '' ) {
658745 $ result ['maximum ' ] = (int ) $ ruleParams [0 ];
659- $ result ['description ' ] = "Maximum value: {$ ruleParams [0 ]}. " ;
746+ // Description will be set correctly in post-processing based on type
747+ $ result ['description ' ] = "Maximum constraint: {$ ruleParams [0 ]}. " ;
660748 }
661749 break ;
662750 }
0 commit comments