core icon indicating copy to clipboard operation
core copied to clipboard

IriConverterParameterProvider / HeaderParameter not working

Open JuanLuisGarciaBorrego opened this issue 3 months ago • 0 comments

API Platform version(s) affected: 4.2.3 (symfony 7.3.5)

Description
IriConverterParameterProvider does not work correctly with HeaderParameter in GetCollection operations. Even if a HeaderParameter is defined with this provider and a valid IRI is sent in the request header, the converted entity is not injected into _api_header_parameters in the context. As a result, in the collection provider, the entity is always null, even when the IRI is valid.

(View image) In the parameters, it appears under key 0: at position 0 there is the string "organization", and at position 1 there is the HeaderParameter which, in its extraProperties, contains the organization object — but I can’t manage to actually access it.

How to reproduce

GET /staffs
Header:  organization: /organizations/f2ba46cd-8009-4c7b-8cc4-a709befaa958
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\HeaderParameter;
use ApiPlatform\State\ParameterProvider\IriConverterParameterProvider;
use App\Entity\Organization;
use App\Entity\Staff;

#[ApiResource(operations: [
    new GetCollection(
        uriTemplate: '/staffs',
        parameters: [
            new HeaderParameter(
                key: 'organization',
                provider: IriConverterParameterProvider::class,
                extraProperties: [
                    'resource_class' => Organization::class,
                    'fetch_data' => true,
                ]
            )
        ],
        provider: [Staff::class, 'provideForOrganization'],
    )
])]
class Staff
{
    public static function provideForOrganization($operation, array $uriVariables = [], array $context = []): iterable
    {
        // Always null in GetCollection
        dd($organization); show object , view imagen dd 
         dd($operation->getParameters()->get('organization')); //= null
    }
}

Using Get operation same thing happens

Possible Solution
no

Additional Context
Quiero utilizar esta opción porque parece más limpia que crear subrecursos para aplicaciones multinenant.

Image

JuanLuisGarciaBorrego avatar Nov 04 '25 19:11 JuanLuisGarciaBorrego