api-platform / api-platform/core

Symfony Serializer polution : Unable to generate an IRI

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

Mô tả

**API Platform version(s) affected**: 2.5.5

**Description**
The APIPlatform serializer is used even outside ou APIPlatform and creates problem when serializing object using the Symfony Serializer

**How to reproduce**
- Create an entity marked as an API Resource
- Create a new Instance (not persisted) and try to serialize it.

```php
// In a Symfony Controller, outside of the API Platform scope
$fake = new Entity();

// Unable to generate an IRI for "Entity".
$serializer->serialize(
$fake,
'json',
['groups' => ['nofields']]
);

// But if we disable iri, using iri = false, it works
$serializer->serialize(
$fake,
'json',
['groups' => ['nofields'], 'iri' => false]
);
```

**Possible Solution**
At the moment the user has to edit his code to add "iri" into the context if the entity is a non persisted object (this is not ideal).
I didn't dive deep enough to offer a specific solution but I think a specific context should be used for API Platform to avoid poluting the Symfony serialization outside of the API.

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.