Skip to content

Commit ef5c44d

Browse files
committed
#1 Dingo api Support feature
1 parent d571fa9 commit ef5c44d

File tree

3 files changed

+31
-9
lines changed

3 files changed

+31
-9
lines changed

resources/views/main.blade.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@
55
<meta name="viewport" content="width=device-width, initial-scale=1.0">
66
<meta http-equiv="X-UA-Compatible" content="ie=edge">
77
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500">
8-
<link rel="stylesheet" href="{{route('apiexplorer.asset', ['file' => 'styles.css'])}}">
8+
<link rel="stylesheet" href="{{route('laravelapiexplorer.asset', ['file' => 'styles.css'])}}">
99
<style>
1010
body {margin: 0;}
1111
</style>
1212
<script>
13-
window.api_info_url = "{{route('apiexplorer.info')}}";
13+
window.api_info_url = "{{route('laravelapiexplorer.info')}}";
1414
</script>
1515
<title>API explorer</title>
1616
</head>
1717
<body>
1818
<div id="app"></div>
19-
<script src="{{route('apiexplorer.asset', ['file' => 'bundle.js'])}}"></script>
19+
<script src="{{route('laravelapiexplorer.asset', ['file' => 'bundle.js'])}}"></script>
2020
</body>
2121
</html>

src/LaravelApiExplorer.php

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,45 @@ public function getConfig() {
2626
private function getRoutes() {
2727
$routes = [];
2828
$routeCollection = Route::getRoutes();
29-
$allRoutes = $routeCollection->getRoutes();
29+
30+
$laravelRoutes = $routeCollection->getRoutes();
31+
$dingoRoutes = $this->getDingoRoutes();
32+
33+
$allRoutes = array_merge($laravelRoutes, $dingoRoutes);
3034

31-
return $this->filterRoutes($allRoutes);;
35+
return $this->filterRoutes($allRoutes);
36+
}
37+
38+
private function getDingoRoutes() {
39+
40+
if(!class_exists(\Dingo\Api\Routing\Router::class)){
41+
return [];
42+
}
43+
44+
$dingoRouter = app('Dingo\Api\Routing\Router');
45+
$versions = $dingoRouter->getRoutes();
46+
$routes = [];
47+
foreach($versions as $version){
48+
$routes[] = $version->getRoutes();
49+
}
50+
51+
$routes = collect($routes)->flatten()->toArray();
52+
53+
return $routes;
3254
}
3355

3456
private function filterRoutes($routes) {
3557
$filtered = [];
3658

37-
$match = config('laravelapiexplorer.match');
59+
$match = trim(config('laravelapiexplorer.match'), '/');
3860
$ignoreList = collect(config('laravelapiexplorer.ignore'));
3961
$ignoreList->push('laravelapiexplorer.view');
4062
$ignoreList->push('laravelapiexplorer.info');
4163
$ignoreList->push('laravelapiexplorer.asset');
4264

4365
foreach($routes as $route) {
4466
$name = $route->getName();
45-
$uri = $route->uri();
67+
$uri = trim($route->uri(), '/');
4668

4769
if(
4870
!str_is($match, $name) &&
@@ -91,7 +113,7 @@ private function formatRoute($route) {
91113
'name' => $route->getName(),
92114
'description' => $description,
93115
'url' => url($uri),
94-
'uri' => $uri,
116+
'uri' => trim($uri, '/'),
95117
'exists' => $exists,
96118
'http_verb' => $httpVerb,
97119
'controller' => $controller,

src/routes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
if($enabled){
66
$prefix = config('laravelapiexplorer.route');
7-
Route::namespace('\NetoJose\LaravelApiExplorer')->prefix($prefix)->name('apiexplorer.')->group(function () {
7+
Route::namespace('\NetoJose\LaravelApiExplorer')->prefix($prefix)->name('laravelapiexplorer.')->group(function () {
88
Route::get('/', 'LaravelApiExplorerController@getView')->name('view');
99
Route::get('info', 'LaravelApiExplorerController@getInfo')->name('info');
1010
Route::get('assets/{file}', 'LaravelApiExplorerController@getAsset')->where('file', '^([a-z0-9_\-\.]+).(js|css|svg)$')->name('asset');

0 commit comments

Comments
 (0)