api-platform / core

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

[3.3] Accept header validation no longer works with event_listeners_backward_compatibility_layer set to false #6340

Closed JarJak closed 4 months ago

JarJak commented 5 months ago

API Platform version(s) affected: 3.3.0

Description
in version 3.2.x Accept header validation worked correctly with event bc layer set to false. Now it needs to be enabled to work. Without enabling, \ApiPlatform\Symfony\EventListener\AddFormatListener isn't even called.

How to reproduce Set event_listeners_backward_compatibility_layer config variable to true Create Api Resource like this one:

#[GetCollection(
    outputFormats: ['json']
)]
class Test
{
    public string $foo = 'bar';
}

Call the API to get the resource with Accept: application/vnd.api+json header. Result will be:

      {
          "errors": [
              {
                  "status": "406",
                  "detail": "Requested format \"application/vnd.api+json\" is not supported. Supported MIME types are \"application/json\"."
              }
          ]
      }

Now, change event_listeners_backward_compatibility_layer config variable to false and redo the Api Call.

Expected result Still 406 error.

Actual result Regular 200 response.

soyuka commented 5 months ago

Not sure I understand, what's the value of use_symfony_listeners?

soyuka commented 5 months ago

I'm not sure I tried that at https://github.com/soyuka/repro6340 it's probably the same as https://github.com/api-platform/core/issues/6343

soyuka commented 4 months ago

closing as I think that this is fixed, lmk if that's not the case.

JarJak commented 4 months ago

@soyuka I haven't set specific value of use_symfony_listeners so I think it defaults to false. Also I don't use a custom controller or custom event listener in my case so I don't think it is related to #6343

JarJak commented 4 months ago

After upgrading API Plaftorm core to 3.3.2 and setting use_symfony_listeners: true I get another error:

Could not resolve argument $data of \"api_platform.action.placeholder::__invoke()\", maybe you forgot to register the controller as a service or missed tagging it with the \"controller.service_arguments\"?

It is 500 error on operation defined as:

        new Delete(
            openapi: new Operation(
                responses: [
                    204 => new Response(
                        content: null
                    ),
                    401 => new Response(
                        description: 'Unauthorized',
                    ),
                ],
            ),
            read: false,
            processor: DeleteProcessor::class
        ),

After setting it back to false this error is gone, but the main issue is still unresolved. For now the only combination of settings which works fine on version 3.3.2 is:

    event_listeners_backward_compatibility_layer: true
    use_symfony_listeners: false