]> BookStack Code Mirror - bookstack/blob - app/Http/Controllers/Api/ApiDocsController.php
Default OpenID display name set to standard value
[bookstack] / app / Http / Controllers / Api / ApiDocsController.php
1 <?php namespace BookStack\Http\Controllers\Api;
2
3 use BookStack\Api\ApiDocsGenerator;
4 use Cache;
5 use Illuminate\Support\Collection;
6
7 class ApiDocsController extends ApiController
8 {
9
10     /**
11      * Load the docs page for the API.
12      */
13     public function display()
14     {
15         $docs = $this->getDocs();
16         return view('api-docs.index', [
17             'docs' => $docs,
18         ]);
19     }
20
21     /**
22      * Show a JSON view of the API docs data.
23      */
24     public function json() {
25         $docs = $this->getDocs();
26         return response()->json($docs);
27     }
28
29     /**
30      * Get the base docs data.
31      * Checks and uses the system cache for quick re-fetching.
32      */
33     protected function getDocs(): Collection
34     {
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);
39         } else {
40             $docs = (new ApiDocsGenerator())->generate();
41             Cache::put($cacheKey, $docs, 60*24);
42         }
43
44         return $docs;
45     }
46
47 }