Skip to content
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

Route with custom uriTemplate stopped working after upgrade to 3.0.5 #5234

Closed
acirulis opened this issue Nov 27, 2022 · 4 comments
Closed

Route with custom uriTemplate stopped working after upgrade to 3.0.5 #5234

acirulis opened this issue Nov 27, 2022 · 4 comments

Comments

@acirulis
Copy link
Contributor

acirulis commented Nov 27, 2022

API Platform version(s) affected: 3.0.5 - 3.0.6

Description
I have a resource with following config:

#[ApiResource(
    shortName: 'Inventory',
    operations: [
        new GetCollection(
            uriTemplate: '/warehouses/{warehouseId}/inventory',
        ),
        new Get(
            uriTemplate: '/warehouses/{warehouseId}/inventory/{id}',
        ),
    ],
    uriVariables: [
        'warehouseId' => new Link(
            fromProperty: 'id',
            fromClass: WarehouseResource::class,
        )
    ],
    normalizationContext: ['groups' => ['inventory:read']],
    denormalizationContext: ['groups' => ['inventory:write']],
    provider: InventoryResourceProvider::class,
)]
...

After upgrade to v3.0.5, GetCollection endpoint dies with error ( "Unable to generate an IRI for the item of type "App\ApiResource\InventoryResource"",)

Stack:

"Symfony\Component\Routing\Exception\MissingMandatoryParametersException: Some mandatory parameters are missing ("id") to generate a URL for route "_api_/warehouses/{warehouseId}/inventory/{id}_get". in /var/www/html/api/vendor/symfony/routing/Generator/UrlGenerator.php:175
Stack trace:
#0 /var/www/html/api/vendor/symfony/routing/Generator/CompiledUrlGenerator.php(67): Symfony\Component\Routing\Generator\UrlGenerator->doGenerate(Array, Array, Array, Array, Array, '_api_/warehouse...', 1, Array, Array)
#1 /var/www/html/api/vendor/symfony/routing/Router.php(225): Symfony\Component\Routing\Generator\CompiledUrlGenerator->generate('_api_/warehouse...', Array, 1)
#2 /var/www/html/api/vendor/api-platform/core/src/Symfony/Routing/Router.php(102): Symfony\Component\Routing\Router->generate('_api_/warehouse...', Array, 1)
#3 /var/www/html/api/vendor/api-platform/core/src/Symfony/Routing/IriConverter.php(187): ApiPlatform\Symfony\Routing\Router->generate('_api_/warehouse...', Array, 1)
#4 /var/www/html/api/vendor/api-pl"

Additional Context
Worked before 3.0.5

@Aerendir
Copy link

May be linked to #5235

@soyuka
Copy link
Member

soyuka commented Nov 28, 2022

nvm: #5235 and #5237

@soyuka soyuka pinned this issue Nov 28, 2022
@soyuka
Copy link
Member

soyuka commented Nov 28, 2022

Sorry about this, update to 3.0.6.

@soyuka soyuka closed this as completed Nov 28, 2022
@acirulis
Copy link
Contributor Author

Sorry, after update to 3.0.6 problem still exists @soyuka
$id is my default identifier #[ApiProperty(identifier: true)] so I thought that it shouldn't be configured separately.

Without your suggestion:

"Unable to generate an IRI for the item of type "App\ApiResource\InventoryResource"",

"Symfony\Component\Routing\Exception\MissingMandatoryParametersException: Some mandatory parameters are missing ("id") to generate a URL for route "_api_/warehouses/{warehouseId}/inventory/{id}_get". in /var/www/html/api/vendor/symfony/routing/Generator/UrlGenerator.php:175
Stack trace:
#0 /var/www/html/api/vendor/symfony/routing/Generator/CompiledUrlGenerator.php(67): Symfony\Component\Routing\Generator\UrlGenerator->doGenerate(Array, Array, Array, Array, Array, '_api_/warehouse...', 1, Array, Array)
#1 /var/www/html/api/vendor/symfony/routing/Router.php(225): Symfony\Component\Routing\Generator\CompiledUrlGenerator->generate('_api_/warehouse...', Array, 1)
#2 /var/www/html/api/vendor/api-platform/core/src/Symfony/Routing/Router.php(102): Symfony\Component\Routing\Router->generate('_api_/warehouse...', Array, 1)
#3 /var/www/html/api/vendor/api-platform/core/src/Symfony/Routing/IriConverter.php(187): ApiPlatform\Symfony\Routing\Router->generate('_api_/warehouse...', Array, 1)
#4 /var/www/html/api/vendor/api-pl"

With your suggestion: ( 'id' => new Link(identifiers: ['id'], fromClass: self::class))

"Invalid identifier value or configuration.",

"ApiPlatform\Exception\InvalidIdentifierException: Parameter "id" not found, check the identifiers configuration. in /var/www/html/api/vendor/api-platform/core/src/State/UriVariablesResolverTrait.php:39
Stack trace:
#0 /var/www/html/api/vendor/api-platform/core/src/Symfony/EventListener/ReadListener.php(87): ApiPlatform\Symfony\EventListener\ReadListener->getOperationUriVariables(Object(ApiPlatform\Metadata\GetCollection), Array, 'App\\ApiResource...')
#1 /var/www/html/api/vendor/symfony/event-dispatcher/Debug/WrappedListener.php(115): ApiPlatform\Symfony\EventListener\ReadListener->onKernelRequest(Object(Symfony\Component\HttpKernel\Event\RequestEvent), 'kernel.request', Object(Symfony\Component\HttpKernel\Debug\TraceableEventDispatcher))
#2 /var/www/html/api/vendor/symfony/event-dispatcher/EventDispatcher.php(230): Symfony\Component\EventDispatcher\Debug\WrappedListener->__invoke(Object(Symfony\Component\HttpKernel\Event\RequestEvent), 'kernel.request', Object(Symfony\Component\HttpKernel\Debug\TraceableEven"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants