X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/45b5e631e241e7809d8752279d781ec391245423..refs/pull/2302/head:/app/Api/ApiDocsGenerator.php diff --git a/app/Api/ApiDocsGenerator.php b/app/Api/ApiDocsGenerator.php index 41decd23d..ddba24bdb 100644 --- a/app/Api/ApiDocsGenerator.php +++ b/app/Api/ApiDocsGenerator.php @@ -3,6 +3,7 @@ use BookStack\Http\Controllers\Api\ApiController; use Illuminate\Support\Collection; use Illuminate\Support\Facades\Route; +use Illuminate\Support\Str; use ReflectionClass; use ReflectionException; use ReflectionMethod; @@ -31,9 +32,12 @@ class ApiDocsGenerator protected function loadDetailsFromFiles(Collection $routes): Collection { return $routes->map(function (array $route) { - $exampleResponseFile = base_path('dev/api/responses/' . $route['name'] . '.json'); - $exampleResponse = file_exists($exampleResponseFile) ? file_get_contents($exampleResponseFile) : null; - $route['example_response'] = $exampleResponse; + $exampleTypes = ['request', 'response']; + foreach ($exampleTypes as $exampleType) { + $exampleFile = base_path("dev/api/{$exampleType}s/{$route['name']}.json"); + $exampleContent = file_exists($exampleFile) ? file_get_contents($exampleFile) : null; + $route["example_{$exampleType}"] = $exampleContent; + } return $route; }); } @@ -114,6 +118,7 @@ class ApiDocsGenerator 'method' => $route->methods[0], 'controller' => $controller, 'controller_method' => $controllerMethod, + 'controller_method_kebab' => Str::kebab($controllerMethod), 'base_model' => $baseModelName, ]; });