api-platform / core

The server component of API Platform: hypermedia and GraphQL APIs in minutes
https://api-platform.com
MIT License
2.39k stars 846 forks source link

Attempted to call an undefined method named "withParameterName" of class "ApiPlatform\Metadata\ApiProperty" #6383

Closed jusdepixel closed 1 month ago

jusdepixel commented 1 month ago

Hello everybody !

API Platform version(s) affected: 3.3.3

I have this resource :

#[ApiResource(
    uriTemplate: '/compta/dossiers/{dosId}/journals/{JrnId}',
    shortName: 'Journal',
    operations: [
        new Post(
            uriTemplate: '/compta/dossiers/{dosId}/journals'
        ),
        new Put(),
        new Delete(),
    ],
    uriVariables: [
        'jrnId' => new ApiProperty(identifier: true),
        'dosId' => new ApiProperty(identifier: false)
    ],
    provider: JournalProvider::class,
    processor: JournalProcessor::class,
)]

I have this error with ApiProperty : Attempted to call an undefined method named "withParameterName" of class "ApiPlatform\Metadata\ApiProperty".

soyuka commented 1 month ago

uriVariables should be:

     * @param array<string, Link>|array<string, mixed[]>|string[]|string|null        $uriVariables

Try

#[ApiResource(
    uriTemplate: '/compta/dossiers/{dosId}/journals/{JrnId}',
    shortName: 'Journal',
    operations: [
        new Post(
            uriTemplate: '/compta/dossiers/{dosId}/journals'
        ),
        new Put(),
        new Delete(),
    ],
    uriVariables: [
        'jrnId',
        'dosId'
    ],
    provider: JournalProvider::class,
    processor: JournalProcessor::class,
)]