]> BookStack Code Mirror - bookstack/blobdiff - app/Api/ApiDocsGenerator.php
add tests for priority
[bookstack] / app / Api / ApiDocsGenerator.php
index 76157c9a5c8ad60924fc8907d598526bb05c6f95..3cd33ffa576b5d8564a91c7827f708e611ff8cdf 100644 (file)
@@ -2,7 +2,7 @@
 
 namespace BookStack\Api;
 
-use BookStack\Http\Controllers\Api\ApiController;
+use BookStack\Http\ApiController;
 use Exception;
 use Illuminate\Contracts\Container\BindingResolutionException;
 use Illuminate\Support\Collection;
@@ -16,8 +16,8 @@ use ReflectionMethod;
 
 class ApiDocsGenerator
 {
-    protected $reflectionClasses = [];
-    protected $controllerClasses = [];
+    protected array $reflectionClasses = [];
+    protected array $controllerClasses = [];
 
     /**
      * Load the docs form the cache if existing
@@ -102,8 +102,8 @@ class ApiDocsGenerator
             $this->controllerClasses[$className] = $class;
         }
 
-        $rules = collect($class->getValidationRules()[$methodName] ?? [])->map(function($validations) {
-            return array_map(function($validation) {
+        $rules = collect($class->getValidationRules()[$methodName] ?? [])->map(function ($validations) {
+            return array_map(function ($validation) {
                 return $this->getValidationAsString($validation);
             }, $validations);
         })->toArray();
@@ -129,6 +129,7 @@ class ApiDocsGenerator
         }
 
         $class = get_class($validation);
+
         throw new Exception("Cannot provide string representation of rule for class: {$class}");
     }
 
@@ -138,9 +139,10 @@ class ApiDocsGenerator
     protected function parseDescriptionFromMethodComment(string $comment): string
     {
         $matches = [];
-        preg_match_all('/^\s*?\*\s((?![@\s]).*?)$/m', $comment, $matches);
+        preg_match_all('/^\s*?\*\s?($|((?![\/@\s]).*?))$/m', $comment, $matches);
 
-        return implode(' ', $matches[1] ?? []);
+        $text = implode(' ', $matches[1] ?? []);
+        return str_replace('  ', "\n", $text);
     }
 
     /**