mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-02 15:51:48 +03:00
Merge pull request #395 from fechu/master
Implement tags in ApiDoc annotation.
This commit is contained in:
commit
56124e7c40
@ -135,6 +135,11 @@ class ApiDoc
|
|||||||
*/
|
*/
|
||||||
private $statusCodes = array();
|
private $statusCodes = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private $tags = array();
|
||||||
|
|
||||||
public function __construct(array $data)
|
public function __construct(array $data)
|
||||||
{
|
{
|
||||||
$this->resource = !empty($data['resource']) ? $data['resource'] : false;
|
$this->resource = !empty($data['resource']) ? $data['resource'] : false;
|
||||||
@ -223,6 +228,16 @@ class ApiDoc
|
|||||||
$this->deprecated = $data['deprecated'];
|
$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'])) {
|
if (isset($data['https'])) {
|
||||||
$this->https = $data['https'];
|
$this->https = $data['https'];
|
||||||
}
|
}
|
||||||
@ -507,6 +522,14 @@ class ApiDoc
|
|||||||
return $this->requirements;
|
return $this->requirements;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getTags()
|
||||||
|
{
|
||||||
|
return $this->tags;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param boolean $deprecated
|
* @param boolean $deprecated
|
||||||
*/
|
*/
|
||||||
@ -571,6 +594,10 @@ class ApiDoc
|
|||||||
$data['cache'] = $cache;
|
$data['cache'] = $cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($tags = $this->tags) {
|
||||||
|
$data['tags'] = $tags;
|
||||||
|
}
|
||||||
|
|
||||||
$data['https'] = $this->https;
|
$data['https'] = $this->https;
|
||||||
$data['authentication'] = $this->authentication;
|
$data['authentication'] = $this->authentication;
|
||||||
$data['authenticationRoles'] = $this->authenticationRoles;
|
$data['authenticationRoles'] = $this->authenticationRoles;
|
||||||
|
@ -127,6 +127,8 @@ The following properties are available:
|
|||||||
|
|
||||||
* `deprecated`: allow to set method as deprecated (default: `false`);
|
* `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;
|
* `filters`: an array of filters;
|
||||||
|
|
||||||
* `requirements`: an array of requirements;
|
* `requirements`: an array of requirements;
|
||||||
|
@ -296,6 +296,18 @@ li.operation a.heading h3 span.path {
|
|||||||
padding-left: 5px;
|
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 {
|
li.operation div.content {
|
||||||
border: 1px solid #ddd;
|
border: 1px solid #ddd;
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
|
@ -25,6 +25,11 @@
|
|||||||
{% endif -%}
|
{% endif -%}
|
||||||
{{ data.uri }}
|
{{ data.uri }}
|
||||||
</span>
|
</span>
|
||||||
|
{% if data.tags is defined %}
|
||||||
|
{% for tag in data.tags %}
|
||||||
|
<span class="tag">{{ tag }}</span>
|
||||||
|
{% endfor %}
|
||||||
|
{% endif %}
|
||||||
</h3>
|
</h3>
|
||||||
<ul class="options">
|
<ul class="options">
|
||||||
{% if data.description is defined %}
|
{% if data.description is defined %}
|
||||||
|
@ -288,4 +288,35 @@ class ApiDocTest extends TestCase
|
|||||||
$this->assertTrue(isset($array['parameters']['fooId']));
|
$this->assertTrue(isset($array['parameters']['fooId']));
|
||||||
$this->assertTrue(isset($array['parameters']['fooId']['dataType']));
|
$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']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user