api-platform / api-platform/core

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

未关闭
#2,782 2 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看
Has a PR Hydra State
主要语言
PHP
星标
2.6k
派生
980
平均合并
2 天 5 小时
30 天内合并 PR
48

描述

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!

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。