Core: [2.5] Problem with the new swagger version configuration

Created on 27 Sep 2019  路  4Comments  路  Source: api-platform/core

Dear guys, by default when swagger is not enabled, the version are set to empty

https://github.com/api-platform/core/blob/9799193466b0059fd82254798e9a06f32d8ef2f4/src/Bridge/Symfony/Bundle/DependencyInjection/Configuration.php#L59-L68

Therefore the json_schema.xml is not loaded and the api_platform.swagger.versions parameter is not set at all.

https://github.com/api-platform/core/blob/9799193466b0059fd82254798e9a06f32d8ef2f4/src/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php#L315-L328

The thing is that it will throw in the ContainerBuilder You have requested a non-existent service "api_platform.json_schema.schema_factory".

That because the service is decorated in hydra.xml :

https://github.com/api-platform/core/blob/9799193466b0059fd82254798e9a06f32d8ef2f4/src/Bridge/Symfony/Bundle/Resources/config/hydra.xml#L81-L83

In the same way, the api_platform.action.documentation is requiring the api_platform.swagger.versions parameter (which hasn't been defined) leads to the following error : The service "api_platform.action.documentation" has a dependency on a non-existent parameter "api_platform.swagger.versions". Did you mean this: "api_platform.version

https://github.com/api-platform/core/blob/9799193466b0059fd82254798e9a06f32d8ef2f4/src/Bridge/Symfony/Bundle/Resources/config/api.xml#L245
The on-invalid="null" doesn't seems to have any impact...

Proposed solution

Set the versions to the default array [2, 3] even when swagger is not enabled because obviously it is used anyway.

I can do the PR off course but I just wanted to make sure/understand the reason to empty this values in every cases...

bug

Most helpful comment

Note to reproduce:

    enable_swagger: false
    enable_swagger_ui: false

All 4 comments

Note to reproduce:

    enable_swagger: false
    enable_swagger_ui: false

Proposed solution:

  • The api_platform.hydra.json_schema.schema_factory service should be ~moved to json_schema.xml~ removed when the api_platform.json_schema.schema_factory service is not available.
  • The api_platform.swagger.versions parameter should be set to null when Swagger support is disabled.

This is what I tried to do @teohhanhui, still I wanted a failing test case and it's hard to reproduce programatically in the ApiPlatformExtensionTest :|.
We def need this quickfix before 2.5 stable imo.

still I wanted a failing test case and it's hard to reproduce programatically in the ApiPlatformExtensionTest

We already have tests for disabling GraphQL support etc., I think they're not too dissimilar?

Was this page helpful?
0 / 5 - 0 ratings