New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JsonLD: plain array converted to hydra:member inside Get operation in custom StateProvider #6304
Comments
Can you show the provider? also why is this typed array if it returns a string?
|
no, it returns array: json_decode('{"googleMaps":{"aggregate":"4.4"}}',true); Provider code is complicated, as it resolves concrete stores set from config, and then convert each of them to public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|array|null
{
if(!array_key_exists('uuid',$uriVariables)){
throw new \RuntimeException('No uuid provided');
}
$uuid = UuidV4::fromString($uriVariables['uuid']);
/** @var StoreInterface $store */
foreach ($this->stores as $store) {
if (!$store->getUuid()->equals($uuid)) {
continue;
}
$store->addRating(GoogleMapsRatingProvider::NAME, $this->googleRatingProvider->getAggregateRating($store));
break;
}
$storeDto = StoreDto::createFromStore($store);
return $storeDto;
} |
Does adding |
I have rewritten code to use ApiResource directly, with no DTO use at all, and it works now as expected. |
it does, but then jsonLd context lost (no // apiResource
#[Get(
uriTemplate: 'stores/uuid/{uuid}',
uriVariables: ['uuid'],
output: StoreDto::class,
provider: StoreByUuidProvider::class
)]
class Store {/* ... */} response: {
...
"ratings": {
"googleMaps": {
"aggregate": "4.4"
}
}
} |
API Platform version(s) affected: "api-platform/core": "^3.1"
Description
By some reason, same dto inside
CollectionProvider
andGetProvider
have different output.I have custom resource
Store
:Both state provider's return same
StoreDTO
(array of DTO or single DTO):Inside
StoreCollectionProvider
i return array of DTO's, i get following response (notice howratings
field rendered):If i return same DTO inside
StoreByUuidProvider
, by some reason i getratings
rendered as collection:Expected
ratings
field will be the rendered the same forStoreCollectionProvider
andStoreByUuidProvider
In
StoreByUuidProvider
I expected it to be like this:Actual
In
StoreByUuidProvider
I got this:I tried to modify
#[ApiProperty]
attribute overratings
(addingreadableLink: false
, overridingjsonLd
/openapi
contexts) - no luckThe text was updated successfully, but these errors were encountered: