Add tests for query parameters (array of integer/string) (#17686)

* add tests for query parameters in python client

* update other samples

* update samples
This commit is contained in:
William Cheng
2024-01-24 10:20:18 +08:00
committed by GitHub
parent dccb147055
commit d0187ab359
69 changed files with 7538 additions and 3 deletions

View File

@@ -87,6 +87,12 @@ class QueryApi
'testQueryStyleDeepObjectExplodeTrueObjectAllOf' => [
'application/json',
],
'testQueryStyleFormExplodeFalseArrayInteger' => [
'application/json',
],
'testQueryStyleFormExplodeFalseArrayString' => [
'application/json',
],
'testQueryStyleFormExplodeTrueArrayString' => [
'application/json',
],
@@ -1776,6 +1782,640 @@ 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 testQueryStyleFormExplodeFalseArrayInteger
*
* Test query parameter(s)
*
* @param int[]|null $query_object query_object (optional)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['testQueryStyleFormExplodeFalseArrayInteger'] 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 testQueryStyleFormExplodeFalseArrayInteger(
?array $query_object = null,
string $contentType = self::contentTypes['testQueryStyleFormExplodeFalseArrayInteger'][0]
): string
{
list($response) = $this->testQueryStyleFormExplodeFalseArrayIntegerWithHttpInfo($query_object, $contentType);
return $response;
}
/**
* Operation testQueryStyleFormExplodeFalseArrayIntegerWithHttpInfo
*
* Test query parameter(s)
*
* @param int[]|null $query_object (optional)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['testQueryStyleFormExplodeFalseArrayInteger'] 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 testQueryStyleFormExplodeFalseArrayIntegerWithHttpInfo(
?array $query_object = null,
string $contentType = self::contentTypes['testQueryStyleFormExplodeFalseArrayInteger'][0]
): array
{
$request = $this->testQueryStyleFormExplodeFalseArrayIntegerRequest($query_object, $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();
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()
);
}
switch($statusCode) {
case 200:
if ('string' === '\SplFileObject') {
$content = $response->getBody(); //stream goes to serializer
} else {
$content = (string) $response->getBody();
if ('string' !== 'string') {
try {
$content = json_decode($content, false, 512, JSON_THROW_ON_ERROR);
} catch (\JsonException $exception) {
throw new ApiException(
sprintf(
'Error JSON decoding server response (%s)',
$request->getUri()
),
$statusCode,
$response->getHeaders(),
$content
);
}
}
}
return [
ObjectSerializer::deserialize($content, 'string', []),
$response->getStatusCode(),
$response->getHeaders()
];
}
$returnType = 'string';
if ($returnType === '\SplFileObject') {
$content = $response->getBody(); //stream goes to serializer
} else {
$content = (string) $response->getBody();
if ($returnType !== 'string') {
try {
$content = json_decode($content, false, 512, JSON_THROW_ON_ERROR);
} catch (\JsonException $exception) {
throw new ApiException(
sprintf(
'Error JSON decoding server response (%s)',
$request->getUri()
),
$statusCode,
$response->getHeaders(),
$content
);
}
}
}
return [
ObjectSerializer::deserialize($content, $returnType, []),
$response->getStatusCode(),
$response->getHeaders()
];
} catch (ApiException $e) {
switch ($e->getCode()) {
case 200:
$data = ObjectSerializer::deserialize(
$e->getResponseBody(),
'string',
$e->getResponseHeaders()
);
$e->setResponseObject($data);
break;
}
throw $e;
}
}
/**
* Operation testQueryStyleFormExplodeFalseArrayIntegerAsync
*
* Test query parameter(s)
*
* @param int[]|null $query_object (optional)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['testQueryStyleFormExplodeFalseArrayInteger'] to see the possible values for this operation
*
* @throws InvalidArgumentException
* @return PromiseInterface
*/
public function testQueryStyleFormExplodeFalseArrayIntegerAsync(
?array $query_object = null,
string $contentType = self::contentTypes['testQueryStyleFormExplodeFalseArrayInteger'][0]
): PromiseInterface
{
return $this->testQueryStyleFormExplodeFalseArrayIntegerAsyncWithHttpInfo($query_object, $contentType)
->then(
function ($response) {
return $response[0];
}
);
}
/**
* Operation testQueryStyleFormExplodeFalseArrayIntegerAsyncWithHttpInfo
*
* Test query parameter(s)
*
* @param int[]|null $query_object (optional)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['testQueryStyleFormExplodeFalseArrayInteger'] to see the possible values for this operation
*
* @throws InvalidArgumentException
* @return PromiseInterface
*/
public function testQueryStyleFormExplodeFalseArrayIntegerAsyncWithHttpInfo(
$query_object = null,
string $contentType = self::contentTypes['testQueryStyleFormExplodeFalseArrayInteger'][0]
): PromiseInterface
{
$returnType = 'string';
$request = $this->testQueryStyleFormExplodeFalseArrayIntegerRequest($query_object, $contentType);
return $this->client
->sendAsync($request, $this->createHttpClientOption())
->then(
function ($response) use ($returnType) {
if ($returnType === '\SplFileObject') {
$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 'testQueryStyleFormExplodeFalseArrayInteger'
*
* @param int[]|null $query_object (optional)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['testQueryStyleFormExplodeFalseArrayInteger'] to see the possible values for this operation
*
* @throws InvalidArgumentException
* @return \GuzzleHttp\Psr7\Request
*/
public function testQueryStyleFormExplodeFalseArrayIntegerRequest(
$query_object = null,
string $contentType = self::contentTypes['testQueryStyleFormExplodeFalseArrayInteger'][0]
): Request
{
$resourcePath = '/query/style_form/explode_false/array_integer';
$formParams = [];
$queryParams = [];
$headerParams = [];
$httpBody = '';
$multipart = false;
// query params
$queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
$query_object,
'query_object', // param base name
'array', // openApiType
'form', // style
false, // explode
false // required
) ?? []);
$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 testQueryStyleFormExplodeFalseArrayString
*
* Test query parameter(s)
*
* @param string[]|null $query_object query_object (optional)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['testQueryStyleFormExplodeFalseArrayString'] 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 testQueryStyleFormExplodeFalseArrayString(
?array $query_object = null,
string $contentType = self::contentTypes['testQueryStyleFormExplodeFalseArrayString'][0]
): string
{
list($response) = $this->testQueryStyleFormExplodeFalseArrayStringWithHttpInfo($query_object, $contentType);
return $response;
}
/**
* Operation testQueryStyleFormExplodeFalseArrayStringWithHttpInfo
*
* Test query parameter(s)
*
* @param string[]|null $query_object (optional)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['testQueryStyleFormExplodeFalseArrayString'] 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 testQueryStyleFormExplodeFalseArrayStringWithHttpInfo(
?array $query_object = null,
string $contentType = self::contentTypes['testQueryStyleFormExplodeFalseArrayString'][0]
): array
{
$request = $this->testQueryStyleFormExplodeFalseArrayStringRequest($query_object, $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();
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()
);
}
switch($statusCode) {
case 200:
if ('string' === '\SplFileObject') {
$content = $response->getBody(); //stream goes to serializer
} else {
$content = (string) $response->getBody();
if ('string' !== 'string') {
try {
$content = json_decode($content, false, 512, JSON_THROW_ON_ERROR);
} catch (\JsonException $exception) {
throw new ApiException(
sprintf(
'Error JSON decoding server response (%s)',
$request->getUri()
),
$statusCode,
$response->getHeaders(),
$content
);
}
}
}
return [
ObjectSerializer::deserialize($content, 'string', []),
$response->getStatusCode(),
$response->getHeaders()
];
}
$returnType = 'string';
if ($returnType === '\SplFileObject') {
$content = $response->getBody(); //stream goes to serializer
} else {
$content = (string) $response->getBody();
if ($returnType !== 'string') {
try {
$content = json_decode($content, false, 512, JSON_THROW_ON_ERROR);
} catch (\JsonException $exception) {
throw new ApiException(
sprintf(
'Error JSON decoding server response (%s)',
$request->getUri()
),
$statusCode,
$response->getHeaders(),
$content
);
}
}
}
return [
ObjectSerializer::deserialize($content, $returnType, []),
$response->getStatusCode(),
$response->getHeaders()
];
} catch (ApiException $e) {
switch ($e->getCode()) {
case 200:
$data = ObjectSerializer::deserialize(
$e->getResponseBody(),
'string',
$e->getResponseHeaders()
);
$e->setResponseObject($data);
break;
}
throw $e;
}
}
/**
* Operation testQueryStyleFormExplodeFalseArrayStringAsync
*
* Test query parameter(s)
*
* @param string[]|null $query_object (optional)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['testQueryStyleFormExplodeFalseArrayString'] to see the possible values for this operation
*
* @throws InvalidArgumentException
* @return PromiseInterface
*/
public function testQueryStyleFormExplodeFalseArrayStringAsync(
?array $query_object = null,
string $contentType = self::contentTypes['testQueryStyleFormExplodeFalseArrayString'][0]
): PromiseInterface
{
return $this->testQueryStyleFormExplodeFalseArrayStringAsyncWithHttpInfo($query_object, $contentType)
->then(
function ($response) {
return $response[0];
}
);
}
/**
* Operation testQueryStyleFormExplodeFalseArrayStringAsyncWithHttpInfo
*
* Test query parameter(s)
*
* @param string[]|null $query_object (optional)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['testQueryStyleFormExplodeFalseArrayString'] to see the possible values for this operation
*
* @throws InvalidArgumentException
* @return PromiseInterface
*/
public function testQueryStyleFormExplodeFalseArrayStringAsyncWithHttpInfo(
$query_object = null,
string $contentType = self::contentTypes['testQueryStyleFormExplodeFalseArrayString'][0]
): PromiseInterface
{
$returnType = 'string';
$request = $this->testQueryStyleFormExplodeFalseArrayStringRequest($query_object, $contentType);
return $this->client
->sendAsync($request, $this->createHttpClientOption())
->then(
function ($response) use ($returnType) {
if ($returnType === '\SplFileObject') {
$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 'testQueryStyleFormExplodeFalseArrayString'
*
* @param string[]|null $query_object (optional)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['testQueryStyleFormExplodeFalseArrayString'] to see the possible values for this operation
*
* @throws InvalidArgumentException
* @return \GuzzleHttp\Psr7\Request
*/
public function testQueryStyleFormExplodeFalseArrayStringRequest(
$query_object = null,
string $contentType = self::contentTypes['testQueryStyleFormExplodeFalseArrayString'][0]
): Request
{
$resourcePath = '/query/style_form/explode_false/array_string';
$formParams = [];
$queryParams = [];
$headerParams = [];
$httpBody = '';
$multipart = false;
// query params
$queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
$query_object,
'query_object', // param base name
'array', // openApiType
'form', // style
false, // explode
false // required
) ?? []);
$headers = $this->headerSelector->selectHeaders(
['text/plain', ],
$contentType,