mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-09 02:59:27 +03:00
Merge pull request #97 from FlorianLB/request-param-annotation
RequestParam annotation create a parameter item
This commit is contained in:
commit
aee8108413
@ -205,6 +205,15 @@ class ApiDoc
|
|||||||
$this->uri = $uri;
|
$this->uri = $uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $name
|
||||||
|
* @param array $parameter
|
||||||
|
*/
|
||||||
|
public function addParameter($name, array $parameter)
|
||||||
|
{
|
||||||
|
$this->parameters[$name] = $parameter;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $parameters
|
* @param array $parameters
|
||||||
*/
|
*/
|
||||||
|
@ -24,7 +24,9 @@ class ApiDocExtractor
|
|||||||
{
|
{
|
||||||
const ANNOTATION_CLASS = 'Nelmio\\ApiDocBundle\\Annotation\\ApiDoc';
|
const ANNOTATION_CLASS = 'Nelmio\\ApiDocBundle\\Annotation\\ApiDoc';
|
||||||
|
|
||||||
const FOS_REST_PARAM_CLASS = 'FOS\\RestBundle\\Controller\\Annotations\\Param';
|
const FOS_REST_QUERY_PARAM_CLASS = 'FOS\\RestBundle\\Controller\\Annotations\\QueryParam';
|
||||||
|
|
||||||
|
const FOS_REST_REQUEST_PARAM_CLASS = 'FOS\\RestBundle\\Controller\\Annotations\\RequestParam';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \Symfony\Component\DependencyInjection\ContainerInterface
|
* @var \Symfony\Component\DependencyInjection\ContainerInterface
|
||||||
@ -338,7 +340,7 @@ class ApiDocExtractor
|
|||||||
protected function parseAnnotations(ApiDoc $annotation, Route $route, \ReflectionMethod $method)
|
protected function parseAnnotations(ApiDoc $annotation, Route $route, \ReflectionMethod $method)
|
||||||
{
|
{
|
||||||
foreach ($this->reader->getMethodAnnotations($method) as $annot) {
|
foreach ($this->reader->getMethodAnnotations($method) as $annot) {
|
||||||
if (is_subclass_of($annot, self::FOS_REST_PARAM_CLASS)) {
|
if (is_a($annot, self::FOS_REST_QUERY_PARAM_CLASS)) {
|
||||||
if ($annot->strict) {
|
if ($annot->strict) {
|
||||||
$annotation->addRequirement($annot->name, array(
|
$annotation->addRequirement($annot->name, array(
|
||||||
'requirement' => $annot->requirements,
|
'requirement' => $annot->requirements,
|
||||||
@ -351,6 +353,13 @@ class ApiDocExtractor
|
|||||||
'description' => $annot->description,
|
'description' => $annot->description,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
} else if (is_a($annot, self::FOS_REST_REQUEST_PARAM_CLASS)) {
|
||||||
|
$annotation->addParameter($annot->name, array(
|
||||||
|
'required' => !$annot->nullable,
|
||||||
|
'dataType' => $annot->requirements,
|
||||||
|
'description' => $annot->description,
|
||||||
|
'readonly' => false
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ class ApiDocExtractorTest extends WebTestCase
|
|||||||
$data = $extractor->all();
|
$data = $extractor->all();
|
||||||
|
|
||||||
$this->assertTrue(is_array($data));
|
$this->assertTrue(is_array($data));
|
||||||
$this->assertCount(12, $data);
|
$this->assertCount(13, $data);
|
||||||
|
|
||||||
foreach ($data as $d) {
|
foreach ($data as $d) {
|
||||||
$this->assertTrue(is_array($d));
|
$this->assertTrue(is_array($d));
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
namespace Nelmio\ApiDocBundle\Tests\Fixtures\Controller;
|
namespace Nelmio\ApiDocBundle\Tests\Fixtures\Controller;
|
||||||
|
|
||||||
use FOS\RestBundle\Controller\Annotations\QueryParam;
|
use FOS\RestBundle\Controller\Annotations\QueryParam;
|
||||||
|
use FOS\RestBundle\Controller\Annotations\RequestParam;
|
||||||
use Nelmio\ApiDocBundle\Annotation\ApiDoc;
|
use Nelmio\ApiDocBundle\Annotation\ApiDoc;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
|
||||||
@ -111,4 +112,12 @@ class TestController
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ApiDoc()
|
||||||
|
* @RequestParam(name="param1", requirements="string", nullable=false, description="Param1 description.")
|
||||||
|
*/
|
||||||
|
public function zActionWithRequestParamAction()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -52,6 +52,12 @@ test_route_10:
|
|||||||
requirements:
|
requirements:
|
||||||
_method: GET
|
_method: GET
|
||||||
|
|
||||||
|
test_route_11:
|
||||||
|
pattern: /z-action-with-request-param
|
||||||
|
defaults: { _controller: NelmioApiDocTestBundle:Test:zActionWithRequestParam }
|
||||||
|
requirements:
|
||||||
|
_method: POST
|
||||||
|
|
||||||
test_service_route_1:
|
test_service_route_1:
|
||||||
pattern: /tests.{_format}
|
pattern: /tests.{_format}
|
||||||
defaults: { _controller: nemlio.test.controller:indexAction, _format: json }
|
defaults: { _controller: nemlio.test.controller:indexAction, _format: json }
|
||||||
|
@ -266,6 +266,18 @@ page:
|
|||||||
|
|
||||||
* Requirement: \d+
|
* Requirement: \d+
|
||||||
* Description: Page of the overview.
|
* Description: Page of the overview.
|
||||||
|
|
||||||
|
|
||||||
|
### `POST` /z-action-with-request-param ###
|
||||||
|
|
||||||
|
|
||||||
|
#### Parameters ####
|
||||||
|
|
||||||
|
param1:
|
||||||
|
|
||||||
|
* type: string
|
||||||
|
* required: true
|
||||||
|
* description: Param1 description.
|
||||||
MARKDOWN;
|
MARKDOWN;
|
||||||
|
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
|
@ -314,6 +314,15 @@ With multiple lines.',
|
|||||||
'page' => array('description' => 'Page of the overview.', 'requirement' => '\d+')
|
'page' => array('description' => 'Page of the overview.', 'requirement' => '\d+')
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
8 =>
|
||||||
|
array(
|
||||||
|
'method' => 'POST',
|
||||||
|
'uri' => '/z-action-with-request-param',
|
||||||
|
'parameters' =>
|
||||||
|
array(
|
||||||
|
'param1' => array('description' => 'Param1 description.', 'required' => true, 'dataType' => 'string', 'readonly' => false)
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user