From 9b65393307d7b9a502b373abb3c3ac34fe27a48a Mon Sep 17 00:00:00 2001 From: Philippe Thiers Date: Wed, 5 Feb 2020 14:17:14 -0300 Subject: [PATCH 1/3] Fix for URL::formatRoot for lumen in PostmanCollectionWriter --- composer.json | 1 + src/Writing/PostmanCollectionWriter.php | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index bea30e4d..fd052cad 100644 --- a/composer.json +++ b/composer.json @@ -31,6 +31,7 @@ "require-dev": { "dingo/api": "^2.3.0", "dms/phpunit-arraysubset-asserts": "^0.1.0", + "laravel/lumen-framework": "^5.7|^6.0|^7.0", "league/fractal": "^0.17.0", "mockery/mockery": "^1.2.0", "orchestra/testbench": "^3.7|^4.0", diff --git a/src/Writing/PostmanCollectionWriter.php b/src/Writing/PostmanCollectionWriter.php index 9528bd74..d2209185 100644 --- a/src/Writing/PostmanCollectionWriter.php +++ b/src/Writing/PostmanCollectionWriter.php @@ -6,6 +6,7 @@ use Illuminate\Support\Facades\URL; use Illuminate\Support\Str; use Ramsey\Uuid\Uuid; +use ReflectionMethod; class PostmanCollectionWriter { @@ -38,7 +39,7 @@ public function __construct(Collection $routeGroups, $baseUrl) { $this->routeGroups = $routeGroups; $this->protocol = Str::startsWith($baseUrl, 'https') ? 'https' : 'http'; - $this->baseUrl = URL::formatRoot('', $baseUrl); + $this->baseUrl = $this->getBaseUrl($baseUrl); $this->auth = config('apidoc.postman.auth'); } @@ -181,4 +182,16 @@ protected function getAuthHeader() return null; } } + + protected function getBaseUrl($baseUrl) + { + if (Str::contains(app()->version(), 'Lumen')) { //Is Lumen + $reflectionMethod = new ReflectionMethod(\Laravel\Lumen\Routing\UrlGenerator::class, 'getRootUrl'); + $reflectionMethod->setAccessible(true); + $url = app('url'); + return $reflectionMethod->invokeArgs($url, ['', $baseUrl]); + } else { //Is Laravel + return URL::formatRoot('', $baseUrl); + } + } } From 2383f84e05064cd9c70df2775615da823720ff8b Mon Sep 17 00:00:00 2001 From: Philippe Thiers Date: Wed, 5 Feb 2020 14:17:14 -0300 Subject: [PATCH 2/3] Fix for URL::formatRoot for lumen in PostmanCollectionWriter --- composer.json | 1 + src/Writing/PostmanCollectionWriter.php | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index bea30e4d..fd052cad 100644 --- a/composer.json +++ b/composer.json @@ -31,6 +31,7 @@ "require-dev": { "dingo/api": "^2.3.0", "dms/phpunit-arraysubset-asserts": "^0.1.0", + "laravel/lumen-framework": "^5.7|^6.0|^7.0", "league/fractal": "^0.17.0", "mockery/mockery": "^1.2.0", "orchestra/testbench": "^3.7|^4.0", diff --git a/src/Writing/PostmanCollectionWriter.php b/src/Writing/PostmanCollectionWriter.php index 9528bd74..d2209185 100644 --- a/src/Writing/PostmanCollectionWriter.php +++ b/src/Writing/PostmanCollectionWriter.php @@ -6,6 +6,7 @@ use Illuminate\Support\Facades\URL; use Illuminate\Support\Str; use Ramsey\Uuid\Uuid; +use ReflectionMethod; class PostmanCollectionWriter { @@ -38,7 +39,7 @@ public function __construct(Collection $routeGroups, $baseUrl) { $this->routeGroups = $routeGroups; $this->protocol = Str::startsWith($baseUrl, 'https') ? 'https' : 'http'; - $this->baseUrl = URL::formatRoot('', $baseUrl); + $this->baseUrl = $this->getBaseUrl($baseUrl); $this->auth = config('apidoc.postman.auth'); } @@ -181,4 +182,16 @@ protected function getAuthHeader() return null; } } + + protected function getBaseUrl($baseUrl) + { + if (Str::contains(app()->version(), 'Lumen')) { //Is Lumen + $reflectionMethod = new ReflectionMethod(\Laravel\Lumen\Routing\UrlGenerator::class, 'getRootUrl'); + $reflectionMethod->setAccessible(true); + $url = app('url'); + return $reflectionMethod->invokeArgs($url, ['', $baseUrl]); + } else { //Is Laravel + return URL::formatRoot('', $baseUrl); + } + } } From c610b2505c19e2a2e34c678f16979d4a240dd312 Mon Sep 17 00:00:00 2001 From: Philippe Thiers Date: Wed, 5 Feb 2020 14:53:59 -0300 Subject: [PATCH 3/3] Reformat getBaseUrl method --- src/Writing/PostmanCollectionWriter.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Writing/PostmanCollectionWriter.php b/src/Writing/PostmanCollectionWriter.php index d2209185..3a58fc54 100644 --- a/src/Writing/PostmanCollectionWriter.php +++ b/src/Writing/PostmanCollectionWriter.php @@ -189,9 +189,10 @@ protected function getBaseUrl($baseUrl) $reflectionMethod = new ReflectionMethod(\Laravel\Lumen\Routing\UrlGenerator::class, 'getRootUrl'); $reflectionMethod->setAccessible(true); $url = app('url'); + return $reflectionMethod->invokeArgs($url, ['', $baseUrl]); - } else { //Is Laravel - return URL::formatRoot('', $baseUrl); } + + return URL::formatRoot('', $baseUrl); } }