diff --git a/modules/swagger-codegen/src/main/resources/php/ApiClient.mustache b/modules/swagger-codegen/src/main/resources/php/ApiClient.mustache index 8f0f1167151..a83a6ff4c02 100644 --- a/modules/swagger-codegen/src/main/resources/php/ApiClient.mustache +++ b/modules/swagger-codegen/src/main/resources/php/ApiClient.mustache @@ -146,7 +146,7 @@ class ApiClient $postData = json_encode(\{{invokerPackage}}\ObjectSerializer::sanitizeForSerialization($postData)); } - $url = $this->config->getHost() . $resourcePath; + $url = $this->config->getBaseUrl() . $resourcePath; $curl = curl_init(); // set timeout, if needed diff --git a/modules/swagger-codegen/src/main/resources/php/Configuration.mustache b/modules/swagger-codegen/src/main/resources/php/Configuration.mustache index cdbba93a000..b1f211371cb 100644 --- a/modules/swagger-codegen/src/main/resources/php/Configuration.mustache +++ b/modules/swagger-codegen/src/main/resources/php/Configuration.mustache @@ -66,12 +66,26 @@ class Configuration */ protected $password = ''; + /** + * The scheme + * + * @var string + */ + protected $scheme = '{{scheme}}'; + /** * The host * * @var string */ - protected $host = '{{basePath}}'; + protected $host = '{{host}}'; + + /** + * The basePath + * + * @var string + */ + protected $basePath = '{{contextPath}}'; /** * User agent of the HTTP request, set to "PHP-Swagger" by default @@ -230,6 +244,29 @@ class Configuration return $this->password; } + /** + * Sets the Scheme + * + * @param string $scheme Scheme + * + * @return $this + */ + public function setScheme($scheme) + { + $this->scheme = $scheme; + return $this; + } + + /** + * Gets the Scheme + * + * @return string Scheme + */ + public function getScheme() + { + return $this->scheme; + } + /** * Sets the host * @@ -253,6 +290,44 @@ class Configuration return $this->host; } + /** + * Sets the Base Path + * + * @param string $basePath Base Path + * + * @return $this + */ + public function setBasePath($basePath) + { + $this->basePath = $basePath; + return $this; + } + + /** + * Gets the Base Path + * + * @return string Base Path + */ + public function getBasePath() + { + return $this->basePath; + } + + /** + * Gets the Base URL + * + * @return string Base URL + */ + public function getBaseUrl() + { + return sprintf( + '%s://%s/%s', + $this->scheme, + trim($this->host, '/'), + trim($this->basePath, '/') + ); + } + /** * Sets the user agent of the api client * diff --git a/modules/swagger-codegen/src/main/resources/php/api.mustache b/modules/swagger-codegen/src/main/resources/php/api.mustache index 8066b67db3a..d9db75c65b5 100644 --- a/modules/swagger-codegen/src/main/resources/php/api.mustache +++ b/modules/swagger-codegen/src/main/resources/php/api.mustache @@ -482,7 +482,7 @@ use {{invokerPackage}}\ObjectSerializer; $query = \GuzzleHttp\Psr7\build_query($queryParams); return new Request( '{{httpMethod}}', - $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $this->config->getBaseUrl() . $resourcePath . ($query ? "?{$query}" : ''), $headers, $httpBody ); diff --git a/samples/client/petstore-security-test/php/SwaggerClient-php/lib/Api/FakeApi.php b/samples/client/petstore-security-test/php/SwaggerClient-php/lib/Api/FakeApi.php index cd3f4ab623f..4c3529adcd3 100644 --- a/samples/client/petstore-security-test/php/SwaggerClient-php/lib/Api/FakeApi.php +++ b/samples/client/petstore-security-test/php/SwaggerClient-php/lib/Api/FakeApi.php @@ -291,7 +291,7 @@ protected function testCodeInjectEndRnNRRequest($test_code_inject____end____rn_n $query = \GuzzleHttp\Psr7\build_query($queryParams); return new Request( 'PUT', - $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $this->config->getBaseUrl() . $resourcePath . ($query ? "?{$query}" : ''), $headers, $httpBody ); diff --git a/samples/client/petstore-security-test/php/SwaggerClient-php/lib/Configuration.php b/samples/client/petstore-security-test/php/SwaggerClient-php/lib/Configuration.php index 0d34cfd15a4..b0a0a22ddc1 100644 --- a/samples/client/petstore-security-test/php/SwaggerClient-php/lib/Configuration.php +++ b/samples/client/petstore-security-test/php/SwaggerClient-php/lib/Configuration.php @@ -76,12 +76,26 @@ class Configuration */ protected $password = ''; + /** + * The scheme + * + * @var string + */ + protected $scheme = 'https'; + /** * The host * * @var string */ - protected $host = 'https://petstore.swagger.io *_/ ' \" =end -- \\r\\n \\n \\r/v2 *_/ ' \" =end -- \\r\\n \\n \\r'; + protected $host = 'petstore.swagger.io */ ' " =end -- \r\n \n \r'; + + /** + * The basePath + * + * @var string + */ + protected $basePath = '/v2 *_/ ' \" =end -- \\r\\n \\n \\r'; /** * User agent of the HTTP request, set to "PHP-Swagger" by default @@ -240,6 +254,29 @@ public function getPassword() return $this->password; } + /** + * Sets the Scheme + * + * @param string $scheme Scheme + * + * @return $this + */ + public function setScheme($scheme) + { + $this->scheme = $scheme; + return $this; + } + + /** + * Gets the Scheme + * + * @return string Scheme + */ + public function getScheme() + { + return $this->scheme; + } + /** * Sets the host * @@ -263,6 +300,44 @@ public function getHost() return $this->host; } + /** + * Sets the Base Path + * + * @param string $basePath Base Path + * + * @return $this + */ + public function setBasePath($basePath) + { + $this->basePath = $basePath; + return $this; + } + + /** + * Gets the Base Path + * + * @return string Base Path + */ + public function getBasePath() + { + return $this->basePath; + } + + /** + * Gets the Base URL + * + * @return string Base URL + */ + public function getBaseUrl() + { + return sprintf( + '%s://%s/%s', + $this->scheme, + trim($this->host, '/'), + trim($this->basePath, '/') + ); + } + /** * Sets the user agent of the api client * diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Api/AnotherFakeApi.php b/samples/client/petstore/php/SwaggerClient-php/lib/Api/AnotherFakeApi.php index 690831ca09e..876f7d74ae4 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/AnotherFakeApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/AnotherFakeApi.php @@ -333,7 +333,7 @@ protected function testSpecialTagsRequest($body) $query = \GuzzleHttp\Psr7\build_query($queryParams); return new Request( 'PATCH', - $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $this->config->getBaseUrl() . $resourcePath . ($query ? "?{$query}" : ''), $headers, $httpBody ); 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 81e515b3ab4..7705c935599 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/FakeApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/FakeApi.php @@ -323,7 +323,7 @@ protected function fakeOuterBooleanSerializeRequest($body = null) $query = \GuzzleHttp\Psr7\build_query($queryParams); return new Request( 'POST', - $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $this->config->getBaseUrl() . $resourcePath . ($query ? "?{$query}" : ''), $headers, $httpBody ); @@ -570,7 +570,7 @@ protected function fakeOuterCompositeSerializeRequest($body = null) $query = \GuzzleHttp\Psr7\build_query($queryParams); return new Request( 'POST', - $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $this->config->getBaseUrl() . $resourcePath . ($query ? "?{$query}" : ''), $headers, $httpBody ); @@ -817,7 +817,7 @@ protected function fakeOuterNumberSerializeRequest($body = null) $query = \GuzzleHttp\Psr7\build_query($queryParams); return new Request( 'POST', - $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $this->config->getBaseUrl() . $resourcePath . ($query ? "?{$query}" : ''), $headers, $httpBody ); @@ -1064,7 +1064,7 @@ protected function fakeOuterStringSerializeRequest($body = null) $query = \GuzzleHttp\Psr7\build_query($queryParams); return new Request( 'POST', - $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $this->config->getBaseUrl() . $resourcePath . ($query ? "?{$query}" : ''), $headers, $httpBody ); @@ -1321,7 +1321,7 @@ protected function testClientModelRequest($body) $query = \GuzzleHttp\Psr7\build_query($queryParams); return new Request( 'PATCH', - $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $this->config->getBaseUrl() . $resourcePath . ($query ? "?{$query}" : ''), $headers, $httpBody ); @@ -1728,7 +1728,7 @@ protected function testEndpointParametersRequest($number, $double, $pattern_with $query = \GuzzleHttp\Psr7\build_query($queryParams); return new Request( 'POST', - $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $this->config->getBaseUrl() . $resourcePath . ($query ? "?{$query}" : ''), $headers, $httpBody ); @@ -2012,7 +2012,7 @@ protected function testEnumParametersRequest($enum_form_string_array = null, $en $query = \GuzzleHttp\Psr7\build_query($queryParams); return new Request( 'GET', - $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $this->config->getBaseUrl() . $resourcePath . ($query ? "?{$query}" : ''), $headers, $httpBody ); @@ -2232,7 +2232,7 @@ protected function testInlineAdditionalPropertiesRequest($param) $query = \GuzzleHttp\Psr7\build_query($queryParams); return new Request( 'POST', - $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $this->config->getBaseUrl() . $resourcePath . ($query ? "?{$query}" : ''), $headers, $httpBody ); @@ -2468,7 +2468,7 @@ protected function testJsonFormDataRequest($param, $param2) $query = \GuzzleHttp\Psr7\build_query($queryParams); return new Request( 'GET', - $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $this->config->getBaseUrl() . $resourcePath . ($query ? "?{$query}" : ''), $headers, $httpBody ); diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Api/FakeClassnameTags123Api.php b/samples/client/petstore/php/SwaggerClient-php/lib/Api/FakeClassnameTags123Api.php index 8588d48a5e3..0e34e056558 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/FakeClassnameTags123Api.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/FakeClassnameTags123Api.php @@ -338,7 +338,7 @@ protected function testClassnameRequest($body) $query = \GuzzleHttp\Psr7\build_query($queryParams); return new Request( 'PATCH', - $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $this->config->getBaseUrl() . $resourcePath . ($query ? "?{$query}" : ''), $headers, $httpBody ); 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 410d6a42913..30a6ba95af8 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php @@ -300,7 +300,7 @@ protected function addPetRequest($body) $query = \GuzzleHttp\Psr7\build_query($queryParams); return new Request( 'POST', - $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $this->config->getBaseUrl() . $resourcePath . ($query ? "?{$query}" : ''), $headers, $httpBody ); @@ -538,7 +538,7 @@ protected function deletePetRequest($pet_id, $api_key = null) $query = \GuzzleHttp\Psr7\build_query($queryParams); return new Request( 'DELETE', - $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $this->config->getBaseUrl() . $resourcePath . ($query ? "?{$query}" : ''), $headers, $httpBody ); @@ -803,7 +803,7 @@ protected function findPetsByStatusRequest($status) $query = \GuzzleHttp\Psr7\build_query($queryParams); return new Request( 'GET', - $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $this->config->getBaseUrl() . $resourcePath . ($query ? "?{$query}" : ''), $headers, $httpBody ); @@ -1068,7 +1068,7 @@ protected function findPetsByTagsRequest($tags) $query = \GuzzleHttp\Psr7\build_query($queryParams); return new Request( 'GET', - $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $this->config->getBaseUrl() . $resourcePath . ($query ? "?{$query}" : ''), $headers, $httpBody ); @@ -1335,7 +1335,7 @@ protected function getPetByIdRequest($pet_id) $query = \GuzzleHttp\Psr7\build_query($queryParams); return new Request( 'GET', - $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $this->config->getBaseUrl() . $resourcePath . ($query ? "?{$query}" : ''), $headers, $httpBody ); @@ -1559,7 +1559,7 @@ protected function updatePetRequest($body) $query = \GuzzleHttp\Psr7\build_query($queryParams); return new Request( 'PUT', - $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $this->config->getBaseUrl() . $resourcePath . ($query ? "?{$query}" : ''), $headers, $httpBody ); @@ -1806,7 +1806,7 @@ protected function updatePetWithFormRequest($pet_id, $name = null, $status = nul $query = \GuzzleHttp\Psr7\build_query($queryParams); return new Request( 'POST', - $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $this->config->getBaseUrl() . $resourcePath . ($query ? "?{$query}" : ''), $headers, $httpBody ); @@ -2091,7 +2091,7 @@ protected function uploadFileRequest($pet_id, $additional_metadata = null, $file $query = \GuzzleHttp\Psr7\build_query($queryParams); return new Request( 'POST', - $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $this->config->getBaseUrl() . $resourcePath . ($query ? "?{$query}" : ''), $headers, $httpBody ); 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 5df7f9f279b..4f504ce0400 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php @@ -301,7 +301,7 @@ protected function deleteOrderRequest($order_id) $query = \GuzzleHttp\Psr7\build_query($queryParams); return new Request( 'DELETE', - $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $this->config->getBaseUrl() . $resourcePath . ($query ? "?{$query}" : ''), $headers, $httpBody ); @@ -549,7 +549,7 @@ protected function getInventoryRequest() $query = \GuzzleHttp\Psr7\build_query($queryParams); return new Request( 'GET', - $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $this->config->getBaseUrl() . $resourcePath . ($query ? "?{$query}" : ''), $headers, $httpBody ); @@ -818,7 +818,7 @@ protected function getOrderByIdRequest($order_id) $query = \GuzzleHttp\Psr7\build_query($queryParams); return new Request( 'GET', - $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $this->config->getBaseUrl() . $resourcePath . ($query ? "?{$query}" : ''), $headers, $httpBody ); @@ -1075,7 +1075,7 @@ protected function placeOrderRequest($body) $query = \GuzzleHttp\Psr7\build_query($queryParams); return new Request( 'POST', - $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $this->config->getBaseUrl() . $resourcePath . ($query ? "?{$query}" : ''), $headers, $httpBody ); 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 58e0abec8c2..280f2b406ee 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/UserApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/UserApi.php @@ -296,7 +296,7 @@ protected function createUserRequest($body) $query = \GuzzleHttp\Psr7\build_query($queryParams); return new Request( 'POST', - $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $this->config->getBaseUrl() . $resourcePath . ($query ? "?{$query}" : ''), $headers, $httpBody ); @@ -516,7 +516,7 @@ protected function createUsersWithArrayInputRequest($body) $query = \GuzzleHttp\Psr7\build_query($queryParams); return new Request( 'POST', - $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $this->config->getBaseUrl() . $resourcePath . ($query ? "?{$query}" : ''), $headers, $httpBody ); @@ -736,7 +736,7 @@ protected function createUsersWithListInputRequest($body) $query = \GuzzleHttp\Psr7\build_query($queryParams); return new Request( 'POST', - $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $this->config->getBaseUrl() . $resourcePath . ($query ? "?{$query}" : ''), $headers, $httpBody ); @@ -961,7 +961,7 @@ protected function deleteUserRequest($username) $query = \GuzzleHttp\Psr7\build_query($queryParams); return new Request( 'DELETE', - $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $this->config->getBaseUrl() . $resourcePath . ($query ? "?{$query}" : ''), $headers, $httpBody ); @@ -1223,7 +1223,7 @@ protected function getUserByNameRequest($username) $query = \GuzzleHttp\Psr7\build_query($queryParams); return new Request( 'GET', - $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $this->config->getBaseUrl() . $resourcePath . ($query ? "?{$query}" : ''), $headers, $httpBody ); @@ -1496,7 +1496,7 @@ protected function loginUserRequest($username, $password) $query = \GuzzleHttp\Psr7\build_query($queryParams); return new Request( 'GET', - $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $this->config->getBaseUrl() . $resourcePath . ($query ? "?{$query}" : ''), $headers, $httpBody ); @@ -1702,7 +1702,7 @@ protected function logoutUserRequest() $query = \GuzzleHttp\Psr7\build_query($queryParams); return new Request( 'GET', - $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $this->config->getBaseUrl() . $resourcePath . ($query ? "?{$query}" : ''), $headers, $httpBody ); @@ -1941,7 +1941,7 @@ protected function updateUserRequest($username, $body) $query = \GuzzleHttp\Psr7\build_query($queryParams); return new Request( 'PUT', - $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $this->config->getBaseUrl() . $resourcePath . ($query ? "?{$query}" : ''), $headers, $httpBody ); diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Configuration.php b/samples/client/petstore/php/SwaggerClient-php/lib/Configuration.php index 85e7de94902..edb654df131 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Configuration.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Configuration.php @@ -76,12 +76,26 @@ class Configuration */ protected $password = ''; + /** + * The scheme + * + * @var string + */ + protected $scheme = 'http'; + /** * The host * * @var string */ - protected $host = 'http://petstore.swagger.io:80/v2'; + protected $host = 'petstore.swagger.io:80'; + + /** + * The basePath + * + * @var string + */ + protected $basePath = '/v2'; /** * User agent of the HTTP request, set to "PHP-Swagger" by default @@ -240,6 +254,29 @@ public function getPassword() return $this->password; } + /** + * Sets the Scheme + * + * @param string $scheme Scheme + * + * @return $this + */ + public function setScheme($scheme) + { + $this->scheme = $scheme; + return $this; + } + + /** + * Gets the Scheme + * + * @return string Scheme + */ + public function getScheme() + { + return $this->scheme; + } + /** * Sets the host * @@ -263,6 +300,44 @@ public function getHost() return $this->host; } + /** + * Sets the Base Path + * + * @param string $basePath Base Path + * + * @return $this + */ + public function setBasePath($basePath) + { + $this->basePath = $basePath; + return $this; + } + + /** + * Gets the Base Path + * + * @return string Base Path + */ + public function getBasePath() + { + return $this->basePath; + } + + /** + * Gets the Base URL + * + * @return string Base URL + */ + public function getBaseUrl() + { + return sprintf( + '%s://%s/%s', + $this->scheme, + trim($this->host, '/'), + trim($this->basePath, '/') + ); + } + /** * Sets the user agent of the api client * diff --git a/samples/client/petstore/php/SwaggerClient-php/tests/ConfigurationTest.php b/samples/client/petstore/php/SwaggerClient-php/tests/ConfigurationTest.php new file mode 100644 index 00000000000..8613cf65a09 --- /dev/null +++ b/samples/client/petstore/php/SwaggerClient-php/tests/ConfigurationTest.php @@ -0,0 +1,67 @@ +assertSame('http', (new Configuration())->getScheme()); + } + + /** + * @test + */ + public function setScheme() + { + $this->assertSame('ws', (new Configuration())->setScheme('ws')->getScheme()); + } + + /** + * @test + */ + public function getHost() + { + $this->assertSame('petstore.swagger.io:80', (new Configuration())->getHost()); + } + + /** + * @test + */ + public function setHost() + { + $this->assertSame('newpetstore.swagger.io:80', (new Configuration())->setHost('newpetstore.swagger.io:80')->getHost()); + } + + /** + * @test + */ + public function getBasePath() + { + $this->assertSame('/v2', (new Configuration())->getBasePath()); + } + + /** + * @test + */ + public function setBasePath() + { + $this->assertSame('/v3', (new Configuration())->setBasePath('/v3')->getBasePath()); + } + + /** + * @test + */ + public function getBaseUrl() + { + $configuration = new Configuration(); + $this->assertSame('http://petstore.swagger.io:80/v2', $configuration->getBaseUrl()); + + $configuration->setHost('newpetstore.swagger.io:80/') + ->setBasePath('/v3/'); + $this->assertSame('http://newpetstore.swagger.io:80/v3', $configuration->getBaseUrl()); + } +}