Skip to content

Commit

Permalink
[php] Fix JSON object deserialization (#8481)
Browse files Browse the repository at this point in the history
* Fix JSON object deserialization

* Revert "Fix JSON object deserialization"

This reverts commit 42a4637e53020d8d3e921f72bc66de9d4ccd8151.

* Add JSON body decoding before deserialize call

* Add two more json_decode calls

Co-authored-by: Thomas Hansen <thomas@thomasphansen.dk>
  • Loading branch information
ybelenko and thomasphansen authored Mar 28, 2022
1 parent 081619e commit 956ad2a
Show file tree
Hide file tree
Showing 8 changed files with 189 additions and 0 deletions.
9 changes: 9 additions & 0 deletions modules/openapi-generator/src/main/resources/php/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@ use {{invokerPackage}}\ObjectSerializer;
$content = $response->getBody(); //stream goes to serializer
} else {
$content = (string) $response->getBody();
if ('{{dataType}}' !== 'string') {
$content = json_decode($content);
}
}

return [
Expand All @@ -251,6 +254,9 @@ use {{invokerPackage}}\ObjectSerializer;
$content = $response->getBody(); //stream goes to serializer
} else {
$content = (string) $response->getBody();
if ($returnType !== 'string') {
$content = json_decode($content);
}
}

return [
Expand Down Expand Up @@ -375,6 +381,9 @@ use {{invokerPackage}}\ObjectSerializer;
$content = $response->getBody(); //stream goes to serializer
} else {
$content = (string) $response->getBody();
if ($returnType !== 'string') {
$content = json_decode($content);
}
}

return [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ public function call123TestSpecialTagsWithHttpInfo($client)
$content = $response->getBody(); //stream goes to serializer
} else {
$content = (string) $response->getBody();
if ('\OpenAPI\Client\Model\Client' !== 'string') {
$content = json_decode($content);
}
}

return [
Expand All @@ -202,6 +205,9 @@ public function call123TestSpecialTagsWithHttpInfo($client)
$content = $response->getBody(); //stream goes to serializer
} else {
$content = (string) $response->getBody();
if ($returnType !== 'string') {
$content = json_decode($content);
}
}

