Skip to content

Commit 1d1f122

Browse files
committed
Fix issue #88
1 parent fba1d54 commit 1d1f122

File tree

5 files changed

+22
-2
lines changed

5 files changed

+22
-2
lines changed

src/Mpociot/ApiDoc/Generators/AbstractGenerator.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ protected function getParameters($routeData, $routeAction, $bindings)
4141
foreach ($validator->getRules() as $attribute => $rules) {
4242
$attributeData = [
4343
'required' => false,
44-
'type' => 'string',
44+
'type' => null,
4545
'default' => '',
4646
'value' => '',
4747
'description' => [],
@@ -235,7 +235,9 @@ protected function parseRule($rule, $ruleName, &$attributeData, $seed)
235235
$attributeData['description'][] = Description::parse($rule)->with($parameters)->getDescription();
236236
break;
237237
case 'between':
238-
$attributeData['type'] = 'numeric';
238+
if (!isset($attributeData['type'])) {
239+
$attributeData['type'] = 'numeric';
240+
}
239241
$attributeData['description'][] = Description::parse($rule)->with($parameters)->getDescription();
240242
$attributeData['value'] = $faker->numberBetween($parameters[0], $parameters[1]);
241243
break;
@@ -354,6 +356,10 @@ protected function parseRule($rule, $ruleName, &$attributeData, $seed)
354356
if ($attributeData['value'] === '') {
355357
$attributeData['value'] = $faker->word;
356358
}
359+
360+
if (is_null($attributeData['type'])) {
361+
$attributeData['type'] = 'string';
362+
}
357363
}
358364

359365
/**

tests/ApiDocGeneratorTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,12 @@ public function testCanParseFormRequestRules()
135135
$this->assertCount(1, $attribute['description']);
136136
$this->assertSame('Between: `5` and `200`', $attribute['description'][0]);
137137
break;
138+
case 'string_between':
139+
$this->assertFalse($attribute['required']);
140+
$this->assertSame('string', $attribute['type']);
141+
$this->assertCount(1, $attribute['description']);
142+
$this->assertSame('Between: `5` and `200`', $attribute['description'][0]);
143+
break;
138144
case 'before':
139145
$this->assertFalse($attribute['required']);
140146
$this->assertSame('date', $attribute['type']);

tests/DingoGeneratorTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,12 @@ public function testCanParseFormRequestRules()
138138
$this->assertCount(1, $attribute['description']);
139139
$this->assertSame('Between: `5` and `200`', $attribute['description'][0]);
140140
break;
141+
case 'string_between':
142+
$this->assertFalse($attribute['required']);
143+
$this->assertSame('string', $attribute['type']);
144+
$this->assertCount(1, $attribute['description']);
145+
$this->assertSame('Between: `5` and `200`', $attribute['description'][0]);
146+
break;
141147
case 'before':
142148
$this->assertFalse($attribute['required']);
143149
$this->assertSame('date', $attribute['type']);

tests/Fixtures/DingoTestRequest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public function rules()
1919
'array' => 'array',
2020
'before' => 'before:2016-04-23 14:31:00',
2121
'between' => 'between:5,200',
22+
'string_between' => 'string|between:5,200',
2223
'boolean' => 'boolean',
2324
'date' => 'date',
2425
'date_format' => 'date_format:j.n.Y H:iP',

tests/Fixtures/TestRequest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public function rules()
1919
'array' => 'array',
2020
'before' => 'before:2016-04-23 14:31:00',
2121
'between' => 'between:5,200',
22+
'string_between' => 'string|between:5,200',
2223
'boolean' => 'boolean',
2324
'date' => 'date',
2425
'date_format' => 'date_format:j.n.Y H:iP',

0 commit comments

Comments
 (0)