api-platform / api-platform/core

Field incorrectly shows up as hydra @context but is not included in @vocab

Đang mở
#2,782 2 bình luận 1 reaction 0 người được giao Xem trên GitHub
Has a PR Hydra State
Ngôn ngữ chính
PHP
Star
2.6k
Fork
980
Merge trung bình
2 ngày 5 giờ
Pull request đã merge (30 ngày)
48

Mô tả

Hi!

Apologies if I'm misunderstanding something :); Suppose you have this situation:

```php
/**
* @ApiResource(
* normalizationContext={"groups"={"cheese_listing:read"}},
* denormalizationContext={"groups"={"cheese_listing:write"}
* )
* @ORM\Entity()
*/
class CheeseListing
{
// ...

private $isPublished;

public function getIsPublished(): ?bool
{
return $this->isPublished;
}

public function setIsPublished(bool $isPublished): self
{
$this->isPublished = $isPublished;
}
}
```

This has an `isPublished` field, which is *not* included in the normalization or denormalization context. This field is simply not part of the API in any way. However, if you go to: https://localhost:8000/api/contexts/cheese_listings, it *is* present:

```json
{
"@context": {
"@vocab": "https://localhost:8000/api/docs.jsonld#",
"hydra": "http://www.w3.org/ns/hydra/core#",
"isPublished": "cheese_listings/isPublished"
}
}
```

I believe the `isPublished` field should *not* be there. And, to further my point, if you go to https://localhost:8000/api/docs.jsonld to look at the vocab, there is *no* `hydra:property` for `cheese_listings/isPublished`. In other words, the `isPublished` property in the hydra `@context` is referring to a property that doesn't exist anywhere.

**Note**: If I'm correct that the `isPublished` property should not be added to the `cheese_listings` context, things get more interesting if you add a filter referencing the field:

```
* @ApiFilter(BooleanFilter::class, properties={"isPublished"})
```

What should happen here? This adds a `hydra:search` to the collection resource like this:

```json
"hydra:search": {
"@type": "hydra:IriTemplate",
"hydra:template": "/api/cheeses{?isPublished}",
"hydra:variableRepresentation": "BasicRepresentation",
"hydra:mapping": [
{
"@type": "IriTemplateMapping",
"variable": "isPublished",
"property": "isPublished",
"required": false
}
]
}
```

Should the presence of this filter *now* cause the property to be defined in https://localhost:8000/api/docs.jsonld - because it's referenced under the `hydra:mapping`?

Thanks!

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.