diff --git a/modules/swagger-codegen/src/main/resources/php/api.mustache b/modules/swagger-codegen/src/main/resources/php/api.mustache index 1768ff7ac5e..bfbb6fca373 100644 --- a/modules/swagger-codegen/src/main/resources/php/api.mustache +++ b/modules/swagger-codegen/src/main/resources/php/api.mustache @@ -49,7 +49,6 @@ use \{{invokerPackage}}\ObjectSerializer; { if ($apiClient === null) { $apiClient = new ApiClient(); - $apiClient->getConfig()->setHost('{{basePath}}'); } $this->apiClient = $apiClient; 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 b589c11a32a..d99eea4c925 100644 --- a/samples/client/petstore/php/SwaggerClient-php/docs/Api/PetApi.md +++ b/samples/client/petstore/php/SwaggerClient-php/docs/Api/PetApi.md @@ -389,7 +389,7 @@ Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- **pet_id** | **int**| ID of pet to update | **additional_metadata** | **string**| Additional data to pass to server | [optional] - **file** | **\SplFileObject****\SplFileObject**| file to upload | [optional] + **file** | **\SplFileObject**| file to upload | [optional] ### Return type diff --git a/samples/client/petstore/php/SwaggerClient-php/docs/Model/ClassModel.md b/samples/client/petstore/php/SwaggerClient-php/docs/Model/ClassModel.md new file mode 100644 index 00000000000..3ad025b6ed3 --- /dev/null +++ b/samples/client/petstore/php/SwaggerClient-php/docs/Model/ClassModel.md @@ -0,0 +1,10 @@ +# ClassModel + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**_class** | **string** | | [optional] + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/samples/client/petstore/php/SwaggerClient-php/docs/Model/OuterEnum.md b/samples/client/petstore/php/SwaggerClient-php/docs/Model/OuterEnum.md new file mode 100644 index 00000000000..06d413b0168 --- /dev/null +++ b/samples/client/petstore/php/SwaggerClient-php/docs/Model/OuterEnum.md @@ -0,0 +1,9 @@ +# OuterEnum + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Api/FakeApi.php b/samples/client/petstore/php/SwaggerClient-php/lib/Api/FakeApi.php index 9d13660091f..54522e7a792 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/FakeApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/FakeApi.php @@ -59,7 +59,6 @@ public function __construct(\Swagger\Client\ApiClient $apiClient = null) { if ($apiClient === null) { $apiClient = new ApiClient(); - $apiClient->getConfig()->setHost('http://petstore.swagger.io/v2'); } $this->apiClient = $apiClient; 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 efee25ca687..cb902068dd4 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php @@ -59,7 +59,6 @@ public function __construct(\Swagger\Client\ApiClient $apiClient = null) { if ($apiClient === null) { $apiClient = new ApiClient(); - $apiClient->getConfig()->setHost('http://petstore.swagger.io/v2'); } $this->apiClient = $apiClient; diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php b/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php index 7070313661d..61531c1ada4 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php @@ -59,7 +59,6 @@ public function __construct(\Swagger\Client\ApiClient $apiClient = null) { if ($apiClient === null) { $apiClient = new ApiClient(); - $apiClient->getConfig()->setHost('http://petstore.swagger.io/v2'); } $this->apiClient = $apiClient; diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Api/UserApi.php b/samples/client/petstore/php/SwaggerClient-php/lib/Api/UserApi.php index db404dd8818..31580e1b3c1 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/UserApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/UserApi.php @@ -59,7 +59,6 @@ public function __construct(\Swagger\Client\ApiClient $apiClient = null) { if ($apiClient === null) { $apiClient = new ApiClient(); - $apiClient->getConfig()->setHost('http://petstore.swagger.io/v2'); } $this->apiClient = $apiClient; diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/ApiClient.php b/samples/client/petstore/php/SwaggerClient-php/lib/ApiClient.php index 8bda07de03f..51935028b00 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/ApiClient.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/ApiClient.php @@ -163,6 +163,11 @@ public function callApi($resourcePath, $method, $queryParams, $postData, $header if ($this->config->getCurlTimeout() !== 0) { curl_setopt($curl, CURLOPT_TIMEOUT, $this->config->getCurlTimeout()); } + // set connect timeout, if needed + if ($this->config->getCurlConnectTimeout() != 0) { + curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, $this->config->getCurlConnectTimeout()); + } + // return the result on success, rather than just true curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Configuration.php b/samples/client/petstore/php/SwaggerClient-php/lib/Configuration.php index ca4e62be7ee..8066ae8ac66 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Configuration.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Configuration.php @@ -97,6 +97,13 @@ class Configuration */ protected $curlTimeout = 0; + /** + * Timeout (second) of the HTTP connection, by default set to 0, no timeout + * + * @var string + */ + protected $curlConnectTimeout = 0; + /** * User agent of the HTTP request, set to "PHP-Swagger" by default * @@ -380,6 +387,33 @@ public function getCurlTimeout() return $this->curlTimeout; } + /** + * Sets the HTTP connect timeout value + * + * @param integer $seconds Number of seconds before connection times out [set to 0 for no timeout] + * + * @return Configuration + */ + public function setCurlConnectTimeout($seconds) + { + if (!is_numeric($seconds) || $seconds < 0) { + throw new \InvalidArgumentException('Connect timeout value must be numeric and a non-negative number.'); + } + + $this->curlConnectTimeout = $seconds; + return $this; + } + + /** + * Gets the HTTP connect timeout value + * + * @return string HTTP connect timeout value + */ + public function getCurlConnectTimeout() + { + return $this->curlConnectTimeout; + } + /** * Sets debug flag * diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/ClassModel.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/ClassModel.php new file mode 100644 index 00000000000..74b0aff6da0 --- /dev/null +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/ClassModel.php @@ -0,0 +1,229 @@ + 'string' + ]; + + public static function swaggerTypes() + { + return self::$swaggerTypes; + } + + /** + * Array of attributes where the key is the local name, and the value is the original name + * @var string[] + */ + protected static $attributeMap = [ + '_class' => '_class' + ]; + + + /** + * Array of attributes to setter functions (for deserialization of responses) + * @var string[] + */ + protected static $setters = [ + '_class' => 'setClass' + ]; + + + /** + * Array of attributes to getter functions (for serialization of requests) + * @var string[] + */ + protected static $getters = [ + '_class' => 'getClass' + ]; + + public static function attributeMap() + { + return self::$attributeMap; + } + + public static function setters() + { + return self::$setters; + } + + public static function getters() + { + return self::$getters; + } + + + + + + /** + * Associative array for storing property values + * @var mixed[] + */ + protected $container = []; + + /** + * Constructor + * @param mixed[] $data Associated array of property values initializing the model + */ + public function __construct(array $data = null) + { + $this->container['_class'] = isset($data['_class']) ? $data['_class'] : null; + } + + /** + * show all the invalid properties with reasons. + * + * @return array invalid properties with reasons + */ + public function listInvalidProperties() + { + $invalid_properties = []; + return $invalid_properties; + } + + /** + * validate all the properties in the model + * return true if all passed + * + * @return bool True if all properteis are valid + */ + public function valid() + { + return true; + } + + + /** + * Gets _class + * @return string + */ + public function getClass() + { + return $this->container['_class']; + } + + /** + * Sets _class + * @param string $_class + * @return $this + */ + public function setClass($_class) + { + $this->container['_class'] = $_class; + + return $this; + } + /** + * Returns true if offset exists. False otherwise. + * @param integer $offset Offset + * @return boolean + */ + public function offsetExists($offset) + { + return isset($this->container[$offset]); + } + + /** + * Gets offset. + * @param integer $offset Offset + * @return mixed + */ + public function offsetGet($offset) + { + return isset($this->container[$offset]) ? $this->container[$offset] : null; + } + + /** + * Sets value based on offset. + * @param integer $offset Offset + * @param mixed $value Value to be set + * @return void + */ + public function offsetSet($offset, $value) + { + if (is_null($offset)) { + $this->container[] = $value; + } else { + $this->container[$offset] = $value; + } + } + + /** + * Unsets offset. + * @param integer $offset Offset + * @return void + */ + public function offsetUnset($offset) + { + unset($this->container[$offset]); + } + + /** + * Gets the string presentation of the object + * @return string + */ + public function __toString() + { + if (defined('JSON_PRETTY_PRINT')) { // use JSON pretty print + return json_encode(\Swagger\Client\ObjectSerializer::sanitizeForSerialization($this), JSON_PRETTY_PRINT); + } + + return json_encode(\Swagger\Client\ObjectSerializer::sanitizeForSerialization($this)); + } +} + + diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/OuterEnum.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/OuterEnum.php new file mode 100644 index 00000000000..26c54fd1b2e --- /dev/null +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/OuterEnum.php @@ -0,0 +1,51 @@ +assertSame('red', $dog->getColor()); $this->assertSame('red', $animal->getColor()); } + + // Ensure that API Classes pickup ApiClient defaults to prevent regressions of PR #4525 + public function testHostOverride() + { + $orig_default = Configuration::getDefaultConfiguration(); + $new_default = new Configuration(); + + $new_default->setHost("http://localhost/whatever"); + Configuration::setDefaultConfiguration($new_default); + + $pet_api = new Api\PetApi(); + $pet_host = $pet_api->getApiClient()->getConfig()->getHost(); + $this->assertSame($pet_host, $new_default->getHost()); + + Configuration::setDefaultConfiguration($orig_default); // Reset to original to prevent failure of other tests that rely on this state + } }