api-platform / core

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

"Unable to generate IRI" error after upgrade to 3.3 #6494

Open cristi-contiu opened 2 months ago

cristi-contiu commented 2 months ago

API Platform version(s) affected: 3.3.0 and above

Description
After upgrading from 3.2 to 3.3, we started getting the "Unable to generate IRI" error for ApiResources without ApiProperty identifier.

The error comes from the RespondProcessor:115 (called from the MainController:111) not being able to generate an IRI to be used in the Content-Location header.

Generating an IRI from the JsonLd\Serializer\ItemNormalizer:127 works OK (as before), because it also passess the $context to the Symfony IriConverter, so it's able to extract the identifier from the URI variables.

How to reproduce
The error is thrown when using an ApiResource that has no ApiProperty identifier, but has an identifier in the URI.

Possible Solution
Pass the operation and context when generating the IRI in the RespondProcessor, so that it matches the one generated for JsonLd in the body (@id).

If it's mandatory for ApiResources to have ApiProperty identifiers starting from a specific ApiPlatform version, please let me know.

soyuka commented 1 month ago

If it's mandatory for ApiResources to have ApiProperty identifiers starting from a specific ApiPlatform version, please let me know.

ApiResource must have an identifier if there's one in the URI Template.