openapi-generator
openapi-generator copied to clipboard
feat(php): allow to pass raw boolean to api
This allows users to use APIs that require booleans in query params not to be cast to int, e.g. &foo=true. Currently, true is cast to 1 so it's passed as &foo=1. That might not be supported by the target API.
The fix contains copy-pasted function from guzzlehttp/psr7 Query::build() with minor tweaks.
https://github.com/guzzle/psr7/blob/540ec79fb2f2e96591febb0de464bc16ac2ea341/src/Query.php#L73
Related to https://github.com/OpenAPITools/openapi-generator/issues/2204
There's a proposal by me to include the functionality in guzzlehttp/psr7 https://github.com/guzzle/psr7/pull/603
PR checklist
- [x] Read the contribution guidelines.
- [x] Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
- [x] Run the following to build the project and update samples:
(For Windows users, please run the script in Git BASH) Commit all changed files. This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master. These must match the expectations made by your contribution. You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example./mvnw clean package ./bin/generate-samples.sh ./bin/configs/*.yaml ./bin/utils/export_docs_generators.sh./bin/generate-samples.sh bin/configs/java*. IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed. - [ ] File the PR against the correct branch:
master(upcoming 7.1.0 minor release - breaking changes with fallbacks),8.0.x(breaking changes without fallbacks) - [ ] If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.
thanks for the PR
cc @jebentier (2017/07), @dkarlovi (2017/07), @mandrean (2017/08), @jfastnacht (2017/09), @ybelenko (2018/07), @renepardon (2018/12)
I have just applied this in my prod env in order to consume PowerDNS's api.
can you please update the sample when you've time?
https://github.com/OpenAPITools/openapi-generator/actions/runs/8875561978/job/24365404901?pr=18520
sure, my bad, sorry
no problem. it looks good overall
can you please add a test in https://github.com/OpenAPITools/openapi-generator/blob/master/samples/client/petstore/php/OpenAPIClient-php/tests/ObjectSerializerTest.php to ensure the fix is covered moving forward?
Good call. There's already some singleton BooleanFormatForQueryString, I'll try to leverage that.
php petstore tests also passed:
[INFO] --- exec:1.2.1:exec (bundle-test) @ PhpPetstoreOAS3Tests ---
PHPUnit 9.6.19 by Sebastian Bergmann and contributors.
............................................................... 63 / 221 ( 28%)
............................................................... 126 / 221 ( 57%)
............................................................... 189 / 221 ( 85%)
................................ 221 / 221 (100%)
Time: 00:01.543, Memory: 12.00 MB
OK (221 tests, 379 assertions)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7.621 s
[INFO] Finished at: 2024-05-01T18:05:43+08:00
[INFO] ------------------------------------------------------------------------