Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions src/Mpociot/ApiDoc/Generators/AbstractGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,19 +178,15 @@ protected function getParameters($routeData, $routeAction, $bindings)
protected function simplifyRules($rules)
{
// this will split all string rules into arrays of strings
$rules = Validator::make([], $rules)->getRules();

if (count($rules) === 0) {
return $rules;
}
$newRules = Validator::make([], $rules)->getRules();

// Laravel will ignore the nested array rules unless the key referenced exists and is an array
// So we'll to create an empty array for each array attribute
$values = collect($rules)
// So we'll create an empty array for each array attribute
$values = collect($newRules)
->filter(function ($values) {
return in_array('array', $values);
})->map(function ($val, $key) {
return [''];
return [str_random()];
})->all();

// Now this will return the complete ruleset.
Expand Down Expand Up @@ -371,6 +367,7 @@ protected function splitValuePairs($parameters, $first = 'is ', $last = 'or ')
*/
protected function parseRule($rule, $attribute, &$attributeData, $seed, $routeData)
{
if (starts_with($attribute, 'array.')) { dd(array_keys($routeData)); }
$faker = Factory::create();
$faker->seed(crc32($seed));

Expand Down Expand Up @@ -532,8 +529,9 @@ protected function parseRule($rule, $attribute, &$attributeData, $seed, $routeDa
$attributeData['type'] = $rule;
break;
case 'array':
$attributeData['value'] = $faker->word;
$attributeData['value'] = [$faker->word];
$attributeData['type'] = $rule;
$attributeData['description'][] = Description::parse($rule)->getDescription();
break;
case 'date':
$attributeData['value'] = $faker->date();
Expand Down
1 change: 1 addition & 0 deletions src/resources/lang/en/rules.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
'alpha' => 'Only alphabetic characters allowed',
'alpha_dash' => 'Allowed: alpha-numeric characters, as well as dashes and underscores.',
'alpha_num' => 'Only alpha-numeric characters allowed',
'array' => 'Must be an array',
'in' => ':attribute',
'not_in' => 'Not in: :attribute',
'min' => 'Minimum: `:attribute`',
Expand Down
2 changes: 1 addition & 1 deletion tests/ApiDocGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public function testCanParseFormRequestRules()
case 'array':
$this->assertFalse($attribute['required']);
$this->assertSame('array', $attribute['type']);
$this->assertCount(0, $attribute['description']);
$this->assertCount(1, $attribute['description']);
break;
case 'between':
$this->assertFalse($attribute['required']);
Expand Down