Description
Hi!
Apologies if I'm misunderstanding something :); Suppose you have this situation:
/**
* @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:
{
"@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:
"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!