Browse Source

changed documentation to read multiple configs

MooseH 3 years ago
parent
commit
6ee322995a

+ 9 - 0
src/Commands/GenerateDocumentation.php

@@ -23,6 +23,7 @@ class GenerateDocumentation extends Command
                             {--force : Discard any changes you've made to the YAML or Markdown files}
                             {--no-extraction : Skip extraction of route and API info and just transform the YAML and Markdown files into HTML}
                             {--no-upgrade-check : Skip checking for config file upgrades. Won't make things faster, but can be helpful if the command is buggy}
+                            {--config= : choose which config file to use}
     ";
 
     protected $description = 'Generate API documentation from your Laravel/Dingo routes.';
@@ -92,6 +93,14 @@ class GenerateDocumentation extends Command
 
         $this->docConfig = new DocumentationConfig(config('scribe'));
 
+        if($this->option('config')){
+            $config = config_path($this->option('config')).".php";
+            if(!file_exists($config)){
+                die("There is no suitable config found at {$config}\n");
+            }
+            $this->docConfig = new DocumentationConfig(config($this->option('config')));
+        }
+
         // Force root URL so it works in Postman collection
         $baseUrl = $this->docConfig->get('base_url') ?? config('app.url');
         URL::forceRootUrl($baseUrl);

+ 8 - 1
src/GroupedEndpoints/GroupedEndpointsFromApp.php

@@ -41,7 +41,6 @@ class GroupedEndpointsFromApp implements GroupedEndpointsContract
         $this->routeMatcher = $routeMatcher;
         $this->docConfig = $command->getDocConfig();
         $this->preserveUserChanges = $preserveUserChanges;
-
         static::$camelDir = Camel::$camelDir;
         static::$cacheDir = Camel::$cacheDir;
     }
@@ -265,6 +264,14 @@ class GroupedEndpointsFromApp implements GroupedEndpointsContract
         }
 
         $methodDocBlock = new DocBlock(u::getReflectedRouteMethod($routeControllerAndMethod)->getDocComment() ?: '');
+
+        $routes = $this->docConfig->get('routes');
+        $configs = $routes[0]['apply']['response_calls']['config'];
+
+        if(isset($configs['ignore_hidden']) && $configs['ignore_hidden'] !== true){
+            return collect();
+        }
+
         $shouldIgnoreMethod = collect($methodDocBlock->getTags())
             ->filter(function (Tag $tag) {
                 return Str::lower($tag->getName()) === 'hidefromapidocumentation';

+ 1 - 1
src/Writing/Writer.php

@@ -148,6 +148,7 @@ class Writer
 
     protected function performFinalTasksForLaravelType(): void
     {
+
         if (!is_dir($this->laravelTypeOutputPath)) {
             mkdir($this->laravelTypeOutputPath, 0777, true);
         }
@@ -172,7 +173,6 @@ class Writer
         $contents = preg_replace('#src="\.\./docs/(js|images)/(.+?)"#', 'src="{{ asset("' . $this->laravelAssetsPath . '/$1/$2") }}"', $contents);
         $contents = str_replace('href="../docs/collection.json"', 'href="{{ route("scribe.postman") }}"', $contents);
         $contents = str_replace('href="../docs/openapi.yaml"', 'href="{{ route("scribe.openapi") }}"', $contents);
-
         file_put_contents("$this->laravelTypeOutputPath/index.blade.php", $contents);
     }