From ef5c44df5d3585e504eaf84ab0bb9715fef1e085 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Neto?= Date: Sun, 29 Jul 2018 11:24:59 +0100 Subject: [PATCH] #1 Dingo api Support feature --- resources/views/main.blade.php | 6 +++--- src/LaravelApiExplorer.php | 32 +++++++++++++++++++++++++++----- src/routes.php | 2 +- 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/resources/views/main.blade.php b/resources/views/main.blade.php index 5ad52f2..7cd8883 100644 --- a/resources/views/main.blade.php +++ b/resources/views/main.blade.php @@ -5,17 +5,17 @@ - + API explorer
- + \ No newline at end of file diff --git a/src/LaravelApiExplorer.php b/src/LaravelApiExplorer.php index 2d3c307..d11ebc6 100644 --- a/src/LaravelApiExplorer.php +++ b/src/LaravelApiExplorer.php @@ -26,15 +26,37 @@ public function getConfig() { private function getRoutes() { $routes = []; $routeCollection = Route::getRoutes(); - $allRoutes = $routeCollection->getRoutes(); + + $laravelRoutes = $routeCollection->getRoutes(); + $dingoRoutes = $this->getDingoRoutes(); + + $allRoutes = array_merge($laravelRoutes, $dingoRoutes); - return $this->filterRoutes($allRoutes);; + return $this->filterRoutes($allRoutes); + } + + private function getDingoRoutes() { + + if(!class_exists(\Dingo\Api\Routing\Router::class)){ + return []; + } + + $dingoRouter = app('Dingo\Api\Routing\Router'); + $versions = $dingoRouter->getRoutes(); + $routes = []; + foreach($versions as $version){ + $routes[] = $version->getRoutes(); + } + + $routes = collect($routes)->flatten()->toArray(); + + return $routes; } private function filterRoutes($routes) { $filtered = []; - $match = config('laravelapiexplorer.match'); + $match = trim(config('laravelapiexplorer.match'), '/'); $ignoreList = collect(config('laravelapiexplorer.ignore')); $ignoreList->push('laravelapiexplorer.view'); $ignoreList->push('laravelapiexplorer.info'); @@ -42,7 +64,7 @@ private function filterRoutes($routes) { foreach($routes as $route) { $name = $route->getName(); - $uri = $route->uri(); + $uri = trim($route->uri(), '/'); if( !str_is($match, $name) && @@ -91,7 +113,7 @@ private function formatRoute($route) { 'name' => $route->getName(), 'description' => $description, 'url' => url($uri), - 'uri' => $uri, + 'uri' => trim($uri, '/'), 'exists' => $exists, 'http_verb' => $httpVerb, 'controller' => $controller, diff --git a/src/routes.php b/src/routes.php index e7829da..8803b5c 100644 --- a/src/routes.php +++ b/src/routes.php @@ -4,7 +4,7 @@ if($enabled){ $prefix = config('laravelapiexplorer.route'); - Route::namespace('\NetoJose\LaravelApiExplorer')->prefix($prefix)->name('apiexplorer.')->group(function () { + Route::namespace('\NetoJose\LaravelApiExplorer')->prefix($prefix)->name('laravelapiexplorer.')->group(function () { Route::get('/', 'LaravelApiExplorerController@getView')->name('view'); Route::get('info', 'LaravelApiExplorerController@getInfo')->name('info'); Route::get('assets/{file}', 'LaravelApiExplorerController@getAsset')->where('file', '^([a-z0-9_\-\.]+).(js|css|svg)$')->name('asset');