Skip to content

Commit

Permalink
Fix Request class not found exception (#216)
Browse files Browse the repository at this point in the history
* Fix Request class not found exception
* Refactor the routes file and inclusion
  • Loading branch information
joemugen authored and DarkaOnLine committed Sep 3, 2019
1 parent 624b3f8 commit 085ca35
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 30 deletions.
16 changes: 9 additions & 7 deletions src/Http/Controllers/SwaggerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

namespace L5Swagger\Http\Controllers;

use File;
use Request;
use Response;
use L5Swagger\Generator;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Request;
use Illuminate\Support\Facades\Response;
use L5Swagger\Exceptions\L5SwaggerException;
use Illuminate\Routing\Controller as BaseController;

class SwaggerController extends BaseController
Expand All @@ -15,7 +16,7 @@ class SwaggerController extends BaseController
*
* @param string $jsonFile
*
* @return \Response
* @return \Illuminate\Http\Response
*/
public function docs($jsonFile = null)
{
Expand All @@ -40,15 +41,15 @@ public function docs($jsonFile = null)
/**
* Display Swagger API page.
*
* @return \Response
* @return \Illuminate\Http\Response
*/
public function api()
{
if ($proxy = config('l5-swagger.proxy')) {
if (! is_array($proxy)) {
$proxy = [$proxy];
}
Request::setTrustedProxies($proxy, \Illuminate\Http\Request::HEADER_X_FORWARDED_ALL);
\Illuminate\Http\Request::setTrustedProxies($proxy, \Illuminate\Http\Request::HEADER_X_FORWARDED_ALL);
}

// Need the / at the end to avoid CORS errors on Homestead systems.
Expand All @@ -70,9 +71,10 @@ public function api()
* Display Oauth2 callback pages.
*
* @return string
* @throws L5SwaggerException
*/
public function oauth2Callback()
{
return \File::get(swagger_ui_dist_path('oauth2-redirect.html'));
return File::get(swagger_ui_dist_path('oauth2-redirect.html'));
}
}
4 changes: 1 addition & 3 deletions src/L5SwaggerServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ public function boot()
], 'views');

//Include routes
\Route::group(['namespace' => 'L5Swagger'], function ($router) {
require __DIR__.'/routes.php';
});
$this->loadRoutesFrom(__DIR__.'/routes.php');

//Register commands
$this->commands([GenerateDocsCommand::class]);
Expand Down
45 changes: 25 additions & 20 deletions src/routes.php
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
<?php

$router->get(config('l5-swagger.routes.api'), [
'as' => 'l5-swagger.api',
'middleware' => config('l5-swagger.routes.middleware.api', []),
'uses' => '\L5Swagger\Http\Controllers\SwaggerController@api',
]);
use Illuminate\Routing\Router;
use Illuminate\Support\Facades\Route;

$router->any(config('l5-swagger.routes.docs').'/{jsonFile?}', [
'as' => 'l5-swagger.docs',
'middleware' => config('l5-swagger.routes.middleware.docs', []),
'uses' => '\L5Swagger\Http\Controllers\SwaggerController@docs',
]);
Route::group(['namespace' => 'L5Swagger'], function (Router $router) {
$router->get(config('l5-swagger.routes.api'), [
'as' => 'l5-swagger.api',
'middleware' => config('l5-swagger.routes.middleware.api', []),
'uses' => '\L5Swagger\Http\Controllers\SwaggerController@api',
]);

$router->get(config('l5-swagger.routes.docs').'/asset/{asset}', [
'as' => 'l5-swagger.asset',
'middleware' => config('l5-swagger.routes.middleware.asset', []),
'uses' => '\L5Swagger\Http\Controllers\SwaggerAssetController@index',
]);
$router->any(config('l5-swagger.routes.docs').'/{jsonFile?}', [
'as' => 'l5-swagger.docs',
'middleware' => config('l5-swagger.routes.middleware.docs', []),
'uses' => '\L5Swagger\Http\Controllers\SwaggerController@docs',
]);

$router->get(config('l5-swagger.routes.oauth2_callback'), [
'as' => 'l5-swagger.oauth2_callback',
'middleware' => config('l5-swagger.routes.middleware.oauth2_callback', []),
'uses' => '\L5Swagger\Http\Controllers\SwaggerController@oauth2Callback',
]);
$router->get(config('l5-swagger.routes.docs').'/asset/{asset}', [
'as' => 'l5-swagger.asset',
'middleware' => config('l5-swagger.routes.middleware.asset', []),
'uses' => '\L5Swagger\Http\Controllers\SwaggerAssetController@index',
]);

$router->get(config('l5-swagger.routes.oauth2_callback'), [
'as' => 'l5-swagger.oauth2_callback',
'middleware' => config('l5-swagger.routes.middleware.oauth2_callback', []),
'uses' => '\L5Swagger\Http\Controllers\SwaggerController@oauth2Callback',
]);
});

0 comments on commit 085ca35

Please sign in to comment.