[2.5] Problem with the new swagger version configuration
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...
Note to reproduce:
enable_swagger: false
enable_swagger_ui: false
Proposed solution:
- The
api_platform.hydra.json_schema.schema_factoryservice should be ~moved tojson_schema.xml~ removed when theapi_platform.json_schema.schema_factoryservice is not available. - The
api_platform.swagger.versionsparameter should be set tonullwhen 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?