Use FOSRest *Param::$key when defined

This commit is contained in:
Guilhem Niot 2020-02-21 10:42:13 +01:00
parent ebf7fa589b
commit b88793267e
2 changed files with 6 additions and 4 deletions

View File

@ -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)));
}

View File

@ -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()