return [
Expand Down Expand Up @@ -268,6 +274,9 @@ function ($response) use ($returnType) {
$content = $response->getBody(); //stream goes to serializer
} else {
$content = (string) $response->getBody();
if ($returnType !== 'string') {
$content = json_decode($content);
}
}

return [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ public function fooGetWithHttpInfo()
$content = $response->getBody(); //stream goes to serializer
} else {
$content = (string) $response->getBody();
if ('\OpenAPI\Client\Model\InlineResponseDefault' !== 'string') {
$content = json_decode($content);
}
}

return [
Expand All @@ -196,6 +199,9 @@ public function fooGetWithHttpInfo()
$content = $response->getBody(); //stream goes to serializer
} else {
$content = (string) $response->getBody();
if ($returnType !== 'string') {
$content = json_decode($content);
}
}

return [
Expand Down Expand Up @@ -256,6 +262,9 @@ function ($response) use ($returnType) {
$content = $response->getBody(); //stream goes to serializer
} else {
$content = (string) $response->getBody();
if ($returnType !== 'string') {
$content = json_decode($content);
}
}

return [
Expand Down
63 changes: 63 additions & 0 deletions samples/client/petstore/php/OpenAPIClient-php/lib/Api/FakeApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ public function fakeHealthGetWithHttpInfo()
$content = $response->getBody(); //stream goes to serializer
} else {
$content = (string) $response->getBody();
if ('\OpenAPI\Client\Model\HealthCheckResult' !== 'string') {
$content = json_decode($content);
}
}

return [
Expand All @@ -200,6 +203,9 @@ public function fakeHealthGetWithHttpInfo()
$content = $response->getBody(); //stream goes to serializer
} else {
$content = (string) $response->getBody();
if ($returnType !== 'string') {
$content = json_decode($content);
}
}

return [
Expand Down Expand Up @@ -264,6 +270,9 @@ function ($response) use ($returnType) {
$content = $response->getBody(); //stream goes to serializer
} else {
$content = (string) $response->getBody();
if ($returnType !== 'string') {
$content = json_decode($content);
}
}

return [
Expand Down Expand Up @@ -682,6 +691,9 @@ public function fakeOuterBooleanSerializeWithHttpInfo($body = null)
$content = $response->getBody(); //stream goes to serializer
} else {
$content = (string) $response->getBody();
if ('bool' !== 'string') {
$content = json_decode($content);
}
}

return [
Expand All @@ -696,6 +708,9 @@ public function fakeOuterBooleanSerializeWithHttpInfo($body = null)
$content = $response->getBody(); //stream goes to serializer
} else {
$content = (string) $response->getBody();
if ($returnType !== 'string') {
$content = json_decode($content);
}
}

return [
Expand Down Expand Up @@ -758,6 +773,9 @@ function ($response) use ($returnType) {
$content = $response->getBody(); //stream goes to serializer
} else {
$content = (string) $response->getBody();
if ($returnType !== 'string') {
$content = json_decode($content);
}
}

return [
Expand Down Expand Up @@ -937,6 +955,9 @@ public function fakeOuterCompositeSerializeWithHttpInfo($outer_composite = null)
$content = $response->getBody(); //stream goes to serializer
} else {
$content = (string) $response->getBody();
if ('\OpenAPI\Client\Model\OuterComposite' !== 'string') {
$content = json_decode($content);
}
}

return [
Expand All @@ -951,6 +972,9 @@ public function fakeOuterCompositeSerializeWithHttpInfo($outer_composite = null)
$content = $response->getBody(); //stream goes to serializer
} else {
$content = (string) $response->getBody();
if ($returnType !== 'string') {
$content = json_decode($content);
}
}

return [
Expand Down Expand Up @@ -1013,6 +1037,9 @@ function ($response) use ($returnType) {
$content = $response->getBody(); //stream goes to serializer
} else {
$content = (string) $response->getBody();
if ($returnType !== 'string') {
$content = json_decode($content);
}
}

return [
Expand Down Expand Up @@ -1192,6 +1219,9 @@ public function fakeOuterNumberSerializeWithHttpInfo($body = null)
$content = $response->getBody(); //stream goes to serializer
} else {
$content = (string) $response->getBody();
if ('float' !== 'string') {
$content = json_decode($content);
}
}

return [
Expand All @@ -1206,6 +1236,9 @@ public function fakeOuterNumberSerializeWithHttpInfo($body = null)
$content = $response->getBody(); //stream goes to serializer
} else {
$content = (string) $response->getBody();
if ($returnType !== 'string') {
$content = json_decode($content);
}
}

return [
Expand Down Expand Up @@ -1268,6 +1301,9 @@ function ($response) use ($returnType) {
$content = $response->getBody(); //stream goes to serializer
} else {
$content = (string) $response->getBody();
if ($returnType !== 'string') {
$content = json_decode($content);
}
}

return [
Expand Down Expand Up @@ -1447,6 +1483,9 @@ public function fakeOuterStringSerializeWithHttpInfo($body = null)
$content = $response->getBody(); //stream goes to serializer
} else {
$content = (string) $response->getBody();
if ('string' !== 'string') {
$content = json_decode($content);
}
}

return [
Expand All @@ -1461,6 +1500,9 @@ public function fakeOuterStringSerializeWithHttpInfo($body = null)
$content = $response->getBody(); //stream goes to serializer
} else {
$content = (string) $response->getBody();
if ($returnType !== 'string') {
$content = json_decode($content);
}
}

return [
Expand Down Expand Up @@ -1523,6 +1565,9 @@ function ($response) use ($returnType) {
$content = $response->getBody(); //stream goes to serializer
} else {
$content = (string) $response->getBody();
if ($returnType !== 'string') {
$content = json_decode($content);
}
}

return [
Expand Down Expand Up @@ -1702,6 +1747,9 @@ public function fakePropertyEnumIntegerSerializeWithHttpInfo($outer_object_with_
$content = $response->getBody(); //stream goes to serializer
} else {
$content = (string) $response->getBody();
if ('\OpenAPI\Client\Model\OuterObjectWithEnumProperty' !== 'string') {
$content = json_decode($content);
}
}

return [
Expand All @@ -1716,6 +1764,9 @@ public function fakePropertyEnumIntegerSerializeWithHttpInfo($outer_object_with_
$content = $response->getBody(); //stream goes to serializer
} else {
$content = (string) $response->getBody();
if ($returnType !== 'string') {
$content = json_decode($content);
}
}

return [
Expand Down Expand Up @@ -1778,6 +1829,9 @@ function ($response) use ($returnType) {
$content = $response->getBody(); //stream goes to serializer
} else {
$content = (string) $response->getBody();
if ($returnType !== 'string') {
$content = json_decode($content);
}
}

return [
Expand Down Expand Up @@ -2634,6 +2688,9 @@ public function testClientModelWithHttpInfo($client)
$content = $response->getBody(); //stream goes to serializer
} else {
$content = (string) $response->getBody();
if ('\OpenAPI\Client\Model\Client' !== 'string') {
$content = json_decode($content);
}
}

return [
Expand All @@ -2648,6 +2705,9 @@ public function testClientModelWithHttpInfo($client)
$content = $response->getBody(); //stream goes to serializer
} else {
$content = (string) $response->getBody();
if ($returnType !== 'string') {
$content = json_decode($content);
}
}

return [
Expand Down Expand Up @@ -2714,6 +2774,9 @@ function ($response) use ($returnType) {
$content = $response->getBody(); //stream goes to serializer
} else {
$content = (string) $response->getBody();
if ($returnType !== 'string') {
$content = json_decode($content);
}
}

return [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ public function testClassnameWithHttpInfo($client)
$content = $response->getBody(); //stream goes to serializer
} else {
$content = (string) $response->getBody();
if ('\OpenAPI\Client\Model\Client' !== 'string') {
$content = json_decode($content);
}
}

return [
Expand All @@ -202,6 +205,9 @@ public function testClassnameWithHttpInfo($client)
$content = $response->getBody(); //stream goes to serializer
} else {
$content = (string) $response->getBody();
if ($returnType !== 'string') {
$content = json_decode($content);
}
}

return [
Expand Down Expand Up @@ -268,6 +274,9 @@ function ($response) use ($returnType) {
$content = $response->getBody(); //stream goes to serializer
} else {
$content = (string) $response->getBody();
if ($returnType !== 'string') {
$content = json_decode($content);
}
}

return [
Expand Down
Loading

0 comments on commit 956ad2a

Please sign in to comment.