瀏覽代碼

Fix issue #88

Marcel Pociot 8 年之前
父節點
當前提交
1d1f122017

+ 8 - 2
src/Mpociot/ApiDoc/Generators/AbstractGenerator.php

@@ -41,7 +41,7 @@ abstract class AbstractGenerator
         foreach ($validator->getRules() as $attribute => $rules) {
             $attributeData = [
                 'required' => false,
-                'type' => 'string',
+                'type' => null,
                 'default' => '',
                 'value' => '',
                 'description' => [],
@@ -235,7 +235,9 @@ abstract class AbstractGenerator
                 $attributeData['description'][] = Description::parse($rule)->with($parameters)->getDescription();
                 break;
             case 'between':
-                $attributeData['type'] = 'numeric';
+                if (!isset($attributeData['type'])) {
+                    $attributeData['type'] = 'numeric';
+                }
                 $attributeData['description'][] = Description::parse($rule)->with($parameters)->getDescription();
                 $attributeData['value'] = $faker->numberBetween($parameters[0], $parameters[1]);
                 break;
@@ -354,6 +356,10 @@ abstract class AbstractGenerator
         if ($attributeData['value'] === '') {
             $attributeData['value'] = $faker->word;
         }
+
+        if (is_null($attributeData['type'])) {
+            $attributeData['type'] = 'string';
+        }
     }
 
     /**

+ 6 - 0
tests/ApiDocGeneratorTest.php

@@ -135,6 +135,12 @@ class ApiDocGeneratorTest extends TestCase
                     $this->assertCount(1, $attribute['description']);
                     $this->assertSame('Between: `5` and `200`', $attribute['description'][0]);
                     break;
+                case 'string_between':
+                    $this->assertFalse($attribute['required']);
+                    $this->assertSame('string', $attribute['type']);
+                    $this->assertCount(1, $attribute['description']);
+                    $this->assertSame('Between: `5` and `200`', $attribute['description'][0]);
+                    break;
                 case 'before':
                     $this->assertFalse($attribute['required']);
                     $this->assertSame('date', $attribute['type']);

+ 6 - 0
tests/DingoGeneratorTest.php

@@ -138,6 +138,12 @@ class DingoGeneratorTest extends TestCase
                     $this->assertCount(1, $attribute['description']);
                     $this->assertSame('Between: `5` and `200`', $attribute['description'][0]);
                     break;
+                case 'string_between':
+                    $this->assertFalse($attribute['required']);
+                    $this->assertSame('string', $attribute['type']);
+                    $this->assertCount(1, $attribute['description']);
+                    $this->assertSame('Between: `5` and `200`', $attribute['description'][0]);
+                    break;
                 case 'before':
                     $this->assertFalse($attribute['required']);
                     $this->assertSame('date', $attribute['type']);

+ 1 - 0
tests/Fixtures/DingoTestRequest.php

@@ -19,6 +19,7 @@ class DingoTestRequest extends FormRequest
             'array' => 'array',
             'before' => 'before:2016-04-23 14:31:00',
             'between' => 'between:5,200',
+            'string_between' => 'string|between:5,200',
             'boolean' => 'boolean',
             'date' => 'date',
             'date_format' => 'date_format:j.n.Y H:iP',

+ 1 - 0
tests/Fixtures/TestRequest.php

@@ -19,6 +19,7 @@ class TestRequest extends FormRequest
             'array' => 'array',
             'before' => 'before:2016-04-23 14:31:00',
             'between' => 'between:5,200',
+            'string_between' => 'string|between:5,200',
             'boolean' => 'boolean',
             'date' => 'date',
             'date_format' => 'date_format:j.n.Y H:iP',