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;

Constructor Signature

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

Request Style

$url = rtrim($this->baseUrl, '/') . '/pets/' . rawurlencode((string) $petId);
$response = $this->httpClient->request(
    'GET',
    $url,
);

For operations with a request body, the generator sends:

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

Query parameters are serialized into the URL by the generated buildQueryString() helper according to their OpenAPI style/explode settings.

Header parameters are sent as request headers. Cookie parameters are encoded into the Cookie header. Any non-2xx response throws a RuntimeException containing the operation ID and HTTP status code.

Response Mapping

Notes