Merge pull request #395 from fechu/master

Implement tags in ApiDoc annotation.
This commit is contained in:
William Durand 2014-06-01 15:56:45 +02:00
commit 56124e7c40
5 changed files with 77 additions and 0 deletions

View File

@ -135,6 +135,11 @@ class ApiDoc
*/
private $statusCodes = array();
/**
* @var array
*/
private $tags = array();
public function __construct(array $data)
{
$this->resource = !empty($data['resource']) ? $data['resource'] : false;
@ -223,6 +228,16 @@ class ApiDoc
$this->deprecated = $data['deprecated'];
}
if (isset($data['tags'])) {
$tags = $data['tags'];
if (!is_array($tags)) {
$tags = array($tags);
}
$this->tags = $tags;
}
if (isset($data['https'])) {
$this->https = $data['https'];
}
@ -507,6 +522,14 @@ class ApiDoc
return $this->requirements;
}
/**
* @return array
*/
public function getTags()
{
return $this->tags;
}
/**
* @param boolean $deprecated
*/
@ -571,6 +594,10 @@ class ApiDoc
$data['cache'] = $cache;
}
if ($tags = $this->tags) {
$data['tags'] = $tags;
}
$data['https'] = $this->https;
$data['authentication'] = $this->authentication;
$data['authenticationRoles'] = $this->authenticationRoles;

View File

@ -127,6 +127,8 @@ The following properties are available:
* `deprecated`: allow to set method as deprecated (default: `false`);
* `tags`: allow to tag a method (e.g. `beta` or `in-development`). Either a single tag or an array of tags.
* `filters`: an array of filters;
* `requirements`: an array of requirements;

View File

@ -296,6 +296,18 @@ li.operation a.heading h3 span.path {
padding-left: 5px;
}
li.operation a.heading h3 span.tag {
color: #FFFFFF;
font-size: 0.7em;
vertical-align: baseline;
background-color: #d9534f;
padding-bottom: 3px;
padding-left: 6px;
padding-right: 6px;
padding-top: 2px;
border-radius: 4px;
}
li.operation div.content {
border: 1px solid #ddd;
padding: 10px;

View File

@ -25,6 +25,11 @@
{% endif -%}
{{ data.uri }}
</span>
{% if data.tags is defined %}
{% for tag in data.tags %}
<span class="tag">{{ tag }}</span>
{% endfor %}
{% endif %}
</h3>
<ul class="options">
{% if data.description is defined %}

View File

@ -288,4 +288,35 @@ class ApiDocTest extends TestCase
$this->assertTrue(isset($array['parameters']['fooId']));
$this->assertTrue(isset($array['parameters']['fooId']['dataType']));
}
public function testConstructWithOneTag()
{
$data = array(
'tags' => 'beta'
);
$annot = new ApiDoc($data);
$array = $annot->toArray();
$this->assertTrue(is_array($array));
$this->assertTrue(is_array($array['tags']), 'Single tag should be put in array');
$this->assertEquals(array('beta'), $array['tags']);
}
public function testConstructWithMultipleTags()
{
$data = array(
'tags' => array(
'experimental',
'alpha'
)
);
$annot = new ApiDoc($data);
$array = $annot->toArray();
$this->assertTrue(is_array($array));
$this->assertTrue(is_array($array['tags']), 'Tags should be in array');
$this->assertEquals($data['tags'], $array['tags']);
}
}