mapado/rest-client-sdk

@Attribute name annotation giving NULL when the class parameter name is different

leroy0211 opened this issue · 9 comments

First of all let me define my resouces.

I use this Hydra API: http://www.markus-lanthaler.com/hydra/event-api/events/41
I created a class Event like:

/**
 * Class Event
 *
 * @package Acme\DemoBundle\Entity
 * @Rest\Entity(key="events", client="Acme\DemoBundle\Command\BasicClient")
 */
class Event
{
    /**
     * @var int
     * @Rest\Id()
     */
    protected $id;

    /**
     * @var string
     * @Rest\Attribute(name="name", type="string")
     */
    protected $firstName;

    /**
     * @return mixed
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * @param mixed $id
     */
    public function setId($id)
    {
        $this->id = $id;
    }

    /**
     * @return string
     */
    public function getFirstName()
    {
        return $this->firstName;
    }

    /**
     * @param string $firstName
     */
    public function setFirstName($firstName)
    {
        $this->firstName = $firstName;
    }

}

Now when I try to get the Event Entity the Id is correct. But the $firstName attribute gives me back NULL.

When I change the $firstName attribute to $name, everything works like a charm.

It looks like the @Attribute name annotation doesn't seem to work as it should.

This is still happening in the lastest version.

@rubiodamian Can you copy the class you are using ? thanks

Yes, sorry!

/**
 * Agentes
 * @Rest\Entity(key="agentes")
 */
class Agentes
{
    /**
     * @Rest\Id
     * @Rest\Attribute(name="@id", type="string")
     */
    private $iri;
    /**
     * @var integer
     *
     * @Rest\Attribute(name="id", type="string")
     */
    private $codigo;
    /**
     * @var integer
     *
     * @Rest\Attribute(name="legajo", type="integer")
     */
    private $legajo;
    /**
     * @var array
     *
     * @Rest\Attribute(name="tipoCuil", type="array")
     */
    private $tipo_cuil;

the api responds with tipoCuil (array)
when the Entity attribute is tipoCuil and the field is $tipo_cuil, the field remains null. If i change the field to $tipoCuil the field fills up.

Ok it's probably due to the fact that it's an array (the code is pretty ugly for arrays, because it can be a relation or an array), I will try to look at it tomorrow

@rubiodamian Do you think it's related to #75 or not ?

Maybe it is related because it's in the same part of code i think

Can you see if the bug is still present in the 0.29.0 ?

bug fixed!! 👍

Great, I'm closing this