From 911aaae0fda5eec348469e741f4f54e48baa8273 Mon Sep 17 00:00:00 2001 From: Alexander Date: Fri, 10 Aug 2012 11:38:01 +0200 Subject: [PATCH] Remove .{_format} from routes used for resource grouping --- Extractor/ApiDocExtractor.php | 3 +- Tests/EventListener/RequestListenerTest.php | 2 +- Tests/Fixtures/app/config/routing.yml | 8 ++--- Tests/Formatter/MarkdownFormatterTest.php | 35 ++++++++++++++++++--- Tests/Formatter/SimpleFormatterTest.php | 27 ++++++++++++---- 5 files changed, 58 insertions(+), 17 deletions(-) diff --git a/Extractor/ApiDocExtractor.php b/Extractor/ApiDocExtractor.php index dcc8af1..820651a 100644 --- a/Extractor/ApiDocExtractor.php +++ b/Extractor/ApiDocExtractor.php @@ -68,7 +68,8 @@ class ApiDocExtractor if ($method = $this->getReflectionMethod($route->getDefault('_controller'))) { if ($annotation = $this->reader->getMethodAnnotation($method, self::ANNOTATION_CLASS)) { if ($annotation->isResource()) { - $resources[] = $route->getPattern(); + // remove format from routes used for resource grouping + $resources[] = str_replace('.{_format}', '', $route->getPattern()); } $array[] = array('annotation' => $this->extractData($annotation, $route, $method)); diff --git a/Tests/EventListener/RequestListenerTest.php b/Tests/EventListener/RequestListenerTest.php index 7434efe..e51d380 100644 --- a/Tests/EventListener/RequestListenerTest.php +++ b/Tests/EventListener/RequestListenerTest.php @@ -20,7 +20,7 @@ class RequestListenerTest extends WebTestCase $client = $this->createClient(); $crawler = $client->request('GET', '/tests?_doc=1'); - $this->assertEquals('/tests', trim($crawler->filter(".operation .path:contains('/tests')")->text()), 'Event listener should capture ?_doc=1 requests'); + $this->assertEquals('/tests.{_format}', trim($crawler->filter(".operation .path:contains('/tests')")->text()), 'Event listener should capture ?_doc=1 requests'); $client->request('GET', '/tests'); $this->assertEquals('tests', $client->getResponse()->getContent(), 'Event listener should let normal requests through'); diff --git a/Tests/Fixtures/app/config/routing.yml b/Tests/Fixtures/app/config/routing.yml index 092dde5..7907b75 100644 --- a/Tests/Fixtures/app/config/routing.yml +++ b/Tests/Fixtures/app/config/routing.yml @@ -1,11 +1,11 @@ test_route_1: - pattern: /tests + pattern: /tests.{_format} defaults: { _controller: NelmioApiDocTestBundle:Test:index, _format: json } requirements: _method: GET test_route_2: - pattern: /tests + pattern: /tests.{_format} defaults: { _controller: NelmioApiDocTestBundle:Test:postTest, _format: json } requirements: _method: POST @@ -41,13 +41,13 @@ test_route_8: _method: GET test_service_route_1: - pattern: /tests + pattern: /tests.{_format} defaults: { _controller: nemlio.test.controller:indexAction, _format: json } requirements: _method: GET test_service_route_2: - pattern: /tests + pattern: /tests.{_format} defaults: { _controller: nemlio.test.controller:postTestAction, _format: json } requirements: _method: POST diff --git a/Tests/Formatter/MarkdownFormatterTest.php b/Tests/Formatter/MarkdownFormatterTest.php index f686655..6e8a9cd 100644 --- a/Tests/Formatter/MarkdownFormatterTest.php +++ b/Tests/Formatter/MarkdownFormatterTest.php @@ -26,10 +26,15 @@ class MarkdownFormatterTest extends WebTestCase $expected = <<get('nelmio_api_doc.formatter.markdown_formatter')->formatOne($annotation); $expected = << array( 'method' => 'GET', - 'uri' => '/tests', + 'uri' => '/tests.{_format}', 'filters' => array( 'a' => @@ -47,11 +47,14 @@ class SimpleFormatterTest extends WebTestCase ), ), 'description' => 'index action', + 'requirements' => array( + '_format' => array('type' => '', 'description' => '', 'requirement' => ''), + ), ), 1 => array( 'method' => 'GET', - 'uri' => '/tests', + 'uri' => '/tests.{_format}', 'filters' => array( 'a' => @@ -69,11 +72,14 @@ class SimpleFormatterTest extends WebTestCase ), ), 'description' => 'index action', + 'requirements' => array( + '_format' => array('type' => '', 'description' => '', 'requirement' => ''), + ), ), 2 => array( 'method' => 'POST', - 'uri' => '/tests', + 'uri' => '/tests.{_format}', 'parameters' => array( 'a' => @@ -99,11 +105,14 @@ class SimpleFormatterTest extends WebTestCase ), ), 'description' => 'create test', + 'requirements' => array( + '_format' => array('type' => '', 'description' => '', 'requirement' => ''), + ), ), 3 => array( 'method' => 'POST', - 'uri' => '/tests', + 'uri' => '/tests.{_format}', 'parameters' => array( 'a' => @@ -129,6 +138,9 @@ class SimpleFormatterTest extends WebTestCase ), ), 'description' => 'create test', + 'requirements' => array( + '_format' => array('type' => '', 'description' => '', 'requirement' => ''), + ), ), ), 'others' => @@ -211,7 +223,7 @@ class SimpleFormatterTest extends WebTestCase $expected = array( 'method' => 'GET', - 'uri' => '/tests', + 'uri' => '/tests.{_format}', 'filters' => array( 'a' => array( 'dataType' => 'integer', @@ -224,7 +236,10 @@ class SimpleFormatterTest extends WebTestCase ), ), ), - 'description' => 'index action' + 'description' => 'index action', + 'requirements' => array( + '_format' => array('type' => '', 'description' => '', 'requirement' => ''), + ), ); $this->assertEquals($expected, $result);