瀏覽代碼

fallback to method docblock if FormRequest subclass has no docblock

Michael Wallner 6 年之前
父節點
當前提交
1265719bf4

+ 5 - 1
src/Tools/Generator.php

@@ -96,7 +96,11 @@ class Generator
 
         if ($cls) {
             $docBlock = new DocBlock($cls->getDocComment());
-            return $this->getBodyParametersFromDocBlock($docBlock->getTags());
+            $result = $this->getBodyParametersFromDocBlock($docBlock->getTags());
+
+            if (count($result)) {
+                return $result;
+            }
         }
 
         return $this->getBodyParametersFromDocBlock($tags);

+ 8 - 0
tests/Fixtures/TestController.php

@@ -57,6 +57,14 @@ class TestController extends Controller
         return '';
     }
 
+    /**
+     * @bodyParam direct_one string Is found directly on the method.
+     */
+    public function withNonCommentedFormRequestParameter(TestNonCommentedRequest $request)
+    {
+        return '';
+    }
+
     /**
      * @queryParam location_id required The id of the location.
      * @queryParam user_id required The id of the user. Example: me

+ 8 - 0
tests/Fixtures/TestNonCommentedRequest.php

@@ -0,0 +1,8 @@
+<?php namespace Mpociot\ApiDoc\Tests\Fixtures;
+
+use Dingo\Api\Http\FormRequest;
+
+class TestNonCommentedRequest extends FormRequest
+{
+
+}

+ 14 - 0
tests/Unit/GeneratorTestCase.php

@@ -83,6 +83,20 @@ abstract class GeneratorTestCase extends TestCase
         ], $bodyParameters);
     }
 
+    /** @test */
+    public function it_ignores_non_commented_form_request()
+    {
+        $route = $this->createRoute('GET', '/api/test', 'withNonCommentedFormRequestParameter');
+        $bodyParameters = $this->generator->processRoute($route)['bodyParameters'];
+
+        $this->assertArraySubset([
+            'direct_one' => [
+                'type' => 'string',
+                'description' => 'Is found directly on the method.'
+            ],
+        ], $bodyParameters);
+    }
+
     /** @test */
     public function can_parse_form_request_body_parameters()
     {