From 827880a62448520659f533cafc0851b75e054caf Mon Sep 17 00:00:00 2001 From: "akihito.nakano" Date: Sun, 8 Apr 2018 12:18:17 +0900 Subject: [PATCH 1/5] Update samples before starting fixes --- .../php/SwaggerClient-php/docs/Api/FakeApi.md | 8 ++++---- .../php/SwaggerClient-php/docs/Api/PetApi.md | 2 +- .../php/SwaggerClient-php/lib/Api/FakeApi.php | 6 ++++-- .../php/SwaggerClient-php/lib/Api/PetApi.php | 3 ++- .../php/SwaggerClient-php/lib/Model/Body3.php | 12 ++++++------ .../php/SwaggerClient-php/lib/Model/FormatTest.php | 12 ++++++------ 6 files changed, 23 insertions(+), 20 deletions(-) diff --git a/samples/openapi3/client/petstore/php/SwaggerClient-php/docs/Api/FakeApi.md b/samples/openapi3/client/petstore/php/SwaggerClient-php/docs/Api/FakeApi.md index 93a0a021bed..407ee95e994 100644 --- a/samples/openapi3/client/petstore/php/SwaggerClient-php/docs/Api/FakeApi.md +++ b/samples/openapi3/client/petstore/php/SwaggerClient-php/docs/Api/FakeApi.md @@ -294,8 +294,8 @@ $int64 = 56; // int | None $float = 3.4; // float | None $string = "string_example"; // string | None $binary = "binary_example"; // string | None -$date = "date_example"; // \DateTime | None -$date_time = "date_time_example"; // \DateTime | None +$date = new \DateTime("2013-10-20T19:20:30+01:00"); // \DateTime | None +$date_time = new \DateTime("2013-10-20T19:20:30+01:00"); // \DateTime | None $password = "password_example"; // string | None $callback = "callback_example"; // string | None @@ -314,13 +314,13 @@ Name | Type | Description | Notes **number** | **BigDecimal**| None | **double** | **double**| None | **pattern_without_delimiter** | **string**| None | - **byte** | **string**| None | + **byte** | **string****string**| None | **integer** | **int**| None | [optional] **int32** | **int**| None | [optional] **int64** | **int**| None | [optional] **float** | **float**| None | [optional] **string** | **string**| None | [optional] - **binary** | **string**| None | [optional] + **binary** | **string****string**| None | [optional] **date** | **\DateTime**| None | [optional] **date_time** | **\DateTime**| None | [optional] **password** | **string**| None | [optional] diff --git a/samples/openapi3/client/petstore/php/SwaggerClient-php/docs/Api/PetApi.md b/samples/openapi3/client/petstore/php/SwaggerClient-php/docs/Api/PetApi.md index dc6a9fb94e1..5beb474fe54 100644 --- a/samples/openapi3/client/petstore/php/SwaggerClient-php/docs/Api/PetApi.md +++ b/samples/openapi3/client/petstore/php/SwaggerClient-php/docs/Api/PetApi.md @@ -419,7 +419,7 @@ Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- **pet_id** | **int**| ID of pet to update | **additional_metadata** | **string**| Additional data to pass to server | [optional] - **file** | **string**| file to upload | [optional] + **file** | **string****string**| file to upload | [optional] ### Return type diff --git a/samples/openapi3/client/petstore/php/SwaggerClient-php/lib/Api/FakeApi.php b/samples/openapi3/client/petstore/php/SwaggerClient-php/lib/Api/FakeApi.php index b35eda5bd31..306cf69eefb 100644 --- a/samples/openapi3/client/petstore/php/SwaggerClient-php/lib/Api/FakeApi.php +++ b/samples/openapi3/client/petstore/php/SwaggerClient-php/lib/Api/FakeApi.php @@ -1641,11 +1641,13 @@ class FakeApi } // form params if ($byte !== null) { - $formParams['byte'] = ObjectSerializer::toFormValue($byte); + $multipart = true; + $formParams['byte'] = \GuzzleHttp\Psr7\try_fopen(ObjectSerializer::toFormValue($byte), 'rb'); } // form params if ($binary !== null) { - $formParams['binary'] = ObjectSerializer::toFormValue($binary); + $multipart = true; + $formParams['binary'] = \GuzzleHttp\Psr7\try_fopen(ObjectSerializer::toFormValue($binary), 'rb'); } // form params if ($date !== null) { diff --git a/samples/openapi3/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php b/samples/openapi3/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php index a0fb0b9a48e..302392042a1 100644 --- a/samples/openapi3/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php +++ b/samples/openapi3/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php @@ -2031,7 +2031,8 @@ class PetApi } // form params if ($file !== null) { - $formParams['file'] = ObjectSerializer::toFormValue($file); + $multipart = true; + $formParams['file'] = \GuzzleHttp\Psr7\try_fopen(ObjectSerializer::toFormValue($file), 'rb'); } // body params $_tempBody = null; diff --git a/samples/openapi3/client/petstore/php/SwaggerClient-php/lib/Model/Body3.php b/samples/openapi3/client/petstore/php/SwaggerClient-php/lib/Model/Body3.php index 1d5e6732eb1..cf6c0709d8d 100644 --- a/samples/openapi3/client/petstore/php/SwaggerClient-php/lib/Model/Body3.php +++ b/samples/openapi3/client/petstore/php/SwaggerClient-php/lib/Model/Body3.php @@ -295,11 +295,11 @@ class Body3 implements ModelInterface, ArrayAccess if ($this->container['byte'] === null) { $invalidProperties[] = "'byte' can't be null"; } - if (!is_null($this->container['password']) && (strlen($this->container['password']) > 64)) { + if (!is_null($this->container['password']) && (mb_strlen($this->container['password']) > 64)) { $invalidProperties[] = "invalid value for 'password', the character length must be smaller than or equal to 64."; } - if (!is_null($this->container['password']) && (strlen($this->container['password']) < 10)) { + if (!is_null($this->container['password']) && (mb_strlen($this->container['password']) < 10)) { $invalidProperties[] = "invalid value for 'password', the character length must be bigger than or equal to 10."; } @@ -339,10 +339,10 @@ class Body3 implements ModelInterface, ArrayAccess if ($this->container['byte'] === null) { return false; } - if (strlen($this->container['password']) > 64) { + if (mb_strlen($this->container['password']) > 64) { return false; } - if (strlen($this->container['password']) < 10) { + if (mb_strlen($this->container['password']) < 10) { return false; } return true; @@ -672,10 +672,10 @@ class Body3 implements ModelInterface, ArrayAccess */ public function setPassword($password) { - if (!is_null($password) && (strlen($password) > 64)) { + if (!is_null($password) && (mb_strlen($password) > 64)) { throw new \InvalidArgumentException('invalid length for $password when calling Body3., must be smaller than or equal to 64.'); } - if (!is_null($password) && (strlen($password) < 10)) { + if (!is_null($password) && (mb_strlen($password) < 10)) { throw new \InvalidArgumentException('invalid length for $password when calling Body3., must be bigger than or equal to 10.'); } diff --git a/samples/openapi3/client/petstore/php/SwaggerClient-php/lib/Model/FormatTest.php b/samples/openapi3/client/petstore/php/SwaggerClient-php/lib/Model/FormatTest.php index b80143dbc3a..9210ba363d0 100644 --- a/samples/openapi3/client/petstore/php/SwaggerClient-php/lib/Model/FormatTest.php +++ b/samples/openapi3/client/petstore/php/SwaggerClient-php/lib/Model/FormatTest.php @@ -289,11 +289,11 @@ class FormatTest implements ModelInterface, ArrayAccess if ($this->container['password'] === null) { $invalidProperties[] = "'password' can't be null"; } - if ((strlen($this->container['password']) > 64)) { + if ((mb_strlen($this->container['password']) > 64)) { $invalidProperties[] = "invalid value for 'password', the character length must be smaller than or equal to 64."; } - if ((strlen($this->container['password']) < 10)) { + if ((mb_strlen($this->container['password']) < 10)) { $invalidProperties[] = "invalid value for 'password', the character length must be bigger than or equal to 10."; } @@ -333,10 +333,10 @@ class FormatTest implements ModelInterface, ArrayAccess if ($this->container['password'] === null) { return false; } - if (strlen($this->container['password']) > 64) { + if (mb_strlen($this->container['password']) > 64) { return false; } - if (strlen($this->container['password']) < 10) { + if (mb_strlen($this->container['password']) < 10) { return false; } return true; @@ -666,10 +666,10 @@ class FormatTest implements ModelInterface, ArrayAccess */ public function setPassword($password) { - if ((strlen($password) > 64)) { + if ((mb_strlen($password) > 64)) { throw new \InvalidArgumentException('invalid length for $password when calling FormatTest., must be smaller than or equal to 64.'); } - if ((strlen($password) < 10)) { + if ((mb_strlen($password) < 10)) { throw new \InvalidArgumentException('invalid length for $password when calling FormatTest., must be bigger than or equal to 10.'); } From 0e744adb806b931a40cef889a13e2ce067fcd208 Mon Sep 17 00:00:00 2001 From: "akihito.nakano" Date: Sun, 8 Apr 2018 12:20:28 +0900 Subject: [PATCH 2/5] Apply collection format to SIMPLE enum style in order to separate 'header' parameter values --- .../main/java/org/openapitools/codegen/DefaultCodegen.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java index fafe588a903..5fe3335f777 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java @@ -3941,7 +3941,10 @@ public class DefaultCodegen implements CodegenConfig { } protected String getCollectionFormat(Parameter parameter) { - if (Parameter.StyleEnum.FORM.equals(parameter.getStyle())) { + if ( + Parameter.StyleEnum.FORM.equals(parameter.getStyle()) + || Parameter.StyleEnum.SIMPLE.equals(parameter.getStyle()) + ) { if (parameter.getExplode() != null && parameter.getExplode()) { return "csv"; } else { From 016087c4622fbeb23f094f65e336f48227016b75 Mon Sep 17 00:00:00 2001 From: "akihito.nakano" Date: Sun, 8 Apr 2018 12:31:39 +0900 Subject: [PATCH 3/5] Explode the header value --- .../3_0/petstore-with-fake-endpoints-models-for-testing.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml b/modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml index fa3e490a4b5..d2a9e5e92f9 100644 --- a/modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml @@ -580,6 +580,7 @@ paths: parameters: - name: enum_header_string_array in: header + explode: true description: Header parameter enum test (string array) schema: type: array From 6e0e6fb7a10040a0989c5d8c8936b529dc9cf7ab Mon Sep 17 00:00:00 2001 From: "akihito.nakano" Date: Sun, 8 Apr 2018 12:32:14 +0900 Subject: [PATCH 4/5] Update samples bin/openapi3/php-petstore.sh --- .../client/petstore/php/SwaggerClient-php/lib/Api/FakeApi.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/samples/openapi3/client/petstore/php/SwaggerClient-php/lib/Api/FakeApi.php b/samples/openapi3/client/petstore/php/SwaggerClient-php/lib/Api/FakeApi.php index 306cf69eefb..e73dbd6fab9 100644 --- a/samples/openapi3/client/petstore/php/SwaggerClient-php/lib/Api/FakeApi.php +++ b/samples/openapi3/client/petstore/php/SwaggerClient-php/lib/Api/FakeApi.php @@ -1929,6 +1929,9 @@ class FakeApi $queryParams['enum_query_integer'] = ObjectSerializer::toQueryValue($enum_query_integer); } // header params + if (is_array($enum_header_string_array)) { + $enum_header_string_array = ObjectSerializer::serializeCollection($enum_header_string_array, 'csv'); + } if ($enum_header_string_array !== null) { $headerParams['enum_header_string_array'] = ObjectSerializer::toHeaderValue($enum_header_string_array); } From 63449a49c459aa2942a5480f381f6f71160eed58 Mon Sep 17 00:00:00 2001 From: "akihito.nakano" Date: Sun, 8 Apr 2018 12:33:47 +0900 Subject: [PATCH 5/5] Tweak test codes according to the parameter order changes same changes in another PR: https://github.com/wing328/openapi-generator/pull/24/commits/36ed29852ee9135242fd209a7a270fdc3289742b --- .../petstore/php/SwaggerClient-php/tests/ParametersTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/openapi3/client/petstore/php/SwaggerClient-php/tests/ParametersTest.php b/samples/openapi3/client/petstore/php/SwaggerClient-php/tests/ParametersTest.php index 37877556d01..024c51a1c6d 100644 --- a/samples/openapi3/client/petstore/php/SwaggerClient-php/tests/ParametersTest.php +++ b/samples/openapi3/client/petstore/php/SwaggerClient-php/tests/ParametersTest.php @@ -36,7 +36,7 @@ class ParametersTest extends \PHPUnit_Framework_TestCase public function testHeaderParamCollection() { - $this->fakeApi->testEnumParameters([], [], ['string1', 'string2']); + $this->fakeApi->testEnumParameters(['string1', 'string2']); $request = $this->fakeHttpClient->getLastRequest(); $headers = $request->getHeaders();