Skip to content

Commit

Permalink
Support partial resource controller (fixes mpociot#426)
Browse files Browse the repository at this point in the history
  • Loading branch information
phanan committed Dec 11, 2018
1 parent 8fca019 commit b530057
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Commands/GenerateDocumentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Mpociot\ApiDoc\Commands;

use ReflectionClass;
use ReflectionException;
use Illuminate\Routing\Route;
use Illuminate\Console\Command;
use Mpociot\Reflection\DocBlock;
Expand Down Expand Up @@ -215,12 +216,19 @@ private function isValidRoute(Route $route)
* @param $route
*
* @return bool
* @throws ReflectionException
*/
private function isRouteVisibleForDocumentation($route)
{
list($class, $method) = explode('@', $route);
$reflection = new ReflectionClass($class);

if (!$reflection->hasMethod($method)) {
return false;
}

$comment = $reflection->getMethod($method)->getDocComment();

if ($comment) {
$phpdoc = new DocBlock($comment);

Expand Down
20 changes: 20 additions & 0 deletions tests/Fixtures/TestPartialResourceController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Mpociot\ApiDoc\Tests\Fixtures;

class TestPartialResourceController
{
/**
* @group Group A
*/
public function index()
{
}

/**
* @group Group B
*/
public function update()
{
}
}
23 changes: 23 additions & 0 deletions tests/GenerateDocumentationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Mpociot\ApiDoc\Tests;

use ReflectionException;
use RecursiveIteratorIterator;
use RecursiveDirectoryIterator;
use Orchestra\Testbench\TestCase;
Expand All @@ -11,6 +12,7 @@
use Mpociot\ApiDoc\ApiDocGeneratorServiceProvider;
use Illuminate\Support\Facades\Route as RouteFacade;
use Mpociot\ApiDoc\Tests\Fixtures\TestResourceController;
use Mpociot\ApiDoc\Tests\Fixtures\TestPartialResourceController;

class GenerateDocumentationTest extends TestCase
{
Expand Down Expand Up @@ -256,6 +258,27 @@ public function can_parse_utf8_response()
$this->assertContains('Лорем ипсум долор сит амет', $generatedMarkdown);
}

/** @test */
public function supports_partial_resource_controller()
{
RouteFacade::resource('/api/partial', TestPartialResourceController::class);

config(['apidoc.routes.0.prefixes' => ['api/*']]);

$thrownException = null;

try {
$this->artisan('apidoc:generate');
} catch (ReflectionException $e) {
$thrownException = $e;
}

$this->assertNull($thrownException);
$generatedMarkdown = file_get_contents(__DIR__.'/../public/docs/source/index.md');
$this->assertContains('Group A', $generatedMarkdown);
$this->assertContains('Group B', $generatedMarkdown);
}

/**
* @param string $command
* @param array $parameters
Expand Down

0 comments on commit b530057

Please sign in to comment.