-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
[BUG] PHP sends boolean params as "1" or "" instead of "true" or "false" #2204
Comments
@jacobweber thanks for reporting the issue. I think https://github.com/OpenAPITools/openapi-generator/blob/master/samples/client/petstore-security-test/php/lib/ObjectSerializer.php#L51 si a good starting point to fix it. |
@wing328 Thanks. But isn't that function just used for serializing model objects? I think in this case I should change I'm not really sure what this function should do, though. I'm sure there are more types besides dates and booleans that need to be serialized. It looks like OpenAPI 3.0 can handle complex serialized parameters using the |
Thanks for this issue!
|
@ackintosh But I don’t think those are valid in OpenAPI 2.0. The spec refers to https://tools.ietf.org/html/draft-zyp-json-schema-04#section-3.5, which says that booleans are JSON boolean values. JSON only uses true/false for booleans. |
https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#data-types
From my understanding, that defines how to describe the specification of API. That doesn't define the representation of a value on HTTP communications. If we follow JSON representation, string values in HTTP query parameter should be surrounded with
|
When they refer to "primitive data types", I'm pretty sure they're talking about the values you actually send in an HTTP request, not just the format of the spec. Otherwise they wouldn't specify things like the format for dates and integers. And they say things like "Query parameters only support primitive types." You're right that they don't make it very clear, at least for booleans. However, in one of the examples here, they do use It would seem like an incomplete spec if it used a data type but didn't specify how to send it. Even if it doesn't, all the other generators that I've tried send |
@jacobweber @ackintosh you both have valid points. To move this forward, I suggest we go with #2257 and if there are demands to send boolean values as 1/0 in the query string or other parameters, then we can make an option to cater both cases. (I did work on 1 or 2 issues before in which the users are expecting the client to send true/false in the query string) |
We've just come across this issue with booleans, as @etremblay says, it seems that removing |
Yes, I can confirm, hat the boolean issue in a query is still / again in place. Is there anything going on to fix this issue? |
I don't think anyone is working on a fix for this issue. We welcome a PR from anyone in the community to start with. |
I found out, that the issue may have been fixed in guzzle guzzle/psr7#264 and was relased a view days ago with guzzle/psr7 2.0.0. But this whould mean, that openapi-generator needs to use the new version of guzzle/psr with slightly changed function names. Is this possible in the near future? Othterwise a workaround would be needed - which I could provide. |
We definitely want to upgrade guzzle to the latest stable version. I think there's a PR for that but some tests failed (which may be caused by the slightly changed functions names that you've pointed out). If it's not a lot of work, I would suggest filing a PR to upgrade guzzle to the latest stable version to start with and we'll start from there (fixing tests, etc) |
Folks, I am still experiencing this in 6.0.1, the day is coming as true/false, but read as 1 / "". What do I do? |
@mysticaltech Same issue, did you find any patch? |
@Dibbyo456 I solved it, but sadly I do not remember how. |
I ended up replacing boolean values to string. |
Bug Report Checklist
Description
When params are of type "boolean", they should be sent as "true" or "false", but the PHP generator sends them as "1" or "". But it correctly documents the parameters as
@param bool
. So if you send boolean parameters, it ends up doing something like(string) true
, which evaluates to1
.openapi-generator version
4.0.0-SNAPSHOT
OpenAPI declaration file content or url
https://gist.github.com/jacobweber/e83874fbf1c0ee6ede79100a7507e11f
Command line used for generation
java -jar openapi-generator.jar generate -i <url> -g php -o /path/to/output
Steps to reproduce
composer install
from the output dir.GET http://localhost/api/users?admin=1
instead ofGET http://localhost/api/users?admin=true
.Related issues/PRs
N/A
Suggest a fix
Detect booleans and convert to "true" or "false".
The text was updated successfully, but these errors were encountered: