Skip to content

Commit b9e5bdc

Browse files
authored
Merge pull request #458 from Sh1d0w/master
Fix domain name for the generated links
2 parents e98c7f4 + d915818 commit b9e5bdc

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/Commands/GenerateDocumentation.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Illuminate\Console\Command;
99
use Mpociot\Reflection\DocBlock;
1010
use Illuminate\Support\Collection;
11+
use Illuminate\Support\Facades\URL;
1112
use Mpociot\ApiDoc\Tools\Generator;
1213
use Mpociot\ApiDoc\Tools\RouteMatcher;
1314
use Mpociot\Documentarian\Documentarian;
@@ -46,6 +47,7 @@ public function __construct(RouteMatcher $routeMatcher)
4647
*/
4748
public function handle()
4849
{
50+
URL::forceRootUrl(config('app.url'));
4951
$usingDingoRouter = strtolower(config('apidoc.router')) == 'dingo';
5052
if ($usingDingoRouter) {
5153
$routes = $this->routeMatcher->getDingoRoutesToBeDocumented(config('apidoc.routes'));

tests/GenerateDocumentationTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Mpociot\ApiDoc\Tests;
44

55
use ReflectionException;
6+
use Illuminate\Support\Str;
67
use RecursiveIteratorIterator;
78
use RecursiveDirectoryIterator;
89
use Orchestra\Testbench\TestCase;
@@ -230,6 +231,21 @@ public function generated_postman_collection_file_is_correct()
230231
$this->assertEquals($generatedCollection, $fixtureCollection);
231232
}
232233

234+
/** @test */
235+
public function generated_postman_collection_domain_is_correct()
236+
{
237+
$domain = 'http://somedomain.test';
238+
RouteFacade::get('/api/test', TestController::class.'@withEndpointDescription');
239+
240+
config(['app.url' => $domain]);
241+
config(['apidoc.routes.0.match.prefixes' => ['api/*']]);
242+
$this->artisan('apidoc:generate');
243+
244+
$generatedCollection = json_decode(file_get_contents(__DIR__.'/../public/docs/collection.json'));
245+
$endpointUrl = $generatedCollection->item[0]->item[0]->request->url;
246+
$this->assertTrue(Str::startsWith($endpointUrl, $domain));
247+
}
248+
233249
/** @test */
234250
public function generated_postman_collection_can_have_custom_url()
235251
{

0 commit comments

Comments
 (0)