From 195abcf6b70782d94a6c5f04e4e1f50c3cdcc2bf Mon Sep 17 00:00:00 2001 From: Christian Stoller Date: Fri, 20 Feb 2026 09:33:55 +0100 Subject: [PATCH] [PHP] Always prefer host config over static servers from OpenAPI declaration Currently the host in the config object is ignored if an operation declares its own `servers` in the OpenAPI file, which makes it impossible to override it in the application. Fixes #23016 --- .../main/resources/php/libraries/psr-18/api.mustache | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/php/libraries/psr-18/api.mustache b/modules/openapi-generator/src/main/resources/php/libraries/psr-18/api.mustache index 47a50d446cbf..ed6d555bacca 100644 --- a/modules/openapi-generator/src/main/resources/php/libraries/psr-18/api.mustache +++ b/modules/openapi-generator/src/main/resources/php/libraries/psr-18/api.mustache @@ -704,15 +704,15 @@ use function sprintf; $headers ); - {{^servers.0}} $operationHost = $this->config->getHost(); - {{/servers.0}} {{#servers.0}} - $operationHosts = [{{#servers}}"{{{url}}}"{{^-last}}, {{/-last}}{{/servers}}]; - if ($this->hostIndex < 0 || $this->hostIndex >= sizeof($operationHosts)) { - throw new \InvalidArgumentException("Invalid index {$this->hostIndex} when selecting the host. Must be less than ".sizeof($operationHosts)); + if (!$operationHost) { + $operationHosts = [{{#servers}}"{{{url}}}"{{^-last}}, {{/-last}}{{/servers}}]; + if ($this->hostIndex < 0 || $this->hostIndex >= sizeof($operationHosts)) { + throw new \InvalidArgumentException("Invalid index {$this->hostIndex} when selecting the host. Must be less than ".sizeof($operationHosts)); + } + $operationHost = $operationHosts[$this->hostIndex]; } - $operationHost = $operationHosts[$this->hostIndex]; {{/servers.0}} $uri = $this->createUri($operationHost, $resourcePath, $queryParams);