php-openapi-generator

Symfony HttpClient Adapter

Use this adapter when generating clients for projects that already use Symfony contracts.

Config

$config->generationTarget = GenerationTarget::Client;
$config->httpClient = HttpClientAdapter::SymfonyHttpClient;
$config->httpClientVersion = '7.0';

Constructor Signature

public function __construct(
    private readonly HttpClientInterface $httpClient,
    private readonly string $baseUrl,
) {
}

Request Style

$response = $this->httpClient->request(
    'GET',
    $this->baseUrl . "/pets/{$petId}",
);

For operations with a request body, the generator sends:

[
    'json' => $body->toArray(),
]

For operations with query parameters, the generator sends:

[
    'query' => $query,
]

Response Mapping

Notes