mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-02 15:51:48 +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 array
|
||||
*/
|
||||
public function getParameters()
|
||||
{
|
||||
return $this->parameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
|
@ -32,7 +32,7 @@ class FosRestHandler implements HandlerInterface
|
||||
|
||||
$requirements = $this->handleRequirements($annot->requirements);
|
||||
$annotation->addParameter($annot->name, array(
|
||||
'required' => $annot->strict && $annot->default === null,
|
||||
'required' => $annot->strict && $annot->nullable === false && $annot->default === null,
|
||||
'dataType' => $requirements,
|
||||
'actualType' => $this->inferType($requirements),
|
||||
'subType' => null,
|
||||
|
@ -15,7 +15,7 @@ use Nelmio\ApiDocBundle\Tests\WebTestCase;
|
||||
|
||||
class ApiDocExtractorTest extends WebTestCase
|
||||
{
|
||||
const ROUTES_QUANTITY = 24;
|
||||
const ROUTES_QUANTITY = 25;
|
||||
|
||||
public function testAll()
|
||||
{
|
||||
|
@ -105,4 +105,55 @@ class FosRestHandlerTest extends WebTestCase
|
||||
$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()
|
||||
*/
|
||||
|
@ -155,3 +155,9 @@ test_route_21:
|
||||
defaults: { _controller: NelmioApiDocTestBundle:Test:zActionWithConstraintAsRequirements }
|
||||
requirements:
|
||||
_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 ###
|
||||
|
||||
|
||||
|
@ -837,6 +837,27 @@ With multiple lines.',
|
||||
'deprecated' => true,
|
||||
),
|
||||
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(
|
||||
'method' => 'GET',
|
||||
'uri' => '/z-action-with-query-param',
|
||||
@ -854,7 +875,7 @@ With multiple lines.',
|
||||
'authenticationRoles' => array(),
|
||||
'deprecated' => false,
|
||||
),
|
||||
12 =>
|
||||
13 =>
|
||||
array(
|
||||
'method' => 'GET',
|
||||
'uri' => '/z-action-with-query-param-no-default',
|
||||
@ -871,7 +892,7 @@ With multiple lines.',
|
||||
'authenticationRoles' => array(),
|
||||
'deprecated' => false,
|
||||
),
|
||||
13 =>
|
||||
14 =>
|
||||
array(
|
||||
'method' => 'GET',
|
||||
'uri' => '/z-action-with-query-param-strict',
|
||||
@ -889,7 +910,7 @@ With multiple lines.',
|
||||
'authenticationRoles' => array(),
|
||||
'deprecated' => false,
|
||||
),
|
||||
14 =>
|
||||
15 =>
|
||||
array(
|
||||
'method' => 'POST',
|
||||
'uri' => '/z-action-with-request-param',
|
||||
@ -910,7 +931,7 @@ With multiple lines.',
|
||||
'authenticationRoles' => array(),
|
||||
'deprecated' => false,
|
||||
),
|
||||
15 =>
|
||||
16 =>
|
||||
array(
|
||||
'method' => 'ANY',
|
||||
'uri' => '/z-return-jms-and-validator-output',
|
||||
@ -962,7 +983,7 @@ With multiple lines.',
|
||||
),
|
||||
'authenticationRoles' => array(),
|
||||
),
|
||||
16 =>
|
||||
17 =>
|
||||
array(
|
||||
'method' => "ANY",
|
||||
'uri' => "/z-return-selected-parsers-input",
|
||||
@ -998,7 +1019,7 @@ With multiple lines.',
|
||||
),
|
||||
)
|
||||
),
|
||||
17 =>
|
||||
18 =>
|
||||
array(
|
||||
'method' => "ANY",
|
||||
'uri' => "/z-return-selected-parsers-output",
|
||||
|
Loading…
x
Reference in New Issue
Block a user