From aec1abb9f59ef183f4492ea7446f65beb6d81778 Mon Sep 17 00:00:00 2001 From: Thomas Hansen Date: Fri, 14 Sep 2018 10:57:47 +0200 Subject: [PATCH 1/9] PR: Fix error when giving an array as parameter to an endpoint body request --- .../src/main/resources/php/api.mustache | 35 +++++- .../lib/Api/AnotherFakeApi.php | 35 +++++- .../php/OpenAPIClient-php/lib/Api/FakeApi.php | 115 +++++++++++------- .../lib/Api/FakeClassnameTags123Api.php | 35 +++++- .../php/OpenAPIClient-php/lib/Api/PetApi.php | 99 +++++++++------ .../OpenAPIClient-php/lib/Api/StoreApi.php | 59 ++++++--- .../php/OpenAPIClient-php/lib/Api/UserApi.php | 91 +++++++++----- .../lib/Api/AnotherFakeApi.php | 35 +++++- .../php/OpenAPIClient-php/lib/Api/FakeApi.php | 115 +++++++++++------- .../lib/Api/FakeClassnameTags123Api.php | 35 +++++- .../php/OpenAPIClient-php/lib/Api/PetApi.php | 99 +++++++++------ .../OpenAPIClient-php/lib/Api/StoreApi.php | 59 ++++++--- .../php/OpenAPIClient-php/lib/Api/UserApi.php | 91 +++++++++----- 13 files changed, 627 insertions(+), 276 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/php/api.mustache b/modules/openapi-generator/src/main/resources/php/api.mustache index 7ecf4fc92861..44a395279e72 100644 --- a/modules/openapi-generator/src/main/resources/php/api.mustache +++ b/modules/openapi-generator/src/main/resources/php/api.mustache @@ -77,6 +77,33 @@ use {{invokerPackage}}\ObjectSerializer; return $this->config; } + + /** + * @param mixed $body Element to become the body of the Request + * + * @return mixed|string + */ + private function formatBody($body) + { + // \stdClass and arrays have no __toString(), so we should encode them manually + if($body instanceof \stdClass) { + return \GuzzleHttp\json_encode($body); + } + + // arrays must be encoded manually as well, otherwise the objects inside it don't get encoded + if(is_array($body)) { + $return = "["; + + foreach($body as $item) { + $return .="\n".$this->formatBody($item).","; + } + + return trim($return, ',')."\n]"; + } + + return $body; + } + {{#operation}} /** * Operation {{{operationId}}} @@ -444,10 +471,10 @@ use {{invokerPackage}}\ObjectSerializer; // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - $httpBody = $_tempBody; - // \stdClass has no __toString(), so we should encode it manually - if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { - $httpBody = \GuzzleHttp\json_encode($httpBody); + if($headers['Content-Type'] !== 'application/json') { + $httpBody = $_tempBody; + } else { + $httpBody = $this->formatBody($_tempBody); } } elseif (count($formParams) > 0) { if ($multipart) { diff --git a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/AnotherFakeApi.php b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/AnotherFakeApi.php index 644aaca9230c..0a880cf2dff2 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/AnotherFakeApi.php +++ b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/AnotherFakeApi.php @@ -87,6 +87,33 @@ public function getConfig() return $this->config; } + + /** + * @param mixed $body Element to become the body of the Request + * + * @return mixed|string + */ + private function formatBody($body) + { + // \stdClass and arrays have no __toString(), so we should encode them manually + if($body instanceof \stdClass) { + return \GuzzleHttp\json_encode($body); + } + + // arrays must be encoded manually as well, otherwise the objects inside it don't get encoded + if(is_array($body)) { + $return = "["; + + foreach($body as $item) { + $return .="\n".$this->formatBody($item).","; + } + + return trim($return, ',')."\n]"; + } + + return $body; + } + /** * Operation call123TestSpecialTags * @@ -307,10 +334,10 @@ protected function call123TestSpecialTagsRequest($client) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - $httpBody = $_tempBody; - // \stdClass has no __toString(), so we should encode it manually - if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { - $httpBody = \GuzzleHttp\json_encode($httpBody); + if($headers['Content-Type'] !== 'application/json') { + $httpBody = $_tempBody; + } else { + $httpBody = $this->formatBody($_tempBody); } } elseif (count($formParams) > 0) { if ($multipart) { diff --git a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/FakeApi.php b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/FakeApi.php index c8691f7e9328..9eaa5d0043a7 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/FakeApi.php +++ b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/FakeApi.php @@ -87,6 +87,33 @@ public function getConfig() return $this->config; } + + /** + * @param mixed $body Element to become the body of the Request + * + * @return mixed|string + */ + private function formatBody($body) + { + // \stdClass and arrays have no __toString(), so we should encode them manually + if($body instanceof \stdClass) { + return \GuzzleHttp\json_encode($body); + } + + // arrays must be encoded manually as well, otherwise the objects inside it don't get encoded + if(is_array($body)) { + $return = "["; + + foreach($body as $item) { + $return .="\n".$this->formatBody($item).","; + } + + return trim($return, ',')."\n]"; + } + + return $body; + } + /** * Operation fakeOuterBooleanSerialize * @@ -297,10 +324,10 @@ protected function fakeOuterBooleanSerializeRequest($body = null) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - $httpBody = $_tempBody; - // \stdClass has no __toString(), so we should encode it manually - if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { - $httpBody = \GuzzleHttp\json_encode($httpBody); + if($headers['Content-Type'] !== 'application/json') { + $httpBody = $_tempBody; + } else { + $httpBody = $this->formatBody($_tempBody); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -554,10 +581,10 @@ protected function fakeOuterCompositeSerializeRequest($outer_composite = null) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - $httpBody = $_tempBody; - // \stdClass has no __toString(), so we should encode it manually - if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { - $httpBody = \GuzzleHttp\json_encode($httpBody); + if($headers['Content-Type'] !== 'application/json') { + $httpBody = $_tempBody; + } else { + $httpBody = $this->formatBody($_tempBody); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -811,10 +838,10 @@ protected function fakeOuterNumberSerializeRequest($body = null) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - $httpBody = $_tempBody; - // \stdClass has no __toString(), so we should encode it manually - if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { - $httpBody = \GuzzleHttp\json_encode($httpBody); + if($headers['Content-Type'] !== 'application/json') { + $httpBody = $_tempBody; + } else { + $httpBody = $this->formatBody($_tempBody); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1068,10 +1095,10 @@ protected function fakeOuterStringSerializeRequest($body = null) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - $httpBody = $_tempBody; - // \stdClass has no __toString(), so we should encode it manually - if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { - $httpBody = \GuzzleHttp\json_encode($httpBody); + if($headers['Content-Type'] !== 'application/json') { + $httpBody = $_tempBody; + } else { + $httpBody = $this->formatBody($_tempBody); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1283,10 +1310,10 @@ protected function testBodyWithFileSchemaRequest($file_schema_test_class) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - $httpBody = $_tempBody; - // \stdClass has no __toString(), so we should encode it manually - if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { - $httpBody = \GuzzleHttp\json_encode($httpBody); + if($headers['Content-Type'] !== 'application/json') { + $httpBody = $_tempBody; + } else { + $httpBody = $this->formatBody($_tempBody); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1513,10 +1540,10 @@ protected function testBodyWithQueryParamsRequest($query, $user) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - $httpBody = $_tempBody; - // \stdClass has no __toString(), so we should encode it manually - if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { - $httpBody = \GuzzleHttp\json_encode($httpBody); + if($headers['Content-Type'] !== 'application/json') { + $httpBody = $_tempBody; + } else { + $httpBody = $this->formatBody($_tempBody); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1780,10 +1807,10 @@ protected function testClientModelRequest($client) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - $httpBody = $_tempBody; - // \stdClass has no __toString(), so we should encode it manually - if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { - $httpBody = \GuzzleHttp\json_encode($httpBody); + if($headers['Content-Type'] !== 'application/json') { + $httpBody = $_tempBody; + } else { + $httpBody = $this->formatBody($_tempBody); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -2183,10 +2210,10 @@ protected function testEndpointParametersRequest($number, $double, $pattern_with // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - $httpBody = $_tempBody; - // \stdClass has no __toString(), so we should encode it manually - if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { - $httpBody = \GuzzleHttp\json_encode($httpBody); + if($headers['Content-Type'] !== 'application/json') { + $httpBody = $_tempBody; + } else { + $httpBody = $this->formatBody($_tempBody); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -2470,10 +2497,10 @@ protected function testEnumParametersRequest($enum_header_string_array = null, $ // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - $httpBody = $_tempBody; - // \stdClass has no __toString(), so we should encode it manually - if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { - $httpBody = \GuzzleHttp\json_encode($httpBody); + if($headers['Content-Type'] !== 'application/json') { + $httpBody = $_tempBody; + } else { + $httpBody = $this->formatBody($_tempBody); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -2689,10 +2716,10 @@ protected function testInlineAdditionalPropertiesRequest($request_body) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - $httpBody = $_tempBody; - // \stdClass has no __toString(), so we should encode it manually - if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { - $httpBody = \GuzzleHttp\json_encode($httpBody); + if($headers['Content-Type'] !== 'application/json') { + $httpBody = $_tempBody; + } else { + $httpBody = $this->formatBody($_tempBody); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -2924,10 +2951,10 @@ protected function testJsonFormDataRequest($param, $param2) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - $httpBody = $_tempBody; - // \stdClass has no __toString(), so we should encode it manually - if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { - $httpBody = \GuzzleHttp\json_encode($httpBody); + if($headers['Content-Type'] !== 'application/json') { + $httpBody = $_tempBody; + } else { + $httpBody = $this->formatBody($_tempBody); } } elseif (count($formParams) > 0) { if ($multipart) { diff --git a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/FakeClassnameTags123Api.php b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/FakeClassnameTags123Api.php index 2870a4c90507..842e6e86008e 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/FakeClassnameTags123Api.php +++ b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/FakeClassnameTags123Api.php @@ -87,6 +87,33 @@ public function getConfig() return $this->config; } + + /** + * @param mixed $body Element to become the body of the Request + * + * @return mixed|string + */ + private function formatBody($body) + { + // \stdClass and arrays have no __toString(), so we should encode them manually + if($body instanceof \stdClass) { + return \GuzzleHttp\json_encode($body); + } + + // arrays must be encoded manually as well, otherwise the objects inside it don't get encoded + if(is_array($body)) { + $return = "["; + + foreach($body as $item) { + $return .="\n".$this->formatBody($item).","; + } + + return trim($return, ',')."\n]"; + } + + return $body; + } + /** * Operation testClassname * @@ -307,10 +334,10 @@ protected function testClassnameRequest($client) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - $httpBody = $_tempBody; - // \stdClass has no __toString(), so we should encode it manually - if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { - $httpBody = \GuzzleHttp\json_encode($httpBody); + if($headers['Content-Type'] !== 'application/json') { + $httpBody = $_tempBody; + } else { + $httpBody = $this->formatBody($_tempBody); } } elseif (count($formParams) > 0) { if ($multipart) { diff --git a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/PetApi.php b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/PetApi.php index 40d4cb8e1b7d..26f1b3cd7f83 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/PetApi.php +++ b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/PetApi.php @@ -87,6 +87,33 @@ public function getConfig() return $this->config; } + + /** + * @param mixed $body Element to become the body of the Request + * + * @return mixed|string + */ + private function formatBody($body) + { + // \stdClass and arrays have no __toString(), so we should encode them manually + if($body instanceof \stdClass) { + return \GuzzleHttp\json_encode($body); + } + + // arrays must be encoded manually as well, otherwise the objects inside it don't get encoded + if(is_array($body)) { + $return = "["; + + foreach($body as $item) { + $return .="\n".$this->formatBody($item).","; + } + + return trim($return, ',')."\n]"; + } + + return $body; + } + /** * Operation addPet * @@ -259,10 +286,10 @@ protected function addPetRequest($pet) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - $httpBody = $_tempBody; - // \stdClass has no __toString(), so we should encode it manually - if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { - $httpBody = \GuzzleHttp\json_encode($httpBody); + if($headers['Content-Type'] !== 'application/json') { + $httpBody = $_tempBody; + } else { + $httpBody = $this->formatBody($_tempBody); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -496,10 +523,10 @@ protected function deletePetRequest($pet_id, $api_key = null) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - $httpBody = $_tempBody; - // \stdClass has no __toString(), so we should encode it manually - if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { - $httpBody = \GuzzleHttp\json_encode($httpBody); + if($headers['Content-Type'] !== 'application/json') { + $httpBody = $_tempBody; + } else { + $httpBody = $this->formatBody($_tempBody); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -771,10 +798,10 @@ protected function findPetsByStatusRequest($status) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - $httpBody = $_tempBody; - // \stdClass has no __toString(), so we should encode it manually - if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { - $httpBody = \GuzzleHttp\json_encode($httpBody); + if($headers['Content-Type'] !== 'application/json') { + $httpBody = $_tempBody; + } else { + $httpBody = $this->formatBody($_tempBody); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1046,10 +1073,10 @@ protected function findPetsByTagsRequest($tags) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - $httpBody = $_tempBody; - // \stdClass has no __toString(), so we should encode it manually - if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { - $httpBody = \GuzzleHttp\json_encode($httpBody); + if($headers['Content-Type'] !== 'application/json') { + $httpBody = $_tempBody; + } else { + $httpBody = $this->formatBody($_tempBody); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1322,10 +1349,10 @@ protected function getPetByIdRequest($pet_id) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - $httpBody = $_tempBody; - // \stdClass has no __toString(), so we should encode it manually - if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { - $httpBody = \GuzzleHttp\json_encode($httpBody); + if($headers['Content-Type'] !== 'application/json') { + $httpBody = $_tempBody; + } else { + $httpBody = $this->formatBody($_tempBody); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1546,10 +1573,10 @@ protected function updatePetRequest($pet) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - $httpBody = $_tempBody; - // \stdClass has no __toString(), so we should encode it manually - if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { - $httpBody = \GuzzleHttp\json_encode($httpBody); + if($headers['Content-Type'] !== 'application/json') { + $httpBody = $_tempBody; + } else { + $httpBody = $this->formatBody($_tempBody); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1792,10 +1819,10 @@ protected function updatePetWithFormRequest($pet_id, $name = null, $status = nul // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - $httpBody = $_tempBody; - // \stdClass has no __toString(), so we should encode it manually - if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { - $httpBody = \GuzzleHttp\json_encode($httpBody); + if($headers['Content-Type'] !== 'application/json') { + $httpBody = $_tempBody; + } else { + $httpBody = $this->formatBody($_tempBody); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -2087,10 +2114,10 @@ protected function uploadFileRequest($pet_id, $additional_metadata = null, $file // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - $httpBody = $_tempBody; - // \stdClass has no __toString(), so we should encode it manually - if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { - $httpBody = \GuzzleHttp\json_encode($httpBody); + if($headers['Content-Type'] !== 'application/json') { + $httpBody = $_tempBody; + } else { + $httpBody = $this->formatBody($_tempBody); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -2388,10 +2415,10 @@ protected function uploadFileWithRequiredFileRequest($pet_id, $required_file, $a // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - $httpBody = $_tempBody; - // \stdClass has no __toString(), so we should encode it manually - if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { - $httpBody = \GuzzleHttp\json_encode($httpBody); + if($headers['Content-Type'] !== 'application/json') { + $httpBody = $_tempBody; + } else { + $httpBody = $this->formatBody($_tempBody); } } elseif (count($formParams) > 0) { if ($multipart) { diff --git a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/StoreApi.php b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/StoreApi.php index f12f7270d96b..9bb646c29de6 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/StoreApi.php +++ b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/StoreApi.php @@ -87,6 +87,33 @@ public function getConfig() return $this->config; } + + /** + * @param mixed $body Element to become the body of the Request + * + * @return mixed|string + */ + private function formatBody($body) + { + // \stdClass and arrays have no __toString(), so we should encode them manually + if($body instanceof \stdClass) { + return \GuzzleHttp\json_encode($body); + } + + // arrays must be encoded manually as well, otherwise the objects inside it don't get encoded + if(is_array($body)) { + $return = "["; + + foreach($body as $item) { + $return .="\n".$this->formatBody($item).","; + } + + return trim($return, ',')."\n]"; + } + + return $body; + } + /** * Operation deleteOrder * @@ -264,10 +291,10 @@ protected function deleteOrderRequest($order_id) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - $httpBody = $_tempBody; - // \stdClass has no __toString(), so we should encode it manually - if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { - $httpBody = \GuzzleHttp\json_encode($httpBody); + if($headers['Content-Type'] !== 'application/json') { + $httpBody = $_tempBody; + } else { + $httpBody = $this->formatBody($_tempBody); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -517,10 +544,10 @@ protected function getInventoryRequest() // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - $httpBody = $_tempBody; - // \stdClass has no __toString(), so we should encode it manually - if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { - $httpBody = \GuzzleHttp\json_encode($httpBody); + if($headers['Content-Type'] !== 'application/json') { + $httpBody = $_tempBody; + } else { + $httpBody = $this->formatBody($_tempBody); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -801,10 +828,10 @@ protected function getOrderByIdRequest($order_id) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - $httpBody = $_tempBody; - // \stdClass has no __toString(), so we should encode it manually - if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { - $httpBody = \GuzzleHttp\json_encode($httpBody); + if($headers['Content-Type'] !== 'application/json') { + $httpBody = $_tempBody; + } else { + $httpBody = $this->formatBody($_tempBody); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1068,10 +1095,10 @@ protected function placeOrderRequest($order) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - $httpBody = $_tempBody; - // \stdClass has no __toString(), so we should encode it manually - if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { - $httpBody = \GuzzleHttp\json_encode($httpBody); + if($headers['Content-Type'] !== 'application/json') { + $httpBody = $_tempBody; + } else { + $httpBody = $this->formatBody($_tempBody); } } elseif (count($formParams) > 0) { if ($multipart) { diff --git a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/UserApi.php b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/UserApi.php index 492c68ff5735..8234552623c3 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/UserApi.php +++ b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/UserApi.php @@ -87,6 +87,33 @@ public function getConfig() return $this->config; } + + /** + * @param mixed $body Element to become the body of the Request + * + * @return mixed|string + */ + private function formatBody($body) + { + // \stdClass and arrays have no __toString(), so we should encode them manually + if($body instanceof \stdClass) { + return \GuzzleHttp\json_encode($body); + } + + // arrays must be encoded manually as well, otherwise the objects inside it don't get encoded + if(is_array($body)) { + $return = "["; + + foreach($body as $item) { + $return .="\n".$this->formatBody($item).","; + } + + return trim($return, ',')."\n]"; + } + + return $body; + } + /** * Operation createUser * @@ -259,10 +286,10 @@ protected function createUserRequest($user) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - $httpBody = $_tempBody; - // \stdClass has no __toString(), so we should encode it manually - if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { - $httpBody = \GuzzleHttp\json_encode($httpBody); + if($headers['Content-Type'] !== 'application/json') { + $httpBody = $_tempBody; + } else { + $httpBody = $this->formatBody($_tempBody); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -478,10 +505,10 @@ protected function createUsersWithArrayInputRequest($user) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - $httpBody = $_tempBody; - // \stdClass has no __toString(), so we should encode it manually - if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { - $httpBody = \GuzzleHttp\json_encode($httpBody); + if($headers['Content-Type'] !== 'application/json') { + $httpBody = $_tempBody; + } else { + $httpBody = $this->formatBody($_tempBody); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -697,10 +724,10 @@ protected function createUsersWithListInputRequest($user) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - $httpBody = $_tempBody; - // \stdClass has no __toString(), so we should encode it manually - if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { - $httpBody = \GuzzleHttp\json_encode($httpBody); + if($headers['Content-Type'] !== 'application/json') { + $httpBody = $_tempBody; + } else { + $httpBody = $this->formatBody($_tempBody); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -921,10 +948,10 @@ protected function deleteUserRequest($username) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - $httpBody = $_tempBody; - // \stdClass has no __toString(), so we should encode it manually - if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { - $httpBody = \GuzzleHttp\json_encode($httpBody); + if($headers['Content-Type'] !== 'application/json') { + $httpBody = $_tempBody; + } else { + $httpBody = $this->formatBody($_tempBody); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1193,10 +1220,10 @@ protected function getUserByNameRequest($username) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - $httpBody = $_tempBody; - // \stdClass has no __toString(), so we should encode it manually - if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { - $httpBody = \GuzzleHttp\json_encode($httpBody); + if($headers['Content-Type'] !== 'application/json') { + $httpBody = $_tempBody; + } else { + $httpBody = $this->formatBody($_tempBody); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1476,10 +1503,10 @@ protected function loginUserRequest($username, $password) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - $httpBody = $_tempBody; - // \stdClass has no __toString(), so we should encode it manually - if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { - $httpBody = \GuzzleHttp\json_encode($httpBody); + if($headers['Content-Type'] !== 'application/json') { + $httpBody = $_tempBody; + } else { + $httpBody = $this->formatBody($_tempBody); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1681,10 +1708,10 @@ protected function logoutUserRequest() // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - $httpBody = $_tempBody; - // \stdClass has no __toString(), so we should encode it manually - if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { - $httpBody = \GuzzleHttp\json_encode($httpBody); + if($headers['Content-Type'] !== 'application/json') { + $httpBody = $_tempBody; + } else { + $httpBody = $this->formatBody($_tempBody); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1919,10 +1946,10 @@ protected function updateUserRequest($username, $user) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - $httpBody = $_tempBody; - // \stdClass has no __toString(), so we should encode it manually - if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { - $httpBody = \GuzzleHttp\json_encode($httpBody); + if($headers['Content-Type'] !== 'application/json') { + $httpBody = $_tempBody; + } else { + $httpBody = $this->formatBody($_tempBody); } } elseif (count($formParams) > 0) { if ($multipart) { diff --git a/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/AnotherFakeApi.php b/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/AnotherFakeApi.php index 644aaca9230c..0a880cf2dff2 100644 --- a/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/AnotherFakeApi.php +++ b/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/AnotherFakeApi.php @@ -87,6 +87,33 @@ public function getConfig() return $this->config; } + + /** + * @param mixed $body Element to become the body of the Request + * + * @return mixed|string + */ + private function formatBody($body) + { + // \stdClass and arrays have no __toString(), so we should encode them manually + if($body instanceof \stdClass) { + return \GuzzleHttp\json_encode($body); + } + + // arrays must be encoded manually as well, otherwise the objects inside it don't get encoded + if(is_array($body)) { + $return = "["; + + foreach($body as $item) { + $return .="\n".$this->formatBody($item).","; + } + + return trim($return, ',')."\n]"; + } + + return $body; + } + /** * Operation call123TestSpecialTags * @@ -307,10 +334,10 @@ protected function call123TestSpecialTagsRequest($client) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - $httpBody = $_tempBody; - // \stdClass has no __toString(), so we should encode it manually - if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { - $httpBody = \GuzzleHttp\json_encode($httpBody); + if($headers['Content-Type'] !== 'application/json') { + $httpBody = $_tempBody; + } else { + $httpBody = $this->formatBody($_tempBody); } } elseif (count($formParams) > 0) { if ($multipart) { diff --git a/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/FakeApi.php b/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/FakeApi.php index 8e18423c90a7..961e37a036ae 100644 --- a/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/FakeApi.php +++ b/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/FakeApi.php @@ -87,6 +87,33 @@ public function getConfig() return $this->config; } + + /** + * @param mixed $body Element to become the body of the Request + * + * @return mixed|string + */ + private function formatBody($body) + { + // \stdClass and arrays have no __toString(), so we should encode them manually + if($body instanceof \stdClass) { + return \GuzzleHttp\json_encode($body); + } + + // arrays must be encoded manually as well, otherwise the objects inside it don't get encoded + if(is_array($body)) { + $return = "["; + + foreach($body as $item) { + $return .="\n".$this->formatBody($item).","; + } + + return trim($return, ',')."\n]"; + } + + return $body; + } + /** * Operation fakeOuterBooleanSerialize * @@ -297,10 +324,10 @@ protected function fakeOuterBooleanSerializeRequest($body = null) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - $httpBody = $_tempBody; - // \stdClass has no __toString(), so we should encode it manually - if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { - $httpBody = \GuzzleHttp\json_encode($httpBody); + if($headers['Content-Type'] !== 'application/json') { + $httpBody = $_tempBody; + } else { + $httpBody = $this->formatBody($_tempBody); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -554,10 +581,10 @@ protected function fakeOuterCompositeSerializeRequest($outer_composite = null) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - $httpBody = $_tempBody; - // \stdClass has no __toString(), so we should encode it manually - if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { - $httpBody = \GuzzleHttp\json_encode($httpBody); + if($headers['Content-Type'] !== 'application/json') { + $httpBody = $_tempBody; + } else { + $httpBody = $this->formatBody($_tempBody); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -811,10 +838,10 @@ protected function fakeOuterNumberSerializeRequest($body = null) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - $httpBody = $_tempBody; - // \stdClass has no __toString(), so we should encode it manually - if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { - $httpBody = \GuzzleHttp\json_encode($httpBody); + if($headers['Content-Type'] !== 'application/json') { + $httpBody = $_tempBody; + } else { + $httpBody = $this->formatBody($_tempBody); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1068,10 +1095,10 @@ protected function fakeOuterStringSerializeRequest($body = null) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - $httpBody = $_tempBody; - // \stdClass has no __toString(), so we should encode it manually - if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { - $httpBody = \GuzzleHttp\json_encode($httpBody); + if($headers['Content-Type'] !== 'application/json') { + $httpBody = $_tempBody; + } else { + $httpBody = $this->formatBody($_tempBody); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1283,10 +1310,10 @@ protected function testBodyWithFileSchemaRequest($file_schema_test_class) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - $httpBody = $_tempBody; - // \stdClass has no __toString(), so we should encode it manually - if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { - $httpBody = \GuzzleHttp\json_encode($httpBody); + if($headers['Content-Type'] !== 'application/json') { + $httpBody = $_tempBody; + } else { + $httpBody = $this->formatBody($_tempBody); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1513,10 +1540,10 @@ protected function testBodyWithQueryParamsRequest($query, $user) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - $httpBody = $_tempBody; - // \stdClass has no __toString(), so we should encode it manually - if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { - $httpBody = \GuzzleHttp\json_encode($httpBody); + if($headers['Content-Type'] !== 'application/json') { + $httpBody = $_tempBody; + } else { + $httpBody = $this->formatBody($_tempBody); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1780,10 +1807,10 @@ protected function testClientModelRequest($client) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - $httpBody = $_tempBody; - // \stdClass has no __toString(), so we should encode it manually - if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { - $httpBody = \GuzzleHttp\json_encode($httpBody); + if($headers['Content-Type'] !== 'application/json') { + $httpBody = $_tempBody; + } else { + $httpBody = $this->formatBody($_tempBody); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -2183,10 +2210,10 @@ protected function testEndpointParametersRequest($number, $double, $pattern_with // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - $httpBody = $_tempBody; - // \stdClass has no __toString(), so we should encode it manually - if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { - $httpBody = \GuzzleHttp\json_encode($httpBody); + if($headers['Content-Type'] !== 'application/json') { + $httpBody = $_tempBody; + } else { + $httpBody = $this->formatBody($_tempBody); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -2470,10 +2497,10 @@ protected function testEnumParametersRequest($enum_header_string_array = null, $ // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - $httpBody = $_tempBody; - // \stdClass has no __toString(), so we should encode it manually - if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { - $httpBody = \GuzzleHttp\json_encode($httpBody); + if($headers['Content-Type'] !== 'application/json') { + $httpBody = $_tempBody; + } else { + $httpBody = $this->formatBody($_tempBody); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -2689,10 +2716,10 @@ protected function testInlineAdditionalPropertiesRequest($request_body) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - $httpBody = $_tempBody; - // \stdClass has no __toString(), so we should encode it manually - if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { - $httpBody = \GuzzleHttp\json_encode($httpBody); + if($headers['Content-Type'] !== 'application/json') { + $httpBody = $_tempBody; + } else { + $httpBody = $this->formatBody($_tempBody); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -2924,10 +2951,10 @@ protected function testJsonFormDataRequest($param, $param2) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - $httpBody = $_tempBody; - // \stdClass has no __toString(), so we should encode it manually - if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { - $httpBody = \GuzzleHttp\json_encode($httpBody); + if($headers['Content-Type'] !== 'application/json') { + $httpBody = $_tempBody; + } else { + $httpBody = $this->formatBody($_tempBody); } } elseif (count($formParams) > 0) { if ($multipart) { diff --git a/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/FakeClassnameTags123Api.php b/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/FakeClassnameTags123Api.php index 2870a4c90507..842e6e86008e 100644 --- a/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/FakeClassnameTags123Api.php +++ b/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/FakeClassnameTags123Api.php @@ -87,6 +87,33 @@ public function getConfig() return $this->config; } + + /** + * @param mixed $body Element to become the body of the Request + * + * @return mixed|string + */ + private function formatBody($body) + { + // \stdClass and arrays have no __toString(), so we should encode them manually + if($body instanceof \stdClass) { + return \GuzzleHttp\json_encode($body); + } + + // arrays must be encoded manually as well, otherwise the objects inside it don't get encoded + if(is_array($body)) { + $return = "["; + + foreach($body as $item) { + $return .="\n".$this->formatBody($item).","; + } + + return trim($return, ',')."\n]"; + } + + return $body; + } + /** * Operation testClassname * @@ -307,10 +334,10 @@ protected function testClassnameRequest($client) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - $httpBody = $_tempBody; - // \stdClass has no __toString(), so we should encode it manually - if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { - $httpBody = \GuzzleHttp\json_encode($httpBody); + if($headers['Content-Type'] !== 'application/json') { + $httpBody = $_tempBody; + } else { + $httpBody = $this->formatBody($_tempBody); } } elseif (count($formParams) > 0) { if ($multipart) { diff --git a/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/PetApi.php b/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/PetApi.php index 40d4cb8e1b7d..26f1b3cd7f83 100644 --- a/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/PetApi.php +++ b/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/PetApi.php @@ -87,6 +87,33 @@ public function getConfig() return $this->config; } + + /** + * @param mixed $body Element to become the body of the Request + * + * @return mixed|string + */ + private function formatBody($body) + { + // \stdClass and arrays have no __toString(), so we should encode them manually + if($body instanceof \stdClass) { + return \GuzzleHttp\json_encode($body); + } + + // arrays must be encoded manually as well, otherwise the objects inside it don't get encoded + if(is_array($body)) { + $return = "["; + + foreach($body as $item) { + $return .="\n".$this->formatBody($item).","; + } + + return trim($return, ',')."\n]"; + } + + return $body; + } + /** * Operation addPet * @@ -259,10 +286,10 @@ protected function addPetRequest($pet) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - $httpBody = $_tempBody; - // \stdClass has no __toString(), so we should encode it manually - if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { - $httpBody = \GuzzleHttp\json_encode($httpBody); + if($headers['Content-Type'] !== 'application/json') { + $httpBody = $_tempBody; + } else { + $httpBody = $this->formatBody($_tempBody); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -496,10 +523,10 @@ protected function deletePetRequest($pet_id, $api_key = null) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - $httpBody = $_tempBody; - // \stdClass has no __toString(), so we should encode it manually - if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { - $httpBody = \GuzzleHttp\json_encode($httpBody); + if($headers['Content-Type'] !== 'application/json') { + $httpBody = $_tempBody; + } else { + $httpBody = $this->formatBody($_tempBody); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -771,10 +798,10 @@ protected function findPetsByStatusRequest($status) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - $httpBody = $_tempBody; - // \stdClass has no __toString(), so we should encode it manually - if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { - $httpBody = \GuzzleHttp\json_encode($httpBody); + if($headers['Content-Type'] !== 'application/json') { + $httpBody = $_tempBody; + } else { + $httpBody = $this->formatBody($_tempBody); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1046,10 +1073,10 @@ protected function findPetsByTagsRequest($tags) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - $httpBody = $_tempBody; - // \stdClass has no __toString(), so we should encode it manually - if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { - $httpBody = \GuzzleHttp\json_encode($httpBody); + if($headers['Content-Type'] !== 'application/json') { + $httpBody = $_tempBody; + } else { + $httpBody = $this->formatBody($_tempBody); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1322,10 +1349,10 @@ protected function getPetByIdRequest($pet_id) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - $httpBody = $_tempBody; - // \stdClass has no __toString(), so we should encode it manually - if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { - $httpBody = \GuzzleHttp\json_encode($httpBody); + if($headers['Content-Type'] !== 'application/json') { + $httpBody = $_tempBody; + } else { + $httpBody = $this->formatBody($_tempBody); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1546,10 +1573,10 @@ protected function updatePetRequest($pet) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - $httpBody = $_tempBody; - // \stdClass has no __toString(), so we should encode it manually - if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { - $httpBody = \GuzzleHttp\json_encode($httpBody); + if($headers['Content-Type'] !== 'application/json') { + $httpBody = $_tempBody; + } else { + $httpBody = $this->formatBody($_tempBody); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1792,10 +1819,10 @@ protected function updatePetWithFormRequest($pet_id, $name = null, $status = nul // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - $httpBody = $_tempBody; - // \stdClass has no __toString(), so we should encode it manually - if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { - $httpBody = \GuzzleHttp\json_encode($httpBody); + if($headers['Content-Type'] !== 'application/json') { + $httpBody = $_tempBody; + } else { + $httpBody = $this->formatBody($_tempBody); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -2087,10 +2114,10 @@ protected function uploadFileRequest($pet_id, $additional_metadata = null, $file // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - $httpBody = $_tempBody; - // \stdClass has no __toString(), so we should encode it manually - if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { - $httpBody = \GuzzleHttp\json_encode($httpBody); + if($headers['Content-Type'] !== 'application/json') { + $httpBody = $_tempBody; + } else { + $httpBody = $this->formatBody($_tempBody); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -2388,10 +2415,10 @@ protected function uploadFileWithRequiredFileRequest($pet_id, $required_file, $a // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - $httpBody = $_tempBody; - // \stdClass has no __toString(), so we should encode it manually - if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { - $httpBody = \GuzzleHttp\json_encode($httpBody); + if($headers['Content-Type'] !== 'application/json') { + $httpBody = $_tempBody; + } else { + $httpBody = $this->formatBody($_tempBody); } } elseif (count($formParams) > 0) { if ($multipart) { diff --git a/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/StoreApi.php b/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/StoreApi.php index 44c9421b2cbc..d479e97c663c 100644 --- a/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/StoreApi.php +++ b/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/StoreApi.php @@ -87,6 +87,33 @@ public function getConfig() return $this->config; } + + /** + * @param mixed $body Element to become the body of the Request + * + * @return mixed|string + */ + private function formatBody($body) + { + // \stdClass and arrays have no __toString(), so we should encode them manually + if($body instanceof \stdClass) { + return \GuzzleHttp\json_encode($body); + } + + // arrays must be encoded manually as well, otherwise the objects inside it don't get encoded + if(is_array($body)) { + $return = "["; + + foreach($body as $item) { + $return .="\n".$this->formatBody($item).","; + } + + return trim($return, ',')."\n]"; + } + + return $body; + } + /** * Operation deleteOrder * @@ -264,10 +291,10 @@ protected function deleteOrderRequest($order_id) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - $httpBody = $_tempBody; - // \stdClass has no __toString(), so we should encode it manually - if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { - $httpBody = \GuzzleHttp\json_encode($httpBody); + if($headers['Content-Type'] !== 'application/json') { + $httpBody = $_tempBody; + } else { + $httpBody = $this->formatBody($_tempBody); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -517,10 +544,10 @@ protected function getInventoryRequest() // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - $httpBody = $_tempBody; - // \stdClass has no __toString(), so we should encode it manually - if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { - $httpBody = \GuzzleHttp\json_encode($httpBody); + if($headers['Content-Type'] !== 'application/json') { + $httpBody = $_tempBody; + } else { + $httpBody = $this->formatBody($_tempBody); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -801,10 +828,10 @@ protected function getOrderByIdRequest($order_id) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - $httpBody = $_tempBody; - // \stdClass has no __toString(), so we should encode it manually - if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { - $httpBody = \GuzzleHttp\json_encode($httpBody); + if($headers['Content-Type'] !== 'application/json') { + $httpBody = $_tempBody; + } else { + $httpBody = $this->formatBody($_tempBody); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1068,10 +1095,10 @@ protected function placeOrderRequest($order) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - $httpBody = $_tempBody; - // \stdClass has no __toString(), so we should encode it manually - if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { - $httpBody = \GuzzleHttp\json_encode($httpBody); + if($headers['Content-Type'] !== 'application/json') { + $httpBody = $_tempBody; + } else { + $httpBody = $this->formatBody($_tempBody); } } elseif (count($formParams) > 0) { if ($multipart) { diff --git a/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/UserApi.php b/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/UserApi.php index 5f3227b2878f..d4d9b21b42c5 100644 --- a/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/UserApi.php +++ b/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/UserApi.php @@ -87,6 +87,33 @@ public function getConfig() return $this->config; } + + /** + * @param mixed $body Element to become the body of the Request + * + * @return mixed|string + */ + private function formatBody($body) + { + // \stdClass and arrays have no __toString(), so we should encode them manually + if($body instanceof \stdClass) { + return \GuzzleHttp\json_encode($body); + } + + // arrays must be encoded manually as well, otherwise the objects inside it don't get encoded + if(is_array($body)) { + $return = "["; + + foreach($body as $item) { + $return .="\n".$this->formatBody($item).","; + } + + return trim($return, ',')."\n]"; + } + + return $body; + } + /** * Operation createUser * @@ -259,10 +286,10 @@ protected function createUserRequest($user) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - $httpBody = $_tempBody; - // \stdClass has no __toString(), so we should encode it manually - if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { - $httpBody = \GuzzleHttp\json_encode($httpBody); + if($headers['Content-Type'] !== 'application/json') { + $httpBody = $_tempBody; + } else { + $httpBody = $this->formatBody($_tempBody); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -478,10 +505,10 @@ protected function createUsersWithArrayInputRequest($user) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - $httpBody = $_tempBody; - // \stdClass has no __toString(), so we should encode it manually - if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { - $httpBody = \GuzzleHttp\json_encode($httpBody); + if($headers['Content-Type'] !== 'application/json') { + $httpBody = $_tempBody; + } else { + $httpBody = $this->formatBody($_tempBody); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -697,10 +724,10 @@ protected function createUsersWithListInputRequest($user) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - $httpBody = $_tempBody; - // \stdClass has no __toString(), so we should encode it manually - if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { - $httpBody = \GuzzleHttp\json_encode($httpBody); + if($headers['Content-Type'] !== 'application/json') { + $httpBody = $_tempBody; + } else { + $httpBody = $this->formatBody($_tempBody); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -921,10 +948,10 @@ protected function deleteUserRequest($username) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - $httpBody = $_tempBody; - // \stdClass has no __toString(), so we should encode it manually - if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { - $httpBody = \GuzzleHttp\json_encode($httpBody); + if($headers['Content-Type'] !== 'application/json') { + $httpBody = $_tempBody; + } else { + $httpBody = $this->formatBody($_tempBody); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1193,10 +1220,10 @@ protected function getUserByNameRequest($username) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - $httpBody = $_tempBody; - // \stdClass has no __toString(), so we should encode it manually - if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { - $httpBody = \GuzzleHttp\json_encode($httpBody); + if($headers['Content-Type'] !== 'application/json') { + $httpBody = $_tempBody; + } else { + $httpBody = $this->formatBody($_tempBody); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1476,10 +1503,10 @@ protected function loginUserRequest($username, $password) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - $httpBody = $_tempBody; - // \stdClass has no __toString(), so we should encode it manually - if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { - $httpBody = \GuzzleHttp\json_encode($httpBody); + if($headers['Content-Type'] !== 'application/json') { + $httpBody = $_tempBody; + } else { + $httpBody = $this->formatBody($_tempBody); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1681,10 +1708,10 @@ protected function logoutUserRequest() // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - $httpBody = $_tempBody; - // \stdClass has no __toString(), so we should encode it manually - if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { - $httpBody = \GuzzleHttp\json_encode($httpBody); + if($headers['Content-Type'] !== 'application/json') { + $httpBody = $_tempBody; + } else { + $httpBody = $this->formatBody($_tempBody); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1919,10 +1946,10 @@ protected function updateUserRequest($username, $user) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - $httpBody = $_tempBody; - // \stdClass has no __toString(), so we should encode it manually - if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { - $httpBody = \GuzzleHttp\json_encode($httpBody); + if($headers['Content-Type'] !== 'application/json') { + $httpBody = $_tempBody; + } else { + $httpBody = $this->formatBody($_tempBody); } } elseif (count($formParams) > 0) { if ($multipart) { From 69443eff74dbabd0c311268d64c1eb6fc46a2b20 Mon Sep 17 00:00:00 2001 From: Thomas Hansen Date: Mon, 17 Sep 2018 08:20:02 +0200 Subject: [PATCH 2/9] PR #1037 - Fix issue with array as parameter to operation --- .../src/main/resources/php/api.mustache | 29 +------------------ 1 file changed, 1 insertion(+), 28 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/php/api.mustache b/modules/openapi-generator/src/main/resources/php/api.mustache index 44a395279e72..8613af6301e9 100644 --- a/modules/openapi-generator/src/main/resources/php/api.mustache +++ b/modules/openapi-generator/src/main/resources/php/api.mustache @@ -77,33 +77,6 @@ use {{invokerPackage}}\ObjectSerializer; return $this->config; } - - /** - * @param mixed $body Element to become the body of the Request - * - * @return mixed|string - */ - private function formatBody($body) - { - // \stdClass and arrays have no __toString(), so we should encode them manually - if($body instanceof \stdClass) { - return \GuzzleHttp\json_encode($body); - } - - // arrays must be encoded manually as well, otherwise the objects inside it don't get encoded - if(is_array($body)) { - $return = "["; - - foreach($body as $item) { - $return .="\n".$this->formatBody($item).","; - } - - return trim($return, ',')."\n]"; - } - - return $body; - } - {{#operation}} /** * Operation {{{operationId}}} @@ -474,7 +447,7 @@ use {{invokerPackage}}\ObjectSerializer; if($headers['Content-Type'] !== 'application/json') { $httpBody = $_tempBody; } else { - $httpBody = $this->formatBody($_tempBody); + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); } } elseif (count($formParams) > 0) { if ($multipart) { From 25c79869ca23e7e41b2e7867960cd8759b3c68c0 Mon Sep 17 00:00:00 2001 From: Thomas Hansen Date: Mon, 17 Sep 2018 08:23:21 +0200 Subject: [PATCH 3/9] update samples --- .../lib/Api/AnotherFakeApi.php | 29 +---------- .../php/OpenAPIClient-php/lib/Api/FakeApi.php | 49 +++++-------------- .../lib/Api/FakeClassnameTags123Api.php | 29 +---------- .../php/OpenAPIClient-php/lib/Api/PetApi.php | 45 ++++------------- .../OpenAPIClient-php/lib/Api/StoreApi.php | 35 ++----------- .../php/OpenAPIClient-php/lib/Api/UserApi.php | 43 +++------------- .../lib/Api/AnotherFakeApi.php | 29 +---------- .../php/OpenAPIClient-php/lib/Api/FakeApi.php | 49 +++++-------------- .../lib/Api/FakeClassnameTags123Api.php | 29 +---------- .../php/OpenAPIClient-php/lib/Api/PetApi.php | 45 ++++------------- .../OpenAPIClient-php/lib/Api/StoreApi.php | 35 ++----------- .../php/OpenAPIClient-php/lib/Api/UserApi.php | 43 +++------------- 12 files changed, 68 insertions(+), 392 deletions(-) diff --git a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/AnotherFakeApi.php b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/AnotherFakeApi.php index 0a880cf2dff2..3ad317c3d711 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/AnotherFakeApi.php +++ b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/AnotherFakeApi.php @@ -87,33 +87,6 @@ public function getConfig() return $this->config; } - - /** - * @param mixed $body Element to become the body of the Request - * - * @return mixed|string - */ - private function formatBody($body) - { - // \stdClass and arrays have no __toString(), so we should encode them manually - if($body instanceof \stdClass) { - return \GuzzleHttp\json_encode($body); - } - - // arrays must be encoded manually as well, otherwise the objects inside it don't get encoded - if(is_array($body)) { - $return = "["; - - foreach($body as $item) { - $return .="\n".$this->formatBody($item).","; - } - - return trim($return, ',')."\n]"; - } - - return $body; - } - /** * Operation call123TestSpecialTags * @@ -337,7 +310,7 @@ protected function call123TestSpecialTagsRequest($client) if($headers['Content-Type'] !== 'application/json') { $httpBody = $_tempBody; } else { - $httpBody = $this->formatBody($_tempBody); + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); } } elseif (count($formParams) > 0) { if ($multipart) { diff --git a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/FakeApi.php b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/FakeApi.php index 9eaa5d0043a7..60d4fce2fe35 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/FakeApi.php +++ b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/FakeApi.php @@ -87,33 +87,6 @@ public function getConfig() return $this->config; } - - /** - * @param mixed $body Element to become the body of the Request - * - * @return mixed|string - */ - private function formatBody($body) - { - // \stdClass and arrays have no __toString(), so we should encode them manually - if($body instanceof \stdClass) { - return \GuzzleHttp\json_encode($body); - } - - // arrays must be encoded manually as well, otherwise the objects inside it don't get encoded - if(is_array($body)) { - $return = "["; - - foreach($body as $item) { - $return .="\n".$this->formatBody($item).","; - } - - return trim($return, ',')."\n]"; - } - - return $body; - } - /** * Operation fakeOuterBooleanSerialize * @@ -327,7 +300,7 @@ protected function fakeOuterBooleanSerializeRequest($body = null) if($headers['Content-Type'] !== 'application/json') { $httpBody = $_tempBody; } else { - $httpBody = $this->formatBody($_tempBody); + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -584,7 +557,7 @@ protected function fakeOuterCompositeSerializeRequest($outer_composite = null) if($headers['Content-Type'] !== 'application/json') { $httpBody = $_tempBody; } else { - $httpBody = $this->formatBody($_tempBody); + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -841,7 +814,7 @@ protected function fakeOuterNumberSerializeRequest($body = null) if($headers['Content-Type'] !== 'application/json') { $httpBody = $_tempBody; } else { - $httpBody = $this->formatBody($_tempBody); + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1098,7 +1071,7 @@ protected function fakeOuterStringSerializeRequest($body = null) if($headers['Content-Type'] !== 'application/json') { $httpBody = $_tempBody; } else { - $httpBody = $this->formatBody($_tempBody); + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1313,7 +1286,7 @@ protected function testBodyWithFileSchemaRequest($file_schema_test_class) if($headers['Content-Type'] !== 'application/json') { $httpBody = $_tempBody; } else { - $httpBody = $this->formatBody($_tempBody); + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1543,7 +1516,7 @@ protected function testBodyWithQueryParamsRequest($query, $user) if($headers['Content-Type'] !== 'application/json') { $httpBody = $_tempBody; } else { - $httpBody = $this->formatBody($_tempBody); + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1810,7 +1783,7 @@ protected function testClientModelRequest($client) if($headers['Content-Type'] !== 'application/json') { $httpBody = $_tempBody; } else { - $httpBody = $this->formatBody($_tempBody); + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -2213,7 +2186,7 @@ protected function testEndpointParametersRequest($number, $double, $pattern_with if($headers['Content-Type'] !== 'application/json') { $httpBody = $_tempBody; } else { - $httpBody = $this->formatBody($_tempBody); + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -2500,7 +2473,7 @@ protected function testEnumParametersRequest($enum_header_string_array = null, $ if($headers['Content-Type'] !== 'application/json') { $httpBody = $_tempBody; } else { - $httpBody = $this->formatBody($_tempBody); + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -2719,7 +2692,7 @@ protected function testInlineAdditionalPropertiesRequest($request_body) if($headers['Content-Type'] !== 'application/json') { $httpBody = $_tempBody; } else { - $httpBody = $this->formatBody($_tempBody); + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -2954,7 +2927,7 @@ protected function testJsonFormDataRequest($param, $param2) if($headers['Content-Type'] !== 'application/json') { $httpBody = $_tempBody; } else { - $httpBody = $this->formatBody($_tempBody); + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); } } elseif (count($formParams) > 0) { if ($multipart) { diff --git a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/FakeClassnameTags123Api.php b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/FakeClassnameTags123Api.php index 842e6e86008e..8998ec886ddf 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/FakeClassnameTags123Api.php +++ b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/FakeClassnameTags123Api.php @@ -87,33 +87,6 @@ public function getConfig() return $this->config; } - - /** - * @param mixed $body Element to become the body of the Request - * - * @return mixed|string - */ - private function formatBody($body) - { - // \stdClass and arrays have no __toString(), so we should encode them manually - if($body instanceof \stdClass) { - return \GuzzleHttp\json_encode($body); - } - - // arrays must be encoded manually as well, otherwise the objects inside it don't get encoded - if(is_array($body)) { - $return = "["; - - foreach($body as $item) { - $return .="\n".$this->formatBody($item).","; - } - - return trim($return, ',')."\n]"; - } - - return $body; - } - /** * Operation testClassname * @@ -337,7 +310,7 @@ protected function testClassnameRequest($client) if($headers['Content-Type'] !== 'application/json') { $httpBody = $_tempBody; } else { - $httpBody = $this->formatBody($_tempBody); + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); } } elseif (count($formParams) > 0) { if ($multipart) { diff --git a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/PetApi.php b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/PetApi.php index 26f1b3cd7f83..b6b90747f7c5 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/PetApi.php +++ b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/PetApi.php @@ -87,33 +87,6 @@ public function getConfig() return $this->config; } - - /** - * @param mixed $body Element to become the body of the Request - * - * @return mixed|string - */ - private function formatBody($body) - { - // \stdClass and arrays have no __toString(), so we should encode them manually - if($body instanceof \stdClass) { - return \GuzzleHttp\json_encode($body); - } - - // arrays must be encoded manually as well, otherwise the objects inside it don't get encoded - if(is_array($body)) { - $return = "["; - - foreach($body as $item) { - $return .="\n".$this->formatBody($item).","; - } - - return trim($return, ',')."\n]"; - } - - return $body; - } - /** * Operation addPet * @@ -289,7 +262,7 @@ protected function addPetRequest($pet) if($headers['Content-Type'] !== 'application/json') { $httpBody = $_tempBody; } else { - $httpBody = $this->formatBody($_tempBody); + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -526,7 +499,7 @@ protected function deletePetRequest($pet_id, $api_key = null) if($headers['Content-Type'] !== 'application/json') { $httpBody = $_tempBody; } else { - $httpBody = $this->formatBody($_tempBody); + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -801,7 +774,7 @@ protected function findPetsByStatusRequest($status) if($headers['Content-Type'] !== 'application/json') { $httpBody = $_tempBody; } else { - $httpBody = $this->formatBody($_tempBody); + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1076,7 +1049,7 @@ protected function findPetsByTagsRequest($tags) if($headers['Content-Type'] !== 'application/json') { $httpBody = $_tempBody; } else { - $httpBody = $this->formatBody($_tempBody); + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1352,7 +1325,7 @@ protected function getPetByIdRequest($pet_id) if($headers['Content-Type'] !== 'application/json') { $httpBody = $_tempBody; } else { - $httpBody = $this->formatBody($_tempBody); + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1576,7 +1549,7 @@ protected function updatePetRequest($pet) if($headers['Content-Type'] !== 'application/json') { $httpBody = $_tempBody; } else { - $httpBody = $this->formatBody($_tempBody); + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1822,7 +1795,7 @@ protected function updatePetWithFormRequest($pet_id, $name = null, $status = nul if($headers['Content-Type'] !== 'application/json') { $httpBody = $_tempBody; } else { - $httpBody = $this->formatBody($_tempBody); + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -2117,7 +2090,7 @@ protected function uploadFileRequest($pet_id, $additional_metadata = null, $file if($headers['Content-Type'] !== 'application/json') { $httpBody = $_tempBody; } else { - $httpBody = $this->formatBody($_tempBody); + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -2418,7 +2391,7 @@ protected function uploadFileWithRequiredFileRequest($pet_id, $required_file, $a if($headers['Content-Type'] !== 'application/json') { $httpBody = $_tempBody; } else { - $httpBody = $this->formatBody($_tempBody); + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); } } elseif (count($formParams) > 0) { if ($multipart) { diff --git a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/StoreApi.php b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/StoreApi.php index 9bb646c29de6..ad9c5515d7f7 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/StoreApi.php +++ b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/StoreApi.php @@ -87,33 +87,6 @@ public function getConfig() return $this->config; } - - /** - * @param mixed $body Element to become the body of the Request - * - * @return mixed|string - */ - private function formatBody($body) - { - // \stdClass and arrays have no __toString(), so we should encode them manually - if($body instanceof \stdClass) { - return \GuzzleHttp\json_encode($body); - } - - // arrays must be encoded manually as well, otherwise the objects inside it don't get encoded - if(is_array($body)) { - $return = "["; - - foreach($body as $item) { - $return .="\n".$this->formatBody($item).","; - } - - return trim($return, ',')."\n]"; - } - - return $body; - } - /** * Operation deleteOrder * @@ -294,7 +267,7 @@ protected function deleteOrderRequest($order_id) if($headers['Content-Type'] !== 'application/json') { $httpBody = $_tempBody; } else { - $httpBody = $this->formatBody($_tempBody); + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -547,7 +520,7 @@ protected function getInventoryRequest() if($headers['Content-Type'] !== 'application/json') { $httpBody = $_tempBody; } else { - $httpBody = $this->formatBody($_tempBody); + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -831,7 +804,7 @@ protected function getOrderByIdRequest($order_id) if($headers['Content-Type'] !== 'application/json') { $httpBody = $_tempBody; } else { - $httpBody = $this->formatBody($_tempBody); + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1098,7 +1071,7 @@ protected function placeOrderRequest($order) if($headers['Content-Type'] !== 'application/json') { $httpBody = $_tempBody; } else { - $httpBody = $this->formatBody($_tempBody); + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); } } elseif (count($formParams) > 0) { if ($multipart) { diff --git a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/UserApi.php b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/UserApi.php index 8234552623c3..b22af89d7f7e 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/UserApi.php +++ b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/UserApi.php @@ -87,33 +87,6 @@ public function getConfig() return $this->config; } - - /** - * @param mixed $body Element to become the body of the Request - * - * @return mixed|string - */ - private function formatBody($body) - { - // \stdClass and arrays have no __toString(), so we should encode them manually - if($body instanceof \stdClass) { - return \GuzzleHttp\json_encode($body); - } - - // arrays must be encoded manually as well, otherwise the objects inside it don't get encoded - if(is_array($body)) { - $return = "["; - - foreach($body as $item) { - $return .="\n".$this->formatBody($item).","; - } - - return trim($return, ',')."\n]"; - } - - return $body; - } - /** * Operation createUser * @@ -289,7 +262,7 @@ protected function createUserRequest($user) if($headers['Content-Type'] !== 'application/json') { $httpBody = $_tempBody; } else { - $httpBody = $this->formatBody($_tempBody); + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -508,7 +481,7 @@ protected function createUsersWithArrayInputRequest($user) if($headers['Content-Type'] !== 'application/json') { $httpBody = $_tempBody; } else { - $httpBody = $this->formatBody($_tempBody); + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -727,7 +700,7 @@ protected function createUsersWithListInputRequest($user) if($headers['Content-Type'] !== 'application/json') { $httpBody = $_tempBody; } else { - $httpBody = $this->formatBody($_tempBody); + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -951,7 +924,7 @@ protected function deleteUserRequest($username) if($headers['Content-Type'] !== 'application/json') { $httpBody = $_tempBody; } else { - $httpBody = $this->formatBody($_tempBody); + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1223,7 +1196,7 @@ protected function getUserByNameRequest($username) if($headers['Content-Type'] !== 'application/json') { $httpBody = $_tempBody; } else { - $httpBody = $this->formatBody($_tempBody); + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1506,7 +1479,7 @@ protected function loginUserRequest($username, $password) if($headers['Content-Type'] !== 'application/json') { $httpBody = $_tempBody; } else { - $httpBody = $this->formatBody($_tempBody); + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1711,7 +1684,7 @@ protected function logoutUserRequest() if($headers['Content-Type'] !== 'application/json') { $httpBody = $_tempBody; } else { - $httpBody = $this->formatBody($_tempBody); + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1949,7 +1922,7 @@ protected function updateUserRequest($username, $user) if($headers['Content-Type'] !== 'application/json') { $httpBody = $_tempBody; } else { - $httpBody = $this->formatBody($_tempBody); + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); } } elseif (count($formParams) > 0) { if ($multipart) { diff --git a/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/AnotherFakeApi.php b/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/AnotherFakeApi.php index 0a880cf2dff2..3ad317c3d711 100644 --- a/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/AnotherFakeApi.php +++ b/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/AnotherFakeApi.php @@ -87,33 +87,6 @@ public function getConfig() return $this->config; } - - /** - * @param mixed $body Element to become the body of the Request - * - * @return mixed|string - */ - private function formatBody($body) - { - // \stdClass and arrays have no __toString(), so we should encode them manually - if($body instanceof \stdClass) { - return \GuzzleHttp\json_encode($body); - } - - // arrays must be encoded manually as well, otherwise the objects inside it don't get encoded - if(is_array($body)) { - $return = "["; - - foreach($body as $item) { - $return .="\n".$this->formatBody($item).","; - } - - return trim($return, ',')."\n]"; - } - - return $body; - } - /** * Operation call123TestSpecialTags * @@ -337,7 +310,7 @@ protected function call123TestSpecialTagsRequest($client) if($headers['Content-Type'] !== 'application/json') { $httpBody = $_tempBody; } else { - $httpBody = $this->formatBody($_tempBody); + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); } } elseif (count($formParams) > 0) { if ($multipart) { diff --git a/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/FakeApi.php b/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/FakeApi.php index 961e37a036ae..2fa51a2da148 100644 --- a/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/FakeApi.php +++ b/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/FakeApi.php @@ -87,33 +87,6 @@ public function getConfig() return $this->config; } - - /** - * @param mixed $body Element to become the body of the Request - * - * @return mixed|string - */ - private function formatBody($body) - { - // \stdClass and arrays have no __toString(), so we should encode them manually - if($body instanceof \stdClass) { - return \GuzzleHttp\json_encode($body); - } - - // arrays must be encoded manually as well, otherwise the objects inside it don't get encoded - if(is_array($body)) { - $return = "["; - - foreach($body as $item) { - $return .="\n".$this->formatBody($item).","; - } - - return trim($return, ',')."\n]"; - } - - return $body; - } - /** * Operation fakeOuterBooleanSerialize * @@ -327,7 +300,7 @@ protected function fakeOuterBooleanSerializeRequest($body = null) if($headers['Content-Type'] !== 'application/json') { $httpBody = $_tempBody; } else { - $httpBody = $this->formatBody($_tempBody); + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -584,7 +557,7 @@ protected function fakeOuterCompositeSerializeRequest($outer_composite = null) if($headers['Content-Type'] !== 'application/json') { $httpBody = $_tempBody; } else { - $httpBody = $this->formatBody($_tempBody); + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -841,7 +814,7 @@ protected function fakeOuterNumberSerializeRequest($body = null) if($headers['Content-Type'] !== 'application/json') { $httpBody = $_tempBody; } else { - $httpBody = $this->formatBody($_tempBody); + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1098,7 +1071,7 @@ protected function fakeOuterStringSerializeRequest($body = null) if($headers['Content-Type'] !== 'application/json') { $httpBody = $_tempBody; } else { - $httpBody = $this->formatBody($_tempBody); + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1313,7 +1286,7 @@ protected function testBodyWithFileSchemaRequest($file_schema_test_class) if($headers['Content-Type'] !== 'application/json') { $httpBody = $_tempBody; } else { - $httpBody = $this->formatBody($_tempBody); + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1543,7 +1516,7 @@ protected function testBodyWithQueryParamsRequest($query, $user) if($headers['Content-Type'] !== 'application/json') { $httpBody = $_tempBody; } else { - $httpBody = $this->formatBody($_tempBody); + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1810,7 +1783,7 @@ protected function testClientModelRequest($client) if($headers['Content-Type'] !== 'application/json') { $httpBody = $_tempBody; } else { - $httpBody = $this->formatBody($_tempBody); + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -2213,7 +2186,7 @@ protected function testEndpointParametersRequest($number, $double, $pattern_with if($headers['Content-Type'] !== 'application/json') { $httpBody = $_tempBody; } else { - $httpBody = $this->formatBody($_tempBody); + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -2500,7 +2473,7 @@ protected function testEnumParametersRequest($enum_header_string_array = null, $ if($headers['Content-Type'] !== 'application/json') { $httpBody = $_tempBody; } else { - $httpBody = $this->formatBody($_tempBody); + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -2719,7 +2692,7 @@ protected function testInlineAdditionalPropertiesRequest($request_body) if($headers['Content-Type'] !== 'application/json') { $httpBody = $_tempBody; } else { - $httpBody = $this->formatBody($_tempBody); + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -2954,7 +2927,7 @@ protected function testJsonFormDataRequest($param, $param2) if($headers['Content-Type'] !== 'application/json') { $httpBody = $_tempBody; } else { - $httpBody = $this->formatBody($_tempBody); + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); } } elseif (count($formParams) > 0) { if ($multipart) { diff --git a/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/FakeClassnameTags123Api.php b/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/FakeClassnameTags123Api.php index 842e6e86008e..8998ec886ddf 100644 --- a/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/FakeClassnameTags123Api.php +++ b/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/FakeClassnameTags123Api.php @@ -87,33 +87,6 @@ public function getConfig() return $this->config; } - - /** - * @param mixed $body Element to become the body of the Request - * - * @return mixed|string - */ - private function formatBody($body) - { - // \stdClass and arrays have no __toString(), so we should encode them manually - if($body instanceof \stdClass) { - return \GuzzleHttp\json_encode($body); - } - - // arrays must be encoded manually as well, otherwise the objects inside it don't get encoded - if(is_array($body)) { - $return = "["; - - foreach($body as $item) { - $return .="\n".$this->formatBody($item).","; - } - - return trim($return, ',')."\n]"; - } - - return $body; - } - /** * Operation testClassname * @@ -337,7 +310,7 @@ protected function testClassnameRequest($client) if($headers['Content-Type'] !== 'application/json') { $httpBody = $_tempBody; } else { - $httpBody = $this->formatBody($_tempBody); + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); } } elseif (count($formParams) > 0) { if ($multipart) { diff --git a/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/PetApi.php b/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/PetApi.php index 26f1b3cd7f83..b6b90747f7c5 100644 --- a/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/PetApi.php +++ b/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/PetApi.php @@ -87,33 +87,6 @@ public function getConfig() return $this->config; } - - /** - * @param mixed $body Element to become the body of the Request - * - * @return mixed|string - */ - private function formatBody($body) - { - // \stdClass and arrays have no __toString(), so we should encode them manually - if($body instanceof \stdClass) { - return \GuzzleHttp\json_encode($body); - } - - // arrays must be encoded manually as well, otherwise the objects inside it don't get encoded - if(is_array($body)) { - $return = "["; - - foreach($body as $item) { - $return .="\n".$this->formatBody($item).","; - } - - return trim($return, ',')."\n]"; - } - - return $body; - } - /** * Operation addPet * @@ -289,7 +262,7 @@ protected function addPetRequest($pet) if($headers['Content-Type'] !== 'application/json') { $httpBody = $_tempBody; } else { - $httpBody = $this->formatBody($_tempBody); + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -526,7 +499,7 @@ protected function deletePetRequest($pet_id, $api_key = null) if($headers['Content-Type'] !== 'application/json') { $httpBody = $_tempBody; } else { - $httpBody = $this->formatBody($_tempBody); + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -801,7 +774,7 @@ protected function findPetsByStatusRequest($status) if($headers['Content-Type'] !== 'application/json') { $httpBody = $_tempBody; } else { - $httpBody = $this->formatBody($_tempBody); + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1076,7 +1049,7 @@ protected function findPetsByTagsRequest($tags) if($headers['Content-Type'] !== 'application/json') { $httpBody = $_tempBody; } else { - $httpBody = $this->formatBody($_tempBody); + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1352,7 +1325,7 @@ protected function getPetByIdRequest($pet_id) if($headers['Content-Type'] !== 'application/json') { $httpBody = $_tempBody; } else { - $httpBody = $this->formatBody($_tempBody); + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1576,7 +1549,7 @@ protected function updatePetRequest($pet) if($headers['Content-Type'] !== 'application/json') { $httpBody = $_tempBody; } else { - $httpBody = $this->formatBody($_tempBody); + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1822,7 +1795,7 @@ protected function updatePetWithFormRequest($pet_id, $name = null, $status = nul if($headers['Content-Type'] !== 'application/json') { $httpBody = $_tempBody; } else { - $httpBody = $this->formatBody($_tempBody); + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -2117,7 +2090,7 @@ protected function uploadFileRequest($pet_id, $additional_metadata = null, $file if($headers['Content-Type'] !== 'application/json') { $httpBody = $_tempBody; } else { - $httpBody = $this->formatBody($_tempBody); + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -2418,7 +2391,7 @@ protected function uploadFileWithRequiredFileRequest($pet_id, $required_file, $a if($headers['Content-Type'] !== 'application/json') { $httpBody = $_tempBody; } else { - $httpBody = $this->formatBody($_tempBody); + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); } } elseif (count($formParams) > 0) { if ($multipart) { diff --git a/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/StoreApi.php b/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/StoreApi.php index d479e97c663c..132cf21aa5bc 100644 --- a/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/StoreApi.php +++ b/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/StoreApi.php @@ -87,33 +87,6 @@ public function getConfig() return $this->config; } - - /** - * @param mixed $body Element to become the body of the Request - * - * @return mixed|string - */ - private function formatBody($body) - { - // \stdClass and arrays have no __toString(), so we should encode them manually - if($body instanceof \stdClass) { - return \GuzzleHttp\json_encode($body); - } - - // arrays must be encoded manually as well, otherwise the objects inside it don't get encoded - if(is_array($body)) { - $return = "["; - - foreach($body as $item) { - $return .="\n".$this->formatBody($item).","; - } - - return trim($return, ',')."\n]"; - } - - return $body; - } - /** * Operation deleteOrder * @@ -294,7 +267,7 @@ protected function deleteOrderRequest($order_id) if($headers['Content-Type'] !== 'application/json') { $httpBody = $_tempBody; } else { - $httpBody = $this->formatBody($_tempBody); + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -547,7 +520,7 @@ protected function getInventoryRequest() if($headers['Content-Type'] !== 'application/json') { $httpBody = $_tempBody; } else { - $httpBody = $this->formatBody($_tempBody); + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -831,7 +804,7 @@ protected function getOrderByIdRequest($order_id) if($headers['Content-Type'] !== 'application/json') { $httpBody = $_tempBody; } else { - $httpBody = $this->formatBody($_tempBody); + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1098,7 +1071,7 @@ protected function placeOrderRequest($order) if($headers['Content-Type'] !== 'application/json') { $httpBody = $_tempBody; } else { - $httpBody = $this->formatBody($_tempBody); + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); } } elseif (count($formParams) > 0) { if ($multipart) { diff --git a/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/UserApi.php b/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/UserApi.php index d4d9b21b42c5..487f85262462 100644 --- a/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/UserApi.php +++ b/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/UserApi.php @@ -87,33 +87,6 @@ public function getConfig() return $this->config; } - - /** - * @param mixed $body Element to become the body of the Request - * - * @return mixed|string - */ - private function formatBody($body) - { - // \stdClass and arrays have no __toString(), so we should encode them manually - if($body instanceof \stdClass) { - return \GuzzleHttp\json_encode($body); - } - - // arrays must be encoded manually as well, otherwise the objects inside it don't get encoded - if(is_array($body)) { - $return = "["; - - foreach($body as $item) { - $return .="\n".$this->formatBody($item).","; - } - - return trim($return, ',')."\n]"; - } - - return $body; - } - /** * Operation createUser * @@ -289,7 +262,7 @@ protected function createUserRequest($user) if($headers['Content-Type'] !== 'application/json') { $httpBody = $_tempBody; } else { - $httpBody = $this->formatBody($_tempBody); + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -508,7 +481,7 @@ protected function createUsersWithArrayInputRequest($user) if($headers['Content-Type'] !== 'application/json') { $httpBody = $_tempBody; } else { - $httpBody = $this->formatBody($_tempBody); + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -727,7 +700,7 @@ protected function createUsersWithListInputRequest($user) if($headers['Content-Type'] !== 'application/json') { $httpBody = $_tempBody; } else { - $httpBody = $this->formatBody($_tempBody); + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -951,7 +924,7 @@ protected function deleteUserRequest($username) if($headers['Content-Type'] !== 'application/json') { $httpBody = $_tempBody; } else { - $httpBody = $this->formatBody($_tempBody); + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1223,7 +1196,7 @@ protected function getUserByNameRequest($username) if($headers['Content-Type'] !== 'application/json') { $httpBody = $_tempBody; } else { - $httpBody = $this->formatBody($_tempBody); + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1506,7 +1479,7 @@ protected function loginUserRequest($username, $password) if($headers['Content-Type'] !== 'application/json') { $httpBody = $_tempBody; } else { - $httpBody = $this->formatBody($_tempBody); + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1711,7 +1684,7 @@ protected function logoutUserRequest() if($headers['Content-Type'] !== 'application/json') { $httpBody = $_tempBody; } else { - $httpBody = $this->formatBody($_tempBody); + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1949,7 +1922,7 @@ protected function updateUserRequest($username, $user) if($headers['Content-Type'] !== 'application/json') { $httpBody = $_tempBody; } else { - $httpBody = $this->formatBody($_tempBody); + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); } } elseif (count($formParams) > 0) { if ($multipart) { From a6eb56de7f4b2154f187fa2e84dd859152cf2fd8 Mon Sep 17 00:00:00 2001 From: Thomas Hansen Date: Mon, 17 Sep 2018 18:29:59 +0200 Subject: [PATCH 4/9] PHP - ObjectSerializer::sanitizeForSerialization(): manage \stdClass objects properly --- .../resources/php/ObjectSerializer.mustache | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/php/ObjectSerializer.mustache b/modules/openapi-generator/src/main/resources/php/ObjectSerializer.mustache index b9993c0410cf..c68c4c25a730 100644 --- a/modules/openapi-generator/src/main/resources/php/ObjectSerializer.mustache +++ b/modules/openapi-generator/src/main/resources/php/ObjectSerializer.mustache @@ -51,19 +51,25 @@ class ObjectSerializer return $data; } elseif (is_object($data)) { $values = []; - $formats = $data::openAPIFormats(); - foreach ($data::openAPITypes() as $property => $openAPIType) { - $getter = $data::getters()[$property]; - $value = $data->$getter(); - if ($value !== null - && !in_array($openAPIType, [{{&primitives}}], true) - && method_exists($openAPIType, 'getAllowableEnumValues') - && !in_array($value, $openAPIType::getAllowableEnumValues(), true)) { - $imploded = implode("', '", $openAPIType::getAllowableEnumValues()); - throw new \InvalidArgumentException("Invalid value for enum '$openAPIType', must be one of: '$imploded'"); + if($data instanceof ModelInterface) { + $formats = $data::openAPIFormats(); + foreach ($data::openAPITypes() as $property => $openAPIType) { + $getter = $data::getters()[$property]; + $value = $data->$getter(); + if ($value !== null + && !in_array($openAPIType, [{{&primitives}}], true) + && method_exists($openAPIType, 'getAllowableEnumValues') + && !in_array($value, $openAPIType::getAllowableEnumValues(), true)) { + $imploded = implode("', '", $openAPIType::getAllowableEnumValues()); + throw new \InvalidArgumentException("Invalid value for enum '$openAPIType', must be one of: '$imploded'"); + } + if ($value !== null) { + $values[$data::attributeMap()[$property]] = self::sanitizeForSerialization($value, $openAPIType, $formats[$property]); + } } - if ($value !== null) { - $values[$data::attributeMap()[$property]] = self::sanitizeForSerialization($value, $openAPIType, $formats[$property]); + } else { + foreach($data as $property => $value) { + $values[$property] = self::sanitizeForSerialization($value); } } return (object)$values; From 630818578b8a409876b33b94aa39c50ebbbdf4df Mon Sep 17 00:00:00 2001 From: Thomas Hansen Date: Mon, 17 Sep 2018 18:34:06 +0200 Subject: [PATCH 5/9] update samples --- .../lib/ObjectSerializer.php | 30 +++++++++++-------- .../lib/ObjectSerializer.php | 30 +++++++++++-------- 2 files changed, 36 insertions(+), 24 deletions(-) diff --git a/samples/client/petstore/php/OpenAPIClient-php/lib/ObjectSerializer.php b/samples/client/petstore/php/OpenAPIClient-php/lib/ObjectSerializer.php index 3592527a968d..46250e566626 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/lib/ObjectSerializer.php +++ b/samples/client/petstore/php/OpenAPIClient-php/lib/ObjectSerializer.php @@ -61,19 +61,25 @@ public static function sanitizeForSerialization($data, $type = null, $format = n return $data; } elseif (is_object($data)) { $values = []; - $formats = $data::openAPIFormats(); - foreach ($data::openAPITypes() as $property => $openAPIType) { - $getter = $data::getters()[$property]; - $value = $data->$getter(); - if ($value !== null - && !in_array($openAPIType, ['DateTime', 'bool', 'boolean', 'byte', 'double', 'float', 'int', 'integer', 'mixed', 'number', 'object', 'string', 'void'], true) - && method_exists($openAPIType, 'getAllowableEnumValues') - && !in_array($value, $openAPIType::getAllowableEnumValues(), true)) { - $imploded = implode("', '", $openAPIType::getAllowableEnumValues()); - throw new \InvalidArgumentException("Invalid value for enum '$openAPIType', must be one of: '$imploded'"); + if($data instanceof ModelInterface) { + $formats = $data::openAPIFormats(); + foreach ($data::openAPITypes() as $property => $openAPIType) { + $getter = $data::getters()[$property]; + $value = $data->$getter(); + if ($value !== null + && !in_array($openAPIType, ['DateTime', 'bool', 'boolean', 'byte', 'double', 'float', 'int', 'integer', 'mixed', 'number', 'object', 'string', 'void'], true) + && method_exists($openAPIType, 'getAllowableEnumValues') + && !in_array($value, $openAPIType::getAllowableEnumValues(), true)) { + $imploded = implode("', '", $openAPIType::getAllowableEnumValues()); + throw new \InvalidArgumentException("Invalid value for enum '$openAPIType', must be one of: '$imploded'"); + } + if ($value !== null) { + $values[$data::attributeMap()[$property]] = self::sanitizeForSerialization($value, $openAPIType, $formats[$property]); + } } - if ($value !== null) { - $values[$data::attributeMap()[$property]] = self::sanitizeForSerialization($value, $openAPIType, $formats[$property]); + } else { + foreach($data as $property => $value) { + $values[$property] = self::sanitizeForSerialization($value); } } return (object)$values; diff --git a/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/ObjectSerializer.php b/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/ObjectSerializer.php index 3592527a968d..46250e566626 100644 --- a/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/ObjectSerializer.php +++ b/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/ObjectSerializer.php @@ -61,19 +61,25 @@ public static function sanitizeForSerialization($data, $type = null, $format = n return $data; } elseif (is_object($data)) { $values = []; - $formats = $data::openAPIFormats(); - foreach ($data::openAPITypes() as $property => $openAPIType) { - $getter = $data::getters()[$property]; - $value = $data->$getter(); - if ($value !== null - && !in_array($openAPIType, ['DateTime', 'bool', 'boolean', 'byte', 'double', 'float', 'int', 'integer', 'mixed', 'number', 'object', 'string', 'void'], true) - && method_exists($openAPIType, 'getAllowableEnumValues') - && !in_array($value, $openAPIType::getAllowableEnumValues(), true)) { - $imploded = implode("', '", $openAPIType::getAllowableEnumValues()); - throw new \InvalidArgumentException("Invalid value for enum '$openAPIType', must be one of: '$imploded'"); + if($data instanceof ModelInterface) { + $formats = $data::openAPIFormats(); + foreach ($data::openAPITypes() as $property => $openAPIType) { + $getter = $data::getters()[$property]; + $value = $data->$getter(); + if ($value !== null + && !in_array($openAPIType, ['DateTime', 'bool', 'boolean', 'byte', 'double', 'float', 'int', 'integer', 'mixed', 'number', 'object', 'string', 'void'], true) + && method_exists($openAPIType, 'getAllowableEnumValues') + && !in_array($value, $openAPIType::getAllowableEnumValues(), true)) { + $imploded = implode("', '", $openAPIType::getAllowableEnumValues()); + throw new \InvalidArgumentException("Invalid value for enum '$openAPIType', must be one of: '$imploded'"); + } + if ($value !== null) { + $values[$data::attributeMap()[$property]] = self::sanitizeForSerialization($value, $openAPIType, $formats[$property]); + } } - if ($value !== null) { - $values[$data::attributeMap()[$property]] = self::sanitizeForSerialization($value, $openAPIType, $formats[$property]); + } else { + foreach($data as $property => $value) { + $values[$property] = self::sanitizeForSerialization($value); } } return (object)$values; From 1a0ecabb2a0be9108263fc76283e9e7c9114e136 Mon Sep 17 00:00:00 2001 From: Thomas Hansen Date: Mon, 17 Sep 2018 19:26:24 +0200 Subject: [PATCH 6/9] bug fix: missing "use" clause --- .../src/main/resources/php/ObjectSerializer.mustache | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/openapi-generator/src/main/resources/php/ObjectSerializer.mustache b/modules/openapi-generator/src/main/resources/php/ObjectSerializer.mustache index c68c4c25a730..118172511b6c 100644 --- a/modules/openapi-generator/src/main/resources/php/ObjectSerializer.mustache +++ b/modules/openapi-generator/src/main/resources/php/ObjectSerializer.mustache @@ -19,6 +19,8 @@ namespace {{invokerPackage}}; +use {{modelPackage}}\ModelInterface; + /** * ObjectSerializer Class Doc Comment * From 87ffe6f098cf86a251318b23de3e1a9aaa66dd98 Mon Sep 17 00:00:00 2001 From: Thomas Hansen Date: Mon, 17 Sep 2018 19:26:35 +0200 Subject: [PATCH 7/9] update samples --- .../petstore/php/OpenAPIClient-php/lib/ObjectSerializer.php | 2 ++ .../petstore/php/OpenAPIClient-php/lib/ObjectSerializer.php | 2 ++ 2 files changed, 4 insertions(+) diff --git a/samples/client/petstore/php/OpenAPIClient-php/lib/ObjectSerializer.php b/samples/client/petstore/php/OpenAPIClient-php/lib/ObjectSerializer.php index 46250e566626..2b49def0f5e7 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/lib/ObjectSerializer.php +++ b/samples/client/petstore/php/OpenAPIClient-php/lib/ObjectSerializer.php @@ -29,6 +29,8 @@ namespace OpenAPI\Client; +use OpenAPI\Client\Model\ModelInterface; + /** * ObjectSerializer Class Doc Comment * diff --git a/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/ObjectSerializer.php b/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/ObjectSerializer.php index 46250e566626..2b49def0f5e7 100644 --- a/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/ObjectSerializer.php +++ b/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/ObjectSerializer.php @@ -29,6 +29,8 @@ namespace OpenAPI\Client; +use OpenAPI\Client\Model\ModelInterface; + /** * ObjectSerializer Class Doc Comment * From 75178e2e17e72dfd8fe82b217f0882a04875a7c9 Mon Sep 17 00:00:00 2001 From: Thomas Hansen Date: Tue, 18 Sep 2018 23:34:34 +0200 Subject: [PATCH 8/9] Changes after @ackintosh review --- .../src/main/resources/php/ObjectSerializer.mustache | 2 +- .../openapi-generator/src/main/resources/php/api.mustache | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/php/ObjectSerializer.mustache b/modules/openapi-generator/src/main/resources/php/ObjectSerializer.mustache index 118172511b6c..3ab026909ec5 100644 --- a/modules/openapi-generator/src/main/resources/php/ObjectSerializer.mustache +++ b/modules/openapi-generator/src/main/resources/php/ObjectSerializer.mustache @@ -53,7 +53,7 @@ class ObjectSerializer return $data; } elseif (is_object($data)) { $values = []; - if($data instanceof ModelInterface) { + if ($data instanceof ModelInterface) { $formats = $data::openAPIFormats(); foreach ($data::openAPITypes() as $property => $openAPIType) { $getter = $data::getters()[$property]; diff --git a/modules/openapi-generator/src/main/resources/php/api.mustache b/modules/openapi-generator/src/main/resources/php/api.mustache index 8613af6301e9..4f1fc87045e9 100644 --- a/modules/openapi-generator/src/main/resources/php/api.mustache +++ b/modules/openapi-generator/src/main/resources/php/api.mustache @@ -444,10 +444,10 @@ use {{invokerPackage}}\ObjectSerializer; // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - if($headers['Content-Type'] !== 'application/json') { - $httpBody = $_tempBody; - } else { + if ($headers['Content-Type'] === 'application/json') { $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); + } else { + $httpBody = $_tempBody; } } elseif (count($formParams) > 0) { if ($multipart) { From e9db0c01e55a13be407a1c4366bc6caee6514438 Mon Sep 17 00:00:00 2001 From: Thomas Hansen Date: Tue, 18 Sep 2018 23:38:27 +0200 Subject: [PATCH 9/9] update samples --- .../lib/Api/AnotherFakeApi.php | 6 +- .../php/OpenAPIClient-php/lib/Api/FakeApi.php | 66 +++++++++---------- .../lib/Api/FakeClassnameTags123Api.php | 6 +- .../php/OpenAPIClient-php/lib/Api/PetApi.php | 54 +++++++-------- .../OpenAPIClient-php/lib/Api/StoreApi.php | 24 +++---- .../php/OpenAPIClient-php/lib/Api/UserApi.php | 48 +++++++------- .../lib/ObjectSerializer.php | 2 +- .../lib/Api/AnotherFakeApi.php | 6 +- .../php/OpenAPIClient-php/lib/Api/FakeApi.php | 66 +++++++++---------- .../lib/Api/FakeClassnameTags123Api.php | 6 +- .../php/OpenAPIClient-php/lib/Api/PetApi.php | 54 +++++++-------- .../OpenAPIClient-php/lib/Api/StoreApi.php | 24 +++---- .../php/OpenAPIClient-php/lib/Api/UserApi.php | 48 +++++++------- .../lib/ObjectSerializer.php | 2 +- 14 files changed, 206 insertions(+), 206 deletions(-) diff --git a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/AnotherFakeApi.php b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/AnotherFakeApi.php index 3ad317c3d711..07d87634b526 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/AnotherFakeApi.php +++ b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/AnotherFakeApi.php @@ -307,10 +307,10 @@ protected function call123TestSpecialTagsRequest($client) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - if($headers['Content-Type'] !== 'application/json') { - $httpBody = $_tempBody; - } else { + if ($headers['Content-Type'] === 'application/json') { $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); + } else { + $httpBody = $_tempBody; } } elseif (count($formParams) > 0) { if ($multipart) { diff --git a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/FakeApi.php b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/FakeApi.php index 60d4fce2fe35..6ee66f33c0fa 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/FakeApi.php +++ b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/FakeApi.php @@ -297,10 +297,10 @@ protected function fakeOuterBooleanSerializeRequest($body = null) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - if($headers['Content-Type'] !== 'application/json') { - $httpBody = $_tempBody; - } else { + if ($headers['Content-Type'] === 'application/json') { $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); + } else { + $httpBody = $_tempBody; } } elseif (count($formParams) > 0) { if ($multipart) { @@ -554,10 +554,10 @@ protected function fakeOuterCompositeSerializeRequest($outer_composite = null) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - if($headers['Content-Type'] !== 'application/json') { - $httpBody = $_tempBody; - } else { + if ($headers['Content-Type'] === 'application/json') { $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); + } else { + $httpBody = $_tempBody; } } elseif (count($formParams) > 0) { if ($multipart) { @@ -811,10 +811,10 @@ protected function fakeOuterNumberSerializeRequest($body = null) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - if($headers['Content-Type'] !== 'application/json') { - $httpBody = $_tempBody; - } else { + if ($headers['Content-Type'] === 'application/json') { $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); + } else { + $httpBody = $_tempBody; } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1068,10 +1068,10 @@ protected function fakeOuterStringSerializeRequest($body = null) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - if($headers['Content-Type'] !== 'application/json') { - $httpBody = $_tempBody; - } else { + if ($headers['Content-Type'] === 'application/json') { $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); + } else { + $httpBody = $_tempBody; } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1283,10 +1283,10 @@ protected function testBodyWithFileSchemaRequest($file_schema_test_class) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - if($headers['Content-Type'] !== 'application/json') { - $httpBody = $_tempBody; - } else { + if ($headers['Content-Type'] === 'application/json') { $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); + } else { + $httpBody = $_tempBody; } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1513,10 +1513,10 @@ protected function testBodyWithQueryParamsRequest($query, $user) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - if($headers['Content-Type'] !== 'application/json') { - $httpBody = $_tempBody; - } else { + if ($headers['Content-Type'] === 'application/json') { $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); + } else { + $httpBody = $_tempBody; } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1780,10 +1780,10 @@ protected function testClientModelRequest($client) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - if($headers['Content-Type'] !== 'application/json') { - $httpBody = $_tempBody; - } else { + if ($headers['Content-Type'] === 'application/json') { $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); + } else { + $httpBody = $_tempBody; } } elseif (count($formParams) > 0) { if ($multipart) { @@ -2183,10 +2183,10 @@ protected function testEndpointParametersRequest($number, $double, $pattern_with // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - if($headers['Content-Type'] !== 'application/json') { - $httpBody = $_tempBody; - } else { + if ($headers['Content-Type'] === 'application/json') { $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); + } else { + $httpBody = $_tempBody; } } elseif (count($formParams) > 0) { if ($multipart) { @@ -2470,10 +2470,10 @@ protected function testEnumParametersRequest($enum_header_string_array = null, $ // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - if($headers['Content-Type'] !== 'application/json') { - $httpBody = $_tempBody; - } else { + if ($headers['Content-Type'] === 'application/json') { $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); + } else { + $httpBody = $_tempBody; } } elseif (count($formParams) > 0) { if ($multipart) { @@ -2689,10 +2689,10 @@ protected function testInlineAdditionalPropertiesRequest($request_body) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - if($headers['Content-Type'] !== 'application/json') { - $httpBody = $_tempBody; - } else { + if ($headers['Content-Type'] === 'application/json') { $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); + } else { + $httpBody = $_tempBody; } } elseif (count($formParams) > 0) { if ($multipart) { @@ -2924,10 +2924,10 @@ protected function testJsonFormDataRequest($param, $param2) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - if($headers['Content-Type'] !== 'application/json') { - $httpBody = $_tempBody; - } else { + if ($headers['Content-Type'] === 'application/json') { $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); + } else { + $httpBody = $_tempBody; } } elseif (count($formParams) > 0) { if ($multipart) { diff --git a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/FakeClassnameTags123Api.php b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/FakeClassnameTags123Api.php index 8998ec886ddf..0b2de02bc7c9 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/FakeClassnameTags123Api.php +++ b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/FakeClassnameTags123Api.php @@ -307,10 +307,10 @@ protected function testClassnameRequest($client) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - if($headers['Content-Type'] !== 'application/json') { - $httpBody = $_tempBody; - } else { + if ($headers['Content-Type'] === 'application/json') { $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); + } else { + $httpBody = $_tempBody; } } elseif (count($formParams) > 0) { if ($multipart) { diff --git a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/PetApi.php b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/PetApi.php index b6b90747f7c5..ff7d6f689ece 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/PetApi.php +++ b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/PetApi.php @@ -259,10 +259,10 @@ protected function addPetRequest($pet) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - if($headers['Content-Type'] !== 'application/json') { - $httpBody = $_tempBody; - } else { + if ($headers['Content-Type'] === 'application/json') { $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); + } else { + $httpBody = $_tempBody; } } elseif (count($formParams) > 0) { if ($multipart) { @@ -496,10 +496,10 @@ protected function deletePetRequest($pet_id, $api_key = null) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - if($headers['Content-Type'] !== 'application/json') { - $httpBody = $_tempBody; - } else { + if ($headers['Content-Type'] === 'application/json') { $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); + } else { + $httpBody = $_tempBody; } } elseif (count($formParams) > 0) { if ($multipart) { @@ -771,10 +771,10 @@ protected function findPetsByStatusRequest($status) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - if($headers['Content-Type'] !== 'application/json') { - $httpBody = $_tempBody; - } else { + if ($headers['Content-Type'] === 'application/json') { $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); + } else { + $httpBody = $_tempBody; } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1046,10 +1046,10 @@ protected function findPetsByTagsRequest($tags) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - if($headers['Content-Type'] !== 'application/json') { - $httpBody = $_tempBody; - } else { + if ($headers['Content-Type'] === 'application/json') { $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); + } else { + $httpBody = $_tempBody; } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1322,10 +1322,10 @@ protected function getPetByIdRequest($pet_id) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - if($headers['Content-Type'] !== 'application/json') { - $httpBody = $_tempBody; - } else { + if ($headers['Content-Type'] === 'application/json') { $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); + } else { + $httpBody = $_tempBody; } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1546,10 +1546,10 @@ protected function updatePetRequest($pet) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - if($headers['Content-Type'] !== 'application/json') { - $httpBody = $_tempBody; - } else { + if ($headers['Content-Type'] === 'application/json') { $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); + } else { + $httpBody = $_tempBody; } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1792,10 +1792,10 @@ protected function updatePetWithFormRequest($pet_id, $name = null, $status = nul // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - if($headers['Content-Type'] !== 'application/json') { - $httpBody = $_tempBody; - } else { + if ($headers['Content-Type'] === 'application/json') { $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); + } else { + $httpBody = $_tempBody; } } elseif (count($formParams) > 0) { if ($multipart) { @@ -2087,10 +2087,10 @@ protected function uploadFileRequest($pet_id, $additional_metadata = null, $file // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - if($headers['Content-Type'] !== 'application/json') { - $httpBody = $_tempBody; - } else { + if ($headers['Content-Type'] === 'application/json') { $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); + } else { + $httpBody = $_tempBody; } } elseif (count($formParams) > 0) { if ($multipart) { @@ -2388,10 +2388,10 @@ protected function uploadFileWithRequiredFileRequest($pet_id, $required_file, $a // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - if($headers['Content-Type'] !== 'application/json') { - $httpBody = $_tempBody; - } else { + if ($headers['Content-Type'] === 'application/json') { $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); + } else { + $httpBody = $_tempBody; } } elseif (count($formParams) > 0) { if ($multipart) { diff --git a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/StoreApi.php b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/StoreApi.php index ad9c5515d7f7..7a4dc235a379 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/StoreApi.php +++ b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/StoreApi.php @@ -264,10 +264,10 @@ protected function deleteOrderRequest($order_id) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - if($headers['Content-Type'] !== 'application/json') { - $httpBody = $_tempBody; - } else { + if ($headers['Content-Type'] === 'application/json') { $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); + } else { + $httpBody = $_tempBody; } } elseif (count($formParams) > 0) { if ($multipart) { @@ -517,10 +517,10 @@ protected function getInventoryRequest() // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - if($headers['Content-Type'] !== 'application/json') { - $httpBody = $_tempBody; - } else { + if ($headers['Content-Type'] === 'application/json') { $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); + } else { + $httpBody = $_tempBody; } } elseif (count($formParams) > 0) { if ($multipart) { @@ -801,10 +801,10 @@ protected function getOrderByIdRequest($order_id) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - if($headers['Content-Type'] !== 'application/json') { - $httpBody = $_tempBody; - } else { + if ($headers['Content-Type'] === 'application/json') { $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); + } else { + $httpBody = $_tempBody; } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1068,10 +1068,10 @@ protected function placeOrderRequest($order) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - if($headers['Content-Type'] !== 'application/json') { - $httpBody = $_tempBody; - } else { + if ($headers['Content-Type'] === 'application/json') { $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); + } else { + $httpBody = $_tempBody; } } elseif (count($formParams) > 0) { if ($multipart) { diff --git a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/UserApi.php b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/UserApi.php index b22af89d7f7e..b3fecdc2b331 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/UserApi.php +++ b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/UserApi.php @@ -259,10 +259,10 @@ protected function createUserRequest($user) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - if($headers['Content-Type'] !== 'application/json') { - $httpBody = $_tempBody; - } else { + if ($headers['Content-Type'] === 'application/json') { $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); + } else { + $httpBody = $_tempBody; } } elseif (count($formParams) > 0) { if ($multipart) { @@ -478,10 +478,10 @@ protected function createUsersWithArrayInputRequest($user) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - if($headers['Content-Type'] !== 'application/json') { - $httpBody = $_tempBody; - } else { + if ($headers['Content-Type'] === 'application/json') { $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); + } else { + $httpBody = $_tempBody; } } elseif (count($formParams) > 0) { if ($multipart) { @@ -697,10 +697,10 @@ protected function createUsersWithListInputRequest($user) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - if($headers['Content-Type'] !== 'application/json') { - $httpBody = $_tempBody; - } else { + if ($headers['Content-Type'] === 'application/json') { $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); + } else { + $httpBody = $_tempBody; } } elseif (count($formParams) > 0) { if ($multipart) { @@ -921,10 +921,10 @@ protected function deleteUserRequest($username) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - if($headers['Content-Type'] !== 'application/json') { - $httpBody = $_tempBody; - } else { + if ($headers['Content-Type'] === 'application/json') { $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); + } else { + $httpBody = $_tempBody; } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1193,10 +1193,10 @@ protected function getUserByNameRequest($username) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - if($headers['Content-Type'] !== 'application/json') { - $httpBody = $_tempBody; - } else { + if ($headers['Content-Type'] === 'application/json') { $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); + } else { + $httpBody = $_tempBody; } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1476,10 +1476,10 @@ protected function loginUserRequest($username, $password) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - if($headers['Content-Type'] !== 'application/json') { - $httpBody = $_tempBody; - } else { + if ($headers['Content-Type'] === 'application/json') { $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); + } else { + $httpBody = $_tempBody; } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1681,10 +1681,10 @@ protected function logoutUserRequest() // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - if($headers['Content-Type'] !== 'application/json') { - $httpBody = $_tempBody; - } else { + if ($headers['Content-Type'] === 'application/json') { $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); + } else { + $httpBody = $_tempBody; } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1919,10 +1919,10 @@ protected function updateUserRequest($username, $user) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - if($headers['Content-Type'] !== 'application/json') { - $httpBody = $_tempBody; - } else { + if ($headers['Content-Type'] === 'application/json') { $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); + } else { + $httpBody = $_tempBody; } } elseif (count($formParams) > 0) { if ($multipart) { diff --git a/samples/client/petstore/php/OpenAPIClient-php/lib/ObjectSerializer.php b/samples/client/petstore/php/OpenAPIClient-php/lib/ObjectSerializer.php index 2b49def0f5e7..d7b254c954e8 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/lib/ObjectSerializer.php +++ b/samples/client/petstore/php/OpenAPIClient-php/lib/ObjectSerializer.php @@ -63,7 +63,7 @@ public static function sanitizeForSerialization($data, $type = null, $format = n return $data; } elseif (is_object($data)) { $values = []; - if($data instanceof ModelInterface) { + if ($data instanceof ModelInterface) { $formats = $data::openAPIFormats(); foreach ($data::openAPITypes() as $property => $openAPIType) { $getter = $data::getters()[$property]; diff --git a/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/AnotherFakeApi.php b/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/AnotherFakeApi.php index 3ad317c3d711..07d87634b526 100644 --- a/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/AnotherFakeApi.php +++ b/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/AnotherFakeApi.php @@ -307,10 +307,10 @@ protected function call123TestSpecialTagsRequest($client) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - if($headers['Content-Type'] !== 'application/json') { - $httpBody = $_tempBody; - } else { + if ($headers['Content-Type'] === 'application/json') { $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); + } else { + $httpBody = $_tempBody; } } elseif (count($formParams) > 0) { if ($multipart) { diff --git a/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/FakeApi.php b/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/FakeApi.php index 2fa51a2da148..6cc26632fe8d 100644 --- a/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/FakeApi.php +++ b/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/FakeApi.php @@ -297,10 +297,10 @@ protected function fakeOuterBooleanSerializeRequest($body = null) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - if($headers['Content-Type'] !== 'application/json') { - $httpBody = $_tempBody; - } else { + if ($headers['Content-Type'] === 'application/json') { $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); + } else { + $httpBody = $_tempBody; } } elseif (count($formParams) > 0) { if ($multipart) { @@ -554,10 +554,10 @@ protected function fakeOuterCompositeSerializeRequest($outer_composite = null) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - if($headers['Content-Type'] !== 'application/json') { - $httpBody = $_tempBody; - } else { + if ($headers['Content-Type'] === 'application/json') { $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); + } else { + $httpBody = $_tempBody; } } elseif (count($formParams) > 0) { if ($multipart) { @@ -811,10 +811,10 @@ protected function fakeOuterNumberSerializeRequest($body = null) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - if($headers['Content-Type'] !== 'application/json') { - $httpBody = $_tempBody; - } else { + if ($headers['Content-Type'] === 'application/json') { $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); + } else { + $httpBody = $_tempBody; } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1068,10 +1068,10 @@ protected function fakeOuterStringSerializeRequest($body = null) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - if($headers['Content-Type'] !== 'application/json') { - $httpBody = $_tempBody; - } else { + if ($headers['Content-Type'] === 'application/json') { $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); + } else { + $httpBody = $_tempBody; } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1283,10 +1283,10 @@ protected function testBodyWithFileSchemaRequest($file_schema_test_class) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - if($headers['Content-Type'] !== 'application/json') { - $httpBody = $_tempBody; - } else { + if ($headers['Content-Type'] === 'application/json') { $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); + } else { + $httpBody = $_tempBody; } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1513,10 +1513,10 @@ protected function testBodyWithQueryParamsRequest($query, $user) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - if($headers['Content-Type'] !== 'application/json') { - $httpBody = $_tempBody; - } else { + if ($headers['Content-Type'] === 'application/json') { $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); + } else { + $httpBody = $_tempBody; } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1780,10 +1780,10 @@ protected function testClientModelRequest($client) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - if($headers['Content-Type'] !== 'application/json') { - $httpBody = $_tempBody; - } else { + if ($headers['Content-Type'] === 'application/json') { $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); + } else { + $httpBody = $_tempBody; } } elseif (count($formParams) > 0) { if ($multipart) { @@ -2183,10 +2183,10 @@ protected function testEndpointParametersRequest($number, $double, $pattern_with // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - if($headers['Content-Type'] !== 'application/json') { - $httpBody = $_tempBody; - } else { + if ($headers['Content-Type'] === 'application/json') { $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); + } else { + $httpBody = $_tempBody; } } elseif (count($formParams) > 0) { if ($multipart) { @@ -2470,10 +2470,10 @@ protected function testEnumParametersRequest($enum_header_string_array = null, $ // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - if($headers['Content-Type'] !== 'application/json') { - $httpBody = $_tempBody; - } else { + if ($headers['Content-Type'] === 'application/json') { $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); + } else { + $httpBody = $_tempBody; } } elseif (count($formParams) > 0) { if ($multipart) { @@ -2689,10 +2689,10 @@ protected function testInlineAdditionalPropertiesRequest($request_body) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - if($headers['Content-Type'] !== 'application/json') { - $httpBody = $_tempBody; - } else { + if ($headers['Content-Type'] === 'application/json') { $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); + } else { + $httpBody = $_tempBody; } } elseif (count($formParams) > 0) { if ($multipart) { @@ -2924,10 +2924,10 @@ protected function testJsonFormDataRequest($param, $param2) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - if($headers['Content-Type'] !== 'application/json') { - $httpBody = $_tempBody; - } else { + if ($headers['Content-Type'] === 'application/json') { $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); + } else { + $httpBody = $_tempBody; } } elseif (count($formParams) > 0) { if ($multipart) { diff --git a/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/FakeClassnameTags123Api.php b/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/FakeClassnameTags123Api.php index 8998ec886ddf..0b2de02bc7c9 100644 --- a/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/FakeClassnameTags123Api.php +++ b/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/FakeClassnameTags123Api.php @@ -307,10 +307,10 @@ protected function testClassnameRequest($client) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - if($headers['Content-Type'] !== 'application/json') { - $httpBody = $_tempBody; - } else { + if ($headers['Content-Type'] === 'application/json') { $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); + } else { + $httpBody = $_tempBody; } } elseif (count($formParams) > 0) { if ($multipart) { diff --git a/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/PetApi.php b/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/PetApi.php index b6b90747f7c5..ff7d6f689ece 100644 --- a/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/PetApi.php +++ b/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/PetApi.php @@ -259,10 +259,10 @@ protected function addPetRequest($pet) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - if($headers['Content-Type'] !== 'application/json') { - $httpBody = $_tempBody; - } else { + if ($headers['Content-Type'] === 'application/json') { $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); + } else { + $httpBody = $_tempBody; } } elseif (count($formParams) > 0) { if ($multipart) { @@ -496,10 +496,10 @@ protected function deletePetRequest($pet_id, $api_key = null) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - if($headers['Content-Type'] !== 'application/json') { - $httpBody = $_tempBody; - } else { + if ($headers['Content-Type'] === 'application/json') { $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); + } else { + $httpBody = $_tempBody; } } elseif (count($formParams) > 0) { if ($multipart) { @@ -771,10 +771,10 @@ protected function findPetsByStatusRequest($status) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - if($headers['Content-Type'] !== 'application/json') { - $httpBody = $_tempBody; - } else { + if ($headers['Content-Type'] === 'application/json') { $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); + } else { + $httpBody = $_tempBody; } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1046,10 +1046,10 @@ protected function findPetsByTagsRequest($tags) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - if($headers['Content-Type'] !== 'application/json') { - $httpBody = $_tempBody; - } else { + if ($headers['Content-Type'] === 'application/json') { $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); + } else { + $httpBody = $_tempBody; } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1322,10 +1322,10 @@ protected function getPetByIdRequest($pet_id) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - if($headers['Content-Type'] !== 'application/json') { - $httpBody = $_tempBody; - } else { + if ($headers['Content-Type'] === 'application/json') { $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); + } else { + $httpBody = $_tempBody; } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1546,10 +1546,10 @@ protected function updatePetRequest($pet) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - if($headers['Content-Type'] !== 'application/json') { - $httpBody = $_tempBody; - } else { + if ($headers['Content-Type'] === 'application/json') { $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); + } else { + $httpBody = $_tempBody; } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1792,10 +1792,10 @@ protected function updatePetWithFormRequest($pet_id, $name = null, $status = nul // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - if($headers['Content-Type'] !== 'application/json') { - $httpBody = $_tempBody; - } else { + if ($headers['Content-Type'] === 'application/json') { $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); + } else { + $httpBody = $_tempBody; } } elseif (count($formParams) > 0) { if ($multipart) { @@ -2087,10 +2087,10 @@ protected function uploadFileRequest($pet_id, $additional_metadata = null, $file // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - if($headers['Content-Type'] !== 'application/json') { - $httpBody = $_tempBody; - } else { + if ($headers['Content-Type'] === 'application/json') { $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); + } else { + $httpBody = $_tempBody; } } elseif (count($formParams) > 0) { if ($multipart) { @@ -2388,10 +2388,10 @@ protected function uploadFileWithRequiredFileRequest($pet_id, $required_file, $a // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - if($headers['Content-Type'] !== 'application/json') { - $httpBody = $_tempBody; - } else { + if ($headers['Content-Type'] === 'application/json') { $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); + } else { + $httpBody = $_tempBody; } } elseif (count($formParams) > 0) { if ($multipart) { diff --git a/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/StoreApi.php b/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/StoreApi.php index 132cf21aa5bc..c23fc73cb4fe 100644 --- a/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/StoreApi.php +++ b/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/StoreApi.php @@ -264,10 +264,10 @@ protected function deleteOrderRequest($order_id) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - if($headers['Content-Type'] !== 'application/json') { - $httpBody = $_tempBody; - } else { + if ($headers['Content-Type'] === 'application/json') { $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); + } else { + $httpBody = $_tempBody; } } elseif (count($formParams) > 0) { if ($multipart) { @@ -517,10 +517,10 @@ protected function getInventoryRequest() // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - if($headers['Content-Type'] !== 'application/json') { - $httpBody = $_tempBody; - } else { + if ($headers['Content-Type'] === 'application/json') { $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); + } else { + $httpBody = $_tempBody; } } elseif (count($formParams) > 0) { if ($multipart) { @@ -801,10 +801,10 @@ protected function getOrderByIdRequest($order_id) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - if($headers['Content-Type'] !== 'application/json') { - $httpBody = $_tempBody; - } else { + if ($headers['Content-Type'] === 'application/json') { $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); + } else { + $httpBody = $_tempBody; } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1068,10 +1068,10 @@ protected function placeOrderRequest($order) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - if($headers['Content-Type'] !== 'application/json') { - $httpBody = $_tempBody; - } else { + if ($headers['Content-Type'] === 'application/json') { $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); + } else { + $httpBody = $_tempBody; } } elseif (count($formParams) > 0) { if ($multipart) { diff --git a/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/UserApi.php b/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/UserApi.php index 487f85262462..a30fdc19bbf1 100644 --- a/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/UserApi.php +++ b/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/UserApi.php @@ -259,10 +259,10 @@ protected function createUserRequest($user) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - if($headers['Content-Type'] !== 'application/json') { - $httpBody = $_tempBody; - } else { + if ($headers['Content-Type'] === 'application/json') { $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); + } else { + $httpBody = $_tempBody; } } elseif (count($formParams) > 0) { if ($multipart) { @@ -478,10 +478,10 @@ protected function createUsersWithArrayInputRequest($user) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - if($headers['Content-Type'] !== 'application/json') { - $httpBody = $_tempBody; - } else { + if ($headers['Content-Type'] === 'application/json') { $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); + } else { + $httpBody = $_tempBody; } } elseif (count($formParams) > 0) { if ($multipart) { @@ -697,10 +697,10 @@ protected function createUsersWithListInputRequest($user) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - if($headers['Content-Type'] !== 'application/json') { - $httpBody = $_tempBody; - } else { + if ($headers['Content-Type'] === 'application/json') { $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); + } else { + $httpBody = $_tempBody; } } elseif (count($formParams) > 0) { if ($multipart) { @@ -921,10 +921,10 @@ protected function deleteUserRequest($username) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - if($headers['Content-Type'] !== 'application/json') { - $httpBody = $_tempBody; - } else { + if ($headers['Content-Type'] === 'application/json') { $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); + } else { + $httpBody = $_tempBody; } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1193,10 +1193,10 @@ protected function getUserByNameRequest($username) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - if($headers['Content-Type'] !== 'application/json') { - $httpBody = $_tempBody; - } else { + if ($headers['Content-Type'] === 'application/json') { $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); + } else { + $httpBody = $_tempBody; } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1476,10 +1476,10 @@ protected function loginUserRequest($username, $password) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - if($headers['Content-Type'] !== 'application/json') { - $httpBody = $_tempBody; - } else { + if ($headers['Content-Type'] === 'application/json') { $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); + } else { + $httpBody = $_tempBody; } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1681,10 +1681,10 @@ protected function logoutUserRequest() // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - if($headers['Content-Type'] !== 'application/json') { - $httpBody = $_tempBody; - } else { + if ($headers['Content-Type'] === 'application/json') { $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); + } else { + $httpBody = $_tempBody; } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1919,10 +1919,10 @@ protected function updateUserRequest($username, $user) // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present - if($headers['Content-Type'] !== 'application/json') { - $httpBody = $_tempBody; - } else { + if ($headers['Content-Type'] === 'application/json') { $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody)); + } else { + $httpBody = $_tempBody; } } elseif (count($formParams) > 0) { if ($multipart) { diff --git a/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/ObjectSerializer.php b/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/ObjectSerializer.php index 2b49def0f5e7..d7b254c954e8 100644 --- a/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/ObjectSerializer.php +++ b/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/ObjectSerializer.php @@ -63,7 +63,7 @@ public static function sanitizeForSerialization($data, $type = null, $format = n return $data; } elseif (is_object($data)) { $values = []; - if($data instanceof ModelInterface) { + if ($data instanceof ModelInterface) { $formats = $data::openAPIFormats(); foreach ($data::openAPITypes() as $property => $openAPIType) { $getter = $data::getters()[$property];