X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/06b500984250f75b98f38a8f25ac953cb45aeee4..refs/pull/3245/head:/app/Api/ApiDocsGenerator.php diff --git a/app/Api/ApiDocsGenerator.php b/app/Api/ApiDocsGenerator.php index 3aabfb4cc..4cba7900b 100644 --- a/app/Api/ApiDocsGenerator.php +++ b/app/Api/ApiDocsGenerator.php @@ -28,7 +28,7 @@ class ApiDocsGenerator if (Cache::has($cacheKey) && config('app.env') === 'production') { $docs = Cache::get($cacheKey); } else { - $docs = (new static())->generate(); + $docs = (new ApiDocsGenerator())->generate(); Cache::put($cacheKey, $docs, 60 * 24); } @@ -55,10 +55,16 @@ class ApiDocsGenerator { return $routes->map(function (array $route) { $exampleTypes = ['request', 'response']; + $fileTypes = ['json', 'http']; 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; + foreach ($fileTypes as $fileType) { + $exampleFile = base_path("dev/api/{$exampleType}s/{$route['name']}." . $fileType); + if (file_exists($exampleFile)) { + $route["example_{$exampleType}"] = file_get_contents($exampleFile); + continue 2; + } + } + $route["example_{$exampleType}"] = null; } return $route; @@ -95,6 +101,7 @@ class ApiDocsGenerator } $rules = $class->getValdationRules()[$methodName] ?? []; + return empty($rules) ? null : $rules; }