Commit 98aa3dcc authored by Guillaume Perréal's avatar Guillaume Perréal
Browse files

Meilleure prise en compte des collections dans les *Filters.

parent 66d1ad8c
......@@ -26,6 +26,7 @@ use Irstea\NgModelGeneratorBundle\Exceptions\InvalidArgumentException;
use Irstea\NgModelGeneratorBundle\Metadata\OperationMetadata;
use Irstea\NgModelGeneratorBundle\Metadata\SerializationMetadata;
use Irstea\NgModelGeneratorBundle\Models\PHPClass;
use Irstea\NgModelGeneratorBundle\Models\Types\AbstractCollection;
use Irstea\NgModelGeneratorBundle\Models\Types\ArrayType;
use Irstea\NgModelGeneratorBundle\Models\Types\BuiltinType;
use Irstea\NgModelGeneratorBundle\Models\Types\Objects\AnonymousObject;
......@@ -35,6 +36,7 @@ use Irstea\NgModelGeneratorBundle\Models\Types\Operations\Operation;
use Irstea\NgModelGeneratorBundle\Models\Types\Operations\Parameter;
use Irstea\NgModelGeneratorBundle\Models\Types\Operations\Path;
use Irstea\NgModelGeneratorBundle\Models\Types\Placeholder;
use Irstea\NgModelGeneratorBundle\Models\Types\Reference;
use Irstea\NgModelGeneratorBundle\Models\Types\Resources\Collection;
use Irstea\NgModelGeneratorBundle\Models\Types\Resources\IRI;
use Irstea\NgModelGeneratorBundle\Models\Types\Resources\Representation;
......@@ -259,20 +261,18 @@ final class OperationMapper
}
}
$type = $this->resolveFilterType($filterType, $type);
$propName = Inflector::camelize(preg_replace('/\W+/', '_', $name));
if (isset($filterDesc['is_collection']) && $filterDesc['is_collection']) {
$type = new ArrayType($type);
$propName = Inflector::pluralize($propName);
}
$type = $this->resolveFilterType($filterType, $type);
if (isset($properties[$propName])) {
$type = Union::create([$type, $properties[$propName]->getType()]);
$type = $this->getSingularType($type);
$propName = Inflector::singularize($propName);
if (!empty($filterDesc['is_collection']) || substr($name, strlen($name)-2) === '[]') {
$type = new ArrayType($type);
$propName .= 'In';
}
$properties[$propName] = new Property($propName, '', $type, false, true, false, $name);
$properties[] = new Property($propName, '', $type, false, true, false, $name);
}
}
......@@ -338,6 +338,21 @@ final class OperationMapper
return $baseType;
}
/**
* @param Type $type
*
* @return Type
*/
private function getSingularType(Type $type): Type {
if ($type instanceof AbstractCollection) {
return $type->getValueType();
}
if ($type instanceof Reference) {
return $this->getSingularType($type->getTarget());
}
return $type;
}
/**
* @param Property[] $filterProperties
* @param string $varName
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment