Fix DunglasApi filters supports. Fix tests.

This commit is contained in:
Kévin Dunglas 2015-05-14 23:23:41 +02:00
parent 1d7b45e1e7
commit 9c465e37ca
7 changed files with 30 additions and 20 deletions

View File

@ -127,7 +127,9 @@ class DunglasApiProvider implements AnnotationsProviderInterface
$data['filters'] = []; $data['filters'] = [];
foreach ($resource->getFilters() as $filter) { foreach ($resource->getFilters() as $filter) {
$data['filters'][] = ['name' => $filter->getName()]; foreach ($filter->getDescription($resource) as $name => $data) {
$data['filters'][] = ['name' => $name] + $data;
}
} }
$apiDoc = new ApiDoc($data); $apiDoc = new ApiDoc($data);

View File

@ -58,9 +58,12 @@ class DunglasApiParser implements ParserInterface
*/ */
public function supports(array $item) public function supports(array $item)
{ {
list(, $class) = explode(':', $item['class'], 2); $data = explode(':', $item['class'], 2);
if (isset($data[1])) {
return null !== $this->resourceCollection->getResourceForEntity($data[1]);
}
return null !== $this->resourceCollection->getResourceForEntity($class); return false;
} }
/** /**

View File

@ -16,13 +16,13 @@ use Nelmio\ApiDocBundle\Tests\WebTestCase;
/** /**
* @author Kévin Dunglas <dunglas@gmail.com> * @author Kévin Dunglas <dunglas@gmail.com>
*/ */
class DunglasJsonLdApiProviderTest extends WebTestCase class DunglasApiProviderTest extends WebTestCase
{ {
protected function setUp() protected function setUp()
{ {
if (!class_exists('Dunglas\JsonLdApiBundle\DunglasJsonLdApiBundle')) { if (!class_exists('Dunglas\ApiBundle\DunglasApiBundle')) {
$this->markTestSkipped( $this->markTestSkipped(
'DunglasJsonLdApiBundle is not available.' 'DunglasApiBundle is not available.'
); );
} }
} }
@ -30,7 +30,7 @@ class DunglasJsonLdApiProviderTest extends WebTestCase
public function testGetAnnotations() public function testGetAnnotations()
{ {
$container = $this->getContainer(); $container = $this->getContainer();
$provider = $container->get('nelmio_api_doc.annotations_provider.dunglas_json_ld_api_annotation_provider'); $provider = $container->get('nelmio_api_doc.annotations_provider.dunglas_api_annotation_provider');
$annotations = $provider->getAnnotations(); $annotations = $provider->getAnnotations();
$this->assertCount(5, $annotations); $this->assertCount(5, $annotations);

View File

@ -25,7 +25,7 @@ class ApiDocExtractorTest extends WebTestCase
$data = $extractor->all(); $data = $extractor->all();
restore_error_handler(); restore_error_handler();
if(class_exists('Dunglas\JsonLdApiBundle\DunglasJsonLdApiBundle')) { if(class_exists('Dunglas\ApiBundle\DunglasApiBundle')) {
$routesQuantity = 38; $routesQuantity = 38;
$httpsKey = 25; $httpsKey = 25;
} else { } else {

View File

@ -25,7 +25,7 @@ class MarkdownFormatterTest extends WebTestCase
restore_error_handler(); restore_error_handler();
$result = $container->get('nelmio_api_doc.formatter.markdown_formatter')->format($data); $result = $container->get('nelmio_api_doc.formatter.markdown_formatter')->format($data);
if(class_exists('Dunglas\JsonLdApiBundle\DunglasJsonLdApiBundle')) { if(class_exists('Dunglas\ApiBundle\DunglasApiBundle')) {
$expected = <<<MARKDOWN $expected = <<<MARKDOWN
## /api/other-resources ## ## /api/other-resources ##
@ -670,7 +670,7 @@ _This method is useful to test if the getDocComment works._
- Description: The param id - Description: The param id
### `GET|HEAD` /popos ### ### `GET` /popos ###
_Retrieves the collection of Popo resources._ _Retrieves the collection of Popo resources._
@ -699,7 +699,7 @@ foo:
* type: string * type: string
### `GET|HEAD` /popos/{id} ### ### `GET` /popos/{id} ###
_Retrieves Popo resource._ _Retrieves Popo resource._

View File

@ -26,7 +26,7 @@ class SimpleFormatterTest extends WebTestCase
restore_error_handler(); restore_error_handler();
$result = $container->get('nelmio_api_doc.formatter.simple_formatter')->format($data); $result = $container->get('nelmio_api_doc.formatter.simple_formatter')->format($data);
if (class_exists('Dunglas\JsonLdApiBundle\DunglasJsonLdApiBundle')) { if (class_exists('Dunglas\ApiBundle\DunglasApiBundle')) {
$expected = array ( $expected = array (
'/api/other-resources' => '/api/other-resources' =>
array ( array (
@ -1581,7 +1581,7 @@ And, it supports multilines until the first \'@\' char.',
), ),
7 => 7 =>
array ( array (
'method' => 'GET|HEAD', 'method' => 'GET',
'uri' => '/popos', 'uri' => '/popos',
'description' => 'Retrieves the collection of Popo resources.', 'description' => 'Retrieves the collection of Popo resources.',
'documentation' => 'Gets the collection.', 'documentation' => 'Gets the collection.',
@ -1601,6 +1601,7 @@ And, it supports multilines until the first \'@\' char.',
array ( array (
), ),
'deprecated' => false, 'deprecated' => false,
'resourceDescription' => 'Popo',
), ),
8 => 8 =>
array ( array (
@ -1634,10 +1635,11 @@ And, it supports multilines until the first \'@\' char.',
array ( array (
), ),
'deprecated' => false, 'deprecated' => false,
'resourceDescription' => 'Popo',
), ),
9 => 9 =>
array ( array (
'method' => 'GET|HEAD', 'method' => 'GET',
'uri' => '/popos/{id}', 'uri' => '/popos/{id}',
'description' => 'Retrieves Popo resource.', 'description' => 'Retrieves Popo resource.',
'documentation' => 'Gets an element of the collection.', 'documentation' => 'Gets an element of the collection.',
@ -1666,6 +1668,7 @@ And, it supports multilines until the first \'@\' char.',
array ( array (
), ),
'deprecated' => false, 'deprecated' => false,
'resourceDescription' => 'Popo',
), ),
10 => 10 =>
array ( array (
@ -1708,6 +1711,7 @@ And, it supports multilines until the first \'@\' char.',
array ( array (
), ),
'deprecated' => false, 'deprecated' => false,
'resourceDescription' => 'Popo',
), ),
11 => 11 =>
array ( array (
@ -1730,6 +1734,7 @@ And, it supports multilines until the first \'@\' char.',
array ( array (
), ),
'deprecated' => false, 'deprecated' => false,
'resourceDescription' => 'Popo',
), ),
12 => 12 =>
array ( array (

View File

@ -45,7 +45,7 @@ class SwaggerFormatterTest extends WebTestCase
$actual = $this->formatter->format($data, null); $actual = $this->formatter->format($data, null);
if (class_exists('Dunglas\JsonLdApiBundle\DunglasJsonLdApiBundle')) { if (class_exists('Dunglas\ApiBundle\DunglasApiBundle')) {
$expected = array ( $expected = array (
'swaggerVersion' => '1.2', 'swaggerVersion' => '1.2',
'apis' => 'apis' =>
@ -83,27 +83,27 @@ class SwaggerFormatterTest extends WebTestCase
6 => 6 =>
array ( array (
'path' => '/others', 'path' => '/others',
'description' => '', 'description' => 'Popo',
), ),
7 => 7 =>
array ( array (
'path' => '/others', 'path' => '/others',
'description' => '', 'description' => 'Popo',
), ),
8 => 8 =>
array ( array (
'path' => '/others', 'path' => '/others',
'description' => '', 'description' => 'Popo',
), ),
9 => 9 =>
array ( array (
'path' => '/others', 'path' => '/others',
'description' => '', 'description' => 'Popo',
), ),
10 => 10 =>
array ( array (
'path' => '/others', 'path' => '/others',
'description' => '', 'description' => 'Popo',
), ),
), ),
'apiVersion' => '3.14', 'apiVersion' => '3.14',