瀏覽代碼

Add support for multiline descriptions and examples in @-param tags

shalvah 5 年之前
父節點
當前提交
660ebcadc8

+ 1 - 2
config/scribe.php

@@ -233,8 +233,7 @@ INTRO
                      */
                     'config' => [
                         'app.env' => 'documentation',
-                        'app.debug' => false,
-                        // 'service.key' => 'value',
+                        // 'app.debug' => false,
                     ],
 
                     /*

+ 1 - 1
docs/documenting-endpoint-responses.md

@@ -267,7 +267,7 @@ public function listMoreUsers()
   $paginator = User::paginate(15);
   $users = $paginator->getCollection();
 
-    $transformer = new Collection($users, new UserTransformer(), 'data');
+    $transformer = new Fractal\Resource\Collection($users, new UserTransformer(), 'data');
     $transformer->setPaginator(new IlluminatePaginatorAdapter($users));
     
     return $fractal->createData($users)->toArray();

+ 1 - 1
src/Extracting/ParamHelpers.php

@@ -155,7 +155,7 @@ trait ParamHelpers
     protected function parseParamDescription(string $description, string $type)
     {
         $example = null;
-        if (preg_match('/(.*)\bExample:\s*(.+)\s*/', $description, $content)) {
+        if (preg_match('/(.*)\bExample:\s*([\s\S]+)\s*/', $description, $content)) {
             $description = trim($content[1]);
 
             // Examples are parsed as strings by default, we need to cast them properly

+ 1 - 1
src/Extracting/Strategies/BodyParameters/GetFromBodyParamTag.php

@@ -71,7 +71,7 @@ class GetFromBodyParamTag extends Strategy
                 // Examples:
                 // @bodyParam text string required The text.
                 // @bodyParam user_id integer The ID of the user.
-                preg_match('/(.+?)\s+(.+?)\s+(required\s+)?(.*)/', $tag->getContent(), $content);
+                preg_match('/(.+?)\s+(.+?)\s+(required\s+)?([\s\S]*)/', $tag->getContent(), $content);
                 $content = preg_replace('/\s?No-example.?/', '', $content);
                 if (empty($content)) {
                     // this means only name and type were supplied

+ 1 - 1
src/Extracting/Strategies/QueryParameters/GetFromQueryParamTag.php

@@ -71,7 +71,7 @@ class GetFromQueryParamTag extends Strategy
                 // Examples:
                 // @queryParam text string required The text.
                 // @queryParam user_id The ID of the user.
-                preg_match('/(.+?)\s+(required\s+)?(.*)/', $tag->getContent(), $content);
+                preg_match('/(.+?)\s+(required\s+)?([\s\S]*)/', $tag->getContent(), $content);
                 $content = preg_replace('/\s?No-example.?/', '', $content);
                 if (empty($content)) {
                     // this means only name was supplied

+ 1 - 1
src/Extracting/Strategies/ResponseFields/GetFromResponseFieldTag.php

@@ -43,7 +43,7 @@ class GetFromResponseFieldTag extends Strategy
                 // Examples:
                 // @responseField text string The text.
                 // @responseField user_id integer The ID of the user.
-                preg_match('/(.+?)\s+(.+?)\s+(.*)/', $tag->getContent(), $content);
+                preg_match('/(.+?)\s+(.+?)\s+([\s\S]*)/', $tag->getContent(), $content);
                 if (empty($content)) {
                     // this means only name and type were supplied
                     [$name, $type] = preg_split('/\s+/', $tag->getContent());

+ 1 - 1
src/Extracting/Strategies/UrlParameters/GetFromUrlParamTag.php

@@ -66,7 +66,7 @@ class GetFromUrlParamTag extends Strategy
                 // Examples:
                 // @urlParam id required The id of the post.
                 // @urlParam user_id The ID of the user.
-                preg_match('/(.+?)\s+(required\s+)?(.*)/', $tag->getContent(), $content);
+                preg_match('/(.+?)\s+(required\s+)?([\s\S]*)/', $tag->getContent(), $content);
                 $content = preg_replace('/\s?No-example.?/', '', $content);
                 if (empty($content)) {
                     // This means only name was supplied