-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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] json_decode missing when response is object #8394
Comments
Is this more like a server issue? In other words, the server seems to returning an invalid response. Should the correct response look like the following instead?
|
Nope, original response from server(I expect single object):
then client generator cast it to array with the line: settype($data, 'array'); That's why raw request body then looks like:
then cause JSON parsing exception. |
Is that a correct description of the response? I'm confused on the actual response. In #8394 (comment), you said the following is the response
but in #8394 (comment), the "original" response from the server is
Which one is the response from the server? |
Yes, schema is correct I expect single object. I use client php generator to call server and pass response to php output(like an API wrapper, proxy). So php client serializes server response with That one is response from original server:
Then proxy client SDK returns me array with single string( |
Hmm... why would And why would the server further encodes JSON payload as a string before sending it to the client? Shouldn't the payload returned by the server be as simple as the following?
What's the |
I need to retrieve single object with foobar property not an array with one object.
Let's forget about second encoding. The main issue is that I cannot read if ($class === 'object') {
// here comes by some unknown reason not serialized data, string like {"foobar":"foobaz"}
// instead of decode it serializer tries to convert it to array and, so output is ['{"foobar":"foobaz"}']
// I cannot retrieve foobar field from that array like I normally do with array or model
settype($data, 'array');
return $data;
}
It can be, but you can face issues with chars which should be escaped. That's why php
Correct Check the whole serialization function, it decodes json when data is string, but we expect not scalar value(L267, L282): openapi-generator/modules/openapi-generator/src/main/resources/php/ObjectSerializer.mustache Lines 265 to 300 in 047a71c
|
Can you please PM me in Slack when you've time? Thanks. |
Bug Report Checklist
Description
When I call API via generated PHP client I got encoded json string instead of decoded object. Response looks like:
["{\"foobar\":\"foobaz\"}"]
openapi-generator version
5.0.0-beta
OpenAPI declaration file content or url
Generation Details
generate -i \"spec.yaml\" -g php -o \"api-client-sdk\"
Steps to reproduce
Send request via generated SDK to staged server
/objects/1
where response is correct JSON item. The response will be json encoded string instead of object.Related issues/PRs
#6566 Seems close but not really. I'm ok with response as object instead of model. It's just
json_decode
execution missed.Suggest a fix
I don't know why
json_decode
executes based on string check and doesn't checkContent-Type
header but it's a quick fix.The text was updated successfully, but these errors were encountered: