[Provider] Inconsistent $uriVariables types
API Platform version(s) affected: 3.0.0
Description
In Providers that implement ProviderInterface the $uriVariables array contains only int variables. If the uriTemplate receive a string, the received value in the provider is 0.
How to reproduce
new Get(
uriTemplate: '/my_items/{id}/workflow/{transitionName<first_transition|second_transition|third_transition>}',
output: MyOutput::class,
provider: MyProvider::class,
)
In the provider, the $uriVariables contains:
[
"id" => 1,
"transitionName" => 0,
]
instead of
[
"id" => 1,
"transitionName" => "first_transition",
]
It seemd the problem come from UriVariablesResolverTrait, at the end call:
if ($this->uriVariablesConverter) {
$context = ['operation' => $operation];
$identifiers = $this->uriVariablesConverter->convert($identifiers, $operation->getClass() ?? $resourceClass, $context);
}
Before it string is string, after it becames integers.
Did you map the uri variable properly? look at the getIdentifierTypes we need to map your uri variable to a property to find out which type it is.
@soyuka Thanks for your answer.
I've not map uriVatiables, not seen infos about it. Something like it ? I've only find something about Limk() for Subresources in the documentation.
uriVariables: [
'transitionName' => new ApiProperty(types: ['string']),
],
It seems the only one usable is Link, but in my case that param is not a part of the Entity, just a route params used in Processor.
uriVariables: [
'transitionName' => new ApiProperty(identifiers: ['transitionName']),
],
then in the class:
class .. {
public string $transitionName;
}
We should add a way to put this directly to the metadata though.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.