From b88793267e78afd3a27ac3eff8cd68b5e53a4a81 Mon Sep 17 00:00:00 2001 From: Guilhem Niot Date: Fri, 21 Feb 2020 10:42:13 +0100 Subject: [PATCH] Use FOSRest *Param::$key when defined --- RouteDescriber/FosRestDescriber.php | 8 +++++--- Tests/Functional/Controller/FOSRestController.php | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) 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()