Support multiple descriptions for a Status Code

This commit is contained in:
Toni Van de Voorde 2013-02-18 21:07:59 +01:00
parent 986e1a6174
commit e0fb5c3afe
3 changed files with 38 additions and 17 deletions

View File

@ -126,7 +126,9 @@ class ApiDoc
} }
if (isset($data['statusCodes'])) { 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; $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 string $name
* @param array $requirement * @param array $requirement

View File

@ -146,10 +146,16 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{% for status_code, description in data.statusCodes %} {% for status_code, descriptions in data.statusCodes %}
<tr> <tr>
<td><a href="http://en.wikipedia.org/wiki/HTTP_{{ status_code }}" target="_blank">{{ status_code }}<a/></td> <td><a href="http://en.wikipedia.org/wiki/HTTP_{{ status_code }}" target="_blank">{{ status_code }}<a/></td>
<td>{{ description }}</td> <td>
<ul>
{% for description in descriptions %}
<li>{{ description }}</li>
{% endfor %}
</ul>
</td>
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>

View File

@ -174,13 +174,17 @@ class ApiDocTest extends TestCase
$this->assertEquals($data['input'], $annot->getInput()); $this->assertEquals($data['input'], $annot->getInput());
} }
public function testConstructWithHTTPResponseCodes() public function testConstructWithStatusCodes()
{ {
$data = array( $data = array(
'description' => 'Heya', 'description' => 'Heya',
'statusCodes' => array( 'statusCodes' => array(
200 => "Returned when successful", 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));
$this->assertTrue(is_array($array['statusCodes'])); $this->assertTrue(is_array($array['statusCodes']));
foreach ($data['statusCodes'] as $code => $message) { foreach ($data['statusCodes'] as $code => $message) {
$this->assertEquals($array['statusCodes'][$code], $message); $this->assertEquals($array['statusCodes'][$code], !is_array($message) ? array($message) : $message);
} }
} }
} }