diff --git a/modules/openapi-generator/src/main/resources/php-nextgen/Configuration.mustache b/modules/openapi-generator/src/main/resources/php-nextgen/Configuration.mustache index adb3e3bedc45..fd56adcf88b5 100644 --- a/modules/openapi-generator/src/main/resources/php-nextgen/Configuration.mustache +++ b/modules/openapi-generator/src/main/resources/php-nextgen/Configuration.mustache @@ -114,6 +114,13 @@ class Configuration */ protected string $tempFolderPath; + /** + * Ignore operation specific hosts + * + * @var bool + */ + protected bool $ignoreOperationHosts = false; + /** * Constructor */ @@ -383,6 +390,29 @@ class Configuration return $this->tempFolderPath; } + /** + * Sets the ignore operation specific hosts flag + * + * @param bool $ignoreOperationHosts Ignore operation specific hosts flag + * + * @return $this + */ + public function setIgnoreOperationHosts(bool $ignoreOperationHosts): static + { + $this->ignoreOperationHosts = $ignoreOperationHosts; + return $this; + } + + /** + * Gets the ignore operation specific hosts flag + * + * @return bool Ignore operation specific hosts flag + */ + public function getIgnoreOperationHosts(): bool + { + return $this->ignoreOperationHosts; + } + /** * Gets the default configuration instance * diff --git a/modules/openapi-generator/src/main/resources/php-nextgen/api.mustache b/modules/openapi-generator/src/main/resources/php-nextgen/api.mustache index 6a1820f58af3..48df1e87b6b6 100644 --- a/modules/openapi-generator/src/main/resources/php-nextgen/api.mustache +++ b/modules/openapi-generator/src/main/resources/php-nextgen/api.mustache @@ -842,17 +842,21 @@ use {{invokerPackage}}\ObjectSerializer; ); {{#servers.0}} - # Preserve the original behavior of server indexing. - if ($hostIndex === null) { - $hostIndex = $this->hostIndex; - } + if ($this->config->getIgnoreOperationHosts()) { + $operationHost = $this->config->getHost(); + } else { + # Preserve the original behavior of server indexing. + if ($hostIndex === null) { + $hostIndex = $this->hostIndex; + } - $hostSettings = $this->getHostSettingsFor{{operationId}}(); + $hostSettings = $this->getHostSettingsFor{{operationId}}(); - if ($hostIndex < 0 || $hostIndex >= count($hostSettings)) { - throw new InvalidArgumentException("Invalid index {$hostIndex} when selecting the host. Must be less than ".count($hostSettings)); + if ($hostIndex < 0 || $hostIndex >= count($hostSettings)) { + throw new InvalidArgumentException("Invalid index {$hostIndex} when selecting the host. Must be less than ".count($hostSettings)); + } + $operationHost = Configuration::getHostString($hostSettings, $hostIndex, $variables); } - $operationHost = Configuration::getHostString($hostSettings, $hostIndex, $variables); {{/servers.0}} {{^servers.0}} $operationHost = $this->config->getHost(); diff --git a/samples/client/echo_api/php-nextgen-streaming/src/Configuration.php b/samples/client/echo_api/php-nextgen-streaming/src/Configuration.php index 64d71ed3ae7b..854da1ad358f 100644 --- a/samples/client/echo_api/php-nextgen-streaming/src/Configuration.php +++ b/samples/client/echo_api/php-nextgen-streaming/src/Configuration.php @@ -123,6 +123,13 @@ class Configuration */ protected string $tempFolderPath; + /** + * Ignore operation specific hosts + * + * @var bool + */ + protected bool $ignoreOperationHosts = false; + /** * Constructor */ @@ -392,6 +399,29 @@ public function getTempFolderPath(): string return $this->tempFolderPath; } + /** + * Sets the ignore operation specific hosts flag + * + * @param bool $ignoreOperationHosts Ignore operation specific hosts flag + * + * @return $this + */ + public function setIgnoreOperationHosts(bool $ignoreOperationHosts): static + { + $this->ignoreOperationHosts = $ignoreOperationHosts; + return $this; + } + + /** + * Gets the ignore operation specific hosts flag + * + * @return bool Ignore operation specific hosts flag + */ + public function getIgnoreOperationHosts(): bool + { + return $this->ignoreOperationHosts; + } + /** * Gets the default configuration instance * diff --git a/samples/client/echo_api/php-nextgen/src/Configuration.php b/samples/client/echo_api/php-nextgen/src/Configuration.php index 64d71ed3ae7b..854da1ad358f 100644 --- a/samples/client/echo_api/php-nextgen/src/Configuration.php +++ b/samples/client/echo_api/php-nextgen/src/Configuration.php @@ -123,6 +123,13 @@ class Configuration */ protected string $tempFolderPath; + /** + * Ignore operation specific hosts + * + * @var bool + */ + protected bool $ignoreOperationHosts = false; + /** * Constructor */ @@ -392,6 +399,29 @@ public function getTempFolderPath(): string return $this->tempFolderPath; } + /** + * Sets the ignore operation specific hosts flag + * + * @param bool $ignoreOperationHosts Ignore operation specific hosts flag + * + * @return $this + */ + public function setIgnoreOperationHosts(bool $ignoreOperationHosts): static + { + $this->ignoreOperationHosts = $ignoreOperationHosts; + return $this; + } + + /** + * Gets the ignore operation specific hosts flag + * + * @return bool Ignore operation specific hosts flag + */ + public function getIgnoreOperationHosts(): bool + { + return $this->ignoreOperationHosts; + } + /** * Gets the default configuration instance * diff --git a/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/PetApi.php b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/PetApi.php index 6353cf553363..33136f27f8da 100644 --- a/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/PetApi.php +++ b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/PetApi.php @@ -477,17 +477,21 @@ public function addPetRequest( $headers ); - # Preserve the original behavior of server indexing. - if ($hostIndex === null) { - $hostIndex = $this->hostIndex; - } + if ($this->config->getIgnoreOperationHosts()) { + $operationHost = $this->config->getHost(); + } else { + # Preserve the original behavior of server indexing. + if ($hostIndex === null) { + $hostIndex = $this->hostIndex; + } - $hostSettings = $this->getHostSettingsForaddPet(); + $hostSettings = $this->getHostSettingsForaddPet(); - if ($hostIndex < 0 || $hostIndex >= count($hostSettings)) { - throw new InvalidArgumentException("Invalid index {$hostIndex} when selecting the host. Must be less than ".count($hostSettings)); + if ($hostIndex < 0 || $hostIndex >= count($hostSettings)) { + throw new InvalidArgumentException("Invalid index {$hostIndex} when selecting the host. Must be less than ".count($hostSettings)); + } + $operationHost = Configuration::getHostString($hostSettings, $hostIndex, $variables); } - $operationHost = Configuration::getHostString($hostSettings, $hostIndex, $variables); $query = ObjectSerializer::buildQuery($queryParams); return new Request( 'POST', @@ -1870,17 +1874,21 @@ public function updatePetRequest( $headers ); - # Preserve the original behavior of server indexing. - if ($hostIndex === null) { - $hostIndex = $this->hostIndex; - } + if ($this->config->getIgnoreOperationHosts()) { + $operationHost = $this->config->getHost(); + } else { + # Preserve the original behavior of server indexing. + if ($hostIndex === null) { + $hostIndex = $this->hostIndex; + } - $hostSettings = $this->getHostSettingsForupdatePet(); + $hostSettings = $this->getHostSettingsForupdatePet(); - if ($hostIndex < 0 || $hostIndex >= count($hostSettings)) { - throw new InvalidArgumentException("Invalid index {$hostIndex} when selecting the host. Must be less than ".count($hostSettings)); + if ($hostIndex < 0 || $hostIndex >= count($hostSettings)) { + throw new InvalidArgumentException("Invalid index {$hostIndex} when selecting the host. Must be less than ".count($hostSettings)); + } + $operationHost = Configuration::getHostString($hostSettings, $hostIndex, $variables); } - $operationHost = Configuration::getHostString($hostSettings, $hostIndex, $variables); $query = ObjectSerializer::buildQuery($queryParams); return new Request( 'PUT', diff --git a/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Configuration.php b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Configuration.php index c37920097072..ea9c2fcbc88d 100644 --- a/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Configuration.php +++ b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Configuration.php @@ -122,6 +122,13 @@ class Configuration */ protected string $tempFolderPath; + /** + * Ignore operation specific hosts + * + * @var bool + */ + protected bool $ignoreOperationHosts = false; + /** * Constructor */ @@ -391,6 +398,29 @@ public function getTempFolderPath(): string return $this->tempFolderPath; } + /** + * Sets the ignore operation specific hosts flag + * + * @param bool $ignoreOperationHosts Ignore operation specific hosts flag + * + * @return $this + */ + public function setIgnoreOperationHosts(bool $ignoreOperationHosts): static + { + $this->ignoreOperationHosts = $ignoreOperationHosts; + return $this; + } + + /** + * Gets the ignore operation specific hosts flag + * + * @return bool Ignore operation specific hosts flag + */ + public function getIgnoreOperationHosts(): bool + { + return $this->ignoreOperationHosts; + } + /** * Gets the default configuration instance *