From b786fe3a9a84461e76c412ed0a3a7c472362e35c Mon Sep 17 00:00:00 2001 From: Thomas Hansen Date: Wed, 4 Mar 2020 08:17:02 +0100 Subject: [PATCH 1/2] [BUG][PHP] Parameter property style not fully implemented (related to comment on PR #3984) --- .../src/main/resources/php/api.mustache | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/php/api.mustache b/modules/openapi-generator/src/main/resources/php/api.mustache index 537cf815951b..2014b8ec83bd 100644 --- a/modules/openapi-generator/src/main/resources/php/api.mustache +++ b/modules/openapi-generator/src/main/resources/php/api.mustache @@ -472,11 +472,22 @@ use {{invokerPackage}}\ObjectSerializer; $multipart = false; {{#queryParams}} - // query params {{#isExplode}} if (${{paramName}} !== null) { + {{#style}} + if('form' === '{{style}}' && is_array(${{paramName}})) { + foreach(${{paramName}} as $key => $value) { + $queryParams[$key] = $value; + } + } + else { + $queryParams['{{baseName}}'] = ${{paramName}}; + } + {{/style}} + {{^style}} $queryParams['{{baseName}}'] = ${{paramName}}; + {{/style}} } {{/isExplode}} {{^isExplode}} @@ -487,7 +498,6 @@ use {{invokerPackage}}\ObjectSerializer; $queryParams['{{baseName}}'] = ${{paramName}}; } {{/isExplode}} - {{/queryParams}} {{#headerParams}} From 8158848598499296637a5c82f24287b114730959 Mon Sep 17 00:00:00 2001 From: Thomas Hansen Date: Wed, 4 Mar 2020 08:33:05 +0100 Subject: [PATCH 2/2] [AUTOGENERATED][PHP] Sample Files --- .../php/OpenAPIClient-php/lib/Api/FakeApi.php | 45 ++---- .../php/OpenAPIClient-php/lib/Api/PetApi.php | 8 +- .../php/OpenAPIClient-php/lib/Api/UserApi.php | 4 - .../php/OpenAPIClient-php/lib/Api/FakeApi.php | 133 ++++++++++++------ .../php/OpenAPIClient-php/lib/Api/PetApi.php | 8 +- .../php/OpenAPIClient-php/lib/Api/UserApi.php | 22 ++- 6 files changed, 123 insertions(+), 97 deletions(-) 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 e8be7d98afa6..c2508552e1a0 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/FakeApi.php +++ b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/FakeApi.php @@ -1740,7 +1740,6 @@ protected function testBodyWithQueryParamsRequest($query, $body) $httpBody = ''; $multipart = false; - // query params if (is_array($query)) { $query = ObjectSerializer::serializeCollection($query, '', true); @@ -1751,7 +1750,6 @@ protected function testBodyWithQueryParamsRequest($query, $body) - // body params $_tempBody = null; if (isset($body)) { @@ -2674,16 +2672,13 @@ protected function testEnumParametersRequest($enum_header_string_array = null, $ $httpBody = ''; $multipart = false; - // query params if (is_array($enum_query_string_array)) { - $enum_query_string_array = ObjectSerializer::serializeCollection($enum_query_string_array, 'csv', true); + $enum_query_string_array = ObjectSerializer::serializeCollection($enum_query_string_array, 'form', true); } if ($enum_query_string_array !== null) { $queryParams['enum_query_string_array'] = $enum_query_string_array; } - - // query params if (is_array($enum_query_string)) { $enum_query_string = ObjectSerializer::serializeCollection($enum_query_string, '', true); @@ -2691,8 +2686,6 @@ protected function testEnumParametersRequest($enum_header_string_array = null, $ if ($enum_query_string !== null) { $queryParams['enum_query_string'] = $enum_query_string; } - - // query params if (is_array($enum_query_integer)) { $enum_query_integer = ObjectSerializer::serializeCollection($enum_query_integer, '', true); @@ -2700,8 +2693,6 @@ protected function testEnumParametersRequest($enum_header_string_array = null, $ if ($enum_query_integer !== null) { $queryParams['enum_query_integer'] = $enum_query_integer; } - - // query params if (is_array($enum_query_double)) { $enum_query_double = ObjectSerializer::serializeCollection($enum_query_double, '', true); @@ -2710,7 +2701,6 @@ protected function testEnumParametersRequest($enum_header_string_array = null, $ $queryParams['enum_query_double'] = $enum_query_double; } - // header params if (is_array($enum_header_string_array)) { $enum_header_string_array = ObjectSerializer::serializeCollection($enum_header_string_array, 'csv'); @@ -3001,7 +2991,6 @@ protected function testGroupParametersRequest($associative_array) $httpBody = ''; $multipart = false; - // query params if (is_array($required_string_group)) { $required_string_group = ObjectSerializer::serializeCollection($required_string_group, '', true); @@ -3009,8 +2998,6 @@ protected function testGroupParametersRequest($associative_array) if ($required_string_group !== null) { $queryParams['required_string_group'] = $required_string_group; } - - // query params if (is_array($required_int64_group)) { $required_int64_group = ObjectSerializer::serializeCollection($required_int64_group, '', true); @@ -3018,8 +3005,6 @@ protected function testGroupParametersRequest($associative_array) if ($required_int64_group !== null) { $queryParams['required_int64_group'] = $required_int64_group; } - - // query params if (is_array($string_group)) { $string_group = ObjectSerializer::serializeCollection($string_group, '', true); @@ -3027,8 +3012,6 @@ protected function testGroupParametersRequest($associative_array) if ($string_group !== null) { $queryParams['string_group'] = $string_group; } - - // query params if (is_array($int64_group)) { $int64_group = ObjectSerializer::serializeCollection($int64_group, '', true); @@ -3037,7 +3020,6 @@ protected function testGroupParametersRequest($associative_array) $queryParams['int64_group'] = $int64_group; } - // header params if ($required_boolean_group !== null) { $headerParams['required_boolean_group'] = ObjectSerializer::toHeaderValue($required_boolean_group); @@ -3758,16 +3740,13 @@ protected function testQueryParameterCollectionFormatRequest($pipe, $ioutil, $ht $httpBody = ''; $multipart = false; - // query params if (is_array($pipe)) { - $pipe = ObjectSerializer::serializeCollection($pipe, 'csv', true); + $pipe = ObjectSerializer::serializeCollection($pipe, 'form', true); } if ($pipe !== null) { $queryParams['pipe'] = $pipe; } - - // query params if (is_array($ioutil)) { $ioutil = ObjectSerializer::serializeCollection($ioutil, 'csv', true); @@ -3775,34 +3754,34 @@ protected function testQueryParameterCollectionFormatRequest($pipe, $ioutil, $ht if ($ioutil !== null) { $queryParams['ioutil'] = $ioutil; } - - // query params if (is_array($http)) { - $http = ObjectSerializer::serializeCollection($http, 'space', true); + $http = ObjectSerializer::serializeCollection($http, 'spaceDelimited', true); } if ($http !== null) { $queryParams['http'] = $http; } - - // query params if (is_array($url)) { - $url = ObjectSerializer::serializeCollection($url, 'csv', true); + $url = ObjectSerializer::serializeCollection($url, 'form', true); } if ($url !== null) { $queryParams['url'] = $url; } - - // query params if ($context !== null) { - $queryParams['context'] = $context; + if('form' === 'form' && is_array($context)) { + foreach($context as $key => $value) { + $queryParams[$key] = $value; + } + } + else { + $queryParams['context'] = $context; + } } - // body params $_tempBody = null; 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 2038687c4570..90c6ef022319 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/PetApi.php +++ b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/PetApi.php @@ -775,10 +775,9 @@ protected function findPetsByStatusRequest($status) $httpBody = ''; $multipart = false; - // query params if (is_array($status)) { - $status = ObjectSerializer::serializeCollection($status, 'csv', true); + $status = ObjectSerializer::serializeCollection($status, 'form', true); } if ($status !== null) { $queryParams['status'] = $status; @@ -786,7 +785,6 @@ protected function findPetsByStatusRequest($status) - // body params $_tempBody = null; @@ -1053,10 +1051,9 @@ protected function findPetsByTagsRequest($tags) $httpBody = ''; $multipart = false; - // query params if (is_array($tags)) { - $tags = ObjectSerializer::serializeCollection($tags, 'csv', true); + $tags = ObjectSerializer::serializeCollection($tags, 'form', true); } if ($tags !== null) { $queryParams['tags'] = $tags; @@ -1064,7 +1061,6 @@ protected function findPetsByTagsRequest($tags) - // body params $_tempBody = null; 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 9345f4b155b5..22b217fc4eaa 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/UserApi.php +++ b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/UserApi.php @@ -1482,7 +1482,6 @@ protected function loginUserRequest($username, $password) $httpBody = ''; $multipart = false; - // query params if (is_array($username)) { $username = ObjectSerializer::serializeCollection($username, '', true); @@ -1490,8 +1489,6 @@ protected function loginUserRequest($username, $password) if ($username !== null) { $queryParams['username'] = $username; } - - // query params if (is_array($password)) { $password = ObjectSerializer::serializeCollection($password, '', true); @@ -1502,7 +1499,6 @@ protected function loginUserRequest($username, $password) - // body params $_tempBody = null; 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 fa9305cfbb4d..6d1a24aa7de8 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 @@ -1774,15 +1774,20 @@ protected function testBodyWithQueryParamsRequest($query, $user) $httpBody = ''; $multipart = false; - // query params if ($query !== null) { - $queryParams['query'] = $query; + if('form' === 'form' && is_array($query)) { + foreach($query as $key => $value) { + $queryParams[$key] = $value; + } + } + else { + $queryParams['query'] = $query; + } } - // body params $_tempBody = null; if (isset($user)) { @@ -2705,31 +2710,51 @@ protected function testEnumParametersRequest($enum_header_string_array = null, $ $httpBody = ''; $multipart = false; - // query params if ($enum_query_string_array !== null) { - $queryParams['enum_query_string_array'] = $enum_query_string_array; + if('form' === 'form' && is_array($enum_query_string_array)) { + foreach($enum_query_string_array as $key => $value) { + $queryParams[$key] = $value; + } + } + else { + $queryParams['enum_query_string_array'] = $enum_query_string_array; + } } - - // query params if ($enum_query_string !== null) { - $queryParams['enum_query_string'] = $enum_query_string; + if('form' === 'form' && is_array($enum_query_string)) { + foreach($enum_query_string as $key => $value) { + $queryParams[$key] = $value; + } + } + else { + $queryParams['enum_query_string'] = $enum_query_string; + } } - - // query params if ($enum_query_integer !== null) { - $queryParams['enum_query_integer'] = $enum_query_integer; + if('form' === 'form' && is_array($enum_query_integer)) { + foreach($enum_query_integer as $key => $value) { + $queryParams[$key] = $value; + } + } + else { + $queryParams['enum_query_integer'] = $enum_query_integer; + } } - - // query params if ($enum_query_double !== null) { - $queryParams['enum_query_double'] = $enum_query_double; + if('form' === 'form' && is_array($enum_query_double)) { + foreach($enum_query_double as $key => $value) { + $queryParams[$key] = $value; + } + } + else { + $queryParams['enum_query_double'] = $enum_query_double; + } } - // header params if (is_array($enum_header_string_array)) { $enum_header_string_array = ObjectSerializer::serializeCollection($enum_header_string_array, 'csv'); @@ -3020,31 +3045,51 @@ protected function testGroupParametersRequest($associative_array) $httpBody = ''; $multipart = false; - // query params if ($required_string_group !== null) { - $queryParams['required_string_group'] = $required_string_group; + if('form' === 'form' && is_array($required_string_group)) { + foreach($required_string_group as $key => $value) { + $queryParams[$key] = $value; + } + } + else { + $queryParams['required_string_group'] = $required_string_group; + } } - - // query params if ($required_int64_group !== null) { - $queryParams['required_int64_group'] = $required_int64_group; + if('form' === 'form' && is_array($required_int64_group)) { + foreach($required_int64_group as $key => $value) { + $queryParams[$key] = $value; + } + } + else { + $queryParams['required_int64_group'] = $required_int64_group; + } } - - // query params if ($string_group !== null) { - $queryParams['string_group'] = $string_group; + if('form' === 'form' && is_array($string_group)) { + foreach($string_group as $key => $value) { + $queryParams[$key] = $value; + } + } + else { + $queryParams['string_group'] = $string_group; + } } - - // query params if ($int64_group !== null) { - $queryParams['int64_group'] = $int64_group; + if('form' === 'form' && is_array($int64_group)) { + foreach($int64_group as $key => $value) { + $queryParams[$key] = $value; + } + } + else { + $queryParams['int64_group'] = $int64_group; + } } - // header params if ($required_boolean_group !== null) { $headerParams['required_boolean_group'] = ObjectSerializer::toHeaderValue($required_boolean_group); @@ -3769,48 +3814,52 @@ protected function testQueryParameterCollectionFormatRequest($pipe, $ioutil, $ht $httpBody = ''; $multipart = false; - // query params if ($pipe !== null) { - $queryParams['pipe'] = $pipe; + if('form' === 'form' && is_array($pipe)) { + foreach($pipe as $key => $value) { + $queryParams[$key] = $value; + } + } + else { + $queryParams['pipe'] = $pipe; + } } - - // query params if (is_array($ioutil)) { - $ioutil = ObjectSerializer::serializeCollection($ioutil, 'csv', true); + $ioutil = ObjectSerializer::serializeCollection($ioutil, 'form', true); } if ($ioutil !== null) { $queryParams['ioutil'] = $ioutil; } - - // query params if (is_array($http)) { - $http = ObjectSerializer::serializeCollection($http, 'space', true); + $http = ObjectSerializer::serializeCollection($http, 'spaceDelimited', true); } if ($http !== null) { $queryParams['http'] = $http; } - - // query params if (is_array($url)) { - $url = ObjectSerializer::serializeCollection($url, 'csv', true); + $url = ObjectSerializer::serializeCollection($url, 'form', true); } if ($url !== null) { $queryParams['url'] = $url; } - - // query params if ($context !== null) { - $queryParams['context'] = $context; + if('form' === 'form' && is_array($context)) { + foreach($context as $key => $value) { + $queryParams[$key] = $value; + } + } + else { + $queryParams['context'] = $context; + } } - // body params $_tempBody = null; 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 37b798c0417d..4e1803989cac 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 @@ -801,10 +801,9 @@ protected function findPetsByStatusRequest($status) $httpBody = ''; $multipart = false; - // query params if (is_array($status)) { - $status = ObjectSerializer::serializeCollection($status, 'csv', true); + $status = ObjectSerializer::serializeCollection($status, 'form', true); } if ($status !== null) { $queryParams['status'] = $status; @@ -812,7 +811,6 @@ protected function findPetsByStatusRequest($status) - // body params $_tempBody = null; @@ -1079,10 +1077,9 @@ protected function findPetsByTagsRequest($tags) $httpBody = ''; $multipart = false; - // query params if (is_array($tags)) { - $tags = ObjectSerializer::serializeCollection($tags, 'csv', true); + $tags = ObjectSerializer::serializeCollection($tags, 'form', true); } if ($tags !== null) { $queryParams['tags'] = $tags; @@ -1090,7 +1087,6 @@ protected function findPetsByTagsRequest($tags) - // body params $_tempBody = null; 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 4da3fa6fe20b..a274723a1fb7 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 @@ -1482,21 +1482,31 @@ protected function loginUserRequest($username, $password) $httpBody = ''; $multipart = false; - // query params if ($username !== null) { - $queryParams['username'] = $username; + if('form' === 'form' && is_array($username)) { + foreach($username as $key => $value) { + $queryParams[$key] = $value; + } + } + else { + $queryParams['username'] = $username; + } } - - // query params if ($password !== null) { - $queryParams['password'] = $password; + if('form' === 'form' && is_array($password)) { + foreach($password as $key => $value) { + $queryParams[$key] = $value; + } + } + else { + $queryParams['password'] = $password; + } } - // body params $_tempBody = null;