Hi!
with the 2.4beta I got "No encoder found for format "html". for controllers and actions that has nothing to do with api platform but are trying to use the Sension/FrameworkExtraBundle @template annotations.
https://symfony.com/doc/master/bundles/SensioFrameworkExtraBundle/annotations/view.html
Trace
Symfony\Component\Serializer\Exception\RuntimeException:
No encoder found for format "html".
at vendor/symfony/serializer/Encoder/ChainEncoder.php:101
at Symfony\Component\Serializer\Encoder\ChainEncoder->getEncoder('html', array())
(vendor/symfony/serializer/Encoder/ChainEncoder.php:40)
at Symfony\Component\Serializer\Encoder\ChainEncoder->encode(array(), 'html', array())
(vendor/symfony/serializer/Serializer.php:301)
at Symfony\Component\Serializer\Serializer->encode(array(), 'html')
(vendor/api-platform/core/src/EventListener/SerializeListener.php:115)
at ApiPlatform\Core\EventListener\SerializeListener->serializeRawData(object(GetResponseForControllerResultEvent), object(Request), array())
(vendor/api-platform/core/src/EventListener/SerializeListener.php:57)
at ApiPlatform\Core\EventListener\SerializeListener->onKernelView(object(GetResponseForControllerResultEvent), 'kernel.view', object(TraceableEventDispatcher))
(vendor/symfony/event-dispatcher/Debug/WrappedListener.php:115)
at Symfony\Component\EventDispatcher\Debug\WrappedListener->__invoke(object(GetResponseForControllerResultEvent), 'kernel.view', object(TraceableEventDispatcher))
(vendor/symfony/event-dispatcher/EventDispatcher.php:212)
at Symfony\Component\EventDispatcher\EventDispatcher->doDispatch(array(object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener)), 'kernel.view', object(GetResponseForControllerResultEvent))
(vendor/symfony/event-dispatcher/EventDispatcher.php:44)
at Symfony\Component\EventDispatcher\EventDispatcher->dispatch('kernel.view', object(GetResponseForControllerResultEvent))
(vendor/symfony/event-dispatcher/Debug/TraceableEventDispatcher.php:145)
at Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher->dispatch('kernel.view', object(GetResponseForControllerResultEvent))
(vendor/symfony/http-kernel/HttpKernel.php:155)
at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), 1)
(vendor/symfony/http-kernel/HttpKernel.php:67)
at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), 1, true)
(vendor/symfony/http-kernel/Kernel.php:198)
at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
(public/index.php:25)
Do you have any suggestion or workaround for this issue?
Thanks
It'll be fixed in the next beta. Could you try out #2592 and let us know if it fixes your problem?
@teohhanhui unfortunately it doesn't fix it. Same error with same trace.
I did the following in vendor/api-platform:
rm core
git clone https://github.com/teohhanhui/api-platform-core.git core
cd core
git checkout -b test remotes/origin/refactor/separate-item-normalizer-non-resource
Okay, sounds like it's a separate issue then.
Just looked into it. It's because of https://github.com/api-platform/core/blob/5f6e6c9f7730bd677547619a9b930e7540835b37/src/EventListener/SerializeListener.php#L57
As a workaround, you can set the _api_respond attribute to false on the route.
And perhaps we will think of a way to fix this...
I've created a repo for the bug: https://github.com/mmarton/api-platform-2591
I need to set every non api-platform route to _api_respond false? Is there a way to set it default false, and set the only one /api api-platform related route to true?
We're thinking of making it opt-in instead of opt-out, something like:
api_platform:
opt_in_listeners: true
and triggering a deprecation if it's not set to true.
That would help a lot of us.
The FrameworkExtraBundle is part of the default symfony/website-skeleton install,
https://github.com/symfony/website-skeleton/blob/master/composer.json
Indeed, sometimes we make wrong choices when designing something. :see_no_evil:
But hopefully we'll fix it!
I've tried setting api-respond to false:
/**
* @Route("/")
* @Route("/not-api", defaults={"_api_respond"=false})
* @Template()
*/
public function index()
{
return ['foo' => 'bar'];
}
There is no exception this time, but api-platform still tries to respond to the "/not-api" route and I end up with the main swagger page and not my view.
Uhh... You're right. :see_no_evil:
I'm working on a fix.
@mmarton Can you try #2601 and let us know if it fixes the problem?
@teohhanhui it works. Thanks for your help. :+1:
I encountered the same issue (2.4-beta.2) and can confirm that switching to 2.4.x-dev fixes this issue. Looking forward to the next api-platform release!
thanks for the tests guys much appreciated!
Most helpful comment
thanks for the tests guys much appreciated!