diff --git a/src/Extracting/ParsesValidationRules.php b/src/Extracting/ParsesValidationRules.php index 2e1a47a8..320d39f9 100644 --- a/src/Extracting/ParsesValidationRules.php +++ b/src/Extracting/ParsesValidationRules.php @@ -145,9 +145,14 @@ protected function normaliseRules(array $rules): array // Now this will return the complete ruleset. // Nested array parameters will be present, with '*' replaced by '0' $newRules = Validator::make($testData, $rules)->getRules(); - - // Transform the key names back from 'ids.0' to 'ids.*' + return collect($newRules)->mapWithKeys(function ($val, $paramName) use ($rules) { + // Transform the key names back from '__asterisk__' to '*' + if (Str::contains($paramName, '__asterisk__')) { + $paramName = str_replace('__asterisk__', '*', $paramName); + } + + // Transform the key names back from 'ids.0' to 'ids.*' if (Str::contains($paramName, '.0')) { $genericArrayKeyName = str_replace('.0', '.*', $paramName); diff --git a/tests/Unit/ValidationRuleParsingTest.php b/tests/Unit/ValidationRuleParsingTest.php index 10ba7e4b..80fcf761 100644 --- a/tests/Unit/ValidationRuleParsingTest.php +++ b/tests/Unit/ValidationRuleParsingTest.php @@ -110,6 +110,17 @@ public function can_transform_arrays_and_objects() $this->assertEquals('string[]', $results['array_of_objects_with_array[].another[].one.field1']['type']); $this->assertEquals('integer', $results['array_of_objects_with_array[].another[].one.field2']['type']); $this->assertEquals('number', $results['array_of_objects_with_array[].another[].two.field2']['type']); + + $ruleset = [ + '*.foo' => 'required|array', + '*.foo.*' => 'required|array', + '*.foo.*.bar' => 'required', + ]; + $results = $this->strategy->parse($ruleset); + $this->assertCount(3, $results); + $this->assertEquals('object', $results['*']['type']); + $this->assertEquals('object[]', $results['*.foo']['type']); + $this->assertEquals('string', $results['*.foo[].bar']['type']); } public static function supportedRules()