9
9
use Illuminate \Routing \Controller as BaseController ;
10
10
use Illuminate \Support \Facades \Log ;
11
11
use Illuminate \Support \Facades \Request as RequestFacade ;
12
- use Illuminate \ Support \ Facades \ Response as ResponseFacade ;
12
+ use L5Swagger \ ConfigFactory ;
13
13
use L5Swagger \Exceptions \L5SwaggerException ;
14
14
use L5Swagger \GeneratorFactory ;
15
15
@@ -20,9 +20,17 @@ class SwaggerController extends BaseController
20
20
*/
21
21
protected $ generatorFactory ;
22
22
23
- public function __construct (GeneratorFactory $ generatorFactory )
24
- {
23
+ /**
24
+ * @var ConfigFactory
25
+ */
26
+ protected $ configFactory ;
27
+
28
+ public function __construct (
29
+ GeneratorFactory $ generatorFactory ,
30
+ ConfigFactory $ configFactory
31
+ ) {
25
32
$ this ->generatorFactory = $ generatorFactory ;
33
+ $ this ->configFactory = $ configFactory ;
26
34
}
27
35
28
36
/**
@@ -76,13 +84,13 @@ public function docs(Request $request)
76
84
$ content = $ fileSystem ->get ($ filePath );
77
85
78
86
if ($ yamlFormat ) {
79
- return ResponseFacade:: make ($ content , 200 , [
87
+ return response ($ content , 200 , [
80
88
'Content-Type ' => 'application/yaml ' ,
81
89
'Content-Disposition ' => 'inline ' ,
82
90
]);
83
91
}
84
92
85
- return ResponseFacade:: make ($ content , 200 , [
93
+ return response ($ content , 200 , [
86
94
'Content-Type ' => 'application/json ' ,
87
95
]);
88
96
}
@@ -97,8 +105,9 @@ public function api(Request $request)
97
105
{
98
106
$ documentation = $ request ->offsetGet ('documentation ' );
99
107
$ config = $ request ->offsetGet ('config ' );
108
+ $ proxy = $ config ['proxy ' ];
100
109
101
- if ($ proxy = $ config [ ' proxy ' ] ) {
110
+ if ($ proxy ) {
102
111
if (! is_array ($ proxy )) {
103
112
$ proxy = [$ proxy ];
104
113
}
@@ -113,14 +122,17 @@ public function api(Request $request)
113
122
}
114
123
115
124
$ urlToDocs = $ this ->generateDocumentationFileURL ($ documentation , $ config );
125
+ $ urlsToDocs = $ this ->getAllDocumentationUrls ();
116
126
$ useAbsolutePath = config ('l5-swagger.documentations. ' .$ documentation .'.paths.use_absolute_path ' , true );
117
127
118
128
// Need the / at the end to avoid CORS errors on Homestead systems.
119
- return ResponseFacade:: make (
129
+ return response (
120
130
view ('l5-swagger::index ' , [
121
131
'documentation ' => $ documentation ,
132
+ 'documentationTitle ' => $ config ['api ' ]['title ' ] ?? $ documentation ,
122
133
'secure ' => RequestFacade::secure (),
123
- 'urlToDocs ' => $ urlToDocs ,
134
+ 'urlToDocs ' => $ urlToDocs , // Is not used in the view, but still passed for backwards compatibility
135
+ 'urlsToDocs ' => $ urlsToDocs ,
124
136
'operationsSorter ' => $ config ['operations_sort ' ],
125
137
'configUrl ' => $ config ['additional_config_url ' ],
126
138
'validatorUrl ' => $ config ['validator_url ' ],
@@ -173,4 +185,23 @@ protected function generateDocumentationFileURL(string $documentation, array $co
173
185
$ useAbsolutePath
174
186
);
175
187
}
188
+
189
+ /**
190
+ * @return array<string, string> [title => url]
191
+ */
192
+ protected function getAllDocumentationUrls (): array
193
+ {
194
+ $ documentations = array_keys (config ('l5-swagger.documentations ' , []));
195
+
196
+ $ urlsToDocs = [];
197
+
198
+ foreach ($ documentations as $ documentationName ) {
199
+ $ config = $ this ->configFactory ->documentationConfig ($ documentationName );
200
+ $ title = $ config ['api ' ]['title ' ] ?? $ documentationName ;
201
+
202
+ $ urlsToDocs [$ title ] = $ this ->generateDocumentationFileURL ($ documentationName , $ config );
203
+ }
204
+
205
+ return $ urlsToDocs ;
206
+ }
176
207
}
0 commit comments