12
12
class SwaggerController extends BaseController
13
13
{
14
14
/**
15
- * Dump api-docs.json content endpoint.
15
+ * Dump api-docs content endpoint. Supports dumping a json, or yaml file .
16
16
*
17
- * @param string $jsonFile
17
+ * @param string $file
18
18
*
19
- * @return \Illuminate\Http\ Response
19
+ * @return \Response
20
20
*/
21
- public function docs ($ jsonFile = null )
21
+ public function docs (string $ file = null )
22
22
{
23
- $ filePath = config ('l5-swagger.paths.docs ' ).'/ ' .
24
- (! is_null ($ jsonFile ) ? $ jsonFile : config ('l5-swagger.paths.docs_json ' , 'api-docs.json ' ));
23
+ $ extension = 'json ' ;
24
+ $ targetFile = config ('l5-swagger.paths.docs_json ' , 'api-docs.json ' );
25
+
26
+ if (!is_null ($ file )) {
27
+ $ targetFile = $ file ;
28
+ $ extension = explode ('. ' , $ file )[1 ];
29
+ }
30
+
31
+ $ filePath = config ('l5-swagger.paths.docs ' ).'/ ' .$ targetFile ;
25
32
26
33
if (config ('l5-swagger.generate_always ' ) || ! File::exists ($ filePath )) {
27
34
try {
@@ -33,8 +40,15 @@ public function docs($jsonFile = null)
33
40
34
41
$ content = File::get ($ filePath );
35
42
43
+ if ($ extension === 'yaml ' ) {
44
+ return Response::make ($ content , 200 , [
45
+ 'Content-Type ' => 'application/yaml ' ,
46
+ 'Content-Disposition ' => 'inline ' ,
47
+ ]);
48
+ }
49
+
36
50
return Response::make ($ content , 200 , [
37
- 'Content-Type ' => 'application/json ' ,
51
+ 'Content-Type ' => 'application/json '
38
52
]);
39
53
}
40
54
0 commit comments