Skip to content

Commit 79631d0

Browse files
committed
Added 'file' validation rule
1 parent 438eea7 commit 79631d0

File tree

6 files changed

+21
-0
lines changed

6 files changed

+21
-0
lines changed

src/Mpociot/ApiDoc/Generators/AbstractGenerator.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,10 @@ protected function parseRule($rule, $ruleName, &$attributeData, $seed)
262262
$attributeData['type'] = 'numeric';
263263
$attributeData['description'][] = Description::parse($rule)->with($parameters)->getDescription();
264264
break;
265+
case 'file':
266+
$attributeData['type'] = 'file';
267+
$attributeData['description'][] = Description::parse($rule)->getDescription();
268+
break;
265269
case 'image':
266270
$attributeData['type'] = 'image';
267271
$attributeData['description'][] = Description::parse($rule)->getDescription();

src/resources/lang/en/rules.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
'different' => 'Must have a different value than parameter: `:attribute`',
1616
'digits' => 'Must have an exact length of `:attribute`',
1717
'digits_between' => 'Must have a length between `:attribute` and `:attribute`',
18+
'file' => 'Must be a file upload',
1819
'image' => 'Must be an image (jpeg, png, bmp, gif, or svg)',
1920
'json' => 'Must be a valid JSON string.',
2021
'mimetypes' => 'Allowed mime types: :attribute',

tests/ApiDocGeneratorTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,12 @@ public function testCanParseFormRequestRules()
198198
$this->assertCount(1, $attribute['description']);
199199
$this->assertSame('Valid user single_exists', $attribute['description'][0]);
200200
break;
201+
case 'file':
202+
$this->assertFalse($attribute['required']);
203+
$this->assertSame('file', $attribute['type']);
204+
$this->assertCount(1, $attribute['description']);
205+
$this->assertSame('Must be a file upload', $attribute['description'][0]);
206+
break;
201207
case 'image':
202208
$this->assertFalse($attribute['required']);
203209
$this->assertSame('image', $attribute['type']);

tests/DingoGeneratorTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,12 @@ public function testCanParseFormRequestRules()
201201
$this->assertCount(1, $attribute['description']);
202202
$this->assertSame('Valid user single_exists', $attribute['description'][0]);
203203
break;
204+
case 'file':
205+
$this->assertFalse($attribute['required']);
206+
$this->assertSame('file', $attribute['type']);
207+
$this->assertCount(1, $attribute['description']);
208+
$this->assertSame('Must be a file upload', $attribute['description'][0]);
209+
break;
204210
case 'image':
205211
$this->assertFalse($attribute['required']);
206212
$this->assertSame('image', $attribute['type']);

tests/Fixtures/DingoTestRequest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@ public function rules()
2828
'digits_between' => 'digits_between:2,10',
2929
'exists' => 'exists:users,firstname',
3030
'single_exists' => 'exists:users',
31+
'file' => 'file',
3132
'in' => 'in:jpeg,png,bmp,gif,svg',
3233
'integer' => 'integer',
34+
'image' => 'image',
3335
'ip' => 'ip',
3436
'json' => 'json',
3537
'min' => 'min:20',

tests/Fixtures/TestRequest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ public function rules()
2727
'digits' => 'digits:2',
2828
'digits_between' => 'digits_between:2,10',
2929
'exists' => 'exists:users,firstname',
30+
'file' => 'file',
3031
'single_exists' => 'exists:users',
3132
'in' => 'in:jpeg,png,bmp,gif,svg',
33+
'image' => 'image',
3234
'integer' => 'integer',
3335
'ip' => 'ip',
3436
'json' => 'json',

0 commit comments

Comments
 (0)