2023-09-23 15:28:43 +08:00

2195 lines
78 KiB
PHP

<?php
/**
* BodyApi
* PHP version 8.1
*
* @category Class
* @package OpenAPI\Client
* @author OpenAPI Generator team
* @link https://openapi-generator.tech
*/
/**
* Echo Server API
*
* Echo Server API
*
* The version of the OpenAPI document: 0.1.0
* Contact: team@openapitools.org
* @generated Generated by: https://openapi-generator.tech
* OpenAPI Generator version: 7.1.0-SNAPSHOT
*/
/**
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
namespace OpenAPI\Client\Api;
use InvalidArgumentException;
use GuzzleHttp\Client;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\ConnectException;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Psr7\MultipartStream;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\RequestOptions;
use GuzzleHttp\Promise\PromiseInterface;
use OpenAPI\Client\ApiException;
use OpenAPI\Client\Configuration;
use OpenAPI\Client\HeaderSelector;
use OpenAPI\Client\ObjectSerializer;
/**
* BodyApi Class Doc Comment
*
* @category Class
* @package OpenAPI\Client
* @author OpenAPI Generator team
* @link https://openapi-generator.tech
*/
class BodyApi
{
/**
* @var ClientInterface
*/
protected ClientInterface $client;
/**
* @var Configuration
*/
protected Configuration $config;
/**
* @var HeaderSelector
*/
protected HeaderSelector $headerSelector;
/**
* @var int Host index
*/
protected int $hostIndex;
/** @var string[] $contentTypes **/
public const contentTypes = [
'testBinaryGif' => [
'application/json',
],
'testBodyApplicationOctetstreamBinary' => [
'application/octet-stream',
],
'testBodyMultipartFormdataArrayOfBinary' => [
'multipart/form-data',
],
'testEchoBodyFreeFormObjectResponseString' => [
'application/json',
],
'testEchoBodyPet' => [
'application/json',
],
'testEchoBodyPetResponseString' => [
'application/json',
],
'testEchoBodyTagResponseString' => [
'application/json',
],
];
/**
* @param ClientInterface|null $client
* @param Configuration|null $config
* @param HeaderSelector|null $selector
* @param int $hostIndex (Optional) host index to select the list of hosts if defined in the OpenAPI spec
*/
public function __construct(
ClientInterface $client = null,
Configuration $config = null,
HeaderSelector $selector = null,
int $hostIndex = 0
) {
$this->client = $client ?: new Client();
$this->config = $config ?: new Configuration();
$this->headerSelector = $selector ?: new HeaderSelector();
$this->hostIndex = $hostIndex;
}
/**
* Set the host index
*
* @param int $hostIndex Host index (required)
*/
public function setHostIndex(int $hostIndex): void
{
$this->hostIndex = $hostIndex;
}
/**
* Get the host index
*
* @return int Host index
*/
public function getHostIndex(): int
{
return $this->hostIndex;
}
/**
* @return Configuration
*/
public function getConfig(): Configuration
{
return $this->config;
}
/**
* Operation testBinaryGif
*
* Test binary (gif) response body
*
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['testBinaryGif'] to see the possible values for this operation
*
* @throws ApiException on non-2xx response
* @throws InvalidArgumentException
* @return \SplFileObject
*/
public function testBinaryGif(
string $contentType = self::contentTypes['testBinaryGif'][0]
): \SplFileObject
{
list($response) = $this->testBinaryGifWithHttpInfo($contentType);
return $response;
}
/**
* Operation testBinaryGifWithHttpInfo
*
* Test binary (gif) response body
*
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['testBinaryGif'] to see the possible values for this operation
*
* @throws ApiException on non-2xx response
* @throws InvalidArgumentException
* @return array of \SplFileObject, HTTP status code, HTTP response headers (array of strings)
*/
public function testBinaryGifWithHttpInfo(
string $contentType = self::contentTypes['testBinaryGif'][0]
): array
{
$request = $this->testBinaryGifRequest($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 ('\SplFileObject' === '\SplFileObject') {
$content = $response->getBody(); //stream goes to serializer
} else {
$content = (string) $response->getBody();
if ('\SplFileObject' !== 'string') {
$content = json_decode($content);
}
}
return [
ObjectSerializer::deserialize($content, '\SplFileObject', []),
$response->getStatusCode(),
$response->getHeaders()
];
}
$returnType = '\SplFileObject';
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()
];
} catch (ApiException $e) {
switch ($e->getCode()) {
case 200:
$data = ObjectSerializer::deserialize(
$e->getResponseBody(),
'\SplFileObject',
$e->getResponseHeaders()
);
$e->setResponseObject($data);
break;
}
throw $e;
}
}
/**
* Operation testBinaryGifAsync
*
* Test binary (gif) response body
*
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['testBinaryGif'] to see the possible values for this operation
*
* @throws InvalidArgumentException
* @return PromiseInterface
*/
public function testBinaryGifAsync(
string $contentType = self::contentTypes['testBinaryGif'][0]
): PromiseInterface
{
return $this->testBinaryGifAsyncWithHttpInfo($contentType)
->then(
function ($response) {
return $response[0];
}
);
}
/**
* Operation testBinaryGifAsyncWithHttpInfo
*
* Test binary (gif) response body
*
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['testBinaryGif'] to see the possible values for this operation
*
* @throws InvalidArgumentException
* @return PromiseInterface
*/
public function testBinaryGifAsyncWithHttpInfo(
string $contentType = self::contentTypes['testBinaryGif'][0]
): PromiseInterface
{
$returnType = '\SplFileObject';
$request = $this->testBinaryGifRequest($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 'testBinaryGif'
*
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['testBinaryGif'] to see the possible values for this operation
*
* @throws InvalidArgumentException
* @return \GuzzleHttp\Psr7\Request
*/
public function testBinaryGifRequest(
string $contentType = self::contentTypes['testBinaryGif'][0]
): Request
{
$resourcePath = '/binary/gif';
$formParams = [];
$queryParams = [];
$headerParams = [];
$httpBody = '';
$multipart = false;
$headers = $this->headerSelector->selectHeaders(
['image/gif', ],
$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(
'POST',
$operationHost . $resourcePath . ($query ? "?{$query}" : ''),
$headers,
$httpBody
);
}
/**
* Operation testBodyApplicationOctetstreamBinary
*
* Test body parameter(s)
*
* @param \SplFileObject|null $body body (optional)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['testBodyApplicationOctetstreamBinary'] to see the possible values for this operation
*
* @throws ApiException on non-2xx response
* @throws InvalidArgumentException
* @return string
*/
public function testBodyApplicationOctetstreamBinary(
?\SplFileObject $body = null,
string $contentType = self::contentTypes['testBodyApplicationOctetstreamBinary'][0]
): string
{
list($response) = $this->testBodyApplicationOctetstreamBinaryWithHttpInfo($body, $contentType);
return $response;
}
/**
* Operation testBodyApplicationOctetstreamBinaryWithHttpInfo
*
* Test body parameter(s)
*
* @param \SplFileObject|null $body (optional)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['testBodyApplicationOctetstreamBinary'] to see the possible values for this operation
*
* @throws ApiException on non-2xx response
* @throws InvalidArgumentException
* @return array of string, HTTP status code, HTTP response headers (array of strings)
*/
public function testBodyApplicationOctetstreamBinaryWithHttpInfo(
?\SplFileObject $body = null,
string $contentType = self::contentTypes['testBodyApplicationOctetstreamBinary'][0]
): array
{
$request = $this->testBodyApplicationOctetstreamBinaryRequest($body, $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') {
$content = json_decode($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') {
$content = json_decode($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 testBodyApplicationOctetstreamBinaryAsync
*
* Test body parameter(s)
*
* @param \SplFileObject|null $body (optional)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['testBodyApplicationOctetstreamBinary'] to see the possible values for this operation
*
* @throws InvalidArgumentException
* @return PromiseInterface
*/
public function testBodyApplicationOctetstreamBinaryAsync(
?\SplFileObject $body = null,
string $contentType = self::contentTypes['testBodyApplicationOctetstreamBinary'][0]
): PromiseInterface
{
return $this->testBodyApplicationOctetstreamBinaryAsyncWithHttpInfo($body, $contentType)
->then(
function ($response) {
return $response[0];
}
);
}
/**
* Operation testBodyApplicationOctetstreamBinaryAsyncWithHttpInfo
*
* Test body parameter(s)
*
* @param \SplFileObject|null $body (optional)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['testBodyApplicationOctetstreamBinary'] to see the possible values for this operation
*
* @throws InvalidArgumentException
* @return PromiseInterface
*/
public function testBodyApplicationOctetstreamBinaryAsyncWithHttpInfo(
$body = null,
string $contentType = self::contentTypes['testBodyApplicationOctetstreamBinary'][0]
): PromiseInterface
{
$returnType = 'string';
$request = $this->testBodyApplicationOctetstreamBinaryRequest($body, $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 'testBodyApplicationOctetstreamBinary'
*
* @param \SplFileObject|null $body (optional)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['testBodyApplicationOctetstreamBinary'] to see the possible values for this operation
*
* @throws InvalidArgumentException
* @return \GuzzleHttp\Psr7\Request
*/
public function testBodyApplicationOctetstreamBinaryRequest(
$body = null,
string $contentType = self::contentTypes['testBodyApplicationOctetstreamBinary'][0]
): Request
{
$resourcePath = '/body/application/octetstream/binary';
$formParams = [];
$queryParams = [];
$headerParams = [];
$httpBody = '';
$multipart = false;
$headers = $this->headerSelector->selectHeaders(
['text/plain', ],
$contentType,
$multipart
);
// for model (json/xml)
if (isset($body)) {
if (stripos($headers['Content-Type'], 'application/json') !== false) {
# if Content-Type contains "application/json", json_encode the body
$httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($body));
} else {
$httpBody = $body;
}
} elseif (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(
'POST',
$operationHost . $resourcePath . ($query ? "?{$query}" : ''),
$headers,
$httpBody
);
}
/**
* Operation testBodyMultipartFormdataArrayOfBinary
*
* Test array of binary in multipart mime
*
* @param \SplFileObject[] $files files (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['testBodyMultipartFormdataArrayOfBinary'] to see the possible values for this operation
*
* @throws ApiException on non-2xx response
* @throws InvalidArgumentException
* @return string
*/
public function testBodyMultipartFormdataArrayOfBinary(
array $files,
string $contentType = self::contentTypes['testBodyMultipartFormdataArrayOfBinary'][0]
): string
{
list($response) = $this->testBodyMultipartFormdataArrayOfBinaryWithHttpInfo($files, $contentType);
return $response;
}
/**
* Operation testBodyMultipartFormdataArrayOfBinaryWithHttpInfo
*
* Test array of binary in multipart mime
*
* @param \SplFileObject[] $files (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['testBodyMultipartFormdataArrayOfBinary'] to see the possible values for this operation
*
* @throws ApiException on non-2xx response
* @throws InvalidArgumentException
* @return array of string, HTTP status code, HTTP response headers (array of strings)
*/
public function testBodyMultipartFormdataArrayOfBinaryWithHttpInfo(
array $files,
string $contentType = self::contentTypes['testBodyMultipartFormdataArrayOfBinary'][0]
): array
{
$request = $this->testBodyMultipartFormdataArrayOfBinaryRequest($files, $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') {
$content = json_decode($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') {
$content = json_decode($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 testBodyMultipartFormdataArrayOfBinaryAsync
*
* Test array of binary in multipart mime
*
* @param \SplFileObject[] $files (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['testBodyMultipartFormdataArrayOfBinary'] to see the possible values for this operation
*
* @throws InvalidArgumentException
* @return PromiseInterface
*/
public function testBodyMultipartFormdataArrayOfBinaryAsync(
array $files,
string $contentType = self::contentTypes['testBodyMultipartFormdataArrayOfBinary'][0]
): PromiseInterface
{
return $this->testBodyMultipartFormdataArrayOfBinaryAsyncWithHttpInfo($files, $contentType)
->then(
function ($response) {
return $response[0];
}
);
}
/**
* Operation testBodyMultipartFormdataArrayOfBinaryAsyncWithHttpInfo
*
* Test array of binary in multipart mime
*
* @param \SplFileObject[] $files (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['testBodyMultipartFormdataArrayOfBinary'] to see the possible values for this operation
*
* @throws InvalidArgumentException
* @return PromiseInterface
*/
public function testBodyMultipartFormdataArrayOfBinaryAsyncWithHttpInfo(
$files,
string $contentType = self::contentTypes['testBodyMultipartFormdataArrayOfBinary'][0]
): PromiseInterface
{
$returnType = 'string';
$request = $this->testBodyMultipartFormdataArrayOfBinaryRequest($files, $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 'testBodyMultipartFormdataArrayOfBinary'
*
* @param \SplFileObject[] $files (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['testBodyMultipartFormdataArrayOfBinary'] to see the possible values for this operation
*
* @throws InvalidArgumentException
* @return \GuzzleHttp\Psr7\Request
*/
public function testBodyMultipartFormdataArrayOfBinaryRequest(
$files,
string $contentType = self::contentTypes['testBodyMultipartFormdataArrayOfBinary'][0]
): Request
{
// verify the required parameter 'files' is set
if ($files === null || (is_array($files) && count($files) === 0)) {
throw new InvalidArgumentException(
'Missing the required parameter $files when calling testBodyMultipartFormdataArrayOfBinary'
);
}
$resourcePath = '/body/application/octetstream/array_of_binary';
$formParams = [];
$queryParams = [];
$headerParams = [];
$httpBody = '';
$multipart = false;
// form params
if ($files !== null) {
$multipart = true;
$formParams['files'] = [];
$paramFiles = is_array($files) ? $files : [$files];
foreach ($paramFiles as $paramFile) {
$formParams['files'][] = \GuzzleHttp\Psr7\Utils::tryFopen(
ObjectSerializer::toFormValue($paramFile),
'rb'
);
}
}
$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(
'POST',
$operationHost . $resourcePath . ($query ? "?{$query}" : ''),
$headers,
$httpBody
);
}
/**
* Operation testEchoBodyFreeFormObjectResponseString
*
* Test free form object
*
* @param object|null $body Free form object (optional)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['testEchoBodyFreeFormObjectResponseString'] to see the possible values for this operation
*
* @throws ApiException on non-2xx response
* @throws InvalidArgumentException
* @return string
*/
public function testEchoBodyFreeFormObjectResponseString(
?array $body = null,
string $contentType = self::contentTypes['testEchoBodyFreeFormObjectResponseString'][0]
): string
{
list($response) = $this->testEchoBodyFreeFormObjectResponseStringWithHttpInfo($body, $contentType);
return $response;
}
/**
* Operation testEchoBodyFreeFormObjectResponseStringWithHttpInfo
*
* Test free form object
*
* @param object|null $body Free form object (optional)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['testEchoBodyFreeFormObjectResponseString'] to see the possible values for this operation
*
* @throws ApiException on non-2xx response
* @throws InvalidArgumentException
* @return array of string, HTTP status code, HTTP response headers (array of strings)
*/
public function testEchoBodyFreeFormObjectResponseStringWithHttpInfo(
?array $body = null,
string $contentType = self::contentTypes['testEchoBodyFreeFormObjectResponseString'][0]
): array
{
$request = $this->testEchoBodyFreeFormObjectResponseStringRequest($body, $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') {
$content = json_decode($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') {
$content = json_decode($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 testEchoBodyFreeFormObjectResponseStringAsync
*
* Test free form object
*
* @param object|null $body Free form object (optional)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['testEchoBodyFreeFormObjectResponseString'] to see the possible values for this operation
*
* @throws InvalidArgumentException
* @return PromiseInterface
*/
public function testEchoBodyFreeFormObjectResponseStringAsync(
?array $body = null,
string $contentType = self::contentTypes['testEchoBodyFreeFormObjectResponseString'][0]
): PromiseInterface
{
return $this->testEchoBodyFreeFormObjectResponseStringAsyncWithHttpInfo($body, $contentType)
->then(
function ($response) {
return $response[0];
}
);
}
/**
* Operation testEchoBodyFreeFormObjectResponseStringAsyncWithHttpInfo
*
* Test free form object
*
* @param object|null $body Free form object (optional)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['testEchoBodyFreeFormObjectResponseString'] to see the possible values for this operation
*
* @throws InvalidArgumentException
* @return PromiseInterface
*/
public function testEchoBodyFreeFormObjectResponseStringAsyncWithHttpInfo(
$body = null,
string $contentType = self::contentTypes['testEchoBodyFreeFormObjectResponseString'][0]
): PromiseInterface
{
$returnType = 'string';
$request = $this->testEchoBodyFreeFormObjectResponseStringRequest($body, $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 'testEchoBodyFreeFormObjectResponseString'
*
* @param object|null $body Free form object (optional)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['testEchoBodyFreeFormObjectResponseString'] to see the possible values for this operation
*
* @throws InvalidArgumentException
* @return \GuzzleHttp\Psr7\Request
*/
public function testEchoBodyFreeFormObjectResponseStringRequest(
$body = null,
string $contentType = self::contentTypes['testEchoBodyFreeFormObjectResponseString'][0]
): Request
{
$resourcePath = '/echo/body/FreeFormObject/response_string';
$formParams = [];
$queryParams = [];
$headerParams = [];
$httpBody = '';
$multipart = false;
$headers = $this->headerSelector->selectHeaders(
['text/plain', ],
$contentType,
$multipart
);
// for model (json/xml)
if (isset($body)) {
if (stripos($headers['Content-Type'], 'application/json') !== false) {
# if Content-Type contains "application/json", json_encode the body
$httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($body));
} else {
$httpBody = $body;
}
} elseif (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(
'POST',
$operationHost . $resourcePath . ($query ? "?{$query}" : ''),
$headers,
$httpBody
);
}
/**
* Operation testEchoBodyPet
*
* Test body parameter(s)
*
* @param \OpenAPI\Client\Model\Pet|null $pet Pet object that needs to be added to the store (optional)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['testEchoBodyPet'] to see the possible values for this operation
*
* @throws ApiException on non-2xx response
* @throws InvalidArgumentException
* @return \OpenAPI\Client\Model\Pet
*/
public function testEchoBodyPet(
?\OpenAPI\Client\Model\Pet $pet = null,
string $contentType = self::contentTypes['testEchoBodyPet'][0]
): \OpenAPI\Client\Model\Pet
{
list($response) = $this->testEchoBodyPetWithHttpInfo($pet, $contentType);
return $response;
}
/**
* Operation testEchoBodyPetWithHttpInfo
*
* Test body parameter(s)
*
* @param \OpenAPI\Client\Model\Pet|null $pet Pet object that needs to be added to the store (optional)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['testEchoBodyPet'] to see the possible values for this operation
*
* @throws ApiException on non-2xx response
* @throws InvalidArgumentException
* @return array of \OpenAPI\Client\Model\Pet, HTTP status code, HTTP response headers (array of strings)
*/
public function testEchoBodyPetWithHttpInfo(
?\OpenAPI\Client\Model\Pet $pet = null,
string $contentType = self::contentTypes['testEchoBodyPet'][0]
): array
{
$request = $this->testEchoBodyPetRequest($pet, $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 ('\OpenAPI\Client\Model\Pet' === '\SplFileObject') {
$content = $response->getBody(); //stream goes to serializer
} else {
$content = (string) $response->getBody();
if ('\OpenAPI\Client\Model\Pet' !== 'string') {
$content = json_decode($content);
}
}
return [
ObjectSerializer::deserialize($content, '\OpenAPI\Client\Model\Pet', []),
$response->getStatusCode(),
$response->getHeaders()
];
}
$returnType = '\OpenAPI\Client\Model\Pet';
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()
];
} catch (ApiException $e) {
switch ($e->getCode()) {
case 200:
$data = ObjectSerializer::deserialize(
$e->getResponseBody(),
'\OpenAPI\Client\Model\Pet',
$e->getResponseHeaders()
);
$e->setResponseObject($data);
break;
}
throw $e;
}
}
/**
* Operation testEchoBodyPetAsync
*
* Test body parameter(s)
*
* @param \OpenAPI\Client\Model\Pet|null $pet Pet object that needs to be added to the store (optional)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['testEchoBodyPet'] to see the possible values for this operation
*
* @throws InvalidArgumentException
* @return PromiseInterface
*/
public function testEchoBodyPetAsync(
?\OpenAPI\Client\Model\Pet $pet = null,
string $contentType = self::contentTypes['testEchoBodyPet'][0]
): PromiseInterface
{
return $this->testEchoBodyPetAsyncWithHttpInfo($pet, $contentType)
->then(
function ($response) {
return $response[0];
}
);
}
/**
* Operation testEchoBodyPetAsyncWithHttpInfo
*
* Test body parameter(s)
*
* @param \OpenAPI\Client\Model\Pet|null $pet Pet object that needs to be added to the store (optional)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['testEchoBodyPet'] to see the possible values for this operation
*
* @throws InvalidArgumentException
* @return PromiseInterface
*/
public function testEchoBodyPetAsyncWithHttpInfo(
$pet = null,
string $contentType = self::contentTypes['testEchoBodyPet'][0]
): PromiseInterface
{
$returnType = '\OpenAPI\Client\Model\Pet';
$request = $this->testEchoBodyPetRequest($pet, $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 'testEchoBodyPet'
*
* @param \OpenAPI\Client\Model\Pet|null $pet Pet object that needs to be added to the store (optional)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['testEchoBodyPet'] to see the possible values for this operation
*
* @throws InvalidArgumentException
* @return \GuzzleHttp\Psr7\Request
*/
public function testEchoBodyPetRequest(
$pet = null,
string $contentType = self::contentTypes['testEchoBodyPet'][0]
): Request
{
$resourcePath = '/echo/body/Pet';
$formParams = [];
$queryParams = [];
$headerParams = [];
$httpBody = '';
$multipart = false;
$headers = $this->headerSelector->selectHeaders(
['application/json', ],
$contentType,
$multipart
);
// for model (json/xml)
if (isset($pet)) {
if (stripos($headers['Content-Type'], 'application/json') !== false) {
# if Content-Type contains "application/json", json_encode the body
$httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($pet));
} else {
$httpBody = $pet;
}
} elseif (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(
'POST',
$operationHost . $resourcePath . ($query ? "?{$query}" : ''),
$headers,
$httpBody
);
}
/**
* Operation testEchoBodyPetResponseString
*
* Test empty response body
*
* @param \OpenAPI\Client\Model\Pet|null $pet Pet object that needs to be added to the store (optional)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['testEchoBodyPetResponseString'] to see the possible values for this operation
*
* @throws ApiException on non-2xx response
* @throws InvalidArgumentException
* @return string
*/
public function testEchoBodyPetResponseString(
?\OpenAPI\Client\Model\Pet $pet = null,
string $contentType = self::contentTypes['testEchoBodyPetResponseString'][0]
): string
{
list($response) = $this->testEchoBodyPetResponseStringWithHttpInfo($pet, $contentType);
return $response;
}
/**
* Operation testEchoBodyPetResponseStringWithHttpInfo
*
* Test empty response body
*
* @param \OpenAPI\Client\Model\Pet|null $pet Pet object that needs to be added to the store (optional)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['testEchoBodyPetResponseString'] to see the possible values for this operation
*
* @throws ApiException on non-2xx response
* @throws InvalidArgumentException
* @return array of string, HTTP status code, HTTP response headers (array of strings)
*/
public function testEchoBodyPetResponseStringWithHttpInfo(
?\OpenAPI\Client\Model\Pet $pet = null,
string $contentType = self::contentTypes['testEchoBodyPetResponseString'][0]
): array
{
$request = $this->testEchoBodyPetResponseStringRequest($pet, $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') {
$content = json_decode($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') {
$content = json_decode($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 testEchoBodyPetResponseStringAsync
*
* Test empty response body
*
* @param \OpenAPI\Client\Model\Pet|null $pet Pet object that needs to be added to the store (optional)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['testEchoBodyPetResponseString'] to see the possible values for this operation
*
* @throws InvalidArgumentException
* @return PromiseInterface
*/
public function testEchoBodyPetResponseStringAsync(
?\OpenAPI\Client\Model\Pet $pet = null,
string $contentType = self::contentTypes['testEchoBodyPetResponseString'][0]
): PromiseInterface
{
return $this->testEchoBodyPetResponseStringAsyncWithHttpInfo($pet, $contentType)
->then(
function ($response) {
return $response[0];
}
);
}
/**
* Operation testEchoBodyPetResponseStringAsyncWithHttpInfo
*
* Test empty response body
*
* @param \OpenAPI\Client\Model\Pet|null $pet Pet object that needs to be added to the store (optional)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['testEchoBodyPetResponseString'] to see the possible values for this operation
*
* @throws InvalidArgumentException
* @return PromiseInterface
*/
public function testEchoBodyPetResponseStringAsyncWithHttpInfo(
$pet = null,
string $contentType = self::contentTypes['testEchoBodyPetResponseString'][0]
): PromiseInterface
{
$returnType = 'string';
$request = $this->testEchoBodyPetResponseStringRequest($pet, $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 'testEchoBodyPetResponseString'
*
* @param \OpenAPI\Client\Model\Pet|null $pet Pet object that needs to be added to the store (optional)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['testEchoBodyPetResponseString'] to see the possible values for this operation
*
* @throws InvalidArgumentException
* @return \GuzzleHttp\Psr7\Request
*/
public function testEchoBodyPetResponseStringRequest(
$pet = null,
string $contentType = self::contentTypes['testEchoBodyPetResponseString'][0]
): Request
{
$resourcePath = '/echo/body/Pet/response_string';
$formParams = [];
$queryParams = [];
$headerParams = [];
$httpBody = '';
$multipart = false;
$headers = $this->headerSelector->selectHeaders(
['text/plain', ],
$contentType,
$multipart
);
// for model (json/xml)
if (isset($pet)) {
if (stripos($headers['Content-Type'], 'application/json') !== false) {
# if Content-Type contains "application/json", json_encode the body
$httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($pet));
} else {
$httpBody = $pet;
}
} elseif (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(
'POST',
$operationHost . $resourcePath . ($query ? "?{$query}" : ''),
$headers,
$httpBody
);
}
/**
* Operation testEchoBodyTagResponseString
*
* Test empty json (request body)
*
* @param \OpenAPI\Client\Model\Tag|null $tag Tag object (optional)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['testEchoBodyTagResponseString'] to see the possible values for this operation
*
* @throws ApiException on non-2xx response
* @throws InvalidArgumentException
* @return string
*/
public function testEchoBodyTagResponseString(
?\OpenAPI\Client\Model\Tag $tag = null,
string $contentType = self::contentTypes['testEchoBodyTagResponseString'][0]
): string
{
list($response) = $this->testEchoBodyTagResponseStringWithHttpInfo($tag, $contentType);
return $response;
}
/**
* Operation testEchoBodyTagResponseStringWithHttpInfo
*
* Test empty json (request body)
*
* @param \OpenAPI\Client\Model\Tag|null $tag Tag object (optional)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['testEchoBodyTagResponseString'] to see the possible values for this operation
*
* @throws ApiException on non-2xx response
* @throws InvalidArgumentException
* @return array of string, HTTP status code, HTTP response headers (array of strings)
*/
public function testEchoBodyTagResponseStringWithHttpInfo(
?\OpenAPI\Client\Model\Tag $tag = null,
string $contentType = self::contentTypes['testEchoBodyTagResponseString'][0]
): array
{
$request = $this->testEchoBodyTagResponseStringRequest($tag, $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') {
$content = json_decode($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') {
$content = json_decode($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 testEchoBodyTagResponseStringAsync
*
* Test empty json (request body)
*
* @param \OpenAPI\Client\Model\Tag|null $tag Tag object (optional)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['testEchoBodyTagResponseString'] to see the possible values for this operation
*
* @throws InvalidArgumentException
* @return PromiseInterface
*/
public function testEchoBodyTagResponseStringAsync(
?\OpenAPI\Client\Model\Tag $tag = null,
string $contentType = self::contentTypes['testEchoBodyTagResponseString'][0]
): PromiseInterface
{
return $this->testEchoBodyTagResponseStringAsyncWithHttpInfo($tag, $contentType)
->then(
function ($response) {
return $response[0];
}
);
}
/**
* Operation testEchoBodyTagResponseStringAsyncWithHttpInfo
*
* Test empty json (request body)
*
* @param \OpenAPI\Client\Model\Tag|null $tag Tag object (optional)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['testEchoBodyTagResponseString'] to see the possible values for this operation
*
* @throws InvalidArgumentException
* @return PromiseInterface
*/
public function testEchoBodyTagResponseStringAsyncWithHttpInfo(
$tag = null,
string $contentType = self::contentTypes['testEchoBodyTagResponseString'][0]
): PromiseInterface
{
$returnType = 'string';
$request = $this->testEchoBodyTagResponseStringRequest($tag, $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 'testEchoBodyTagResponseString'
*
* @param \OpenAPI\Client\Model\Tag|null $tag Tag object (optional)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['testEchoBodyTagResponseString'] to see the possible values for this operation
*
* @throws InvalidArgumentException
* @return \GuzzleHttp\Psr7\Request
*/
public function testEchoBodyTagResponseStringRequest(
$tag = null,
string $contentType = self::contentTypes['testEchoBodyTagResponseString'][0]
): Request
{
$resourcePath = '/echo/body/Tag/response_string';
$formParams = [];
$queryParams = [];
$headerParams = [];
$httpBody = '';
$multipart = false;
$headers = $this->headerSelector->selectHeaders(
['text/plain', ],
$contentType,
$multipart
);
// for model (json/xml)
if (isset($tag)) {
if (stripos($headers['Content-Type'], 'application/json') !== false) {
# if Content-Type contains "application/json", json_encode the body
$httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($tag));
} else {
$httpBody = $tag;
}
} elseif (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(
'POST',
$operationHost . $resourcePath . ($query ? "?{$query}" : ''),
$headers,
$httpBody
);
}
/**
* Create http client option
*
* @throws \RuntimeException on file opening failure
* @return array of http client options
*/
protected function createHttpClientOption(): array
{
$options = [];
if ($this->config->getDebug()) {
$options[RequestOptions::DEBUG] = fopen($this->config->getDebugFile(), 'a');
if (!$options[RequestOptions::DEBUG]) {
throw new \RuntimeException('Failed to open the debug file: ' . $this->config->getDebugFile());
}
}
return $options;
}
}