Codegen parameter for query json serialization (#21718)

* Add endpoints with query parameters that require Json-serialization

* Add property for query json-serialization

* Update samples

* Adjust indentation for specification
This commit is contained in:
Mattias Sehlstedt
2025-08-10 16:47:51 +02:00
committed by GitHub
parent 6ff9e67bad
commit 8874df4702
75 changed files with 4461 additions and 2 deletions

View File

@@ -105,6 +105,9 @@ class QueryApi
'testQueryStyleFormExplodeTrueObjectAllOf' => [
'application/json',
],
'testQueryStyleJsonSerializationObject' => [
'application/json',
],
];
/**
@@ -2950,6 +2953,301 @@ class QueryApi
$headers = $this->headerSelector->selectHeaders(
['text/plain', ],
$contentType,
$multipart
);
// for model (json/xml)
if (count($formParams) > 0) {
if ($multipart) {
$multipartContents = [];
foreach ($formParams as $formParamName => $formParamValue) {
$formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
foreach ($formParamValueItems as $formParamValueItem) {
$multipartContents[] = [
'name' => $formParamName,
'contents' => $formParamValueItem
];
}
}
// for HTTP post (form)
$httpBody = new MultipartStream($multipartContents);
} elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
# if Content-Type contains "application/json", json_encode the form parameters
$httpBody = \GuzzleHttp\Utils::jsonEncode($formParams);
} else {
// for HTTP post (form)
$httpBody = ObjectSerializer::buildQuery($formParams);
}
}
$defaultHeaders = [];
if ($this->config->getUserAgent()) {
$defaultHeaders['User-Agent'] = $this->config->getUserAgent();
}
$headers = array_merge(
$defaultHeaders,
$headerParams,
$headers
);
$operationHost = $this->config->getHost();
$query = ObjectSerializer::buildQuery($queryParams);
return new Request(
'GET',
$operationHost . $resourcePath . ($query ? "?{$query}" : ''),
$headers,
$httpBody
);
}
/**
* Operation testQueryStyleJsonSerializationObject
*
* Test query parameter(s)
*
* @param \OpenAPI\Client\Model\Pet|null $json_serialized_object_ref_string_query json_serialized_object_ref_string_query (optional)
* @param \OpenAPI\Client\Model\Pet[]|null $json_serialized_object_array_ref_string_query json_serialized_object_array_ref_string_query (optional)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['testQueryStyleJsonSerializationObject'] to see the possible values for this operation
*
* @throws ApiException on non-2xx response or if the response body is not in the expected format
* @throws InvalidArgumentException
* @return string
*/
public function testQueryStyleJsonSerializationObject(
?\OpenAPI\Client\Model\Pet $json_serialized_object_ref_string_query = null,
?array $json_serialized_object_array_ref_string_query = null,
string $contentType = self::contentTypes['testQueryStyleJsonSerializationObject'][0]
): string
{
list($response) = $this->testQueryStyleJsonSerializationObjectWithHttpInfo($json_serialized_object_ref_string_query, $json_serialized_object_array_ref_string_query, $contentType);
return $response;
}
/**
* Operation testQueryStyleJsonSerializationObjectWithHttpInfo
*
* Test query parameter(s)
*
* @param \OpenAPI\Client\Model\Pet|null $json_serialized_object_ref_string_query (optional)
* @param \OpenAPI\Client\Model\Pet[]|null $json_serialized_object_array_ref_string_query (optional)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['testQueryStyleJsonSerializationObject'] to see the possible values for this operation
*
* @throws ApiException on non-2xx response or if the response body is not in the expected format
* @throws InvalidArgumentException
* @return array of string, HTTP status code, HTTP response headers (array of strings)
*/
public function testQueryStyleJsonSerializationObjectWithHttpInfo(
?\OpenAPI\Client\Model\Pet $json_serialized_object_ref_string_query = null,
?array $json_serialized_object_array_ref_string_query = null,
string $contentType = self::contentTypes['testQueryStyleJsonSerializationObject'][0]
): array
{
$request = $this->testQueryStyleJsonSerializationObjectRequest($json_serialized_object_ref_string_query, $json_serialized_object_array_ref_string_query, $contentType);
try {
$options = $this->createHttpClientOption();
try {
$response = $this->client->send($request, $options);
} catch (RequestException $e) {
throw new ApiException(
"[{$e->getCode()}] {$e->getMessage()}",
(int) $e->getCode(),
$e->getResponse() ? $e->getResponse()->getHeaders() : null,
$e->getResponse() ? (string) $e->getResponse()->getBody() : null
);
} catch (ConnectException $e) {
throw new ApiException(
"[{$e->getCode()}] {$e->getMessage()}",
(int) $e->getCode(),
null,
null
);
}
$statusCode = $response->getStatusCode();
switch($statusCode) {
case 200:
return $this->handleResponseWithDataType(
'string',
$request,
$response,
);
}
if ($statusCode < 200 || $statusCode > 299) {
throw new ApiException(
sprintf(
'[%d] Error connecting to the API (%s)',
$statusCode,
(string) $request->getUri()
),
$statusCode,
$response->getHeaders(),
(string) $response->getBody()
);
}
return $this->handleResponseWithDataType(
'string',
$request,
$response,
);
} catch (ApiException $e) {
switch ($e->getCode()) {
case 200:
$data = ObjectSerializer::deserialize(
$e->getResponseBody(),
'string',
$e->getResponseHeaders()
);
$e->setResponseObject($data);
throw $e;
}
throw $e;
}
}
/**
* Operation testQueryStyleJsonSerializationObjectAsync
*
* Test query parameter(s)
*
* @param \OpenAPI\Client\Model\Pet|null $json_serialized_object_ref_string_query (optional)
* @param \OpenAPI\Client\Model\Pet[]|null $json_serialized_object_array_ref_string_query (optional)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['testQueryStyleJsonSerializationObject'] to see the possible values for this operation
*
* @throws InvalidArgumentException
* @return PromiseInterface
*/
public function testQueryStyleJsonSerializationObjectAsync(
?\OpenAPI\Client\Model\Pet $json_serialized_object_ref_string_query = null,
?array $json_serialized_object_array_ref_string_query = null,
string $contentType = self::contentTypes['testQueryStyleJsonSerializationObject'][0]
): PromiseInterface
{
return $this->testQueryStyleJsonSerializationObjectAsyncWithHttpInfo($json_serialized_object_ref_string_query, $json_serialized_object_array_ref_string_query, $contentType)
->then(
function ($response) {
return $response[0];
}
);
}
/**
* Operation testQueryStyleJsonSerializationObjectAsyncWithHttpInfo
*
* Test query parameter(s)
*
* @param \OpenAPI\Client\Model\Pet|null $json_serialized_object_ref_string_query (optional)
* @param \OpenAPI\Client\Model\Pet[]|null $json_serialized_object_array_ref_string_query (optional)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['testQueryStyleJsonSerializationObject'] to see the possible values for this operation
*
* @throws InvalidArgumentException
* @return PromiseInterface
*/
public function testQueryStyleJsonSerializationObjectAsyncWithHttpInfo(
?\OpenAPI\Client\Model\Pet $json_serialized_object_ref_string_query = null,
?array $json_serialized_object_array_ref_string_query = null,
string $contentType = self::contentTypes['testQueryStyleJsonSerializationObject'][0]
): PromiseInterface
{
$returnType = 'string';
$request = $this->testQueryStyleJsonSerializationObjectRequest($json_serialized_object_ref_string_query, $json_serialized_object_array_ref_string_query, $contentType);
return $this->client
->sendAsync($request, $this->createHttpClientOption())
->then(
function ($response) use ($returnType) {
if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) {
$content = $response->getBody(); //stream goes to serializer
} else {
$content = (string) $response->getBody();
if ($returnType !== 'string') {
$content = json_decode($content);
}
}
return [
ObjectSerializer::deserialize($content, $returnType, []),
$response->getStatusCode(),
$response->getHeaders()
];
},
function ($exception) {
$response = $exception->getResponse();
$statusCode = $response->getStatusCode();
throw new ApiException(
sprintf(
'[%d] Error connecting to the API (%s)',
$statusCode,
$exception->getRequest()->getUri()
),
$statusCode,
$response->getHeaders(),
(string) $response->getBody()
);
}
);
}
/**
* Create request for operation 'testQueryStyleJsonSerializationObject'
*
* @param \OpenAPI\Client\Model\Pet|null $json_serialized_object_ref_string_query (optional)
* @param \OpenAPI\Client\Model\Pet[]|null $json_serialized_object_array_ref_string_query (optional)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['testQueryStyleJsonSerializationObject'] to see the possible values for this operation
*
* @throws InvalidArgumentException
* @return \GuzzleHttp\Psr7\Request
*/
public function testQueryStyleJsonSerializationObjectRequest(
?\OpenAPI\Client\Model\Pet $json_serialized_object_ref_string_query = null,
?array $json_serialized_object_array_ref_string_query = null,
string $contentType = self::contentTypes['testQueryStyleJsonSerializationObject'][0]
): Request
{
$resourcePath = '/query/style_jsonSerialization/object';
$formParams = [];
$queryParams = [];
$headerParams = [];
$httpBody = '';
$multipart = false;
// query params
$queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
$json_serialized_object_ref_string_query,
'json_serialized_object_ref_string_query', // param base name
'', // openApiType
'', // style
false, // explode
false // required
) ?? []);
// query params
$queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
$json_serialized_object_array_ref_string_query,
'json_serialized_object_array_ref_string_query', // param base name
'', // openApiType
'', // style
false, // explode
false // required
) ?? []);
$headers = $this->headerSelector->selectHeaders(
['text/plain', ],
$contentType,