Skip to content

Commit 195abcf

Browse files
committed
[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
1 parent d6c2905 commit 195abcf

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

  • modules/openapi-generator/src/main/resources/php/libraries/psr-18

modules/openapi-generator/src/main/resources/php/libraries/psr-18/api.mustache

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -704,15 +704,15 @@ use function sprintf;
704704
$headers
705705
);
706706

707-
{{^servers.0}}
708707
$operationHost = $this->config->getHost();
709-
{{/servers.0}}
710708
{{#servers.0}}
711-
$operationHosts = [{{#servers}}"{{{url}}}"{{^-last}}, {{/-last}}{{/servers}}];
712-
if ($this->hostIndex < 0 || $this->hostIndex >= sizeof($operationHosts)) {
713-
throw new \InvalidArgumentException("Invalid index {$this->hostIndex} when selecting the host. Must be less than ".sizeof($operationHosts));
709+
if (!$operationHost) {
710+
$operationHosts = [{{#servers}}"{{{url}}}"{{^-last}}, {{/-last}}{{/servers}}];
711+
if ($this->hostIndex < 0 || $this->hostIndex >= sizeof($operationHosts)) {
712+
throw new \InvalidArgumentException("Invalid index {$this->hostIndex} when selecting the host. Must be less than ".sizeof($operationHosts));
713+
}
714+
$operationHost = $operationHosts[$this->hostIndex];
714715
}
715-
$operationHost = $operationHosts[$this->hostIndex];
716716
{{/servers.0}}
717717

718718
$uri = $this->createUri($operationHost, $resourcePath, $queryParams);

0 commit comments

Comments
 (0)