-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Open
Labels
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
I am currently facing the issue, that the host that I set in the configuration object, which is passed to the api object, is never used. Instead the server address from the OpenAPI declaration file is used.
Here is a minimal example of the operation:
paths:
'/users/':
get:
responses:
'200':
description: User Found
content:
application/json:
schema:
$ref: '#/components/schemas/User'
servers: # <- this is responsible for the issue
- url: 'http://localhost:3000'In the generated getUsersRequest method of the api class this results in the following code
$operationHosts = ["http://localhost:3000"];
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];Imho this is a bug. It should always be possible to override the value of the specification file per config object.
If the servers value of an operation is missing, the getUsersRequest method would get the host like this:
$operationHost = $this->config->getHost();openapi-generator version
v7.19.0
Suggest a fix
The relevant lines in the mustache template are those:
{{^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));
}
$operationHost = $operationHosts[$this->hostIndex];
{{/servers.0}}Reactions are currently unavailable