Ver código fonte

Added 'file' validation rule

Marcel Pociot 8 anos atrás
pai
commit
79631d0fcb

+ 4 - 0
src/Mpociot/ApiDoc/Generators/AbstractGenerator.php

@@ -262,6 +262,10 @@ abstract class AbstractGenerator
                 $attributeData['type'] = 'numeric';
                 $attributeData['description'][] = Description::parse($rule)->with($parameters)->getDescription();
                 break;
+            case 'file':
+                $attributeData['type'] = 'file';
+                $attributeData['description'][] = Description::parse($rule)->getDescription();
+                break;
             case 'image':
                 $attributeData['type'] = 'image';
                 $attributeData['description'][] = Description::parse($rule)->getDescription();

+ 1 - 0
src/resources/lang/en/rules.php

@@ -15,6 +15,7 @@ return [
     'different' => 'Must have a different value than parameter: `:attribute`',
     'digits' => 'Must have an exact length of `:attribute`',
     'digits_between' => 'Must have a length between `:attribute` and `:attribute`',
+    'file' => 'Must be a file upload',
     'image' => 'Must be an image (jpeg, png, bmp, gif, or svg)',
     'json' => 'Must be a valid JSON string.',
     'mimetypes' => 'Allowed mime types: :attribute',

+ 6 - 0
tests/ApiDocGeneratorTest.php

@@ -198,6 +198,12 @@ class ApiDocGeneratorTest extends TestCase
                     $this->assertCount(1, $attribute['description']);
                     $this->assertSame('Valid user single_exists', $attribute['description'][0]);
                     break;
+                case 'file':
+                    $this->assertFalse($attribute['required']);
+                    $this->assertSame('file', $attribute['type']);
+                    $this->assertCount(1, $attribute['description']);
+                    $this->assertSame('Must be a file upload', $attribute['description'][0]);
+                    break;
                 case 'image':
                     $this->assertFalse($attribute['required']);
                     $this->assertSame('image', $attribute['type']);

+ 6 - 0
tests/DingoGeneratorTest.php

@@ -201,6 +201,12 @@ class DingoGeneratorTest extends TestCase
                     $this->assertCount(1, $attribute['description']);
                     $this->assertSame('Valid user single_exists', $attribute['description'][0]);
                     break;
+                case 'file':
+                    $this->assertFalse($attribute['required']);
+                    $this->assertSame('file', $attribute['type']);
+                    $this->assertCount(1, $attribute['description']);
+                    $this->assertSame('Must be a file upload', $attribute['description'][0]);
+                    break;
                 case 'image':
                     $this->assertFalse($attribute['required']);
                     $this->assertSame('image', $attribute['type']);

+ 2 - 0
tests/Fixtures/DingoTestRequest.php

@@ -28,8 +28,10 @@ class DingoTestRequest extends FormRequest
             'digits_between' => 'digits_between:2,10',
             'exists' => 'exists:users,firstname',
             'single_exists' => 'exists:users',
+            'file' => 'file',
             'in' => 'in:jpeg,png,bmp,gif,svg',
             'integer' => 'integer',
+            'image' => 'image',
             'ip' => 'ip',
             'json' => 'json',
             'min' => 'min:20',

+ 2 - 0
tests/Fixtures/TestRequest.php

@@ -27,8 +27,10 @@ class TestRequest extends FormRequest
             'digits' => 'digits:2',
             'digits_between' => 'digits_between:2,10',
             'exists' => 'exists:users,firstname',
+            'file' => 'file',
             'single_exists' => 'exists:users',
             'in' => 'in:jpeg,png,bmp,gif,svg',
+            'image' => 'image',
             'integer' => 'integer',
             'ip' => 'ip',
             'json' => 'json',