Put RequestParam annotations in body (#1328)

* Put RequestParam annotations in body

* Fix tests

* Cs
This commit is contained in:
Guilhem N 2018-06-01 16:50:50 +02:00 committed by GitHub
parent 8678a21fdd
commit dbfa4ed8bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 6 deletions

View File

@ -40,10 +40,16 @@ final class FosRestDescriber implements RouteDescriberInterface
foreach ($this->getOperations($api, $route) as $operation) {
foreach ($annotations as $annotation) {
$in = $annotation instanceof QueryParam ? 'query' : 'formData';
$parameter = $operation->getParameters()->get($annotation->getName(), $in);
if ($annotation instanceof QueryParam) {
$parameter = $operation->getParameters()->get($annotation->getName(), 'query');
$parameter->setAllowEmptyValue($annotation->nullable && $annotation->allowBlank);
} else {
$body = $operation->getParameters()->get('body', 'body')->getSchema();
$body->setType('object');
$parameter = $body->getProperties()->get($annotation->getName());
}
$parameter->setRequired(!$annotation->nullable && $annotation->strict);
$parameter->setAllowEmptyValue($annotation->nullable && $annotation->allowBlank);
$parameter->setDefault($annotation->getDefault());
if (null === $parameter->getType()) {
$parameter->setType($annotation->map ? 'array' : 'string');

View File

@ -124,20 +124,23 @@ class FunctionalTest extends WebTestCase
$parameters = $operation->getParameters();
$this->assertTrue($parameters->has('foo', 'query'));
$this->assertTrue($parameters->has('bar', 'formData'));
$this->assertTrue($parameters->has('baz', 'formData'));
$this->assertTrue($parameters->has('body', 'body'));
$body = $parameters->get('body', 'body')->getSchema()->getProperties();
$this->assertTrue($body->has('bar'));
$this->assertTrue($body->has('baz'));
$fooParameter = $parameters->get('foo', 'query');
$this->assertNotNull($fooParameter->getPattern());
$this->assertEquals('\d+', $fooParameter->getPattern());
$this->assertNull($fooParameter->getFormat());
$barParameter = $parameters->get('bar', 'formData');
$barParameter = $body->get('bar');
$this->assertNotNull($barParameter->getPattern());
$this->assertEquals('\d+', $barParameter->getPattern());
$this->assertNull($barParameter->getFormat());
$bazParameter = $parameters->get('baz', 'formData');
$bazParameter = $body->get('baz');
$this->assertNotNull($bazParameter->getFormat());
$this->assertEquals('IsTrue', $bazParameter->getFormat());
$this->assertNull($bazParameter->getPattern());