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
This commit is contained in:
Pete Holiday 2017-01-12 03:17:17 -05:00 committed by wing328
parent d7eeb069f2
commit 2e4de0ca1e
15 changed files with 533 additions and 6 deletions

View File

@ -49,7 +49,6 @@ use \{{invokerPackage}}\ObjectSerializer;
{
if ($apiClient === null) {
$apiClient = new ApiClient();
$apiClient->getConfig()->setHost('{{basePath}}');
}
$this->apiClient = $apiClient;

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -59,7 +59,6 @@ class FakeApi
{
if ($apiClient === null) {
$apiClient = new ApiClient();
$apiClient->getConfig()->setHost('http://petstore.swagger.io/v2');
}
$this->apiClient = $apiClient;

View File

@ -59,7 +59,6 @@ class PetApi
{
if ($apiClient === null) {
$apiClient = new ApiClient();
$apiClient->getConfig()->setHost('http://petstore.swagger.io/v2');
}
$this->apiClient = $apiClient;

View File

@ -59,7 +59,6 @@ class StoreApi
{
if ($apiClient === null) {
$apiClient = new ApiClient();
$apiClient->getConfig()->setHost('http://petstore.swagger.io/v2');
}
$this->apiClient = $apiClient;

View File

@ -59,7 +59,6 @@ class UserApi
{
if ($apiClient === null) {
$apiClient = new ApiClient();
$apiClient->getConfig()->setHost('http://petstore.swagger.io/v2');
}
$this->apiClient = $apiClient;

View File

@ -163,6 +163,11 @@ class ApiClient
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);

View File

@ -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 @@ class Configuration
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
*

View File

@ -0,0 +1,229 @@
<?php
/**
* ClassModel
*
* PHP version 5
*
* @category Class
* @package Swagger\Client
* @author Swaagger Codegen team
* @link https://github.com/swagger-api/swagger-codegen
*/
/**
* Swagger Petstore
*
* 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
*
*/
/**
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen
* Do not edit the class manually.
*/
namespace Swagger\Client\Model;
use \ArrayAccess;
/**
* ClassModel Class Doc Comment
*
* @category Class */
// @description Model for testing model with \&quot;_class\&quot; property
/**
* @package Swagger\Client
* @author Swagger Codegen team
* @link https://github.com/swagger-api/swagger-codegen
*/
class ClassModel implements ArrayAccess
{
const DISCRIMINATOR = null;
/**
* The original name of the model.
* @var string
*/
protected static $swaggerModelName = 'ClassModel';
/**
* Array of property to type mappings. Used for (de)serialization
* @var string[]
*/
protected static $swaggerTypes = [
'_class' => '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));
}
}

View File

@ -0,0 +1,51 @@
<?php
/**
* OuterEnum
*
* PHP version 5
*
* @category Class
* @package Swagger\Client
* @author Swaagger Codegen team
* @link https://github.com/swagger-api/swagger-codegen
*/
/**
* Swagger Petstore
*
* 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
*
*/
/**
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen
* Do not edit the class manually.
*/
namespace Swagger\Client\Model;
use \ArrayAccess;
/**
* OuterEnum Class Doc Comment
*
* @category Class */
/**
* @package Swagger\Client
* @author Swagger Codegen team
* @link https://github.com/swagger-api/swagger-codegen
*/
class OuterEnum {
const PLACED = 'placed';
const APPROVED = 'approved';
const DELIVERED = 'delivered';
}

View File

@ -0,0 +1,93 @@
<?php
/**
* ClassModelTest
*
* PHP version 5
*
* @category Class
* @package Swagger\Client
* @author Swagger Codegen team
* @link https://github.com/swagger-api/swagger-codegen
*/
/**
* Swagger Petstore
*
* 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
*
*/
/**
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen
* Please update the test case below to test the model.
*/
namespace Swagger\Client;
/**
* ClassModelTest Class Doc Comment
*
* @category Class */
// * @description Model for testing model with \&quot;_class\&quot; property
/**
* @package Swagger\Client
* @author Swagger Codegen team
* @link https://github.com/swagger-api/swagger-codegen
*/
class ClassModelTest extends \PHPUnit_Framework_TestCase
{
/**
* Setup before running any test case
*/
public static function setUpBeforeClass()
{
}
/**
* Setup before running each test case
*/
public function setUp()
{
}
/**
* Clean up after running each test case
*/
public function tearDown()
{
}
/**
* Clean up after running all test cases
*/
public static function tearDownAfterClass()
{
}
/**
* Test "ClassModel"
*/
public function testClassModel()
{
}
/**
* Test attribute "_class"
*/
public function testPropertyClass()
{
}
}

View File

@ -0,0 +1,85 @@
<?php
/**
* OuterEnumTest
*
* PHP version 5
*
* @category Class
* @package Swagger\Client
* @author Swagger Codegen team
* @link https://github.com/swagger-api/swagger-codegen
*/
/**
* Swagger Petstore
*
* 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
*
*/
/**
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen
* Please update the test case below to test the model.
*/
namespace Swagger\Client;
/**
* OuterEnumTest Class Doc Comment
*
* @category Class */
// * @description OuterEnum
/**
* @package Swagger\Client
* @author Swagger Codegen team
* @link https://github.com/swagger-api/swagger-codegen
*/
class OuterEnumTest extends \PHPUnit_Framework_TestCase
{
/**
* Setup before running any test case
*/
public static function setUpBeforeClass()
{
}
/**
* Setup before running each test case
*/
public function setUp()
{
}
/**
* Clean up after running each test case
*/
public function tearDown()
{
}
/**
* Clean up after running all test cases
*/
public static function tearDownAfterClass()
{
}
/**
* Test "OuterEnum"
*/
public function testOuterEnum()
{
}
}

View File

@ -479,4 +479,20 @@ class PetApiTest extends \PHPUnit_Framework_TestCase
$this->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
}
}