Skip to content

Commit

Permalink
#1 Dingo api Support feature
Browse files Browse the repository at this point in the history
  • Loading branch information
netojose committed Jul 29, 2018
1 parent d571fa9 commit ef5c44d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
6 changes: 3 additions & 3 deletions resources/views/main.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500">
<link rel="stylesheet" href="{{route('apiexplorer.asset', ['file' => 'styles.css'])}}">
<link rel="stylesheet" href="{{route('laravelapiexplorer.asset', ['file' => 'styles.css'])}}">
<style>
body {margin: 0;}
</style>
<script>
window.api_info_url = "{{route('apiexplorer.info')}}";
window.api_info_url = "{{route('laravelapiexplorer.info')}}";
</script>
<title>API explorer</title>
</head>
<body>
<div id="app"></div>
<script src="{{route('apiexplorer.asset', ['file' => 'bundle.js'])}}"></script>
<script src="{{route('laravelapiexplorer.asset', ['file' => 'bundle.js'])}}"></script>
</body>
</html>
32 changes: 27 additions & 5 deletions src/LaravelApiExplorer.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,45 @@ 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');
$ignoreList->push('laravelapiexplorer.asset');

foreach($routes as $route) {
$name = $route->getName();
$uri = $route->uri();
$uri = trim($route->uri(), '/');

if(
!str_is($match, $name) &&
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit ef5c44d

Please sign in to comment.