mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-02 15:51:48 +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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param array $parameter
|
||||
*/
|
||||
public function addParameter($name, array $parameter)
|
||||
{
|
||||
$this->parameters[$name] = $parameter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $parameters
|
||||
*/
|
||||
|
@ -24,7 +24,9 @@ class ApiDocExtractor
|
||||
{
|
||||
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
|
||||
@ -338,7 +340,7 @@ class ApiDocExtractor
|
||||
protected function parseAnnotations(ApiDoc $annotation, Route $route, \ReflectionMethod $method)
|
||||
{
|
||||
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) {
|
||||
$annotation->addRequirement($annot->name, array(
|
||||
'requirement' => $annot->requirements,
|
||||
@ -351,6 +353,13 @@ class ApiDocExtractor
|
||||
'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();
|
||||
|
||||
$this->assertTrue(is_array($data));
|
||||
$this->assertCount(12, $data);
|
||||
$this->assertCount(13, $data);
|
||||
|
||||
foreach ($data as $d) {
|
||||
$this->assertTrue(is_array($d));
|
||||
|
@ -12,6 +12,7 @@
|
||||
namespace Nelmio\ApiDocBundle\Tests\Fixtures\Controller;
|
||||
|
||||
use FOS\RestBundle\Controller\Annotations\QueryParam;
|
||||
use FOS\RestBundle\Controller\Annotations\RequestParam;
|
||||
use Nelmio\ApiDocBundle\Annotation\ApiDoc;
|
||||
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:
|
||||
_method: GET
|
||||
|
||||
test_route_11:
|
||||
pattern: /z-action-with-request-param
|
||||
defaults: { _controller: NelmioApiDocTestBundle:Test:zActionWithRequestParam }
|
||||
requirements:
|
||||
_method: POST
|
||||
|
||||
test_service_route_1:
|
||||
pattern: /tests.{_format}
|
||||
defaults: { _controller: nemlio.test.controller:indexAction, _format: json }
|
||||
|
@ -266,6 +266,18 @@ page:
|
||||
|
||||
* Requirement: \d+
|
||||
* Description: Page of the overview.
|
||||
|
||||
|
||||
### `POST` /z-action-with-request-param ###
|
||||
|
||||
|
||||
#### Parameters ####
|
||||
|
||||
param1:
|
||||
|
||||
* type: string
|
||||
* required: true
|
||||
* description: Param1 description.
|
||||
MARKDOWN;
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
|
@ -314,6 +314,15 @@ With multiple lines.',
|
||||
'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