Use this adapter when generating clients for projects that already use Symfony contracts.
$config->generationTarget = GenerationTarget::Client;
$config->httpClient = HttpClientAdapter::SymfonyHttpClient;
public function __construct(
private readonly HttpClientInterface $httpClient,
private readonly string $baseUrl,
) {
}
$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->getContent(false) and decoded by the
generated decodeJsonResponse() helper, which rejects non-JSON content types
and invalid JSON with an UnexpectedValueException.Pet::fromResponseArray($data)Pet::fromResponseArray($item)symfony/http-client.