mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-02 15:51:48 +03:00
adding optional color codes for tags annotation
This commit is contained in:
parent
f8793d2439
commit
e1c7e8a5bd
@ -244,13 +244,17 @@ class ApiDoc
|
||||
}
|
||||
|
||||
if (isset($data['tags'])) {
|
||||
$tags = $data['tags'];
|
||||
|
||||
if (!is_array($tags)) {
|
||||
$tags = array($tags);
|
||||
if (is_array($data['tags'])) {
|
||||
foreach ($data['tags'] as $tag => $colorCode) {
|
||||
if (is_numeric($tag)) {
|
||||
$this->addTag($colorCode);
|
||||
} else {
|
||||
$this->addTag($tag, $colorCode);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$this->tags[] = $data['tags'];
|
||||
}
|
||||
|
||||
$this->tags = $tags;
|
||||
}
|
||||
|
||||
if (isset($data['https'])) {
|
||||
@ -287,6 +291,15 @@ class ApiDoc
|
||||
$this->statusCodes[$statusCode] = !is_array($description) ? array($description) : $description;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $tag
|
||||
* @param string $colorCode
|
||||
*/
|
||||
public function addTag($tag, $colorCode = '#d9534f')
|
||||
{
|
||||
$this->tags[$tag] = $colorCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param array $requirement
|
||||
@ -556,14 +569,6 @@ class ApiDoc
|
||||
return $this->parameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getTags()
|
||||
{
|
||||
return $this->tags;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param boolean $deprecated
|
||||
*/
|
||||
|
@ -13,7 +13,6 @@ namespace Nelmio\ApiDocBundle\Controller;
|
||||
|
||||
use Nelmio\ApiDocBundle\Formatter\RequestAwareSwaggerFormatter;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
@ -127,7 +127,27 @@ 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.
|
||||
* `tags`: allow to tag a method (e.g. `beta` or `in-development`). Either a single tag or an array of tags. Each tag can have an optional hex colorcode attached.
|
||||
|
||||
``` php
|
||||
<?php
|
||||
|
||||
class YourController
|
||||
{
|
||||
/**
|
||||
* @ApiDoc(
|
||||
* tags={
|
||||
* "stable",
|
||||
* "deprecated" = "#ff0000"
|
||||
* }
|
||||
* )
|
||||
*/
|
||||
public function myFunction()
|
||||
{
|
||||
// ...
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
* `filters`: an array of filters;
|
||||
|
||||
|
@ -26,8 +26,8 @@
|
||||
{{ data.uri }}
|
||||
</span>
|
||||
{% if data.tags is defined %}
|
||||
{% for tag in data.tags %}
|
||||
<span class="tag">{{ tag }}</span>
|
||||
{% for tag, color_code in data.tags %}
|
||||
<span class="tag" {% if color_code is defined and color_code is not empty %}style="background-color:{{ color_code }};"{% endif %}>{{ tag }}</span>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
</h3>
|
||||
@ -58,7 +58,7 @@
|
||||
<div><a href="{{ data.link }}" target="_blank">{{ data.link }}</a></div>
|
||||
{% endif %}
|
||||
|
||||
{% if data.requirements is defined and data.requirements is not empty %}
|
||||
{% if data.requirements is defined and data.requirements is not empty %}
|
||||
<h4>Requirements</h4>
|
||||
<table class="fullwidth">
|
||||
<thead>
|
||||
|
@ -303,12 +303,28 @@ class ApiDocTest extends TestCase
|
||||
$this->assertEquals(array('beta'), $array['tags']);
|
||||
}
|
||||
|
||||
public function testConstructWithOneTagAndColorCode()
|
||||
{
|
||||
$data = array(
|
||||
'tags' => array(
|
||||
'beta' => '#ff0000'
|
||||
)
|
||||
);
|
||||
|
||||
$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' => '#ff0000'), $array['tags']);
|
||||
}
|
||||
|
||||
public function testConstructWithMultipleTags()
|
||||
{
|
||||
$data = array(
|
||||
'tags' => array(
|
||||
'experimental',
|
||||
'alpha'
|
||||
'experimental' => '#0000ff',
|
||||
'beta' => '#0000ff',
|
||||
)
|
||||
);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user