From 48e0ae9443ed3a9d09defa69813eb36888a95b9b Mon Sep 17 00:00:00 2001 From: Benjamin Date: Fri, 27 Aug 2021 15:19:55 +0200 Subject: [PATCH 1/6] Issue_11123: Update templates to support guzzle 7.3 for php client --- .../src/main/resources/php/api.mustache | 18 +++++++++++++----- .../src/main/resources/php/composer.mustache | 2 +- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/php/api.mustache b/modules/swagger-codegen/src/main/resources/php/api.mustache index e0b01e1f678..1efea89f550 100644 --- a/modules/swagger-codegen/src/main/resources/php/api.mustache +++ b/modules/swagger-codegen/src/main/resources/php/api.mustache @@ -21,6 +21,7 @@ namespace {{apiPackage}}; use GuzzleHttp\Client; use GuzzleHttp\ClientInterface; use GuzzleHttp\Exception\RequestException; +use GuzzleHttp\Exception\TransferException; use GuzzleHttp\Psr7\MultipartStream; use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; @@ -138,6 +139,13 @@ use {{invokerPackage}}\ObjectSerializer; $e->getResponse() ? $e->getResponse()->getHeaders() : null, $e->getResponse() ? $e->getResponse()->getBody()->getContents() : null ); + } catch (TransferException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $e->getCode(), + null, + null + ); } $statusCode = $response->getStatusCode(); @@ -162,7 +170,7 @@ use {{invokerPackage}}\ObjectSerializer; } else { $content = $responseBody->getContents(); if ($returnType !== 'string') { - $content = json_decode($content); + $content = \GuzzleHttp\Utils::jsonDecode($content); } } @@ -253,7 +261,7 @@ use {{invokerPackage}}\ObjectSerializer; } else { $content = $responseBody->getContents(); if ($returnType !== 'string') { - $content = json_decode($content); + $content = \GuzzleHttp\Utils::jsonDecode($content); } } @@ -430,11 +438,11 @@ use {{invokerPackage}}\ObjectSerializer; if($headers['Content-Type'] === 'application/json') { // \stdClass has no __toString(), so we should encode it manually if ($httpBody instanceof \stdClass) { - $httpBody = \GuzzleHttp\json_encode($httpBody); + $httpBody = \GuzzleHttp\Utils::jsonEncode($httpBody); } // array has no __toString(), so we should encode it manually if(is_array($httpBody)) { - $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($httpBody)); + $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($httpBody)); } } } elseif (count($formParams) > 0) { @@ -450,7 +458,7 @@ use {{invokerPackage}}\ObjectSerializer; $httpBody = new MultipartStream($multipartContents); } elseif ($headers['Content-Type'] === 'application/json') { - $httpBody = \GuzzleHttp\json_encode($formParams); + $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); } else { // for HTTP post (form) diff --git a/modules/swagger-codegen/src/main/resources/php/composer.mustache b/modules/swagger-codegen/src/main/resources/php/composer.mustache index 5147268142f..6f7986f78ee 100644 --- a/modules/swagger-codegen/src/main/resources/php/composer.mustache +++ b/modules/swagger-codegen/src/main/resources/php/composer.mustache @@ -23,7 +23,7 @@ "ext-curl": "*", "ext-json": "*", "ext-mbstring": "*", - "guzzlehttp/guzzle": "^6.2" + "guzzlehttp/guzzle": "^7.3" }, "require-dev": { "phpunit/phpunit": "^4.8", From d45c3a19cf8048b0d173a2798d2086feb1fb8c32 Mon Sep 17 00:00:00 2001 From: Benjamin Date: Fri, 10 Sep 2021 10:57:05 +0200 Subject: [PATCH 2/6] Issue_11123: Make default gitUserId and gitRepoId conform with composer as running `composer install` in sample repository fails otherwise --- .../codegen/config/CodegenConfigurator.java | 4 +- .../petstore/php/SwaggerClient-php/README.md | 82 +++++++++++++++---- .../php/SwaggerClient-php/composer.json | 2 +- .../docs/Api/AnotherFakeApi.md | 2 +- .../php/SwaggerClient-php/docs/Api/FakeApi.md | 2 +- .../docs/Api/FakeClassnameTags123Api.md | 2 +- .../php/SwaggerClient-php/docs/Api/PetApi.md | 2 +- .../SwaggerClient-php/docs/Api/StoreApi.md | 6 +- .../php/SwaggerClient-php/docs/Api/UserApi.md | 2 +- .../php/SwaggerClient-php/git_push.sh | 4 +- .../php/SwaggerClient-php/lib/Api/PetApi.php | 2 +- .../SwaggerClient-php/lib/Configuration.php | 6 +- 12 files changed, 84 insertions(+), 32 deletions(-) diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/config/CodegenConfigurator.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/config/CodegenConfigurator.java index b6b4396219f..1f611e53921 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/config/CodegenConfigurator.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/config/CodegenConfigurator.java @@ -67,8 +67,8 @@ public class CodegenConfigurator implements Serializable { private Set languageSpecificPrimitives = new HashSet(); private Map reservedWordMappings = new HashMap(); - private String gitUserId = "GIT_USER_ID"; - private String gitRepoId = "GIT_REPO_ID"; + private String gitUserId = "git_user_id"; + private String gitRepoId = "git_repo_id"; private String gitRepoBaseURL = "GIT_REPO_BASE_URL"; private String releaseNote = "Minor update"; private String httpUserAgent; diff --git a/samples/client/petstore/php/SwaggerClient-php/README.md b/samples/client/petstore/php/SwaggerClient-php/README.md index feba5d37b72..a01b076cf01 100644 --- a/samples/client/petstore/php/SwaggerClient-php/README.md +++ b/samples/client/petstore/php/SwaggerClient-php/README.md @@ -1,5 +1,5 @@ # SwaggerClient-php -This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. +This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ This PHP package is automatically generated by the [Swagger Codegen](https://github.com/swagger-api/swagger-codegen) project: @@ -20,11 +20,11 @@ To install the bindings via [Composer](http://getcomposer.org/), add the followi "repositories": [ { "type": "git", - "url": "https://github.com/GIT_USER_ID/GIT_REPO_ID.git" + "url": "https://github.com/git_user_id/git_repo_id.git" } ], "require": { - "GIT_USER_ID/GIT_REPO_ID": "*@dev" + "git_user_id/git_repo_id": "*@dev" } } ``` @@ -56,21 +56,18 @@ Please follow the [installation procedure](#installation--usage) and then run th setAccessToken('YOUR_ACCESS_TOKEN'); - -$apiInstance = new Swagger\Client\Api\PetApi( +$apiInstance = new Swagger\Client\Api\AnotherFakeApi( // If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`. // This is optional, `GuzzleHttp\Client` will be used as default. - new GuzzleHttp\Client(), - $config + new GuzzleHttp\Client() ); -$body = new \Swagger\Client\Model\Pet(); // \Swagger\Client\Model\Pet | Pet object that needs to be added to the store +$body = new \Swagger\Client\Model\Client(); // \Swagger\Client\Model\Client | client model try { - $apiInstance->addPet($body); + $result = $apiInstance->testSpecialTags($body); + print_r($result); } catch (Exception $e) { - echo 'Exception when calling PetApi->addPet: ', $e->getMessage(), PHP_EOL; + echo 'Exception when calling AnotherFakeApi->testSpecialTags: ', $e->getMessage(), PHP_EOL; } ?> @@ -78,10 +75,22 @@ try { ## Documentation for API Endpoints -All URIs are relative to *http://petstore.swagger.io/v2* +All URIs are relative to *https://petstore.swagger.io/v2* Class | Method | HTTP request | Description ------------ | ------------- | ------------- | ------------- +*AnotherFakeApi* | [**testSpecialTags**](docs/Api/AnotherFakeApi.md#testspecialtags) | **PATCH** /another-fake/dummy | To test special tags +*FakeApi* | [**fakeOuterBooleanSerialize**](docs/Api/FakeApi.md#fakeouterbooleanserialize) | **POST** /fake/outer/boolean | +*FakeApi* | [**fakeOuterCompositeSerialize**](docs/Api/FakeApi.md#fakeoutercompositeserialize) | **POST** /fake/outer/composite | +*FakeApi* | [**fakeOuterNumberSerialize**](docs/Api/FakeApi.md#fakeouternumberserialize) | **POST** /fake/outer/number | +*FakeApi* | [**fakeOuterStringSerialize**](docs/Api/FakeApi.md#fakeouterstringserialize) | **POST** /fake/outer/string | +*FakeApi* | [**testBodyWithQueryParams**](docs/Api/FakeApi.md#testbodywithqueryparams) | **PUT** /fake/body-with-query-params | +*FakeApi* | [**testClientModel**](docs/Api/FakeApi.md#testclientmodel) | **PATCH** /fake | To test \"client\" model +*FakeApi* | [**testEndpointParameters**](docs/Api/FakeApi.md#testendpointparameters) | **POST** /fake | Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 +*FakeApi* | [**testEnumParameters**](docs/Api/FakeApi.md#testenumparameters) | **GET** /fake | To test enum parameters +*FakeApi* | [**testInlineAdditionalProperties**](docs/Api/FakeApi.md#testinlineadditionalproperties) | **POST** /fake/inline-additionalProperties | test inline additionalProperties +*FakeApi* | [**testJsonFormData**](docs/Api/FakeApi.md#testjsonformdata) | **GET** /fake/jsonFormData | test json serialization of form data +*FakeClassnameTags123Api* | [**testClassname**](docs/Api/FakeClassnameTags123Api.md#testclassname) | **PATCH** /fake_classname_test | To test class name in snake case *PetApi* | [**addPet**](docs/Api/PetApi.md#addpet) | **POST** /pet | Add a new pet to the store *PetApi* | [**deletePet**](docs/Api/PetApi.md#deletepet) | **DELETE** /pet/{petId} | Deletes a pet *PetApi* | [**findPetsByStatus**](docs/Api/PetApi.md#findpetsbystatus) | **GET** /pet/findByStatus | Finds Pets by status @@ -90,9 +99,9 @@ Class | Method | HTTP request | Description *PetApi* | [**updatePet**](docs/Api/PetApi.md#updatepet) | **PUT** /pet | Update an existing pet *PetApi* | [**updatePetWithForm**](docs/Api/PetApi.md#updatepetwithform) | **POST** /pet/{petId} | Updates a pet in the store with form data *PetApi* | [**uploadFile**](docs/Api/PetApi.md#uploadfile) | **POST** /pet/{petId}/uploadImage | uploads an image -*StoreApi* | [**deleteOrder**](docs/Api/StoreApi.md#deleteorder) | **DELETE** /store/order/{orderId} | Delete purchase order by ID +*StoreApi* | [**deleteOrder**](docs/Api/StoreApi.md#deleteorder) | **DELETE** /store/order/{order_id} | Delete purchase order by ID *StoreApi* | [**getInventory**](docs/Api/StoreApi.md#getinventory) | **GET** /store/inventory | Returns pet inventories by status -*StoreApi* | [**getOrderById**](docs/Api/StoreApi.md#getorderbyid) | **GET** /store/order/{orderId} | Find purchase order by ID +*StoreApi* | [**getOrderById**](docs/Api/StoreApi.md#getorderbyid) | **GET** /store/order/{order_id} | Find purchase order by ID *StoreApi* | [**placeOrder**](docs/Api/StoreApi.md#placeorder) | **POST** /store/order | Place an order for a pet *UserApi* | [**createUser**](docs/Api/UserApi.md#createuser) | **POST** /user | Create user *UserApi* | [**createUsersWithArrayInput**](docs/Api/UserApi.md#createuserswitharrayinput) | **POST** /user/createWithArray | Creates list of users with given input array @@ -106,10 +115,43 @@ Class | Method | HTTP request | Description ## Documentation For Models + - [AdditionalPropertiesClass](docs/Model/AdditionalPropertiesClass.md) + - [Animal](docs/Model/Animal.md) + - [AnimalFarm](docs/Model/AnimalFarm.md) - [ApiResponse](docs/Model/ApiResponse.md) + - [ArrayOfArrayOfNumberOnly](docs/Model/ArrayOfArrayOfNumberOnly.md) + - [ArrayOfNumberOnly](docs/Model/ArrayOfNumberOnly.md) + - [ArrayTest](docs/Model/ArrayTest.md) + - [Boolean](docs/Model/Boolean.md) + - [Capitalization](docs/Model/Capitalization.md) + - [Cat](docs/Model/Cat.md) - [Category](docs/Model/Category.md) + - [ClassModel](docs/Model/ClassModel.md) + - [Client](docs/Model/Client.md) + - [Dog](docs/Model/Dog.md) + - [EnumArrays](docs/Model/EnumArrays.md) + - [EnumClass](docs/Model/EnumClass.md) + - [EnumTest](docs/Model/EnumTest.md) + - [FormatTest](docs/Model/FormatTest.md) + - [HasOnlyReadOnly](docs/Model/HasOnlyReadOnly.md) + - [Ints](docs/Model/Ints.md) + - [MapTest](docs/Model/MapTest.md) + - [MixedPropertiesAndAdditionalPropertiesClass](docs/Model/MixedPropertiesAndAdditionalPropertiesClass.md) + - [Model200Response](docs/Model/Model200Response.md) + - [ModelList](docs/Model/ModelList.md) + - [ModelReturn](docs/Model/ModelReturn.md) + - [Name](docs/Model/Name.md) + - [NumberOnly](docs/Model/NumberOnly.md) + - [Numbers](docs/Model/Numbers.md) - [Order](docs/Model/Order.md) + - [OuterBoolean](docs/Model/OuterBoolean.md) + - [OuterComposite](docs/Model/OuterComposite.md) + - [OuterEnum](docs/Model/OuterEnum.md) + - [OuterNumber](docs/Model/OuterNumber.md) + - [OuterString](docs/Model/OuterString.md) - [Pet](docs/Model/Pet.md) + - [ReadOnlyFirst](docs/Model/ReadOnlyFirst.md) + - [SpecialModelName](docs/Model/SpecialModelName.md) - [Tag](docs/Model/Tag.md) - [User](docs/Model/User.md) @@ -123,6 +165,16 @@ Class | Method | HTTP request | Description - **API key parameter name**: api_key - **Location**: HTTP header +## api_key_query + +- **Type**: API key +- **API key parameter name**: api_key_query +- **Location**: URL query string + +## http_basic_test + +- **Type**: HTTP basic authentication + ## petstore_auth - **Type**: OAuth diff --git a/samples/client/petstore/php/SwaggerClient-php/composer.json b/samples/client/petstore/php/SwaggerClient-php/composer.json index 2d76f02819b..1eb8dff55a2 100644 --- a/samples/client/petstore/php/SwaggerClient-php/composer.json +++ b/samples/client/petstore/php/SwaggerClient-php/composer.json @@ -1,5 +1,5 @@ { - "name": "GIT_USER_ID/GIT_REPO_ID", + "name": "git_user_id/git_repo_id", "description": "", "keywords": [ "swagger", diff --git a/samples/client/petstore/php/SwaggerClient-php/docs/Api/AnotherFakeApi.md b/samples/client/petstore/php/SwaggerClient-php/docs/Api/AnotherFakeApi.md index 9eaff87384b..eda6f7e3643 100644 --- a/samples/client/petstore/php/SwaggerClient-php/docs/Api/AnotherFakeApi.md +++ b/samples/client/petstore/php/SwaggerClient-php/docs/Api/AnotherFakeApi.md @@ -1,6 +1,6 @@ # Swagger\Client\AnotherFakeApi -All URIs are relative to *http://petstore.swagger.io:80/v2* +All URIs are relative to *https://petstore.swagger.io/v2* Method | HTTP request | Description ------------- | ------------- | ------------- diff --git a/samples/client/petstore/php/SwaggerClient-php/docs/Api/FakeApi.md b/samples/client/petstore/php/SwaggerClient-php/docs/Api/FakeApi.md index d82c7a83689..058ba32eb67 100644 --- a/samples/client/petstore/php/SwaggerClient-php/docs/Api/FakeApi.md +++ b/samples/client/petstore/php/SwaggerClient-php/docs/Api/FakeApi.md @@ -1,6 +1,6 @@ # Swagger\Client\FakeApi -All URIs are relative to *http://petstore.swagger.io:80/v2* +All URIs are relative to *https://petstore.swagger.io/v2* Method | HTTP request | Description ------------- | ------------- | ------------- diff --git a/samples/client/petstore/php/SwaggerClient-php/docs/Api/FakeClassnameTags123Api.md b/samples/client/petstore/php/SwaggerClient-php/docs/Api/FakeClassnameTags123Api.md index b8283f11b4f..5f9603b9c1a 100644 --- a/samples/client/petstore/php/SwaggerClient-php/docs/Api/FakeClassnameTags123Api.md +++ b/samples/client/petstore/php/SwaggerClient-php/docs/Api/FakeClassnameTags123Api.md @@ -1,6 +1,6 @@ # Swagger\Client\FakeClassnameTags123Api -All URIs are relative to *http://petstore.swagger.io:80/v2* +All URIs are relative to *https://petstore.swagger.io/v2* Method | HTTP request | Description ------------- | ------------- | ------------- diff --git a/samples/client/petstore/php/SwaggerClient-php/docs/Api/PetApi.md b/samples/client/petstore/php/SwaggerClient-php/docs/Api/PetApi.md index 6a1773d4b28..274e2f1369a 100644 --- a/samples/client/petstore/php/SwaggerClient-php/docs/Api/PetApi.md +++ b/samples/client/petstore/php/SwaggerClient-php/docs/Api/PetApi.md @@ -1,6 +1,6 @@ # Swagger\Client\PetApi -All URIs are relative to *http://petstore.swagger.io/v2* +All URIs are relative to *https://petstore.swagger.io/v2* Method | HTTP request | Description ------------- | ------------- | ------------- diff --git a/samples/client/petstore/php/SwaggerClient-php/docs/Api/StoreApi.md b/samples/client/petstore/php/SwaggerClient-php/docs/Api/StoreApi.md index 649dcc4b265..1c862d0433c 100644 --- a/samples/client/petstore/php/SwaggerClient-php/docs/Api/StoreApi.md +++ b/samples/client/petstore/php/SwaggerClient-php/docs/Api/StoreApi.md @@ -1,12 +1,12 @@ # Swagger\Client\StoreApi -All URIs are relative to *http://petstore.swagger.io/v2* +All URIs are relative to *https://petstore.swagger.io/v2* Method | HTTP request | Description ------------- | ------------- | ------------- -[**deleteOrder**](StoreApi.md#deleteOrder) | **DELETE** /store/order/{orderId} | Delete purchase order by ID +[**deleteOrder**](StoreApi.md#deleteOrder) | **DELETE** /store/order/{order_id} | Delete purchase order by ID [**getInventory**](StoreApi.md#getInventory) | **GET** /store/inventory | Returns pet inventories by status -[**getOrderById**](StoreApi.md#getOrderById) | **GET** /store/order/{orderId} | Find purchase order by ID +[**getOrderById**](StoreApi.md#getOrderById) | **GET** /store/order/{order_id} | Find purchase order by ID [**placeOrder**](StoreApi.md#placeOrder) | **POST** /store/order | Place an order for a pet diff --git a/samples/client/petstore/php/SwaggerClient-php/docs/Api/UserApi.md b/samples/client/petstore/php/SwaggerClient-php/docs/Api/UserApi.md index 7953ca871f6..eea4794acc7 100644 --- a/samples/client/petstore/php/SwaggerClient-php/docs/Api/UserApi.md +++ b/samples/client/petstore/php/SwaggerClient-php/docs/Api/UserApi.md @@ -1,6 +1,6 @@ # Swagger\Client\UserApi -All URIs are relative to *http://petstore.swagger.io/v2* +All URIs are relative to *https://petstore.swagger.io/v2* Method | HTTP request | Description ------------- | ------------- | ------------- diff --git a/samples/client/petstore/php/SwaggerClient-php/git_push.sh b/samples/client/petstore/php/SwaggerClient-php/git_push.sh index 160f6f21399..908f777a402 100644 --- a/samples/client/petstore/php/SwaggerClient-php/git_push.sh +++ b/samples/client/petstore/php/SwaggerClient-php/git_push.sh @@ -8,12 +8,12 @@ git_repo_id=$2 release_note=$3 if [ "$git_user_id" = "" ]; then - git_user_id="GIT_USER_ID" + git_user_id="git_user_id" echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id" fi if [ "$git_repo_id" = "" ]; then - git_repo_id="GIT_REPO_ID" + git_repo_id="git_repo_id" echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id" fi diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php b/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php index 85df4c18fa1..0f61d5494aa 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php @@ -2081,7 +2081,7 @@ protected function uploadFileRequest($pet_id, $additional_metadata = null, $file // form params if ($file !== null) { $multipart = true; - $formParams['file'] = \GuzzleHttp\Psr7\try_fopen(ObjectSerializer::toFormValue($file), 'rb'); + $formParams['file'] = \GuzzleHttp\Psr7\Utils::TryFopen(ObjectSerializer::toFormValue($file), 'rb'); } // body params $_tempBody = null; diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Configuration.php b/samples/client/petstore/php/SwaggerClient-php/lib/Configuration.php index fb610939c5b..12ac04ee841 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Configuration.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Configuration.php @@ -12,12 +12,12 @@ /** * Swagger Petstore * - * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ * * OpenAPI spec version: 1.0.0 * Contact: apiteam@swagger.io * Generated by: https://github.com/swagger-api/swagger-codegen.git - * Swagger Codegen version: 2.4.3-SNAPSHOT + * Swagger Codegen version: 2.4.22-SNAPSHOT */ /** @@ -81,7 +81,7 @@ class Configuration * * @var string */ - protected $host = 'http://petstore.swagger.io/v2'; + protected $host = 'https://petstore.swagger.io/v2'; /** * User agent of the HTTP request, set to "PHP-Swagger" by default From 2957659958c018250ecea7779ed81a3e5b79ad9d Mon Sep 17 00:00:00 2001 From: Benjamin Date: Fri, 10 Sep 2021 11:05:43 +0200 Subject: [PATCH 3/6] Issue_11123: Update petstore.yaml used to generate php-client as missing https scheme led to failing to failing tests --- .../2_0/petstore-with-fake-endpoints-models-for-testing.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml b/modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml index 179de245c0a..3e6e9a3402f 100644 --- a/modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml +++ b/modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml @@ -9,7 +9,7 @@ info: license: name: Apache-2.0 url: 'http://www.apache.org/licenses/LICENSE-2.0.html' -host: petstore.swagger.io:80 +host: petstore.swagger.io basePath: /v2 tags: - name: pet @@ -25,6 +25,7 @@ tags: description: Find out more about our store url: 'http://swagger.io' schemes: + - https - http paths: /pet: From 3b179306d0e92bd696173c15dd05f84b2de1cbca Mon Sep 17 00:00:00 2001 From: Benjamin Date: Fri, 10 Sep 2021 11:08:16 +0200 Subject: [PATCH 4/6] Issue_11123: Replace Guzzle\Psr7\try_fopen in api template, method was removed in update to guzzle 7.3 --- modules/swagger-codegen/src/main/resources/php/api.mustache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/swagger-codegen/src/main/resources/php/api.mustache b/modules/swagger-codegen/src/main/resources/php/api.mustache index 1efea89f550..762fc873920 100644 --- a/modules/swagger-codegen/src/main/resources/php/api.mustache +++ b/modules/swagger-codegen/src/main/resources/php/api.mustache @@ -404,7 +404,7 @@ use {{invokerPackage}}\ObjectSerializer; if (${{paramName}} !== null) { {{#isFile}} $multipart = true; - $formParams['{{baseName}}'] = \GuzzleHttp\Psr7\try_fopen(ObjectSerializer::toFormValue(${{paramName}}), 'rb'); + $formParams['{{baseName}}'] = \GuzzleHttp\Psr7\Utils::TryFopen(ObjectSerializer::toFormValue(${{paramName}}), 'rb'); {{/isFile}} {{^isFile}} $formParams['{{baseName}}'] = ObjectSerializer::toFormValue(${{paramName}}); From f37c19ff932540d0baf73db282f743c851cc5428 Mon Sep 17 00:00:00 2001 From: Benjamin Date: Fri, 10 Sep 2021 11:08:51 +0200 Subject: [PATCH 5/6] Issue_11123: Update FakeApiClient to conform with guzzle 7.3 --- .../php/SwaggerClient-php/tests/FakeHttpClient.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/samples/client/petstore/php/SwaggerClient-php/tests/FakeHttpClient.php b/samples/client/petstore/php/SwaggerClient-php/tests/FakeHttpClient.php index abdfa7cf7c2..28046cd92b8 100644 --- a/samples/client/petstore/php/SwaggerClient-php/tests/FakeHttpClient.php +++ b/samples/client/petstore/php/SwaggerClient-php/tests/FakeHttpClient.php @@ -4,6 +4,7 @@ use GuzzleHttp\ClientInterface; use GuzzleHttp\Exception\GuzzleException; +use GuzzleHttp\Promise\PromiseInterface; use GuzzleHttp\Psr7\Response; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; @@ -41,23 +42,23 @@ public function setResponse(ResponseInterface $response = null) * @return ResponseInterface * @throws GuzzleException */ - public function send(RequestInterface $request, array $options = []) + public function send(RequestInterface $request, array $options = []): ResponseInterface { $this->request = $request; - return $this->response ?: new Response(200); + return $this->response ?: new Response(200, [], "{}"); } - public function sendAsync(RequestInterface $request, array $options = []) + public function sendAsync(RequestInterface $request, array $options = []): PromiseInterface { throw new \RuntimeException('not implemented'); } - public function request($method, $uri, array $options = []) + public function request($method, $uri, array $options = []): ResponseInterface { throw new \RuntimeException('not implemented'); } - public function requestAsync($method, $uri, array $options = []) + public function requestAsync($method, $uri, array $options = []): PromiseInterface { throw new \RuntimeException('not implemented'); } From 0e4c5677c54a93d4a49e105f061ad0c6e44e37af Mon Sep 17 00:00:00 2001 From: Benjamin Date: Fri, 10 Sep 2021 11:10:01 +0200 Subject: [PATCH 6/6] Issue_11123: Stabilize tests which failed due to poor test setup --- .../php/SwaggerClient-php/tests/DebugTest.php | 32 ++++++---- .../SwaggerClient-php/tests/PetApiTest.php | 60 +++++++++++++++---- 2 files changed, 69 insertions(+), 23 deletions(-) diff --git a/samples/client/petstore/php/SwaggerClient-php/tests/DebugTest.php b/samples/client/petstore/php/SwaggerClient-php/tests/DebugTest.php index 6eb9dacaffe..ca4eb9fa885 100644 --- a/samples/client/petstore/php/SwaggerClient-php/tests/DebugTest.php +++ b/samples/client/petstore/php/SwaggerClient-php/tests/DebugTest.php @@ -3,24 +3,36 @@ class DebugTest extends \PHPUnit_Framework_TestCase { - public function testEnableDebugOutput() + const PET_ID = 10005; + + /** @var Api\PetApi */ + private $api; + + protected function setUp() { - $this->expectOutputRegex('#GET /v2/pet/1 HTTP/1.1#'); + $newPetId = self::PET_ID; + $newPet = new Model\Pet; + $newPet->setId($newPetId); + $newPet->setName("PHP Unit Test"); + $newPet->setPhotoUrls(["http://test_php_unit_test.com"]); + + $this->expectOutputRegex('#GET /v2/pet/' . self::PET_ID . ' HTTP/1.1#'); $config = new Configuration(); $config->setDebug(true); - $api = new Api\PetApi(null, $config); - $api->getPetById(1); + $this->api = new Api\PetApi(null, $config); + $this->api->addPet($newPet); } - public function testEnableDebugOutputAsync() + + public function testEnableDebugOutput() { - $this->expectOutputRegex('#GET /v2/pet/1 HTTP/1.1#'); + $this->api->getPetById(self::PET_ID); + } - $config = new Configuration(); - $config->setDebug(true); - $api = new Api\PetApi(null, $config); - $promise = $api->getPetByIdAsync(1); + public function testEnableDebugOutputAsync() + { + $promise = $this->api->getPetByIdAsync(self::PET_ID); $promise->wait(); } } diff --git a/samples/client/petstore/php/SwaggerClient-php/tests/PetApiTest.php b/samples/client/petstore/php/SwaggerClient-php/tests/PetApiTest.php index 1cfad6aaeae..82941dde34e 100644 --- a/samples/client/petstore/php/SwaggerClient-php/tests/PetApiTest.php +++ b/samples/client/petstore/php/SwaggerClient-php/tests/PetApiTest.php @@ -2,6 +2,8 @@ namespace Swagger\Client; +use Exception; +use GuzzleHttp\Client; use Swagger\Client\Api\PetApi; use Swagger\Client\Model\ApiResponse; use Swagger\Client\Model\Pet; @@ -41,7 +43,8 @@ public static function setUpBeforeClass() $newPet->setCategory($category); $config = new Configuration(); - $petApi = new Api\PetApi(null, $config); + $client = new Client(['headers' => ['api_key' => 'special-key']]); + $petApi = new Api\PetApi($client, $config); // add a new pet (model) list(, $status) = $petApi->addPetWithHttpInfo($newPet); @@ -152,10 +155,12 @@ public function testUpdatePet() $this->assertNull($result); // verify updated Pet - $result = $this->api->getPetById($petId); - $this->assertSame($result->getId(), $petId); - $this->assertSame($result->getStatus(), 'pending'); - $this->assertSame($result->getName(), 'updatePet'); + $this->spin(function () use ($petId) { + $result = $this->api->getPetById($petId); + $this->assertSame($result->getId(), $petId); + $this->assertSame($result->getStatus(), 'pending'); + $this->assertSame($result->getName(), 'updatePet'); + }); } // test updatePetWithFormWithHttpInfo and verify by the "name" of the response @@ -172,9 +177,12 @@ public function testUpdatePetWithFormWithHttpInfo() $this->assertNull($update_response); $this->assertSame($status_code, 200); $this->assertSame($http_headers['Content-Type'], ['application/json']); - $response = $this->api->getPetById($petId); - $this->assertSame($response->getId(), $petId); - $this->assertSame($response->getName(), 'update pet with form with http info'); + + $this->spin(function () use ($petId) { + $response = $this->api->getPetById($petId); + $this->assertSame($response->getId(), $petId); + $this->assertSame($response->getName(), 'update pet with form with http info'); + }); } // test updatePetWithForm and verify by the "name" and "status" of the response @@ -185,16 +193,18 @@ public function testUpdatePetWithForm() // return nothing (void) $this->assertNull($result); - $response = $this->api->getPetById($pet_id); - $this->assertSame($response->getId(), $pet_id); - $this->assertSame($response->getName(), 'update pet with form'); - $this->assertSame($response->getStatus(), 'sold'); + $this->spin(function () use ($pet_id) { + $response = $this->api->getPetById($pet_id); + $this->assertSame($response->getId(), $pet_id); + $this->assertSame($response->getName(), 'update pet with form'); + $this->assertSame($response->getStatus(), 'sold'); + }); } // test addPet and verify by the "id" and "name" of the response public function testAddPet() { - $new_pet_id = 10005; + $new_pet_id = 10006; $newPet = new Model\Pet; $newPet->setId($new_pet_id); $newPet->setName("PHP Unit Test 2"); @@ -401,4 +411,28 @@ public function testInvalidArgument() // 'path' => sys_get_temp_dir() . '/' . $result->getFilename() // ]); // } + + /** + * @throws Exception + */ + private function spin($callable, $maxWaitTimeSeconds = 5, $waitingIntervalSeconds = 1) + { + $exception = null; + + for ($index = 0; $index < $maxWaitTimeSeconds; $index++) { + try { + return $callable($this); + } catch (Exception $exception) { + // only rethrow the latest exception when timing out + } + sleep($waitingIntervalSeconds); + } + + if ($exception) { + throw $exception; + } + + $backtrace = debug_backtrace(); + throw new Exception('Timeout thrown by ' . $backtrace[1]['class'] . '::' . $backtrace[1]['function'] . "()\n"); + } }