diff --git a/RouteDescriber/FosRestDescriber.php b/RouteDescriber/FosRestDescriber.php index b4015df..e64303e 100644 --- a/RouteDescriber/FosRestDescriber.php +++ b/RouteDescriber/FosRestDescriber.php @@ -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'); diff --git a/Tests/Functional/FunctionalTest.php b/Tests/Functional/FunctionalTest.php index 64dfbaf..e09a096 100644 --- a/Tests/Functional/FunctionalTest.php +++ b/Tests/Functional/FunctionalTest.php @@ -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());