mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-02 15:51:48 +03:00
Support multiple descriptions for a Status Code
This commit is contained in:
parent
986e1a6174
commit
e0fb5c3afe
@ -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
|
||||
|
@ -136,24 +136,30 @@
|
||||
</table>
|
||||
{% endif %}
|
||||
|
||||
{% if data.statusCodes is defined and data.statusCodes is not empty %}
|
||||
<h4>Status Codes</h4>
|
||||
<table class="fullwidth">
|
||||
<thead>
|
||||
{% if data.statusCodes is defined and data.statusCodes is not empty %}
|
||||
<h4>Status Codes</h4>
|
||||
<table class="fullwidth">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Status Code</th>
|
||||
<th>Description</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for status_code, description in data.statusCodes %}
|
||||
<tr>
|
||||
<td><a href="http://en.wikipedia.org/wiki/HTTP_{{ status_code }}" target="_blank">{{ status_code }}<a/></td>
|
||||
<td>{{ description }}</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for status_code, descriptions in data.statusCodes %}
|
||||
<tr>
|
||||
<td><a href="http://en.wikipedia.org/wiki/HTTP_{{ status_code }}" target="_blank">{{ status_code }}<a/></td>
|
||||
<td>
|
||||
<ul>
|
||||
{% for description in descriptions %}
|
||||
<li>{{ description }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</tbody>
|
||||
</table>
|
||||
{% endif %}
|
||||
|
||||
</div>
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user