diff --git a/RouteDescriber/FosRestDescriber.php b/RouteDescriber/FosRestDescriber.php index 2d5f1ad..209ad7e 100644 --- a/RouteDescriber/FosRestDescriber.php +++ b/RouteDescriber/FosRestDescriber.php @@ -39,8 +39,10 @@ final class FosRestDescriber implements RouteDescriberInterface foreach ($this->getOperations($api, $route) as $operation) { foreach ($annotations as $annotation) { + $parameterName = $annotation->key ?? $annotation->getName(); // the key used by fosrest + if ($annotation instanceof QueryParam) { - $name = $annotation->getName().($annotation->map ? '[]' : ''); + $name = $parameterName.($annotation->map ? '[]' : ''); $parameter = $operation->getParameters()->get($name, 'query'); $parameter->setAllowEmptyValue($annotation->nullable && $annotation->allowBlank); @@ -48,11 +50,11 @@ final class FosRestDescriber implements RouteDescriberInterface } else { $body = $operation->getParameters()->get('body', 'body')->getSchema(); $body->setType('object'); - $parameter = $body->getProperties()->get($annotation->getName()); + $parameter = $body->getProperties()->get($parameterName); if (!$annotation->nullable && $annotation->strict) { $requiredParameters = $body->getRequired(); - $requiredParameters[] = $annotation->getName(); + $requiredParameters[] = $parameterName; $body->setRequired(array_values(array_unique($requiredParameters))); } diff --git a/Tests/Functional/Controller/FOSRestController.php b/Tests/Functional/Controller/FOSRestController.php index 651e45a..5751b02 100644 --- a/Tests/Functional/Controller/FOSRestController.php +++ b/Tests/Functional/Controller/FOSRestController.php @@ -25,7 +25,7 @@ class FOSRestController /** * @Route("/fosrest.{_format}", methods={"POST"}) * @QueryParam(name="foo", requirements=@Regex("/^\d+$/")) - * @RequestParam(name="bar", requirements="\d+") + * @RequestParam(name="Barraa", key="bar", requirements="\d+") * @RequestParam(name="baz", requirements=@IsTrue) */ public function fosrestAction()