From e0fb5c3afe849d8013e2aa5b4db25296bf988be5 Mon Sep 17 00:00:00 2001 From: Toni Van de Voorde Date: Mon, 18 Feb 2013 21:07:59 +0100 Subject: [PATCH] Support multiple descriptions for a Status Code --- Annotation/ApiDoc.php | 13 ++++++++++++- Resources/views/method.html.twig | 32 +++++++++++++++++++------------- Tests/Annotation/ApiDocTest.php | 10 +++++++--- 3 files changed, 38 insertions(+), 17 deletions(-) diff --git a/Annotation/ApiDoc.php b/Annotation/ApiDoc.php index aac6f38..004f4bb 100644 --- a/Annotation/ApiDoc.php +++ b/Annotation/ApiDoc.php @@ -126,7 +126,9 @@ class ApiDoc } if (isset($data['statusCodes'])) { - $this->statusCodes = $data['statusCodes']; + foreach ($data['statusCodes'] as $statusCode => $description) { + $this->addStatusCode($statusCode, $description); + } } } @@ -139,6 +141,15 @@ class ApiDoc $this->filters[$name] = $filter; } + /** + * @param string $statusCode + * @param mixed $description + */ + public function addStatusCode($statusCode, $description) + { + $this->statusCodes[$statusCode] = !is_array($description) ? array($description) : $description; + } + /** * @param string $name * @param array $requirement diff --git a/Resources/views/method.html.twig b/Resources/views/method.html.twig index e623f13..1b93832 100644 --- a/Resources/views/method.html.twig +++ b/Resources/views/method.html.twig @@ -136,24 +136,30 @@ {% endif %} - {% if data.statusCodes is defined and data.statusCodes is not empty %} -

Status Codes

- - + {% if data.statusCodes is defined and data.statusCodes is not empty %} +

Status Codes

+
+ - - - {% for status_code, description in data.statusCodes %} - - - - + + + {% for status_code, descriptions in data.statusCodes %} + + + + {% endfor %} - -
Status Code Description
{{ status_code }}{{ description }}
{{ status_code }} +
    + {% for description in descriptions %} +
  • {{ description }}
  • + {% endfor %} +
+
+ + {% endif %} diff --git a/Tests/Annotation/ApiDocTest.php b/Tests/Annotation/ApiDocTest.php index c03b280..a285e68 100644 --- a/Tests/Annotation/ApiDocTest.php +++ b/Tests/Annotation/ApiDocTest.php @@ -174,13 +174,17 @@ class ApiDocTest extends TestCase $this->assertEquals($data['input'], $annot->getInput()); } - public function testConstructWithHTTPResponseCodes() + public function testConstructWithStatusCodes() { $data = array( 'description' => 'Heya', 'statusCodes' => array( 200 => "Returned when successful", - 403 => "Returned when the user is not authorized" + 403 => "Returned when the user is not authorized", + 404 => array( + "Returned when the user is not found", + "Returned when when something else is not found" + ) ) ); @@ -190,7 +194,7 @@ class ApiDocTest extends TestCase $this->assertTrue(is_array($array)); $this->assertTrue(is_array($array['statusCodes'])); foreach ($data['statusCodes'] as $code => $message) { - $this->assertEquals($array['statusCodes'][$code], $message); + $this->assertEquals($array['statusCodes'][$code], !is_array($message) ? array($message) : $message); } } }