Skip to content

Commit 1362302

Browse files
hop-along-pollyDarkaOnLine
authored andcommitted
Add support for dumping yaml files (#233)
1 parent b1fda96 commit 1362302

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

src/Http/Controllers/SwaggerController.php

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,23 @@
1212
class SwaggerController extends BaseController
1313
{
1414
/**
15-
* Dump api-docs.json content endpoint.
15+
* Dump api-docs content endpoint. Supports dumping a json, or yaml file.
1616
*
17-
* @param string $jsonFile
17+
* @param string $file
1818
*
19-
* @return \Illuminate\Http\Response
19+
* @return \Response
2020
*/
21-
public function docs($jsonFile = null)
21+
public function docs(string $file = null)
2222
{
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;
2532

2633
if (config('l5-swagger.generate_always') || ! File::exists($filePath)) {
2734
try {
@@ -33,8 +40,15 @@ public function docs($jsonFile = null)
3340

3441
$content = File::get($filePath);
3542

43+
if ($extension === 'yaml') {
44+
return Response::make($content, 200, [
45+
'Content-Type' => 'application/yaml',
46+
'Content-Disposition' => 'inline',
47+
]);
48+
}
49+
3650
return Response::make($content, 200, [
37-
'Content-Type' => 'application/json',
51+
'Content-Type' => 'application/json'
3852
]);
3953
}
4054

0 commit comments

Comments
 (0)