{{ key|title }} |
- {{ value|json_encode|trim('"') }} |
+ {{ value|json_encode|replace({'\\\\': '\\'})|trim('"') }} |
{% endfor %}
diff --git a/Tests/Annotation/ApiDocTest.php b/Tests/Annotation/ApiDocTest.php
index 61a0c15..d1904a6 100644
--- a/Tests/Annotation/ApiDocTest.php
+++ b/Tests/Annotation/ApiDocTest.php
@@ -21,11 +21,12 @@ class ApiDocTest extends TestCase
$data = array();
$annot = new ApiDoc($data);
+ $array = $annot->toArray();
- $this->assertTrue(is_array($annot->getFilters()));
- $this->assertCount(0, $annot->getFilters());
+ $this->assertTrue(is_array($array));
+ $this->assertFalse(isset($array['filters']));
$this->assertFalse($annot->isResource());
- $this->assertNull($annot->getDescription());
+ $this->assertFalse(isset($array['description']));
$this->assertNull($annot->getFormType());
}
@@ -37,11 +38,12 @@ class ApiDocTest extends TestCase
);
$annot = new ApiDoc($data);
+ $array = $annot->toArray();
- $this->assertTrue(is_array($annot->getFilters()));
- $this->assertCount(0, $annot->getFilters());
+ $this->assertTrue(is_array($array));
+ $this->assertFalse(isset($array['filters']));
$this->assertFalse($annot->isResource());
- $this->assertNull($annot->getDescription());
+ $this->assertFalse(isset($array['description']));
$this->assertNull($annot->getFormType());
}
@@ -52,11 +54,12 @@ class ApiDocTest extends TestCase
);
$annot = new ApiDoc($data);
+ $array = $annot->toArray();
- $this->assertTrue(is_array($annot->getFilters()));
- $this->assertCount(0, $annot->getFilters());
+ $this->assertTrue(is_array($array));
+ $this->assertFalse(isset($array['filters']));
$this->assertFalse($annot->isResource());
- $this->assertEquals($data['description'], $annot->getDescription());
+ $this->assertEquals($data['description'], $array['description']);
$this->assertNull($annot->getFormType());
}
@@ -68,11 +71,12 @@ class ApiDocTest extends TestCase
);
$annot = new ApiDoc($data);
+ $array = $annot->toArray();
- $this->assertTrue(is_array($annot->getFilters()));
- $this->assertCount(0, $annot->getFilters());
+ $this->assertTrue(is_array($array));
+ $this->assertFalse(isset($array['filters']));
$this->assertFalse($annot->isResource());
- $this->assertEquals($data['description'], $annot->getDescription());
+ $this->assertEquals($data['description'], $array['description']);
$this->assertEquals($data['formType'], $annot->getFormType());
}
@@ -85,11 +89,12 @@ class ApiDocTest extends TestCase
);
$annot = new ApiDoc($data);
+ $array = $annot->toArray();
- $this->assertTrue(is_array($annot->getFilters()));
- $this->assertCount(0, $annot->getFilters());
+ $this->assertTrue(is_array($array));
+ $this->assertFalse(isset($array['filters']));
$this->assertTrue($annot->isResource());
- $this->assertEquals($data['description'], $annot->getDescription());
+ $this->assertEquals($data['description'], $array['description']);
$this->assertEquals($data['formType'], $annot->getFormType());
}
@@ -102,11 +107,12 @@ class ApiDocTest extends TestCase
);
$annot = new ApiDoc($data);
+ $array = $annot->toArray();
- $this->assertTrue(is_array($annot->getFilters()));
- $this->assertCount(0, $annot->getFilters());
+ $this->assertTrue(is_array($array));
+ $this->assertFalse(isset($array['filters']));
$this->assertFalse($annot->isResource());
- $this->assertEquals($data['description'], $annot->getDescription());
+ $this->assertEquals($data['description'], $array['description']);
$this->assertEquals($data['formType'], $annot->getFormType());
}
@@ -121,12 +127,14 @@ class ApiDocTest extends TestCase
);
$annot = new ApiDoc($data);
+ $array = $annot->toArray();
- $this->assertTrue(is_array($annot->getFilters()));
- $this->assertCount(1, $annot->getFilters());
- $this->assertEquals(array('a-filter' => array()), $annot->getFilters());
+ $this->assertTrue(is_array($array));
+ $this->assertTrue(is_array($array['filters']));
+ $this->assertCount(1, $array['filters']);
+ $this->assertEquals(array('a-filter' => array()), $array['filters']);
$this->assertTrue($annot->isResource());
- $this->assertEquals($data['description'], $annot->getDescription());
+ $this->assertEquals($data['description'], $array['description']);
$this->assertNull($annot->getFormType());
}
@@ -157,12 +165,12 @@ class ApiDocTest extends TestCase
);
$annot = new ApiDoc($data);
+ $array = $annot->toArray();
- $this->assertTrue(is_array($annot->getFilters()));
- $this->assertCount(0, $annot->getFilters());
- $this->assertEquals(array(), $annot->getFilters());
+ $this->assertTrue(is_array($array));
+ $this->assertFalse(isset($array['filters']));
$this->assertTrue($annot->isResource());
- $this->assertEquals($data['description'], $annot->getDescription());
+ $this->assertEquals($data['description'], $array['description']);
$this->assertEquals($data['formType'], $annot->getFormType());
}
}
diff --git a/Tests/Extractor/ApiDocExtratorTest.php b/Tests/Extractor/ApiDocExtratorTest.php
index 9da5259..a71a955 100644
--- a/Tests/Extractor/ApiDocExtratorTest.php
+++ b/Tests/Extractor/ApiDocExtratorTest.php
@@ -22,62 +22,67 @@ class ApiDocExtractorTest extends WebTestCase
$data = $extractor->all();
$this->assertTrue(is_array($data));
- $this->assertCount(9, $data);
+ $this->assertCount(10, $data);
foreach ($data as $d) {
$this->assertTrue(is_array($d));
$this->assertArrayHasKey('annotation', $d);
- $this->assertArrayHasKey('route', $d);
$this->assertArrayHasKey('resource', $d);
$this->assertInstanceOf('Nelmio\ApiDocBundle\Annotation\ApiDoc', $d['annotation']);
- $this->assertInstanceOf('Symfony\Component\Routing\Route', $d['route']);
+ $this->assertInstanceOf('Symfony\Component\Routing\Route', $d['annotation']->getRoute());
$this->assertNotNull($d['resource']);
}
$a1 = $data[0]['annotation'];
+ $array1 = $a1->toArray();
$this->assertTrue($a1->isResource());
$this->assertEquals('index action', $a1->getDescription());
- $this->assertTrue(is_array($a1->getFilters()));
+ $this->assertTrue(is_array($array1['filters']));
$this->assertNull($a1->getFormType());
$a1 = $data[1]['annotation'];
+ $array1 = $a1->toArray();
$this->assertTrue($a1->isResource());
$this->assertEquals('index action', $a1->getDescription());
- $this->assertTrue(is_array($a1->getFilters()));
+ $this->assertTrue(is_array($array1['filters']));
$this->assertNull($a1->getFormType());
$a2 = $data[2]['annotation'];
+ $array2 = $a2->toArray();
$this->assertFalse($a2->isResource());
$this->assertEquals('create test', $a2->getDescription());
- $this->assertTrue(is_array($a2->getFilters()));
+ $this->assertFalse(isset($array2['filters']));
$this->assertEquals('Nelmio\ApiDocBundle\Tests\Fixtures\Form\TestType', $a2->getFormType());
$a2 = $data[3]['annotation'];
+ $array2 = $a2->toArray();
$this->assertFalse($a2->isResource());
$this->assertEquals('create test', $a2->getDescription());
- $this->assertTrue(is_array($a2->getFilters()));
+ $this->assertFalse(isset($array2['filters']));
$this->assertEquals('Nelmio\ApiDocBundle\Tests\Fixtures\Form\TestType', $a2->getFormType());
}
public function testGet()
{
- $container = $this->getContainer();
- $extractor = $container->get('nelmio_api_doc.extractor.api_doc_extractor');
- $data = $extractor->get('Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::indexAction', 'test_route_1');
+ $container = $this->getContainer();
+ $extractor = $container->get('nelmio_api_doc.extractor.api_doc_extractor');
+ $annotation = $extractor->get('Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::indexAction', 'test_route_1');
- $this->assertTrue(isset($data['route']));
- $this->assertTrue(isset($data['annotation']));
+ $this->assertInstanceOf('Nelmio\ApiDocBundle\Annotation\ApiDoc', $annotation);
- $a = $data['annotation'];
- $this->assertTrue($a->isResource());
- $this->assertEquals('index action', $a->getDescription());
- $this->assertTrue(is_array($a->getFilters()));
- $this->assertNull($a->getFormType());
+ $this->assertTrue($annotation->isResource());
+ $this->assertEquals('index action', $annotation->getDescription());
- $data2 = $extractor->get('nemlio.test.controller:indexAction', 'test_service_route_1');
- $data2['route']->setDefault('_controller', $data['route']->getDefault('_controller'));
- $this->assertEquals($data, $data2);
+ $array = $annotation->toArray();
+ $this->assertTrue(is_array($array['filters']));
+ $this->assertNull($annotation->getFormType());
+
+ $annotation2 = $extractor->get('nemlio.test.controller:indexAction', 'test_service_route_1');
+ $annotation2->getRoute()
+ ->setDefault('_controller', $annotation->getRoute()->getDefault('_controller'))
+ ->compile(); // compile as we changed a default value
+ $this->assertEquals($annotation, $annotation2);
}
public function testGetWithBadController()
@@ -134,14 +139,14 @@ class ApiDocExtractorTest extends WebTestCase
public function testGetWithDocComment()
{
- $container = $this->getContainer();
- $extractor = $container->get('nelmio_api_doc.extractor.api_doc_extractor');
- $data = $extractor->get('Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::myCommentedAction', 'test_route_5');
+ $container = $this->getContainer();
+ $extractor = $container->get('nelmio_api_doc.extractor.api_doc_extractor');
+ $annotation = $extractor->get('Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::myCommentedAction', 'test_route_5');
- $this->assertNotNull($data);
+ $this->assertNotNull($annotation);
$this->assertEquals(
"This method is useful to test if the getDocComment works.",
- $data['annotation']->getDescription()
+ $annotation->getDescription()
);
}
}
diff --git a/Tests/Fixtures/Controller/TestController.php b/Tests/Fixtures/Controller/TestController.php
index 57907eb..1995a77 100644
--- a/Tests/Fixtures/Controller/TestController.php
+++ b/Tests/Fixtures/Controller/TestController.php
@@ -11,6 +11,7 @@
namespace Nelmio\ApiDocBundle\Tests\Fixtures\Controller;
+use FOS\RestBundle\Controller\Annotations\QueryParam;
use Nelmio\ApiDocBundle\Annotation\ApiDoc;
use Symfony\Component\HttpFoundation\Response;
@@ -81,4 +82,12 @@ class TestController
public function anotherPostAction()
{
}
+
+ /**
+ * @ApiDoc()
+ * @QueryParam(name="page", requirements="\d+", default="1", description="Page of the overview.")
+ */
+ public function zActionWithQueryParamAction()
+ {
+ }
}
diff --git a/Tests/Fixtures/app/config/routing.yml b/Tests/Fixtures/app/config/routing.yml
index 6e04d20..092dde5 100644
--- a/Tests/Fixtures/app/config/routing.yml
+++ b/Tests/Fixtures/app/config/routing.yml
@@ -34,6 +34,12 @@ test_route_7:
requirements:
_method: POST
+test_route_8:
+ pattern: /z-action-with-query-param
+ defaults: { _controller: NelmioApiDocTestBundle:Test:zActionWithQueryParam }
+ requirements:
+ _method: GET
+
test_service_route_1:
pattern: /tests
defaults: { _controller: nemlio.test.controller:indexAction, _format: json }
diff --git a/Tests/Formatter/MarkdownFormatterTest.php b/Tests/Formatter/MarkdownFormatterTest.php
index db64529..f686655 100644
--- a/Tests/Formatter/MarkdownFormatterTest.php
+++ b/Tests/Formatter/MarkdownFormatterTest.php
@@ -34,12 +34,12 @@ _index action_
a:
- * dataType: integer
+ * DataType: integer
b:
- * dataType: string
- * arbitrary: ["arg1","arg2"]
+ * DataType: string
+ * Arbitrary: ["arg1","arg2"]
### `GET` /tests ###
@@ -50,12 +50,12 @@ _index action_
a:
- * dataType: integer
+ * DataType: integer
b:
- * dataType: string
- * arbitrary: ["arg1","arg2"]
+ * DataType: string
+ * Arbitrary: ["arg1","arg2"]
### `POST` /tests ###
@@ -158,6 +158,17 @@ _This method is useful to test if the getDocComment works._
**id**
- Requirement: \d+
+
+
+### `GET` /z-action-with-query-param ###
+
+
+#### Filters ####
+
+page:
+
+ * Requirement: \d+
+ * Description: Page of the overview.
MARKDOWN;
$this->assertEquals($expected, $result);
@@ -167,9 +178,9 @@ MARKDOWN;
{
$container = $this->getContainer();
- $extractor = $container->get('nelmio_api_doc.extractor.api_doc_extractor');
- $data = $extractor->get('Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::indexAction', 'test_route_1');
- $result = $container->get('nelmio_api_doc.formatter.markdown_formatter')->formatOne($data['annotation'], $data['route']);
+ $extractor = $container->get('nelmio_api_doc.extractor.api_doc_extractor');
+ $annotation = $extractor->get('Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::indexAction', 'test_route_1');
+ $result = $container->get('nelmio_api_doc.formatter.markdown_formatter')->formatOne($annotation);
$expected = <<