Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(php): allow to pass raw boolean to api #18520

Merged
merged 1 commit into from
May 1, 2024

Conversation

simPod
Copy link
Contributor

@simPod simPod commented Apr 27, 2024

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 #2204

There's a proposal by me to include the functionality in guzzlehttp/psr7 guzzle/psr7#603

PR checklist

  • Read the contribution guidelines.
  • 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.
  • Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh ./bin/configs/*.yaml
    ./bin/utils/export_docs_generators.sh
    
    (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 ./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.

@wing328
Copy link
Member

wing328 commented Apr 28, 2024

thanks for the PR

cc
@jebentier (2017/07), @dkarlovi (2017/07), @mandrean (2017/08), @jfastnacht (2017/09), @ybelenko (2018/07), @renepardon (2018/12)

@simPod simPod force-pushed the php/bool branch 2 times, most recently from d535e53 to 9c238cc Compare April 28, 2024 19:54
@simPod
Copy link
Contributor Author

simPod commented Apr 28, 2024

I have just applied this in my prod env in order to consume PowerDNS's api.

@simPod simPod force-pushed the php/bool branch 2 times, most recently from 6bd2f35 to 561d540 Compare April 29, 2024 08:27
@wing328
Copy link
Member

wing328 commented Apr 29, 2024

can you please update the sample when you've time?

https://github.com/OpenAPITools/openapi-generator/actions/runs/8875561978/job/24365404901?pr=18520

@simPod
Copy link
Contributor Author

simPod commented Apr 29, 2024

sure, my bad, sorry

@wing328
Copy link
Member

wing328 commented Apr 30, 2024

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?

@simPod
Copy link
Contributor Author

simPod commented Apr 30, 2024

Good call. There's already some singleton BooleanFormatForQueryString, I'll try to leverage that.

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 tweak.
@wing328
Copy link
Member

wing328 commented May 1, 2024

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] ------------------------------------------------------------------------

@wing328 wing328 merged commit 98d0261 into OpenAPITools:master May 1, 2024
14 checks passed
@simPod simPod deleted the php/bool branch May 2, 2024 08:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants