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

[php] Fix JSON object deserialization #8481

Merged
merged 4 commits into from
Mar 28, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions modules/openapi-generator/src/main/resources/php/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,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 Down
21 changes: 21 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 @@ -178,6 +178,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 Down Expand Up @@ -663,6 +666,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 Down Expand Up @@ -911,6 +917,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 Down Expand Up @@ -1159,6 +1168,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 Down Expand Up @@ -1407,6 +1419,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 Down Expand Up @@ -1655,6 +1670,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 Down Expand Up @@ -2353,6 +2371,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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,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 Down
15 changes: 15 additions & 0 deletions samples/client/petstore/php/OpenAPIClient-php/lib/Api/PetApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,9 @@ public function findPetsByStatusWithHttpInfo($status)
$content = $response->getBody(); //stream goes to serializer
} else {
$content = (string) $response->getBody();
if ('\OpenAPI\Client\Model\Pet[]' !== 'string') {
$content = json_decode($content);
}
}

return [
Expand Down Expand Up @@ -926,6 +929,9 @@ public function findPetsByTagsWithHttpInfo($tags)
$content = $response->getBody(); //stream goes to serializer
} else {
$content = (string) $response->getBody();
if ('\OpenAPI\Client\Model\Pet[]' !== 'string') {
$content = json_decode($content);
}
}

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

return [
Expand Down Expand Up @@ -1955,6 +1964,9 @@ public function uploadFileWithHttpInfo($pet_id, $additional_metadata = null, $fi
$content = $response->getBody(); //stream goes to serializer
} else {
$content = (string) $response->getBody();
if ('\OpenAPI\Client\Model\ApiResponse' !== 'string') {
$content = json_decode($content);
}
}

return [
Expand Down Expand Up @@ -2249,6 +2261,9 @@ public function uploadFileWithRequiredFileWithHttpInfo($pet_id, $required_file,
$content = $response->getBody(); //stream goes to serializer
} else {
$content = (string) $response->getBody();
if ('\OpenAPI\Client\Model\ApiResponse' !== 'string') {
$content = json_decode($content);
}
}

return [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,9 @@ public function getInventoryWithHttpInfo()
$content = $response->getBody(); //stream goes to serializer
} else {
$content = (string) $response->getBody();
if ('array<string,int>' !== 'string') {
$content = json_decode($content);
}
}

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

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

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

return [
Expand Down Expand Up @@ -1316,6 +1319,9 @@ public function loginUserWithHttpInfo($username, $password)
$content = $response->getBody(); //stream goes to serializer
} else {
$content = (string) $response->getBody();
if ('string' !== 'string') {
$content = json_decode($content);
}
}

return [
Expand Down