Browse Source

Update service provider and refactor namespaces

shalvah 6 years ago
parent
commit
ad45bca4e2

+ 1 - 1
composer.json

@@ -31,7 +31,7 @@
         "mockery/mockery": "^1.2.0"
     },
     "autoload": {
-        "psr-0": {
+        "psr-4": {
             "Mpociot\\ApiDoc": "src/"
         }
     },

+ 0 - 0
src/resources/views/documentarian.blade.php → resources/views/documentarian.blade.php


+ 0 - 0
src/resources/views/partials/frontmatter.blade.php → resources/views/partials/frontmatter.blade.php


+ 0 - 0
src/resources/views/partials/info.blade.php → resources/views/partials/info.blade.php


+ 0 - 0
src/resources/views/partials/route.blade.php → resources/views/partials/route.blade.php


+ 45 - 0
src/ApiDocGeneratorServiceProvider.php

@@ -0,0 +1,45 @@
+<?php
+
+namespace Mpociot\ApiDoc;
+
+use Illuminate\Support\ServiceProvider;
+use Mpociot\ApiDoc\Commands\UpdateDocumentation;
+use Mpociot\ApiDoc\Commands\GenerateDocumentation;
+
+class ApiDocGeneratorServiceProvider extends ServiceProvider
+{
+    /**
+     * Bootstrap the application events.
+     *
+     * @return void
+     */
+    public function boot()
+    {
+        $this->loadViewsFrom(__DIR__ . '/../resources/views/', 'apidoc');
+
+        $this->publishes([
+            __DIR__ . '/../resources/views' => app()->basePath().'/resources/views/vendor/apidoc',
+        ], 'views');
+
+        $this->publishes([
+            __DIR__.'/../config/apidoc.php' => config_path('apidoc.php'),
+        ], 'config');
+
+        if ($this->app->runningInConsole()) {
+            $this->commands([
+                GenerateDocumentation::class,
+                UpdateDocumentation::class,
+            ]);
+        }
+    }
+
+    /**
+     * Register the API doc commands.
+     *
+     * @return void
+     */
+    public function register()
+    {
+        //
+    }
+}

+ 3 - 3
src/Mpociot/ApiDoc/Commands/GenerateDocumentation.php → src/Commands/GenerateDocumentation.php

@@ -252,12 +252,12 @@ class GenerateDocumentation extends Command
     /**
      * @return mixed
      */
-    private function getRoutes()
+    private function getRoutes($routePrefix)
     {
         if ($this->option('router') === 'laravel') {
             return RouteFacade::getRoutes();
         } else {
-            return app('Dingo\Api\Routing\Router')->getRoutes();
+            return app('Dingo\Api\Routing\Router')->getRoutes($routePrefix)->getRoutes();
         }
     }
 
@@ -272,7 +272,7 @@ class GenerateDocumentation extends Command
     private function processRoutes(AbstractGenerator $generator, array $allowedRoutes, $routeDomain, $routePrefix, $middleware)
     {
         $withResponse = $this->option('noResponseCalls') == false;
-        $routes = $this->getRoutes();
+        $routes = $this->getRoutes($routePrefix);
         $bindings = $this->getBindings();
         $parsedRoutes = [];
         foreach ($routes as $route) {

+ 0 - 0
src/Mpociot/ApiDoc/Commands/UpdateDocumentation.php → src/Commands/UpdateDocumentation.php


+ 1 - 1
src/Mpociot/ApiDoc/Generators/AbstractGenerator.php → src/Generators/AbstractGenerator.php

@@ -20,7 +20,7 @@ abstract class AbstractGenerator
      */
     public function getDomain(Route $route)
     {
-        return $route->domain();
+        return $route->domain() == null ? '*' : $route->domain();
     }
 
     /**

+ 0 - 0
src/Mpociot/ApiDoc/Generators/DingoGenerator.php → src/Generators/DingoGenerator.php


+ 0 - 0
src/Mpociot/ApiDoc/Generators/LaravelGenerator.php → src/Generators/LaravelGenerator.php


+ 0 - 58
src/Mpociot/ApiDoc/ApiDocGeneratorServiceProvider.php

@@ -1,58 +0,0 @@
-<?php
-
-namespace Mpociot\ApiDoc;
-
-use Illuminate\Support\ServiceProvider;
-use Mpociot\ApiDoc\Commands\UpdateDocumentation;
-use Mpociot\ApiDoc\Commands\GenerateDocumentation;
-
-class ApiDocGeneratorServiceProvider extends ServiceProvider
-{
-    /**
-     * Bootstrap the application events.
-     *
-     * @return void
-     */
-    public function boot()
-    {
-        $this->loadViewsFrom(__DIR__.'/../../resources/views/', 'apidoc');
-        $this->loadTranslationsFrom(__DIR__.'/../../resources/lang', 'apidoc');
-
-        $this->publishes([
-            __DIR__.'/../../resources/lang' => $this->resource_path('lang/vendor/apidoc'),
-            __DIR__.'/../../resources/views' => $this->resource_path('views/vendor/apidoc'),
-        ]);
-    }
-
-    /**
-     * Register the API doc commands.
-     *
-     * @return void
-     */
-    public function register()
-    {
-        $this->app->singleton('apidoc.generate', function () {
-            return new GenerateDocumentation();
-        });
-        $this->app->singleton('apidoc.update', function () {
-            return new UpdateDocumentation();
-        });
-
-        $this->commands([
-            'apidoc.generate',
-            'apidoc.update',
-        ]);
-    }
-
-    /**
-     * Return a fully qualified path to a given file.
-     *
-     * @param string $path
-     *
-     * @return string
-     */
-    public function resource_path($path = '')
-    {
-        return app()->basePath().'/resources'.($path ? '/'.$path : $path);
-    }
-}

+ 0 - 0
src/Mpociot/ApiDoc/Postman/CollectionWriter.php → src/Postman/CollectionWriter.php


+ 5 - 9
tests/GenerateDocumentationTest.php

@@ -34,7 +34,7 @@ class GenerateDocumentationTest extends TestCase
     public function tearDown()
     {
         // delete the generated docs - compatible cross-platform
-        $dir = __DIR__.'/../public/docs';
+        $dir = __DIR__.'/../public/docs';/*
         if (is_dir($dir)) {
             $files = new RecursiveIteratorIterator(
                 new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS),
@@ -46,7 +46,7 @@ class GenerateDocumentationTest extends TestCase
                 $todo($fileinfo->getRealPath());
             }
             rmdir($dir);
-        }
+        }*/
     }
 
     /**
@@ -84,20 +84,16 @@ class GenerateDocumentationTest extends TestCase
 
     public function testConsoleCommandDoesNotWorkWithClosureUsingDingo()
     {
-        if (version_compare($this->app->version(), '5.4', '>=')) {
-            $this->markTestSkipped('Dingo does not support Laravel 5.4');
-        }
-
         $api = app('Dingo\Api\Routing\Router');
         $api->version('v1', function ($api) {
-            $api->get('/closure', function () {
+            $api->get('v1/closure', function () {
                 return 'foo';
             });
-            $api->get('/test', DingoTestController::class.'@parseMethodDescription');
+            $api->get('v1/test', DingoTestController::class.'@parseMethodDescription');
 
             $output = $this->artisan('api:generate', [
                 '--router' => 'dingo',
-                '--routePrefix' => 'v1',
+                '--routePrefix' => 'v1/*',
             ]);
             $this->assertContains('Skipping route: [GET] closure', $output);
             $this->assertContains('Processed route: [GET] test', $output);