1414use Mpociot \ApiDoc \Tools \RouteMatcher ;
1515use Mpociot \Documentarian \Documentarian ;
1616use Mpociot \ApiDoc \Postman \CollectionWriter ;
17+ use Mpociot \ApiDoc \Tools \DocumentationConfig ;
1718
1819class GenerateDocumentation extends Command
1920{
@@ -35,6 +36,11 @@ class GenerateDocumentation extends Command
3536
3637 private $ routeMatcher ;
3738
39+ /**
40+ * @var DocumentationConfig
41+ */
42+ private $ docConfig ;
43+
3844 public function __construct (RouteMatcher $ routeMatcher )
3945 {
4046 parent ::__construct ();
@@ -48,20 +54,23 @@ public function __construct(RouteMatcher $routeMatcher)
4854 */
4955 public function handle ()
5056 {
57+ $ this ->docConfig = new DocumentationConfig (config ('apidoc ' ));
58+
5159 try {
52- URL ::forceRootUrl (config ( ' app.url ' ));
60+ URL ::forceRootUrl ($ this -> docConfig -> get ( ' base_url ' ));
5361 } catch (\Exception $ e ) {
54- echo "Warning: Couldn't force base url as Lumen currently doesn't have the forceRootUrl method. \n" ;
62+ echo "Warning: Couldn't force base url as your version of Lumen doesn't have the forceRootUrl method. \n" ;
5563 echo "You should probably double check URLs in your generated documentation. \n" ;
5664 }
57- $ usingDingoRouter = strtolower (config ('apidoc.router ' )) == 'dingo ' ;
65+ $ usingDingoRouter = strtolower ($ this ->docConfig ->get ('router ' )) == 'dingo ' ;
66+ $ routes = $ this ->docConfig ->get ('routes ' );
5867 if ($ usingDingoRouter ) {
59- $ routes = $ this ->routeMatcher ->getDingoRoutesToBeDocumented (config ( ' apidoc. routes' ) );
68+ $ routes = $ this ->routeMatcher ->getDingoRoutesToBeDocumented ($ routes );
6069 } else {
61- $ routes = $ this ->routeMatcher ->getLaravelRoutesToBeDocumented (config ( ' apidoc. routes' ) );
70+ $ routes = $ this ->routeMatcher ->getLaravelRoutesToBeDocumented ($ routes );
6271 }
6372
64- $ generator = new Generator (config ( ' apidoc.faker_seed ' ) );
73+ $ generator = new Generator ($ this -> docConfig );
6574 $ parsedRoutes = $ this ->processRoutes ($ generator , $ routes );
6675 $ parsedRoutes = collect ($ parsedRoutes )->groupBy ('group ' )
6776 ->sortBy (static function ($ group ) {
@@ -79,7 +88,7 @@ public function handle()
7988 */
8089 private function writeMarkdown ($ parsedRoutes )
8190 {
82- $ outputPath = config ( ' apidoc. output ' );
91+ $ outputPath = $ this -> docConfig -> get ( ' output ' );
8392 $ targetFile = $ outputPath .DIRECTORY_SEPARATOR .'source ' .DIRECTORY_SEPARATOR .'index.md ' ;
8493 $ compareFile = $ outputPath .DIRECTORY_SEPARATOR .'source ' .DIRECTORY_SEPARATOR .'.compare.md ' ;
8594 $ prependFile = $ outputPath .DIRECTORY_SEPARATOR .'source ' .DIRECTORY_SEPARATOR .'prepend.md ' ;
@@ -89,7 +98,7 @@ private function writeMarkdown($parsedRoutes)
8998 ->with ('outputPath ' , ltrim ($ outputPath , 'public/ ' ))
9099 ->with ('showPostmanCollectionButton ' , $ this ->shouldGeneratePostmanCollection ());
91100
92- $ settings = ['languages ' => config ( ' apidoc. example_languages ' )];
101+ $ settings = ['languages ' => $ this -> docConfig -> get ( ' example_languages ' )];
93102 $ parsedRouteOutput = $ parsedRoutes ->map (function ($ routeGroup ) use ($ settings ) {
94103 return $ routeGroup ->map (function ($ route ) use ($ settings ) {
95104 if (count ($ route ['cleanBodyParameters ' ]) && ! isset ($ route ['headers ' ]['Content-Type ' ])) {
@@ -98,6 +107,7 @@ private function writeMarkdown($parsedRoutes)
98107 $ route ['output ' ] = (string ) view ('apidoc::partials.route ' )
99108 ->with ('route ' , $ route )
100109 ->with ('settings ' , $ settings )
110+ ->with ('baseUrl ' , $ this ->docConfig ->get ('base_url ' ))
101111 ->render ();
102112
103113 return $ route ;
@@ -150,7 +160,7 @@ private function writeMarkdown($parsedRoutes)
150160 ->with ('infoText ' , $ infoText )
151161 ->with ('prependMd ' , $ prependFileContents )
152162 ->with ('appendMd ' , $ appendFileContents )
153- ->with ('outputPath ' , config ( ' apidoc. output ' ))
163+ ->with ('outputPath ' , $ this -> docConfig -> get ( ' output ' ))
154164 ->with ('showPostmanCollectionButton ' , $ this ->shouldGeneratePostmanCollection ())
155165 ->with ('parsedRoutes ' , $ parsedRouteOutput );
156166
@@ -168,7 +178,7 @@ private function writeMarkdown($parsedRoutes)
168178 ->with ('infoText ' , $ infoText )
169179 ->with ('prependMd ' , $ prependFileContents )
170180 ->with ('appendMd ' , $ appendFileContents )
171- ->with ('outputPath ' , config ( ' apidoc. output ' ))
181+ ->with ('outputPath ' , $ this -> docConfig -> get ( ' output ' ))
172182 ->with ('showPostmanCollectionButton ' , $ this ->shouldGeneratePostmanCollection ())
173183 ->with ('parsedRoutes ' , $ parsedRouteOutput );
174184
@@ -188,7 +198,7 @@ private function writeMarkdown($parsedRoutes)
188198 file_put_contents ($ outputPath .DIRECTORY_SEPARATOR .'collection.json ' , $ this ->generatePostmanCollection ($ parsedRoutes ));
189199 }
190200
191- if ($ logo = config ( ' apidoc. logo ' )) {
201+ if ($ logo = $ this -> docConfig -> get ( ' logo ' )) {
192202 copy (
193203 $ logo ,
194204 $ outputPath .DIRECTORY_SEPARATOR .'images ' .DIRECTORY_SEPARATOR .'logo.png '
@@ -274,7 +284,7 @@ private function isRouteVisibleForDocumentation($action)
274284 */
275285 private function generatePostmanCollection (Collection $ routes )
276286 {
277- $ writer = new CollectionWriter ($ routes );
287+ $ writer = new CollectionWriter ($ routes, $ this -> docConfig -> get ( ' base_url ' ) );
278288
279289 return $ writer ->getCollection ();
280290 }
@@ -286,6 +296,6 @@ private function generatePostmanCollection(Collection $routes)
286296 */
287297 private function shouldGeneratePostmanCollection ()
288298 {
289- return config ( ' apidoc. postman.enabled ' , is_bool (config ( ' apidoc. postman ' )) ? config ( ' apidoc. postman ' ) : false );
299+ return $ this -> docConfig -> get ( ' postman.enabled ' , is_bool ($ this -> docConfig -> get ( ' postman ' )) ? $ this -> docConfig -> get ( ' postman ' ) : false );
290300 }
291301}
0 commit comments