mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-09 02:59:27 +03:00
Fixed disabling required for HTTP PUT requests
This commit is contained in:
parent
eaaa54bf11
commit
f625d9671c
@ -284,7 +284,7 @@ class ApiDocExtractor
|
|||||||
|
|
||||||
if ('PUT' === $annotation->getMethod()) {
|
if ('PUT' === $annotation->getMethod()) {
|
||||||
// All parameters are optional with PUT (update)
|
// All parameters are optional with PUT (update)
|
||||||
array_walk($parameters, function ($val, $key) use (&$data) {
|
array_walk($parameters, function ($val, $key) use (&$parameters) {
|
||||||
$parameters[$key]['required'] = false;
|
$parameters[$key]['required'] = false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,8 @@
|
|||||||
|
|
||||||
namespace Nelmio\ApiDocBundle\Tests\Extractor;
|
namespace Nelmio\ApiDocBundle\Tests\Extractor;
|
||||||
|
|
||||||
|
use Nelmio\ApiDocBundle\Annotation\ApiDoc;
|
||||||
|
use Nelmio\ApiDocBundle\Extractor\ApiDocExtractor;
|
||||||
use Nelmio\ApiDocBundle\Tests\WebTestCase;
|
use Nelmio\ApiDocBundle\Tests\WebTestCase;
|
||||||
|
|
||||||
class ApiDocExtractorTest extends WebTestCase
|
class ApiDocExtractorTest extends WebTestCase
|
||||||
@ -256,4 +258,28 @@ class ApiDocExtractorTest extends WebTestCase
|
|||||||
);
|
);
|
||||||
$this->assertCount(1, $parsers);
|
$this->assertCount(1, $parsers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testPostRequestDoesRequireParametersWhenMarkedAsSuch()
|
||||||
|
{
|
||||||
|
$container = $this->getContainer();
|
||||||
|
/** @var ApiDocExtractor $extractor */
|
||||||
|
$extractor = $container->get('nelmio_api_doc.extractor.api_doc_extractor');
|
||||||
|
/** @var ApiDoc $annotation */
|
||||||
|
$annotation = $extractor->get('Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::requiredParametersAction', 'test_required_parameters');
|
||||||
|
|
||||||
|
$parameters = $annotation->getParameters();
|
||||||
|
$this->assertTrue($parameters['required_field']['required']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPutRequestDoesNeverRequireParameters()
|
||||||
|
{
|
||||||
|
$container = $this->getContainer();
|
||||||
|
/** @var ApiDocExtractor $extractor */
|
||||||
|
$extractor = $container->get('nelmio_api_doc.extractor.api_doc_extractor');
|
||||||
|
/** @var ApiDoc $annotation */
|
||||||
|
$annotation = $extractor->get('Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::requiredParametersAction', 'test_put_disables_required_parameters');
|
||||||
|
|
||||||
|
$parameters = $annotation->getParameters();
|
||||||
|
$this->assertFalse($parameters['required_field']['required']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -65,6 +65,15 @@ class TestController
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ApiDoc(
|
||||||
|
* input="Nelmio\ApiDocBundle\Tests\Fixtures\Form\TestType"
|
||||||
|
* )
|
||||||
|
*/
|
||||||
|
public function requiredParametersAction()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
public function anotherAction()
|
public function anotherAction()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,7 @@ class TestType extends AbstractType
|
|||||||
->add('b')
|
->add('b')
|
||||||
->add($builder->create('c', 'checkbox'))
|
->add($builder->create('c', 'checkbox'))
|
||||||
->add('d','text',array( 'data' => 'DefaultTest'))
|
->add('d','text',array( 'data' => 'DefaultTest'))
|
||||||
|
->add('required_field', 'text', array('required' => true))
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -219,3 +219,18 @@ test_route_24:
|
|||||||
defaults: { _controller: NelmioApiDocTestBundle:Test:zSecured }
|
defaults: { _controller: NelmioApiDocTestBundle:Test:zSecured }
|
||||||
requirements:
|
requirements:
|
||||||
_method: POST
|
_method: POST
|
||||||
|
|
||||||
|
test_required_parameters:
|
||||||
|
pattern: /api/other-resources/{id}.{_format}
|
||||||
|
defaults: { _controller: NelmioApiDocTestBundle:Resource:requiredParametersAction, _format: json }
|
||||||
|
requirements:
|
||||||
|
_method: POST
|
||||||
|
_format: json|xml|html
|
||||||
|
|
||||||
|
test_put_disables_required_parameters:
|
||||||
|
pattern: /api/other-resources/{id}.{_format}
|
||||||
|
defaults: { _controller: NelmioApiDocTestBundle:Resource:requiredParametersAction, _format: json }
|
||||||
|
requirements:
|
||||||
|
_method: PUT
|
||||||
|
_format: json|xml|html
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user