api-platform / api-platform/core

Content Type header has side effects on POST requests

Đang mở
#8,058 1 bình luận 0 reaction 0 người được giao Xem trên GitHub
doctrine Serializer
Ngôn ngữ chính
PHP
Star
2.6k
Fork
980
Merge trung bình
2 ngày 2 giờ
Pull request đã merge (30 ngày)
51

Mô tả

**Description**
I'm trying to POST a resource with id generated by the client (uuid). Doing so fails with [Content-Type: application/json] but works with [Content-Type: application/ld+json]

**How to reproduce**
Using Api Platform v3.0 with the following entity:

```php
'place:write'])
])]
class Place
{
#[ORM\Id]
#[ORM\Column(length: 255)]
#[Groups(['place:write'])]
private string $id;

...

public function __construct(string $id)
{
$this->id = $id;
}

public function getId(): string
{
return $this->id;
}

...
}

```

Curl request that works:
```
curl -kX 'POST' \
'https://localhost/places' \
-H 'accept: application/json' \
-H 'Content-Type: application/ld+json' \
-d '{"id": "0b450e16-6260-4502-9313-feff93b20d18","stuff": "abd"}'
```

Curl request that fails:
```
curl -kX 'POST' \
'https://localhost/places' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{"id": "0b450e16-6260-4502-9313-feff93b20d18","stuff": "abd"}'
```

**Possible Solution**
Setting "Content-Type" from client accordingly is a temporary fix, but IMHO switching for application/json should not fail.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.