add hateoas v3 compat

This commit is contained in:
Asmir Mustafic 2019-01-11 10:40:53 +01:00
parent 66bcf02903
commit d15b4123c1
No known key found for this signature in database
GPG Key ID: 5408354D09CC64FC
3 changed files with 15 additions and 6 deletions
ModelDescriber
Tests/Functional/Entity
composer.json

@ -13,6 +13,7 @@ namespace Nelmio\ApiDocBundle\ModelDescriber;
use Doctrine\Common\Annotations\Reader;
use EXSyst\Component\Swagger\Schema;
use JMS\Serializer\Annotation\VirtualProperty;
use JMS\Serializer\Exclusion\GroupsExclusionStrategy;
use JMS\Serializer\Naming\PropertyNamingStrategyInterface;
use JMS\Serializer\SerializationContext;
@ -94,10 +95,18 @@ class JMSModelDescriber implements ModelDescriberInterface, ModelRegistryAwareIn
$name = $this->namingStrategy ? $this->namingStrategy->translateName($item) : $item->serializedName;
// read property options from Swagger Property annotation if it exists
if (null !== $item->reflection) {
$property = $properties->get($annotationsReader->getPropertyName($item->reflection, $name));
$annotationsReader->updateProperty($item->reflection, $property, $groups);
} else {
try {
if (property_exists($item, 'reflection') && null !== $item->reflection) {
$reflection = $item->reflection;
} elseif ($item instanceof VirtualProperty) {
$reflection = new \ReflectionProperty($item->class, $item->name);
} else {
$reflection = new \ReflectionProperty($item->class, $item->name);
}
$property = $properties->get($annotationsReader->getPropertyName($reflection, $name));
$annotationsReader->updateProperty($reflection, $property, $groups);
} catch (\ReflectionException $e) {
$property = $properties->get($name);
}

@ -18,7 +18,7 @@ use Hateoas\Configuration\Annotation as Hateoas;
*
* @Hateoas\Relation(name="example", attributes={"str_att":"bar", "float_att":5.6, "bool_att": false}, href="http://www.example.com")
* @Hateoas\Relation(name="route", href=@Hateoas\Route("foo"))
* @Hateoas\Relation(name="route", attributes={"foo":"bar"}, embedded=@Hateoas\Embedded("expr(foo)"))
* @Hateoas\Relation(name="route", attributes={"foo":"bar"}, embedded=@Hateoas\Embedded("expr(service('xx'))"))
*/
class BazingaUser
{

@ -43,7 +43,7 @@
"api-platform/core": "^2.1.0",
"friendsofsymfony/rest-bundle": "^2.0",
"willdurand/hateoas-bundle": "^1.0",
"willdurand/hateoas-bundle": "^1.0|^2.0",
"jms/serializer-bundle": "^2.0|^3.0"
},
"suggest": {