Merge pull request #1506 from nelmio/GuilhemN-patch-1

Fix map support of FOSRestBundle
This commit is contained in:
Guilhem N 2019-04-23 21:46:19 +02:00 committed by GitHub
commit 101648bb8f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -40,7 +40,8 @@ final class FosRestDescriber implements RouteDescriberInterface
foreach ($this->getOperations($api, $route) as $operation) { foreach ($this->getOperations($api, $route) as $operation) {
foreach ($annotations as $annotation) { foreach ($annotations as $annotation) {
if ($annotation instanceof QueryParam) { if ($annotation instanceof QueryParam) {
$parameter = $operation->getParameters()->get($annotation->getName(), 'query'); $name = $annotation->getName().($annotation->map ? '[]' : '');
$parameter = $operation->getParameters()->get($name, 'query');
$parameter->setAllowEmptyValue($annotation->nullable && $annotation->allowBlank); $parameter->setAllowEmptyValue($annotation->nullable && $annotation->allowBlank);
$parameter->setRequired(!$annotation->nullable && $annotation->strict); $parameter->setRequired(!$annotation->nullable && $annotation->strict);
@ -58,13 +59,22 @@ final class FosRestDescriber implements RouteDescriberInterface
} }
$parameter->setDefault($annotation->getDefault()); $parameter->setDefault($annotation->getDefault());
if (null === $parameter->getType()) { if (null !== $parameter->getType()) {
$parameter->setType($annotation->map ? 'array' : 'string'); continue;
} }
if (null === $parameter->getDescription()) { if (null === $parameter->getDescription()) {
$parameter->setDescription($annotation->description); $parameter->setDescription($annotation->description);
} }
if ($annotation->map) {
$parameter->setType('array');
$parameter->setCollectionFormat('multi');
$parameter = $parameter->getItems();
}
$parameter->setType('string');
$pattern = $this->getPattern($annotation->requirements); $pattern = $this->getPattern($annotation->requirements);
if (null !== $pattern) { if (null !== $pattern) {
$parameter->setPattern($pattern); $parameter->setPattern($pattern);