Anonymous
Связанное свойство не отображается в схеме POST платформы API.
Сообщение
Anonymous » 24 окт 2024, 12:31
Я пытаюсь создать/опубликовать нового пользователя и его город (уже существующий объект сущности), что представляет собой отношение «многие к одному». Несмотря на то, что я установил группы денормализации, свойство города не отображается, когда я тестирую его в представлении чванства. Есть идеи, что я делаю не так?
Api Platform Swagger:
Код: Выделить всё
{
"email": "string",
"password": "string",
"firstname": "string",
"lastname": "string",
"age": 0,
"availStartDate": "2020-06-21T14:41:38.712Z",
"availEndDate": "2020-06-21T14:41:38.712Z",
"images": [
{
"filename": "string",
"title": "string",
"caption": "string",
"image": "string"
}
]
}
Вот сущность «Пользователь»:
Код: Выделить всё
/**
* @ApiResource(
* iri="http://schema.org/User",
* collectionOperations={"get"={
* "normalization_context"={"groups"={"user:read", "user:item:get"}},
* },
* "post"={
* "validation_groups"={"Default", "create"}
* }},
* itemOperations={"get"={
* "normalization_context"={"groups"={"user:read", "user:item:get"}}
* }, "put"},
* normalizationContext={"groups"={"user:read"}, "swagger_definition_name"="Read"},
* denormalizationContext={"groups"={"user:write"}, "swagger_definition_name"="Write"},
* attributes={
* "pagination_items_per_page"=10
* }
* )
* @ApiFilter(PropertyFilter::class)
*
* @UniqueEntity(fields={"email"})
* @ORM\Entity(repositoryClass=UserRepository::class)
*/
class User implements UserInterface
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
* @Groups({"user:read", "message:read"})
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
* @Groups({"user:read", "user:write", "city:read"})
* @Assert\NotBlank()
* @Assert\Email(
* message = "The email entered is not a valid email."
* )
*/
private $email;
/**
* @ORM\Column(type="string", length=255)
* @Groups({"user:write"})
*
*/
private $password
/**
* @ORM\ManyToOne(targetEntity=City::class, inversedBy="localUsers", fetch="EAGER")
* @ORM\JoinColumn(nullable=true)
* @Groups({"user:read", "user:write"})
*
*/
private $city;
......
public function getCity(): ?City
{
return $this->city;
}
public function setCity(?City $city): self
{
$this->city = $city;
return $this;
}
Подробнее здесь:
https://stackoverflow.com/questions/625 ... ost-schema
1729762292
Anonymous
Я пытаюсь создать/опубликовать нового пользователя и его город (уже существующий объект сущности), что представляет собой отношение «многие к одному». Несмотря на то, что я установил группы денормализации, свойство города не отображается, когда я тестирую его в представлении чванства. Есть идеи, что я делаю не так? Api Platform Swagger: [code]{ "email": "string", "password": "string", "firstname": "string", "lastname": "string", "age": 0, "availStartDate": "2020-06-21T14:41:38.712Z", "availEndDate": "2020-06-21T14:41:38.712Z", "images": [ { "filename": "string", "title": "string", "caption": "string", "image": "string" } ] }[/code] Вот сущность «Пользователь»: [code]/** * @ApiResource( * iri="http://schema.org/User", * collectionOperations={"get"={ * "normalization_context"={"groups"={"user:read", "user:item:get"}}, * }, * "post"={ * "validation_groups"={"Default", "create"} * }}, * itemOperations={"get"={ * "normalization_context"={"groups"={"user:read", "user:item:get"}} * }, "put"}, * normalizationContext={"groups"={"user:read"}, "swagger_definition_name"="Read"}, * denormalizationContext={"groups"={"user:write"}, "swagger_definition_name"="Write"}, * attributes={ * "pagination_items_per_page"=10 * } * ) * @ApiFilter(PropertyFilter::class) * * @UniqueEntity(fields={"email"}) * @ORM\Entity(repositoryClass=UserRepository::class) */ class User implements UserInterface { /** * @ORM\Id() * @ORM\GeneratedValue() * @ORM\Column(type="integer") * @Groups({"user:read", "message:read"}) */ private $id; /** * @ORM\Column(type="string", length=255) * @Groups({"user:read", "user:write", "city:read"}) * @Assert\NotBlank() * @Assert\Email( * message = "The email entered is not a valid email." * ) */ private $email; /** * @ORM\Column(type="string", length=255) * @Groups({"user:write"}) * */ private $password /** * @ORM\ManyToOne(targetEntity=City::class, inversedBy="localUsers", fetch="EAGER") * @ORM\JoinColumn(nullable=true) * @Groups({"user:read", "user:write"}) * */ private $city; ...... public function getCity(): ?City { return $this->city; } public function setCity(?City $city): self { $this->city = $city; return $this; }[/code] Подробнее здесь: [url]https://stackoverflow.com/questions/62500251/related-property-does-not-show-up-in-api-platform-post-schema[/url]