1 <?php namespace BookStack\Http\Controllers\Api;
3 use BookStack\Api\ApiDocsGenerator;
5 use Illuminate\Support\Collection;
7 class ApiDocsController extends ApiController
11 * Load the docs page for the API.
13 public function display()
15 $docs = $this->getDocs();
17 // TODO - Build view for API docs
22 * Show a JSON view of the API docs data.
24 public function json() {
25 $docs = $this->getDocs();
26 return response()->json($docs);
30 * Get the base docs data.
31 * Checks and uses the system cache for quick re-fetching.
33 protected function getDocs(): Collection
35 $appVersion = trim(file_get_contents(base_path('version')));
36 $cacheKey = 'api-docs::' . $appVersion;
37 if (Cache::has($cacheKey) && config('app.env') === 'production') {
38 $docs = Cache::get($cacheKey);
40 $docs = (new ApiDocsGenerator())->generate();
41 Cache::put($cacheKey, $docs, 60*24);