Skip to content

[PHP] API classes override default config unnecessarily #4511

@toomuchpete

Description

@toomuchpete
Description

PHP Base API classes call setPath() on the ApiServer by default. Here's a sample generated constructor:

    public function __construct(\SwaggerUserService\ApiClient $apiClient = null)
    {
        if ($apiClient == null) {
            $apiClient = new ApiClient();
            $apiClient->getConfig()->setHost('http://localhost/v1');
        }

        $this->apiClient = $apiClient;
    }

Calling setHost() is unnecessary because ApiClient() constructor configures itself based on the default. A related issue is that the code assumes (and hardcodes) localhost as the host when one isn't provided.

This combination makes wrapping the Swagger-generated client in our host-discovery code unnecessarily complex.

Swagger-codegen version

Unsure what version is being used, not sure where to find that. I installed codegen through Homebrew. Looking at the code in master, though, this appears to be an issue there as well.

Swagger declaration file content or url

https://gist.github.com/toomuchpete/38ad55e570e103954d404c5df73c0e00

Command line used for generation
swagger-codegen generate -l php -i swagger.yaml
Steps to reproduce
Related issues

None found.

Suggest a Fix

Remove this line:

$apiClient->getConfig()->setHost('{{basePath}}');

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions