Skip to content

Commit

Permalink
Merge pull request #548 from gpressutto5/fix/null-base_url
Browse files Browse the repository at this point in the history
Not using config helper inside config file
  • Loading branch information
shalvah authored Aug 9, 2019
2 parents c4422ce + b3a93de commit 5ce0188
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion config/apidoc.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* The base URL to be used in examples and the Postman collection.
* By default, this will be the value of config('app.url').
*/
'base_url' => config('app.url'),
'base_url' => null,

/*
* Generate a Postman collection in addition to HTML docs.
Expand Down
12 changes: 9 additions & 3 deletions src/Commands/GenerateDocumentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ class GenerateDocumentation extends Command
*/
private $docConfig;

/**
* @var string
*/
private $baseUrl;

public function __construct(RouteMatcher $routeMatcher)
{
parent::__construct();
Expand All @@ -60,9 +65,10 @@ public function handle()
Flags::$shouldBeVerbose = $this->option('verbose');

$this->docConfig = new DocumentationConfig(config('apidoc'));
$this->baseUrl = $this->docConfig->get('base_url') ?? config('app.url');

try {
URL::forceRootUrl($this->docConfig->get('base_url'));
URL::forceRootUrl($this->baseUrl);
} catch (\Error $e) {
echo "Warning: Couldn't force base url as your version of Lumen doesn't have the forceRootUrl method.\n";
echo "You should probably double check URLs in your generated documentation.\n";
Expand Down Expand Up @@ -111,7 +117,7 @@ private function writeMarkdown($parsedRoutes)
$route['output'] = (string) view('apidoc::partials.route')
->with('route', $route)
->with('settings', $settings)
->with('baseUrl', $this->docConfig->get('base_url'))
->with('baseUrl', $this->baseUrl)
->render();

return $route;
Expand Down Expand Up @@ -288,7 +294,7 @@ private function isRouteVisibleForDocumentation($action)
*/
private function generatePostmanCollection(Collection $routes)
{
$writer = new CollectionWriter($routes, $this->docConfig->get('base_url'));
$writer = new CollectionWriter($routes, $this->baseUrl);

return $writer->getCollection();
}
Expand Down

0 comments on commit 5ce0188

Please sign in to comment.