Skip to content

Commit 2e4de0c

Browse files
toomuchpetewing328
authored andcommitted
Remove unnecessary call to setHost() in the constructor (#4525)
* Remove unnecessary call to setHost() in the constructor The default host will be automatically set on the client by the ApiClient constructor. * Updated PHP API Classes corresponding to template updates in #4525. * Additional changes generated by the petstore update unrelated to #4525, but seem to have not been included yet. * Add test to prevent regressions of #4525
1 parent d7eeb06 commit 2e4de0c

File tree

15 files changed

+533
-6
lines changed

15 files changed

+533
-6
lines changed

modules/swagger-codegen/src/main/resources/php/api.mustache

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ use \{{invokerPackage}}\ObjectSerializer;
4949
{
5050
if ($apiClient === null) {
5151
$apiClient = new ApiClient();
52-
$apiClient->getConfig()->setHost('{{basePath}}');
5352
}
5453

5554
$this->apiClient = $apiClient;

samples/client/petstore/php/SwaggerClient-php/docs/Api/PetApi.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ Name | Type | Description | Notes
389389
------------- | ------------- | ------------- | -------------
390390
**pet_id** | **int**| ID of pet to update |
391391
**additional_metadata** | **string**| Additional data to pass to server | [optional]
392-
**file** | **\SplFileObject****\SplFileObject**| file to upload | [optional]
392+
**file** | **\SplFileObject**| file to upload | [optional]
393393

394394
### Return type
395395

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# ClassModel
2+
3+
## Properties
4+
Name | Type | Description | Notes
5+
------------ | ------------- | ------------- | -------------
6+
**_class** | **string** | | [optional]
7+
8+
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
9+
10+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# OuterEnum
2+
3+
## Properties
4+
Name | Type | Description | Notes
5+
------------ | ------------- | ------------- | -------------
6+
7+
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
8+
9+

samples/client/petstore/php/SwaggerClient-php/lib/Api/FakeApi.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ public function __construct(\Swagger\Client\ApiClient $apiClient = null)
5959
{
6060
if ($apiClient === null) {
6161
$apiClient = new ApiClient();
62-
$apiClient->getConfig()->setHost('http://petstore.swagger.io/v2');
6362
}
6463

6564
$this->apiClient = $apiClient;

samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ public function __construct(\Swagger\Client\ApiClient $apiClient = null)
5959
{
6060
if ($apiClient === null) {
6161
$apiClient = new ApiClient();
62-
$apiClient->getConfig()->setHost('http://petstore.swagger.io/v2');
6362
}
6463

6564
$this->apiClient = $apiClient;

samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ public function __construct(\Swagger\Client\ApiClient $apiClient = null)
5959
{
6060
if ($apiClient === null) {
6161
$apiClient = new ApiClient();
62-
$apiClient->getConfig()->setHost('http://petstore.swagger.io/v2');
6362
}
6463

6564
$this->apiClient = $apiClient;

samples/client/petstore/php/SwaggerClient-php/lib/Api/UserApi.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ public function __construct(\Swagger\Client\ApiClient $apiClient = null)
5959
{
6060
if ($apiClient === null) {
6161
$apiClient = new ApiClient();
62-
$apiClient->getConfig()->setHost('http://petstore.swagger.io/v2');
6362
}
6463

6564
$this->apiClient = $apiClient;

samples/client/petstore/php/SwaggerClient-php/lib/ApiClient.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,11 @@ public function callApi($resourcePath, $method, $queryParams, $postData, $header
163163
if ($this->config->getCurlTimeout() !== 0) {
164164
curl_setopt($curl, CURLOPT_TIMEOUT, $this->config->getCurlTimeout());
165165
}
166+
// set connect timeout, if needed
167+
if ($this->config->getCurlConnectTimeout() != 0) {
168+
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, $this->config->getCurlConnectTimeout());
169+
}
170+
166171
// return the result on success, rather than just true
167172
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
168173

samples/client/petstore/php/SwaggerClient-php/lib/Configuration.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,13 @@ class Configuration
9797
*/
9898
protected $curlTimeout = 0;
9999

100+
/**
101+
* Timeout (second) of the HTTP connection, by default set to 0, no timeout
102+
*
103+
* @var string
104+
*/
105+
protected $curlConnectTimeout = 0;
106+
100107
/**
101108
* User agent of the HTTP request, set to "PHP-Swagger" by default
102109
*
@@ -380,6 +387,33 @@ public function getCurlTimeout()
380387
return $this->curlTimeout;
381388
}
382389

390+
/**
391+
* Sets the HTTP connect timeout value
392+
*
393+
* @param integer $seconds Number of seconds before connection times out [set to 0 for no timeout]
394+
*
395+
* @return Configuration
396+
*/
397+
public function setCurlConnectTimeout($seconds)
398+
{
399+
if (!is_numeric($seconds) || $seconds < 0) {
400+
throw new \InvalidArgumentException('Connect timeout value must be numeric and a non-negative number.');
401+
}
402+
403+
$this->curlConnectTimeout = $seconds;
404+
return $this;
405+
}
406+
407+
/**
408+
* Gets the HTTP connect timeout value
409+
*
410+
* @return string HTTP connect timeout value
411+
*/
412+
public function getCurlConnectTimeout()
413+
{
414+
return $this->curlConnectTimeout;
415+
}
416+
383417
/**
384418
* Sets debug flag
385419
*

0 commit comments

Comments
 (0)