Open f1amy opened 9 months ago
use event_listeners_backward_compatibility_layer: true
please not that the name is quite misleading event listeners will always be supported. You can decorate our processors in 3.2 if you don't want to use listeners or just keep it like that.
@soyuka, Oh, did not know that. But still, can we fix the documentation at https://api-platform.com/docs/core/form-data/ to note that it is only working with event_listeners_backward_compatibility_layer: true
, which will be false by default in 4.0?
Yes definitely, actually we should provide a documentation on how to do this with processors! I'll open an issue there thanks!
API Platform version(s) affected: 3.2.7
Description
After upgrading to v3.2 and switching
event_listeners_backward_compatibility_layer
tofalse
, the use of decoratedDeserializeListener
to supportapplication/x-www-form-urlencoded
we relied on stopped working. We followed the current actual guide on https://api-platform.com/docs/core/form-data/ to know if there is a fix, but it seems the guide has not been updated for 3.2.How to reproduce
Use the following config:
config/packages/api_platform.yaml
Add the following listener:
\App\Infrastructure\EventListener\ApiPlatform\DeserializeListener
namespace App\Infrastructure\EventListener\ApiPlatform;
use ApiPlatform\Serializer\SerializerContextBuilderInterface; use ApiPlatform\Symfony\EventListener\DeserializeListener as DecoratedListener; use ApiPlatform\Symfony\Util\RequestAttributesExtractor; use Symfony\Component\DependencyInjection\Attribute\AsDecorator; use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
[AsDecorator('api_platform.listener.request.deserialize')]
[AutoconfigureTag(name: 'kernel.event_listener', attributes: ['event' => 'kernel.request', 'method' => 'onKernelRequest', 'priority' => 2])]
class DeserializeListener { private DecoratedListener $decorated; private DenormalizerInterface $denormalizer; private SerializerContextBuilderInterface $serializerContextBuilder;
}
curl -X POST --location "https://localhost/api/something" \ -H "accept: application/ld+json" \ -H "Content-Type: application/x-www-form-urlencoded" \ -d 'leads%5Bstatus%5D%5B0%5D%5Bid%5D=string&leads%5Bstatus%5D%5B0%5D%5Bstatus_id%5D=string&leads%5Bstatus%5D%5B0%5D%5Bold_status_id%5D=string&leads%5Bstatus%5D%5B0%5D%5Bpipeline_id%5D=string'
HTTP/1.1 415 Unsupported Media Type { "@id": "\/api\/errors\/415", "@type": "hydra:Error", "title": "An error occurred", "detail": "The content-type \"application\/x-www-form-urlencoded\" is not supported. Supported MIME types are \"application\/ld+json\", \"application\/hal+json\", \"application\/vnd.api+json\", \"application\/json\".", "status": 415, "type": "\/errors\/415", "trace": [ { "file": "\/srv\/app\/vendor\/api-platform\/core\/src\/State\/Provider\/ContentNegotiationProvider.php", "line": 48, "function": "getInputFormat", "class": "ApiPlatform\State\Provider\ContentNegotiationProvider", "type": "->" }, { "file": "\/srv\/app\/vendor\/api-platform\/core\/src\/Symfony\/Controller\/MainController.php", "line": 82, "function": "provide", "class": "ApiPlatform\State\Provider\ContentNegotiationProvider", "type": "->" }, { "file": "\/srv\/app\/vendor\/symfony\/http-kernel\/HttpKernel.php", "line": 181, "function": "__invoke", "class": "ApiPlatform\Symfony\Controller\MainController", "type": "->" }, { "file": "\/srv\/app\/vendor\/symfony\/http-kernel\/HttpKernel.php", "line": 76, "function": "handleRaw", "class": "Symfony\Component\HttpKernel\HttpKernel", "type": "->" }, { "file": "\/srv\/app\/vendor\/symfony\/http-kernel\/Kernel.php", "line": 197, "function": "handle", "class": "Symfony\Component\HttpKernel\HttpKernel", "type": "->" }, { "file": "\/srv\/app\/vendor\/symfony\/runtime\/Runner\/Symfony\/HttpKernelRunner.php", "line": 35, "function": "handle", "class": "Symfony\Component\HttpKernel\Kernel", "type": "->" }, { "file": "\/srv\/app\/vendor\/autoload_runtime.php", "line": 29, "function": "run", "class": "Symfony\Component\Runtime\Runner\Symfony\HttpKernelRunner", "type": "->" }, { "file": "\/srv\/app\/public\/index.php", "line": 5, "function": "require_once" } ], "hydra:title": "An error occurred", "hydra:description": "The content-type \"application\/x-www-form-urlencoded\" is not supported. Supported MIME types are \"application\/ld+json\", \"application\/hal+json\", \"application\/vnd.api+json\", \"application\/json\"." }