Skip to content

Commit

Permalink
Allow PHP8 and add new config param (#347)
Browse files Browse the repository at this point in the history
* Allow php8

* Introduce config param format_to_use_for_docs

* Apply fixes from StyleCI

* Refactor to generateDocumentationFileURL

* Apply fixes from StyleCI

* Refactor to generateDocumentationFileURL

Co-authored-by: Darius Matulionis <[email protected]>
  • Loading branch information
DarkaOnLine and DarkaOnLine authored Dec 7, 2020
1 parent d1b2f77 commit 446d3b7
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ matrix:
- php: 7.3
- php: 7.4
env: REPORT_TESTS_COVERAGE=1
- php: 8.0
cache:
directories:
- "$HOME/.composer/cache"
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
}
],
"require": {
"php": "^7.2",
"php": "^7.2 || ^8.0",
"laravel/framework": "^8.0 || ^7.0",
"zircote/swagger-php": "3.*",
"swagger-api/swagger-ui": "^3.0",
Expand Down
5 changes: 5 additions & 0 deletions config/l5-swagger.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
*/
'docs_yaml' => 'api-docs.yaml',

/*
* Set this to `json` or `yaml` to determine which documentation file to use in UI
*/
'format_to_use_for_docs' => env('L5_FORMAT_TO_USE_FOR_DOCS', 'json'),

/*
* Absolute paths to directory containing the swagger annotations are stored.
*/
Expand Down
26 changes: 25 additions & 1 deletion src/Http/Controllers/SwaggerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function api(Request $request)
Request::setTrustedProxies($proxy, Request::HEADER_X_FORWARDED_ALL);
}

$urlToDocs = route('l5-swagger.'.$documentation.'.docs', $config['paths']['docs_json'] ?? 'api-docs.json');
$urlToDocs = $this->generateDocumentationFileURL($documentation);

// Need the / at the end to avoid CORS errors on Homestead systems.
return ResponseFacade::make(
Expand Down Expand Up @@ -135,4 +135,28 @@ public function oauth2Callback(Request $request)

return File::get(swagger_ui_dist_path($documentation, 'oauth2-redirect.html'));
}

/**
* Generate URL for documentation file.
*
* @param string $documentation
*
* @return string
*/
protected function generateDocumentationFileURL(string $documentation)
{
$fileUsedForDocs = $config['paths']['docs_json'] ?? 'api-docs.json';

if (! empty($config['paths']['format_to_use_for_docs'])
&& $config['paths']['format_to_use_for_docs'] === 'yaml'
&& $config['paths']['docs_yaml']
) {
$fileUsedForDocs = $config['paths']['docs_yaml'];
}

return route(
'l5-swagger.'.$documentation.'.docs',
$fileUsedForDocs
);
}
}

0 comments on commit 446d3b7

Please sign in to comment.