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

View File

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

View File

@ -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="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", 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 class BazingaUser
{ {

View File

@ -43,7 +43,7 @@
"api-platform/core": "^2.1.0", "api-platform/core": "^2.1.0",
"friendsofsymfony/rest-bundle": "^2.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" "jms/serializer-bundle": "^2.0|^3.0"
}, },
"suggest": { "suggest": {