core icon indicating copy to clipboard operation
core copied to clipboard

[Provider] Inconsistent $uriVariables types

Open mpiot opened this issue 3 years ago • 3 comments

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.

mpiot avatar Sep 20 '22 09:09 mpiot

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 avatar Sep 20 '22 11:09 soyuka

@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.

mpiot avatar Sep 20 '22 12:09 mpiot

  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.

soyuka avatar Sep 21 '22 15:09 soyuka

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.

stale[bot] avatar Nov 20 '22 15:11 stale[bot]