question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Circular reference trying to decorate api_platform.swagger.normalizer.documentation

See original GitHub issue

Hello,

I tried to decorate api_platform.swagger.normalizer.documentation, as seen here https://api-platform.com/docs/core/swagger/ and ran into a circular reference :

Circular reference detected for service "App\Swagger\SwaggerDecorator", path: "App\Swagger\SwaggerDecorator -> serializer -> App\Swagger\SwaggerDecorator".

Im using symfony4 and api-pack v1.0.1

services:
    App\Swagger\SwaggerDecorator:
        decorates: 'api_platform.swagger.normalizer.documentation'
        arguments: [ '@App\Swagger\SwaggerDecorator.inner' ]
        autoconfigure: false
namespace App\Swagger;

use Symfony\Component\Serializer\Normalizer\NormalizerInterface;

final class SwaggerDecorator implements NormalizerInterface
{
    private $decorated;

    public function __construct(NormalizerInterface $decorated)
    {
        $this->decorated = $decorated;
    }

    public function normalize($object, $format = null, array $context = [])
    {
        $docs = $this->decorated->normalize($object, $format, $context);


        return $docs;
    }

    public function supportsNormalization($data, $format = null)
    {
        return $this->decorated->supportsNormalization($data, $format);
    }
}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:7

github_iconTop GitHub Comments

2reactions
emilien-pugetcommented, Feb 1, 2018

I found the issue, the service was autowired, i moved the service declaration in service.yaml instead of an imported file

1reaction
ghostcommented, May 18, 2020

Hi @coldic3,

I think it is important to configure decorators after “_defaults” and “App” sections (autoconfigure + autowiring + src classes as services) into services.yaml file :

This configuration works :

# config/services.yaml

parameters:
    ...

services:
    # default configuration for services in *this* file
    _defaults:
        autowire: true      # Automatically injects dependencies in your services.
        autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
        public: false

    # makes classes in src/ available to be used as services
    # this creates a service per class whose id is the fully-qualified class name
    App\:
        resource: '../src/*'
        exclude: '../src/{DependencyInjection,Kernel.php,Entity}'

    # Swagger Decorator
    App\Infrastructure\ApiPlatform\Swagger\SwaggerDecorator:
        decorates: 'api_platform.swagger.normalizer.documentation'

In your example, your external configurations were imported before “_defaults” section and it could not work.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Circular reference problem with decorated service
This is an issue with Symfony Dependency Injection component on version 5.3.7. https://github.com/symfony/symfony/issues/42792.
Read more >
The Serialization Process - API Platform
The API Platform Serializer is extendable. You can register custom normalizers and encoders in order to support other formats. You can also decorate...
Read more >
Problem Swagger with Circular Reference | Layer7 API ...
When I make a cyclic reference in swagger, and try to open the documentation in the developer menu, an error occurs on the...
Read more >
api-platform/api-platform - Gitter
I used SonataMediaBundle and I have a circular reference when I try to get a Gallery Entity. Anyone know how to use SonataMediaBundle...
Read more >
Relating Resources > API Platform - SymfonyCasts
Let's try it! Move over and refresh the docs. But before we look at CheeseListing , let's create a User so we have...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found