OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.75k stars 6.56k forks source link

[BUG] [PHP] PSR-18 generator has the wrong argument to selectHeaders #17388

Open bencromwell opened 10 months ago

bencromwell commented 10 months ago

Bug Report Checklist

Description

Had this issue in a generated client and was able to find that it's present in the example client code for the PetStore API.

https://github.com/OpenAPITools/openapi-generator/blob/master/samples/client/petstore/php/psr-18/lib/HeaderSelector.php#L38

The 2nd argument to HeaderSelector is a string.

If you look at the usages on it you'll find for example, https://github.com/OpenAPITools/openapi-generator/blob/master/samples/client/petstore/php/psr-18/lib/Api/StoreApi.php#L340

showing that it tries to pass an array as the 2nd argument to selectHeaders. This fails when you try to call any API method, with:

PHP Fatal error: Uncaught TypeError: <your namespace>\HeaderSelector::selectHeaders(): Argument #2 ($contentType) must be of type string, array given

openapi-generator version

Latest master

OpenAPI declaration file content or url

As per the generated sample in the project

Generation Details
Steps to reproduce

Generate the sample PetStore client with the PSR-18 library.

Related issues/PRs
Suggest a fix
wing328 commented 10 months ago

thanks for reporting the issue

what about php-nextgen client generator? does it have the same issue?

bencromwell commented 10 months ago

thanks for reporting the issue

what about php-nextgen client generator? does it have the same issue?

It doesn't seem to.