Add test cases to cover different collection formats (#3640)

* add test cases to cover different collection format

* add space params to retrofit 1.x

* add space params to retrofit 2.x

* rename url to localVarUrl

* fix exception in haskell servant
This commit is contained in:
William Cheng
2019-08-15 11:09:12 +08:00
committed by GitHub
parent 286cdfdfa2
commit c3535cf9ca
185 changed files with 8369 additions and 190 deletions

View File

@@ -3551,6 +3551,297 @@ class FakeApi
);
}
/**
* Operation testQueryParameterCollectionFormat
*
* @param string[] $pipe pipe (required)
* @param string[] $ioutil ioutil (required)
* @param string[] $http http (required)
* @param string[] $url url (required)
* @param string[] $context context (required)
*
* @throws \OpenAPI\Client\ApiException on non-2xx response
* @throws \InvalidArgumentException
* @return void
*/
public function testQueryParameterCollectionFormat($pipe, $ioutil, $http, $url, $context)
{
$this->testQueryParameterCollectionFormatWithHttpInfo($pipe, $ioutil, $http, $url, $context);
}
/**
* Operation testQueryParameterCollectionFormatWithHttpInfo
*
* @param string[] $pipe (required)
* @param string[] $ioutil (required)
* @param string[] $http (required)
* @param string[] $url (required)
* @param string[] $context (required)
*
* @throws \OpenAPI\Client\ApiException on non-2xx response
* @throws \InvalidArgumentException
* @return array of null, HTTP status code, HTTP response headers (array of strings)
*/
public function testQueryParameterCollectionFormatWithHttpInfo($pipe, $ioutil, $http, $url, $context)
{
$request = $this->testQueryParameterCollectionFormatRequest($pipe, $ioutil, $http, $url, $context);
try {
$options = $this->createHttpClientOption();
try {
$response = $this->client->send($request, $options);
} catch (RequestException $e) {
throw new ApiException(
"[{$e->getCode()}] {$e->getMessage()}",
$e->getCode(),
$e->getResponse() ? $e->getResponse()->getHeaders() : null,
$e->getResponse() ? $e->getResponse()->getBody()->getContents() : null
);
}
$statusCode = $response->getStatusCode();
if ($statusCode < 200 || $statusCode > 299) {
throw new ApiException(
sprintf(
'[%d] Error connecting to the API (%s)',
$statusCode,
$request->getUri()
),
$statusCode,
$response->getHeaders(),
$response->getBody()
);
}
return [null, $statusCode, $response->getHeaders()];
} catch (ApiException $e) {
switch ($e->getCode()) {
}
throw $e;
}
}
/**
* Operation testQueryParameterCollectionFormatAsync
*
*
*
* @param string[] $pipe (required)
* @param string[] $ioutil (required)
* @param string[] $http (required)
* @param string[] $url (required)
* @param string[] $context (required)
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Promise\PromiseInterface
*/
public function testQueryParameterCollectionFormatAsync($pipe, $ioutil, $http, $url, $context)
{
return $this->testQueryParameterCollectionFormatAsyncWithHttpInfo($pipe, $ioutil, $http, $url, $context)
->then(
function ($response) {
return $response[0];
}
);
}
/**
* Operation testQueryParameterCollectionFormatAsyncWithHttpInfo
*
*
*
* @param string[] $pipe (required)
* @param string[] $ioutil (required)
* @param string[] $http (required)
* @param string[] $url (required)
* @param string[] $context (required)
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Promise\PromiseInterface
*/
public function testQueryParameterCollectionFormatAsyncWithHttpInfo($pipe, $ioutil, $http, $url, $context)
{
$returnType = '';
$request = $this->testQueryParameterCollectionFormatRequest($pipe, $ioutil, $http, $url, $context);
return $this->client
->sendAsync($request, $this->createHttpClientOption())
->then(
function ($response) use ($returnType) {
return [null, $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(),
$response->getBody()
);
}
);
}
/**
* Create request for operation 'testQueryParameterCollectionFormat'
*
* @param string[] $pipe (required)
* @param string[] $ioutil (required)
* @param string[] $http (required)
* @param string[] $url (required)
* @param string[] $context (required)
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Psr7\Request
*/
protected function testQueryParameterCollectionFormatRequest($pipe, $ioutil, $http, $url, $context)
{
// verify the required parameter 'pipe' is set
if ($pipe === null || (is_array($pipe) && count($pipe) === 0)) {
throw new \InvalidArgumentException(
'Missing the required parameter $pipe when calling testQueryParameterCollectionFormat'
);
}
// verify the required parameter 'ioutil' is set
if ($ioutil === null || (is_array($ioutil) && count($ioutil) === 0)) {
throw new \InvalidArgumentException(
'Missing the required parameter $ioutil when calling testQueryParameterCollectionFormat'
);
}
// verify the required parameter 'http' is set
if ($http === null || (is_array($http) && count($http) === 0)) {
throw new \InvalidArgumentException(
'Missing the required parameter $http when calling testQueryParameterCollectionFormat'
);
}
// verify the required parameter 'url' is set
if ($url === null || (is_array($url) && count($url) === 0)) {
throw new \InvalidArgumentException(
'Missing the required parameter $url when calling testQueryParameterCollectionFormat'
);
}
// verify the required parameter 'context' is set
if ($context === null || (is_array($context) && count($context) === 0)) {
throw new \InvalidArgumentException(
'Missing the required parameter $context when calling testQueryParameterCollectionFormat'
);
}
$resourcePath = '/fake/test-query-paramters';
$formParams = [];
$queryParams = [];
$headerParams = [];
$httpBody = '';
$multipart = false;
// query params
if (is_array($pipe)) {
$pipe = ObjectSerializer::serializeCollection($pipe, 'multi', true);
}
if ($pipe !== null) {
$queryParams['pipe'] = ObjectSerializer::toQueryValue($pipe);
}
// query params
if (is_array($ioutil)) {
$ioutil = ObjectSerializer::serializeCollection($ioutil, 'csv', true);
}
if ($ioutil !== null) {
$queryParams['ioutil'] = ObjectSerializer::toQueryValue($ioutil);
}
// query params
if (is_array($http)) {
$http = ObjectSerializer::serializeCollection($http, 'space', true);
}
if ($http !== null) {
$queryParams['http'] = ObjectSerializer::toQueryValue($http);
}
// query params
if (is_array($url)) {
$url = ObjectSerializer::serializeCollection($url, 'csv', true);
}
if ($url !== null) {
$queryParams['url'] = ObjectSerializer::toQueryValue($url);
}
// query params
if (is_array($context)) {
$context = ObjectSerializer::serializeCollection($context, 'multi', true);
}
if ($context !== null) {
$queryParams['context'] = ObjectSerializer::toQueryValue($context);
}
// body params
$_tempBody = null;
if ($multipart) {
$headers = $this->headerSelector->selectHeadersForMultipart(
[]
);
} else {
$headers = $this->headerSelector->selectHeaders(
[],
[]
);
}
// for model (json/xml)
if (isset($_tempBody)) {
// $_tempBody is the method argument, if present
if ($headers['Content-Type'] === 'application/json') {
$httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody));
} else {
$httpBody = $_tempBody;
}
} elseif (count($formParams) > 0) {
if ($multipart) {
$multipartContents = [];
foreach ($formParams as $formParamName => $formParamValue) {
$multipartContents[] = [
'name' => $formParamName,
'contents' => $formParamValue
];
}
// for HTTP post (form)
$httpBody = new MultipartStream($multipartContents);
} elseif ($headers['Content-Type'] === 'application/json') {
$httpBody = \GuzzleHttp\json_encode($formParams);
} else {
// for HTTP post (form)
$httpBody = \GuzzleHttp\Psr7\build_query($formParams);
}
}
$defaultHeaders = [];
if ($this->config->getUserAgent()) {
$defaultHeaders['User-Agent'] = $this->config->getUserAgent();
}
$headers = array_merge(
$defaultHeaders,
$headerParams,
$headers
);
$query = \GuzzleHttp\Psr7\build_query($queryParams);
return new Request(
'PUT',
$this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
$headers,
$httpBody
);
}
/**
* Create http client option
*