mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-09 02:59:27 +03:00
Add support for nullable option in RequestParam
This commit is contained in:
parent
607d031051
commit
b4e874e2dc
@ -522,6 +522,14 @@ class ApiDoc
|
|||||||
return $this->requirements;
|
return $this->requirements;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getParameters()
|
||||||
|
{
|
||||||
|
return $this->parameters;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
|
@ -32,7 +32,7 @@ class FosRestHandler implements HandlerInterface
|
|||||||
|
|
||||||
$requirements = $this->handleRequirements($annot->requirements);
|
$requirements = $this->handleRequirements($annot->requirements);
|
||||||
$annotation->addParameter($annot->name, array(
|
$annotation->addParameter($annot->name, array(
|
||||||
'required' => $annot->strict && $annot->default === null,
|
'required' => $annot->strict && $annot->nullable === false && $annot->default === null,
|
||||||
'dataType' => $requirements,
|
'dataType' => $requirements,
|
||||||
'actualType' => $this->inferType($requirements),
|
'actualType' => $this->inferType($requirements),
|
||||||
'subType' => null,
|
'subType' => null,
|
||||||
|
@ -15,7 +15,7 @@ use Nelmio\ApiDocBundle\Tests\WebTestCase;
|
|||||||
|
|
||||||
class ApiDocExtractorTest extends WebTestCase
|
class ApiDocExtractorTest extends WebTestCase
|
||||||
{
|
{
|
||||||
const ROUTES_QUANTITY = 24;
|
const ROUTES_QUANTITY = 25;
|
||||||
|
|
||||||
public function testAll()
|
public function testAll()
|
||||||
{
|
{
|
||||||
|
@ -105,4 +105,55 @@ class FosRestHandlerTest extends WebTestCase
|
|||||||
$this->assertEquals($filter['requirement'], 'Email');
|
$this->assertEquals($filter['requirement'], 'Email');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testGetWithRequestParam()
|
||||||
|
{
|
||||||
|
$container = $this->getContainer();
|
||||||
|
$extractor = $container->get('nelmio_api_doc.extractor.api_doc_extractor');
|
||||||
|
$annotation = $extractor->get('Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::zActionWithRequestParamAction', 'test_route_11');
|
||||||
|
|
||||||
|
$this->assertNotNull($annotation);
|
||||||
|
|
||||||
|
$parameters = $annotation->getParameters();
|
||||||
|
$this->assertCount(1, $parameters);
|
||||||
|
$this->assertArrayHasKey('param1', $parameters);
|
||||||
|
|
||||||
|
$parameter = $parameters['param1'];
|
||||||
|
|
||||||
|
$this->assertArrayHasKey('dataType', $parameter);
|
||||||
|
$this->assertEquals($parameter['dataType'], 'string');
|
||||||
|
|
||||||
|
$this->assertArrayHasKey('description', $parameter);
|
||||||
|
$this->assertEquals($parameter['description'], 'Param1 description.');
|
||||||
|
|
||||||
|
$this->assertArrayHasKey('required', $parameter);
|
||||||
|
$this->assertEquals($parameter['required'], true);
|
||||||
|
|
||||||
|
$this->assertArrayNotHasKey('default', $parameter);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetWithRequestParamNullable()
|
||||||
|
{
|
||||||
|
$container = $this->getContainer();
|
||||||
|
$extractor = $container->get('nelmio_api_doc.extractor.api_doc_extractor');
|
||||||
|
$annotation = $extractor->get('Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::zActionWithNullableRequestParamAction', 'test_route_22');
|
||||||
|
|
||||||
|
$this->assertNotNull($annotation);
|
||||||
|
|
||||||
|
$parameters = $annotation->getParameters();
|
||||||
|
$this->assertCount(1, $parameters);
|
||||||
|
$this->assertArrayHasKey('param1', $parameters);
|
||||||
|
|
||||||
|
$parameter = $parameters['param1'];
|
||||||
|
|
||||||
|
$this->assertArrayHasKey('dataType', $parameter);
|
||||||
|
$this->assertEquals($parameter['dataType'], 'string');
|
||||||
|
|
||||||
|
$this->assertArrayHasKey('description', $parameter);
|
||||||
|
$this->assertEquals($parameter['description'], 'Param1 description.');
|
||||||
|
|
||||||
|
$this->assertArrayHasKey('required', $parameter);
|
||||||
|
$this->assertEquals($parameter['required'], false);
|
||||||
|
|
||||||
|
$this->assertArrayNotHasKey('default', $parameter);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -167,6 +167,14 @@ class TestController
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ApiDoc()
|
||||||
|
* @RequestParam(name="param1", requirements="string", description="Param1 description.", nullable=true)
|
||||||
|
*/
|
||||||
|
public function zActionWithNullableRequestParamAction()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ApiDoc()
|
* @ApiDoc()
|
||||||
*/
|
*/
|
||||||
|
@ -155,3 +155,9 @@ test_route_21:
|
|||||||
defaults: { _controller: NelmioApiDocTestBundle:Test:zActionWithConstraintAsRequirements }
|
defaults: { _controller: NelmioApiDocTestBundle:Test:zActionWithConstraintAsRequirements }
|
||||||
requirements:
|
requirements:
|
||||||
_method: GET
|
_method: GET
|
||||||
|
|
||||||
|
test_route_22:
|
||||||
|
pattern: /z-action-with-nullable-request-param
|
||||||
|
defaults: { _controller: NelmioApiDocTestBundle:Test:zActionWithNullableRequestParam }
|
||||||
|
requirements:
|
||||||
|
_method: POST
|
||||||
|
@ -418,6 +418,18 @@ nested_array[]:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### `POST` /z-action-with-nullable-request-param ###
|
||||||
|
|
||||||
|
|
||||||
|
#### Parameters ####
|
||||||
|
|
||||||
|
param1:
|
||||||
|
|
||||||
|
* type: string
|
||||||
|
* required: false
|
||||||
|
* description: Param1 description.
|
||||||
|
|
||||||
|
|
||||||
### `GET` /z-action-with-query-param ###
|
### `GET` /z-action-with-query-param ###
|
||||||
|
|
||||||
|
|
||||||
|
@ -837,6 +837,27 @@ With multiple lines.',
|
|||||||
'deprecated' => true,
|
'deprecated' => true,
|
||||||
),
|
),
|
||||||
11 =>
|
11 =>
|
||||||
|
array(
|
||||||
|
'method' => 'POST',
|
||||||
|
'uri' => '/z-action-with-nullable-request-param',
|
||||||
|
'parameters' =>
|
||||||
|
array(
|
||||||
|
'param1' =>
|
||||||
|
array(
|
||||||
|
'required' => false,
|
||||||
|
'dataType' => 'string',
|
||||||
|
'description' => 'Param1 description.',
|
||||||
|
'readonly' => false,
|
||||||
|
'actualType' => 'string',
|
||||||
|
'subType' => null,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'https' => false,
|
||||||
|
'authentication' => false,
|
||||||
|
'authenticationRoles' => array(),
|
||||||
|
'deprecated' => false,
|
||||||
|
),
|
||||||
|
12 =>
|
||||||
array(
|
array(
|
||||||
'method' => 'GET',
|
'method' => 'GET',
|
||||||
'uri' => '/z-action-with-query-param',
|
'uri' => '/z-action-with-query-param',
|
||||||
@ -854,7 +875,7 @@ With multiple lines.',
|
|||||||
'authenticationRoles' => array(),
|
'authenticationRoles' => array(),
|
||||||
'deprecated' => false,
|
'deprecated' => false,
|
||||||
),
|
),
|
||||||
12 =>
|
13 =>
|
||||||
array(
|
array(
|
||||||
'method' => 'GET',
|
'method' => 'GET',
|
||||||
'uri' => '/z-action-with-query-param-no-default',
|
'uri' => '/z-action-with-query-param-no-default',
|
||||||
@ -871,7 +892,7 @@ With multiple lines.',
|
|||||||
'authenticationRoles' => array(),
|
'authenticationRoles' => array(),
|
||||||
'deprecated' => false,
|
'deprecated' => false,
|
||||||
),
|
),
|
||||||
13 =>
|
14 =>
|
||||||
array(
|
array(
|
||||||
'method' => 'GET',
|
'method' => 'GET',
|
||||||
'uri' => '/z-action-with-query-param-strict',
|
'uri' => '/z-action-with-query-param-strict',
|
||||||
@ -889,7 +910,7 @@ With multiple lines.',
|
|||||||
'authenticationRoles' => array(),
|
'authenticationRoles' => array(),
|
||||||
'deprecated' => false,
|
'deprecated' => false,
|
||||||
),
|
),
|
||||||
14 =>
|
15 =>
|
||||||
array(
|
array(
|
||||||
'method' => 'POST',
|
'method' => 'POST',
|
||||||
'uri' => '/z-action-with-request-param',
|
'uri' => '/z-action-with-request-param',
|
||||||
@ -910,7 +931,7 @@ With multiple lines.',
|
|||||||
'authenticationRoles' => array(),
|
'authenticationRoles' => array(),
|
||||||
'deprecated' => false,
|
'deprecated' => false,
|
||||||
),
|
),
|
||||||
15 =>
|
16 =>
|
||||||
array(
|
array(
|
||||||
'method' => 'ANY',
|
'method' => 'ANY',
|
||||||
'uri' => '/z-return-jms-and-validator-output',
|
'uri' => '/z-return-jms-and-validator-output',
|
||||||
@ -962,7 +983,7 @@ With multiple lines.',
|
|||||||
),
|
),
|
||||||
'authenticationRoles' => array(),
|
'authenticationRoles' => array(),
|
||||||
),
|
),
|
||||||
16 =>
|
17 =>
|
||||||
array(
|
array(
|
||||||
'method' => "ANY",
|
'method' => "ANY",
|
||||||
'uri' => "/z-return-selected-parsers-input",
|
'uri' => "/z-return-selected-parsers-input",
|
||||||
@ -998,7 +1019,7 @@ With multiple lines.',
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
17 =>
|
18 =>
|
||||||
array(
|
array(
|
||||||
'method' => "ANY",
|
'method' => "ANY",
|
||||||
'uri' => "/z-return-selected-parsers-output",
|
'uri' => "/z-return-selected-parsers-output",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user