mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-02 15:51:48 +03:00
Handle "array" parameter in FOSRestBundle QueryParam or RequestParam
This commit is contained in:
parent
a68dcfe829
commit
213dbdfd1c
@ -33,7 +33,7 @@ class FosRestHandler implements HandlerInterface
|
|||||||
$requirements = $this->handleRequirements($annot->requirements);
|
$requirements = $this->handleRequirements($annot->requirements);
|
||||||
$data = array(
|
$data = array(
|
||||||
'required' => $annot->strict && $annot->nullable === false && $annot->default === null,
|
'required' => $annot->strict && $annot->nullable === false && $annot->default === null,
|
||||||
'dataType' => $requirements,
|
'dataType' => $requirements.($annot->array ? '[]' : ''),
|
||||||
'actualType' => $this->inferType($requirements),
|
'actualType' => $this->inferType($requirements),
|
||||||
'subType' => null,
|
'subType' => null,
|
||||||
'description' => $annot->description,
|
'description' => $annot->description,
|
||||||
@ -46,19 +46,19 @@ class FosRestHandler implements HandlerInterface
|
|||||||
} elseif ($annot instanceof QueryParam) {
|
} elseif ($annot instanceof QueryParam) {
|
||||||
if ($annot->strict && $annot->nullable === false && $annot->default === null) {
|
if ($annot->strict && $annot->nullable === false && $annot->default === null) {
|
||||||
$annotation->addRequirement($annot->name, array(
|
$annotation->addRequirement($annot->name, array(
|
||||||
'requirement' => $this->handleRequirements($annot->requirements),
|
'requirement' => $this->handleRequirements($annot->requirements).($annot->array ? '[]' : ''),
|
||||||
'dataType' => '',
|
'dataType' => '',
|
||||||
'description' => $annot->description,
|
'description' => $annot->description,
|
||||||
));
|
));
|
||||||
} elseif ($annot->default !== null) {
|
} elseif ($annot->default !== null) {
|
||||||
$annotation->addFilter($annot->name, array(
|
$annotation->addFilter($annot->name, array(
|
||||||
'requirement' => $this->handleRequirements($annot->requirements),
|
'requirement' => $this->handleRequirements($annot->requirements).($annot->array ? '[]' : ''),
|
||||||
'description' => $annot->description,
|
'description' => $annot->description,
|
||||||
'default' => $annot->default,
|
'default' => $annot->default,
|
||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
$annotation->addFilter($annot->name, array(
|
$annotation->addFilter($annot->name, array(
|
||||||
'requirement' => $this->handleRequirements($annot->requirements),
|
'requirement' => $this->handleRequirements($annot->requirements).($annot->array ? '[]' : ''),
|
||||||
'description' => $annot->description,
|
'description' => $annot->description,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
@ -156,4 +156,22 @@ class FosRestHandlerTest extends WebTestCase
|
|||||||
|
|
||||||
$this->assertArrayNotHasKey('default', $parameter);
|
$this->assertArrayNotHasKey('default', $parameter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testPostWithArrayRequestParam()
|
||||||
|
{
|
||||||
|
$container = $this->getContainer();
|
||||||
|
$extractor = $container->get('nelmio_api_doc.extractor.api_doc_extractor');
|
||||||
|
$annotation = $extractor->get('Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::zActionWithArrayRequestParamAction', 'test_route_26');
|
||||||
|
|
||||||
|
$this->assertNotNull($annotation);
|
||||||
|
|
||||||
|
$parameters = $annotation->getParameters();
|
||||||
|
$this->assertCount(1, $parameters);
|
||||||
|
$this->assertArrayHasKey('param1', $parameters);
|
||||||
|
|
||||||
|
$parameter = $parameters['param1'];
|
||||||
|
|
||||||
|
$this->assertArrayHasKey('dataType', $parameter);
|
||||||
|
$this->assertEquals('string[]', $parameter['dataType']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -189,6 +189,14 @@ class TestController
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ApiDoc()
|
||||||
|
* @RequestParam(name="param1", requirements="string", array=true)
|
||||||
|
*/
|
||||||
|
public function zActionWithArrayRequestParamAction()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ApiDoc()
|
* @ApiDoc()
|
||||||
*/
|
*/
|
||||||
|
@ -239,3 +239,9 @@ test_route_25:
|
|||||||
defaults: { _controller: NelmioApiDocTestBundle:Test:withLinkAction }
|
defaults: { _controller: NelmioApiDocTestBundle:Test:withLinkAction }
|
||||||
requirements:
|
requirements:
|
||||||
_method: GET
|
_method: GET
|
||||||
|
|
||||||
|
test_route_26:
|
||||||
|
pattern: /z-action-with-array-request-param
|
||||||
|
defaults: { _controller: NelmioApiDocTestBundle:Test:zActionWithArrayRequestParamAction }
|
||||||
|
requirements:
|
||||||
|
_method: POST
|
||||||
|
Loading…
x
Reference in New Issue
Block a user