2017-08-14 6 views
1

別のエンティティから継承するエンティティを持つ場合、プラットフォームAPI(https://api-platform.com/)に問題があります。たとえば、Userエンティティから継承するWorkerエンティティです。 Platform APIドキュメントに行くと、すべてのWorkerプロパティがUserクラスに表示されます。APIプラットフォームを使用する継承エンティティ


説明よりもスキーマが優れています。ここに私の2つのエンティティと問題のドキュメントの結果

/** 
* User 
* 
* @ORM\Table(name="user") 
* @ORM\InheritanceType("SINGLE_TABLE") 
* @ORM\DiscriminatorColumn(name="discr", type="string") 
* @ORM\DiscriminatorMap({"user" = "User", "worker" = "Worker"}) 
* @ApiResource 
* 
*/ 
class User 
{ 
/** 
* @var int 
* 
* @ORM\Column(name="id", type="integer") 
* @ORM\Id 
* @ORM\GeneratedValue(strategy="AUTO") 
*/ 
protected $id; 

/** 
* @var string 
* 
* @ORM\Column(name="lastname", type="string", length=255) 
*/ 
protected $lastname; 

/** 
* @var string 
* 
* @ORM\Column(name="firstname", type="string", length=255) 
*/ 
protected $firstname; 


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

/** 
* Set lastname 
* 
* @param string $lastname 
* @return User 
*/ 
public function setLastname($lastname) 
{ 
    $this->lastname = $lastname; 

    return $this; 
} 

/** 
* Get lastname 
* 
* @return string 
*/ 
public function getLastname() 
{ 
    return $this->lastname; 
} 

/** 
* Set firstname 
* 
* @param string $firstname 
* @return User 
*/ 
public function setFirstname($firstname) 
{ 
    $this->firstname = $firstname; 

    return $this; 
} 

/** 
* Get firstname 
* 
* @return string 
*/ 
public function getFirstname() 
{ 
    return $this->firstname; 
} 
} 


/** 
* Worker 
* 
* @ApiResource 
*/ 
class Worker extends User 
{ 

/** 
* @var \DateTime 
* 
* @ORM\Column(name="birthday", type="datetime") 
* @Assert\NotNull() 
* @Assert\DateTime() 
*/ 
private $birthday; 

/** 
* @var string 
* 
* @ORM\Column(name="mobilePhone", type="string", length=255, nullable=true) 
*/ 
private $mobilePhone; 

/** 
* @return \DateTime 
*/ 
public function getBirthday(): \DateTime 
{ 
    return $this->birthday; 
} 

/** 
* @param \DateTime $birthday 
*/ 
public function setBirthday(\DateTime $birthday) 
{ 
    $this->birthday = $birthday; 
} 

/** 
* @return string 
*/ 
public function getMobilePhone(): string 
{ 
    return ($this->mobilePhone == null) ? '' : $this->mobilePhone; 
} 

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

} 

ここに問題があります。 Worker子クラスのプロパティがUserクラスのモデルに表示されることがわかります。そしてThe result to see the problem

があなたのシリアル化に深みの追加のレベルに行くために必要なすべての

+0

私は注釈付きちょうどこのPHPファイルを持っている –

+0

(このエンドポイントのために)あなたのAPIドキュメントアノテーションをしてください示しています。これがどのように見えるJMS Serialization bundle

、 – ascodix

答えて

0

ありがとうござい

ワーカーエンティティのプロパティが含まれている私は、POSTメソッドを送信してテストするとき、それはUserエンティティを返すことレスポンスでシリアライズされるワーカー・プロパティをサポートします。私は具体的にあなたの実装のためにそれを動作させる方法がわかりません。

/** 
* Get the Birthday.. 
* 
* @MaxDepth(2) 
* @return \DateTime 
*/ 
public function getBirthday(): \DateTime 
{ 
    return $this->birthday; 
} 
関連する問題