[PHP] Allow selecting Content-Type (#13769)

* [PHP] allow selecting Content-Type

* [AUTOGENERATED] update samples

* [PHP] Fixed tests for HeaderSelector

* [PHP] revert Content-Type validation

* [AUTOGENERATED] update samples
This commit is contained in:
Thomas Hansen 2022-10-26 10:58:29 +02:00 committed by GitHub
parent a66874f8f9
commit 824b2aa5f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 1219 additions and 1043 deletions

View File

@ -1,6 +1,6 @@
<?php
/**
* ApiException
* HeaderSelector
* PHP version 7.4
*
* @category Class
@ -18,10 +18,8 @@
namespace {{invokerPackage}};
use \Exception;
/**
* ApiException Class Doc Comment
* HeaderSelector Class Doc Comment
*
* @category Class
* @package {{invokerPackage}}
@ -32,10 +30,11 @@ class HeaderSelector
{
/**
* @param string[] $accept
* @param string[] $contentTypes
* @return array
* @param string $contentType
* @param bool $isMultipart
* @return string[]
*/
public function selectHeaders($accept, $contentTypes)
public function selectHeaders(array $accept, string $contentType, bool $isMultipart): array
{
$headers = [];
@ -43,20 +42,13 @@ class HeaderSelector
if ($accept !== null) {
$headers['Accept'] = $accept;
}
$headers['Content-Type'] = $this->selectContentTypeHeader($contentTypes);
return $headers;
if(!$isMultipart) {
if($contentType === '') {
$contentType = 'application/json';
}
$headers['Content-Type'] = $contentType;
}
/**
* @param string[] $accept
* @return array
*/
public function selectHeadersForMultipart($accept)
{
$headers = $this->selectHeaders($accept, []);
unset($headers['Content-Type']);
return $headers;
}
@ -77,22 +69,4 @@ class HeaderSelector
return implode(',', $accept);
}
}
/**
* Return the content type based on an array of content-type provided
*
* @param string[] $contentType Array fo content-type
*
* @return string Content-Type (e.g. application/json)
*/
private function selectContentTypeHeader($contentType)
{
if (count($contentType) === 0 || (count($contentType) === 1 && $contentType[0] === '')) {
return 'application/json';
} elseif (preg_grep("/application\/json/i", $contentType)) {
return 'application/json';
} else {
return implode(',', $contentType);
}
}
}

View File

@ -60,6 +60,15 @@ use {{invokerPackage}}\ObjectSerializer;
*/
protected $hostIndex;
/** @var string[] $contentTypes **/
public const contentTypes = [{{#operation}}
'{{{operationId}}}' => [{{#consumes}}
'{{{mediaType}}}',{{/consumes}}
{{^consumes}}
'application/json',
{{/consumes}} ],{{/operation}}
];
/**
* @param ClientInterface $client
* @param Configuration $config
@ -151,6 +160,7 @@ use {{invokerPackage}}\ObjectSerializer;
* @param array $variables Associative array of variables to pass to the host. Defaults to empty array.
{{/-first}}
{{/servers}}
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['{{{operationId}}}'] to see the possible values for this operation
*
* @throws \{{invokerPackage}}\ApiException on non-2xx response
* @throws \InvalidArgumentException
@ -159,9 +169,9 @@ use {{invokerPackage}}\ObjectSerializer;
* @deprecated
{{/isDeprecated}}
*/
public function {{operationId}}({{^vendorExtensions.x-group-parameters}}{{#allParams}}${{paramName}}{{^required}} = {{#defaultValue}}{{{.}}}{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}}{{#servers}}{{#-first}}{{#allParams}}{{#-first}}, {{/-first}}{{/allParams}}?int $hostIndex = null, array $variables = []{{/-first}}{{/servers}}{{/vendorExtensions.x-group-parameters}}{{#vendorExtensions.x-group-parameters}}$associative_array{{/vendorExtensions.x-group-parameters}})
public function {{operationId}}({{^vendorExtensions.x-group-parameters}}{{#allParams}}${{paramName}}{{^required}} = {{#defaultValue}}{{{.}}}{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}}{{/required}}, {{/allParams}}{{#servers}}{{#-first}}?int $hostIndex = null, array $variables = [], {{/-first}}{{/servers}}string $contentType = self::contentTypes['{{{operationId}}}'][0]{{/vendorExtensions.x-group-parameters}}{{#vendorExtensions.x-group-parameters}}$associative_array{{/vendorExtensions.x-group-parameters}})
{
{{#returnType}}list($response) = {{/returnType}}$this->{{operationId}}WithHttpInfo({{^vendorExtensions.x-group-parameters}}{{#allParams}}${{paramName}}{{^-last}}, {{/-last}}{{/allParams}}{{#servers}}{{#-first}}{{#allParams}}{{#-first}}, {{/-first}}{{/allParams}}$hostIndex, $variables{{/-first}}{{/servers}}{{/vendorExtensions.x-group-parameters}}{{#vendorExtensions.x-group-parameters}}$associative_array{{/vendorExtensions.x-group-parameters}});{{#returnType}}
{{#returnType}}list($response) = {{/returnType}}$this->{{operationId}}WithHttpInfo({{^vendorExtensions.x-group-parameters}}{{#allParams}}${{paramName}}, {{/allParams}}{{#servers}}{{#-first}}$hostIndex, $variables, {{/-first}}{{/servers}}$contentType{{/vendorExtensions.x-group-parameters}}{{#vendorExtensions.x-group-parameters}}$associative_array{{/vendorExtensions.x-group-parameters}});{{#returnType}}
return $response;{{/returnType}}
}
@ -209,6 +219,7 @@ use {{invokerPackage}}\ObjectSerializer;
* @param array $variables Associative array of variables to pass to the host. Defaults to empty array.
{{/-first}}
{{/servers}}
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['{{{operationId}}}'] to see the possible values for this operation
*
* @throws \{{invokerPackage}}\ApiException on non-2xx response
* @throws \InvalidArgumentException
@ -217,9 +228,9 @@ use {{invokerPackage}}\ObjectSerializer;
* @deprecated
{{/isDeprecated}}
*/
public function {{operationId}}WithHttpInfo({{^vendorExtensions.x-group-parameters}}{{#allParams}}${{paramName}}{{^required}} = {{#defaultValue}}{{{.}}}{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}}{{#servers}}{{#-first}}{{#allParams}}{{#-first}}, {{/-first}}{{/allParams}}?int $hostIndex = null, array $variables = []{{/-first}}{{/servers}}{{/vendorExtensions.x-group-parameters}}{{#vendorExtensions.x-group-parameters}}$associative_array{{/vendorExtensions.x-group-parameters}})
public function {{operationId}}WithHttpInfo({{^vendorExtensions.x-group-parameters}}{{#allParams}}${{paramName}}{{^required}} = {{#defaultValue}}{{{.}}}{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}}{{/required}}, {{/allParams}}{{#servers}}{{#-first}}?int $hostIndex = null, array $variables = [], {{/-first}}{{/servers}}string $contentType = self::contentTypes['{{{operationId}}}'][0]{{/vendorExtensions.x-group-parameters}}{{#vendorExtensions.x-group-parameters}}$associative_array{{/vendorExtensions.x-group-parameters}})
{
$request = $this->{{operationId}}Request({{^vendorExtensions.x-group-parameters}}{{#allParams}}${{paramName}}{{^-last}}, {{/-last}}{{/allParams}}{{#servers}}{{#-first}}{{#allParams}}{{#-first}}, {{/-first}}{{/allParams}}$hostIndex, $variables{{/-first}}{{/servers}}{{/vendorExtensions.x-group-parameters}}{{#vendorExtensions.x-group-parameters}}$associative_array{{/vendorExtensions.x-group-parameters}});
$request = $this->{{operationId}}Request({{^vendorExtensions.x-group-parameters}}{{#allParams}}${{paramName}}, {{/allParams}}{{#servers}}{{#-first}}$hostIndex, $variables, {{/-first}}{{/servers}}$contentType{{/vendorExtensions.x-group-parameters}}{{#vendorExtensions.x-group-parameters}}$associative_array{{/vendorExtensions.x-group-parameters}});
try {
$options = $this->createHttpClientOption();
@ -367,6 +378,7 @@ use {{invokerPackage}}\ObjectSerializer;
* @param array $variables Associative array of variables to pass to the host. Defaults to empty array.
{{/-first}}
{{/servers}}
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['{{{operationId}}}'] to see the possible values for this operation
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Promise\PromiseInterface
@ -374,9 +386,9 @@ use {{invokerPackage}}\ObjectSerializer;
* @deprecated
{{/isDeprecated}}
*/
public function {{operationId}}Async({{^vendorExtensions.x-group-parameters}}{{#allParams}}${{paramName}}{{^required}} = {{#defaultValue}}{{{.}}}{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}}{{#servers}}{{#-first}}{{#allParams}}{{#-first}}, {{/-first}}{{/allParams}}?int $hostIndex = null, array $variables = []{{/-first}}{{/servers}}{{/vendorExtensions.x-group-parameters}}{{#vendorExtensions.x-group-parameters}}$associative_array{{/vendorExtensions.x-group-parameters}})
public function {{operationId}}Async({{^vendorExtensions.x-group-parameters}}{{#allParams}}${{paramName}}{{^required}} = {{#defaultValue}}{{{.}}}{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}}{{/required}}, {{/allParams}}{{#servers}}{{#-first}}?int $hostIndex = null, array $variables = [], {{/-first}}{{/servers}}string $contentType = self::contentTypes['{{{operationId}}}'][0]{{/vendorExtensions.x-group-parameters}}{{#vendorExtensions.x-group-parameters}}$associative_array{{/vendorExtensions.x-group-parameters}})
{
return $this->{{operationId}}AsyncWithHttpInfo({{^vendorExtensions.x-group-parameters}}{{#allParams}}${{paramName}}{{^-last}}, {{/-last}}{{/allParams}}{{#servers}}{{#-first}}{{#allParams}}{{#-first}}, {{/-first}}{{/allParams}}$hostIndex, $variables{{/-first}}{{/servers}}{{/vendorExtensions.x-group-parameters}}{{#vendorExtensions.x-group-parameters}}$associative_array{{/vendorExtensions.x-group-parameters}})
return $this->{{operationId}}AsyncWithHttpInfo({{^vendorExtensions.x-group-parameters}}{{#allParams}}${{paramName}}, {{/allParams}}{{#servers}}{{#-first}}$hostIndex, $variables, {{/-first}}{{/servers}}$contentType{{/vendorExtensions.x-group-parameters}}{{#vendorExtensions.x-group-parameters}}$associative_array{{/vendorExtensions.x-group-parameters}})
->then(
function ($response) {
return $response[0];
@ -428,6 +440,7 @@ use {{invokerPackage}}\ObjectSerializer;
* @param array $variables Associative array of variables to pass to the host. Defaults to empty array.
{{/-first}}
{{/servers}}
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['{{{operationId}}}'] to see the possible values for this operation
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Promise\PromiseInterface
@ -435,10 +448,10 @@ use {{invokerPackage}}\ObjectSerializer;
* @deprecated
{{/isDeprecated}}
*/
public function {{operationId}}AsyncWithHttpInfo({{^vendorExtensions.x-group-parameters}}{{#allParams}}${{paramName}}{{^required}} = {{#defaultValue}}{{{.}}}{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}}{{#servers}}{{#-first}}{{#allParams}}{{#-first}}, {{/-first}}{{/allParams}}?int $hostIndex = null, array $variables = []{{/-first}}{{/servers}}{{/vendorExtensions.x-group-parameters}}{{#vendorExtensions.x-group-parameters}}$associative_array{{/vendorExtensions.x-group-parameters}})
public function {{operationId}}AsyncWithHttpInfo({{^vendorExtensions.x-group-parameters}}{{#allParams}}${{paramName}}{{^required}} = {{#defaultValue}}{{{.}}}{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}}{{/required}}, {{/allParams}}{{#servers}}{{#-first}}?int $hostIndex = null, array $variables = [], {{/-first}}{{/servers}}string $contentType = self::contentTypes['{{{operationId}}}'][0]{{/vendorExtensions.x-group-parameters}}{{#vendorExtensions.x-group-parameters}}$associative_array{{/vendorExtensions.x-group-parameters}})
{
$returnType = '{{{returnType}}}';
$request = $this->{{operationId}}Request({{^vendorExtensions.x-group-parameters}}{{#allParams}}${{paramName}}{{^-last}}, {{/-last}}{{/allParams}}{{#servers}}{{#-first}}{{#allParams}}{{#-first}}, {{/-first}}{{/allParams}}$hostIndex, $variables{{/-first}}{{/servers}}{{/vendorExtensions.x-group-parameters}}{{#vendorExtensions.x-group-parameters}}$associative_array{{/vendorExtensions.x-group-parameters}});
$request = $this->{{operationId}}Request({{^vendorExtensions.x-group-parameters}}{{#allParams}}${{paramName}}, {{/allParams}}{{#servers}}{{#-first}}$hostIndex, $variables, {{/-first}}{{/servers}}$contentType{{/vendorExtensions.x-group-parameters}}{{#vendorExtensions.x-group-parameters}}$associative_array{{/vendorExtensions.x-group-parameters}});
return $this->client
->sendAsync($request, $this->createHttpClientOption())
@ -517,6 +530,7 @@ use {{invokerPackage}}\ObjectSerializer;
* @param array $variables Associative array of variables to pass to the host. Defaults to empty array.
{{/-first}}
{{/servers}}
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['{{{operationId}}}'] to see the possible values for this operation
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Psr7\Request
@ -524,7 +538,7 @@ use {{invokerPackage}}\ObjectSerializer;
* @deprecated
{{/isDeprecated}}
*/
public function {{operationId}}Request({{^vendorExtensions.x-group-parameters}}{{#allParams}}${{paramName}}{{^required}} = {{#defaultValue}}{{{.}}}{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}}{{#servers}}{{#-first}}{{#allParams}}{{#-first}}, {{/-first}}{{/allParams}}?int $hostIndex = null, array $variables = []{{/-first}}{{/servers}}{{/vendorExtensions.x-group-parameters}}{{#vendorExtensions.x-group-parameters}}$associative_array{{/vendorExtensions.x-group-parameters}})
public function {{operationId}}Request({{^vendorExtensions.x-group-parameters}}{{#allParams}}${{paramName}}{{^required}} = {{#defaultValue}}{{{.}}}{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}}{{/required}}, {{/allParams}}{{#servers}}{{#-first}}?int $hostIndex = null, array $variables = [], {{/-first}}{{/servers}}string $contentType = self::contentTypes['{{{operationId}}}'][0]{{/vendorExtensions.x-group-parameters}}{{#vendorExtensions.x-group-parameters}}$associative_array{{/vendorExtensions.x-group-parameters}})
{
{{#vendorExtensions.x-group-parameters}}
// unbox the parameters from the associative array
@ -533,7 +547,9 @@ use {{invokerPackage}}\ObjectSerializer;
{{/allParams}}{{#servers.0}}
$hostIndex = $associative_array['hostIndex'];
$variables = array_key_exists('variables', $associative_array) ? $associative_array['variables'] : [];
{{/servers.0}}{{/vendorExtensions.x-group-parameters}}{{#allParams}}
{{/servers.0}}
$contentType = $associative_array['contentType'] ?? self::contentTypes['{{{operationId}}}'][0];
{{/vendorExtensions.x-group-parameters}}{{#allParams}}
{{#required}}
// verify the required parameter '{{paramName}}' is set
if (${{paramName}} === null || (is_array(${{paramName}}) && count(${{paramName}}) === 0)) {
@ -578,9 +594,7 @@ use {{invokerPackage}}\ObjectSerializer;
throw new \InvalidArgumentException('invalid value for "${{paramName}}" when calling {{classname}}.{{operationId}}, number of items must be greater than or equal to {{minItems}}.');
}
{{/minItems}}
{{/hasValidation}}
{{/allParams}}
{{/hasValidation}}{{/allParams}}
$resourcePath = '{{{path}}}';
$formParams = [];
@ -649,21 +663,17 @@ use {{invokerPackage}}\ObjectSerializer;
}
{{/formParams}}
if ($multipart) {
$headers = $this->headerSelector->selectHeadersForMultipart(
[{{#produces}}'{{{mediaType}}}'{{^-last}}, {{/-last}}{{/produces}}]
);
} else {
$headers = $this->headerSelector->selectHeaders(
[{{#produces}}'{{{mediaType}}}'{{^-last}}, {{/-last}}{{/produces}}],
[{{#consumes}}'{{{mediaType}}}'{{^-last}}, {{/-last}}{{/consumes}}]
[{{#produces}}'{{{mediaType}}}', {{/produces}}],
$contentType,
$multipart
);
}
// for model (json/xml)
{{#bodyParams}}
if (isset(${{paramName}})) {
if ($headers['Content-Type'] === 'application/json') {
if (stripos($headers['Content-Type'], 'application/json') !== false) {
# if Content-Type contains "application/json", json_encode the body
$httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization(${{paramName}}));
} else {
$httpBody = ${{paramName}};
@ -687,9 +697,9 @@ use {{invokerPackage}}\ObjectSerializer;
// for HTTP post (form)
$httpBody = new MultipartStream($multipartContents);
} elseif ($headers['Content-Type'] === 'application/json') {
} elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
# if Content-Type contains "application/json", json_encode the form parameters
$httpBody = \GuzzleHttp\json_encode($formParams);
} else {
// for HTTP post (form)
$httpBody = ObjectSerializer::buildQuery($formParams);

View File

@ -69,6 +69,13 @@ class AnotherFakeApi
*/
protected $hostIndex;
/** @var string[] $contentTypes **/
public const contentTypes = [
'call123TestSpecialTags' => [
'application/json',
],
];
/**
* @param ClientInterface $client
* @param Configuration $config
@ -121,14 +128,15 @@ class AnotherFakeApi
* To test special tags
*
* @param \OpenAPI\Client\Model\Client $client client model (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['call123TestSpecialTags'] to see the possible values for this operation
*
* @throws \OpenAPI\Client\ApiException on non-2xx response
* @throws \InvalidArgumentException
* @return \OpenAPI\Client\Model\Client
*/
public function call123TestSpecialTags($client)
public function call123TestSpecialTags($client, string $contentType = self::contentTypes['call123TestSpecialTags'][0])
{
list($response) = $this->call123TestSpecialTagsWithHttpInfo($client);
list($response) = $this->call123TestSpecialTagsWithHttpInfo($client, $contentType);
return $response;
}
@ -138,14 +146,15 @@ class AnotherFakeApi
* To test special tags
*
* @param \OpenAPI\Client\Model\Client $client client model (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['call123TestSpecialTags'] to see the possible values for this operation
*
* @throws \OpenAPI\Client\ApiException on non-2xx response
* @throws \InvalidArgumentException
* @return array of \OpenAPI\Client\Model\Client, HTTP status code, HTTP response headers (array of strings)
*/
public function call123TestSpecialTagsWithHttpInfo($client)
public function call123TestSpecialTagsWithHttpInfo($client, string $contentType = self::contentTypes['call123TestSpecialTags'][0])
{
$request = $this->call123TestSpecialTagsRequest($client);
$request = $this->call123TestSpecialTagsRequest($client, $contentType);
try {
$options = $this->createHttpClientOption();
@ -237,13 +246,14 @@ class AnotherFakeApi
* To test special tags
*
* @param \OpenAPI\Client\Model\Client $client client model (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['call123TestSpecialTags'] to see the possible values for this operation
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Promise\PromiseInterface
*/
public function call123TestSpecialTagsAsync($client)
public function call123TestSpecialTagsAsync($client, string $contentType = self::contentTypes['call123TestSpecialTags'][0])
{
return $this->call123TestSpecialTagsAsyncWithHttpInfo($client)
return $this->call123TestSpecialTagsAsyncWithHttpInfo($client, $contentType)
->then(
function ($response) {
return $response[0];
@ -257,14 +267,15 @@ class AnotherFakeApi
* To test special tags
*
* @param \OpenAPI\Client\Model\Client $client client model (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['call123TestSpecialTags'] to see the possible values for this operation
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Promise\PromiseInterface
*/
public function call123TestSpecialTagsAsyncWithHttpInfo($client)
public function call123TestSpecialTagsAsyncWithHttpInfo($client, string $contentType = self::contentTypes['call123TestSpecialTags'][0])
{
$returnType = '\OpenAPI\Client\Model\Client';
$request = $this->call123TestSpecialTagsRequest($client);
$request = $this->call123TestSpecialTagsRequest($client, $contentType);
return $this->client
->sendAsync($request, $this->createHttpClientOption())
@ -306,11 +317,12 @@ class AnotherFakeApi
* Create request for operation 'call123TestSpecialTags'
*
* @param \OpenAPI\Client\Model\Client $client client model (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['call123TestSpecialTags'] to see the possible values for this operation
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Psr7\Request
*/
public function call123TestSpecialTagsRequest($client)
public function call123TestSpecialTagsRequest($client, string $contentType = self::contentTypes['call123TestSpecialTags'][0])
{
// verify the required parameter 'client' is set
@ -320,6 +332,7 @@ class AnotherFakeApi
);
}
$resourcePath = '/another-fake/dummy';
$formParams = [];
$queryParams = [];
@ -331,20 +344,16 @@ class AnotherFakeApi
if ($multipart) {
$headers = $this->headerSelector->selectHeadersForMultipart(
['application/json']
);
} else {
$headers = $this->headerSelector->selectHeaders(
['application/json'],
['application/json']
['application/json', ],
$contentType,
$multipart
);
}
// for model (json/xml)
if (isset($client)) {
if ($headers['Content-Type'] === 'application/json') {
if (stripos($headers['Content-Type'], 'application/json') !== false) {
# if Content-Type contains "application/json", json_encode the body
$httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($client));
} else {
$httpBody = $client;
@ -364,9 +373,9 @@ class AnotherFakeApi
// for HTTP post (form)
$httpBody = new MultipartStream($multipartContents);
} elseif ($headers['Content-Type'] === 'application/json') {
} elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
# if Content-Type contains "application/json", json_encode the form parameters
$httpBody = \GuzzleHttp\json_encode($formParams);
} else {
// for HTTP post (form)
$httpBody = ObjectSerializer::buildQuery($formParams);

View File

@ -69,6 +69,13 @@ class DefaultApi
*/
protected $hostIndex;
/** @var string[] $contentTypes **/
public const contentTypes = [
'fooGet' => [
'application/json',
],
];
/**
* @param ClientInterface $client
* @param Configuration $config
@ -118,28 +125,30 @@ class DefaultApi
/**
* Operation fooGet
*
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['fooGet'] to see the possible values for this operation
*
* @throws \OpenAPI\Client\ApiException on non-2xx response
* @throws \InvalidArgumentException
* @return \OpenAPI\Client\Model\FooGetDefaultResponse
*/
public function fooGet()
public function fooGet(string $contentType = self::contentTypes['fooGet'][0])
{
list($response) = $this->fooGetWithHttpInfo();
list($response) = $this->fooGetWithHttpInfo($contentType);
return $response;
}
/**
* Operation fooGetWithHttpInfo
*
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['fooGet'] to see the possible values for this operation
*
* @throws \OpenAPI\Client\ApiException on non-2xx response
* @throws \InvalidArgumentException
* @return array of \OpenAPI\Client\Model\FooGetDefaultResponse, HTTP status code, HTTP response headers (array of strings)
*/
public function fooGetWithHttpInfo()
public function fooGetWithHttpInfo(string $contentType = self::contentTypes['fooGet'][0])
{
$request = $this->fooGetRequest();
$request = $this->fooGetRequest($contentType);
try {
$options = $this->createHttpClientOption();
@ -228,13 +237,14 @@ class DefaultApi
/**
* Operation fooGetAsync
*
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['fooGet'] to see the possible values for this operation
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Promise\PromiseInterface
*/
public function fooGetAsync()
public function fooGetAsync(string $contentType = self::contentTypes['fooGet'][0])
{
return $this->fooGetAsyncWithHttpInfo()
return $this->fooGetAsyncWithHttpInfo($contentType)
->then(
function ($response) {
return $response[0];
@ -245,14 +255,15 @@ class DefaultApi
/**
* Operation fooGetAsyncWithHttpInfo
*
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['fooGet'] to see the possible values for this operation
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Promise\PromiseInterface
*/
public function fooGetAsyncWithHttpInfo()
public function fooGetAsyncWithHttpInfo(string $contentType = self::contentTypes['fooGet'][0])
{
$returnType = '\OpenAPI\Client\Model\FooGetDefaultResponse';
$request = $this->fooGetRequest();
$request = $this->fooGetRequest($contentType);
return $this->client
->sendAsync($request, $this->createHttpClientOption())
@ -293,13 +304,15 @@ class DefaultApi
/**
* Create request for operation 'fooGet'
*
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['fooGet'] to see the possible values for this operation
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Psr7\Request
*/
public function fooGetRequest()
public function fooGetRequest(string $contentType = self::contentTypes['fooGet'][0])
{
$resourcePath = '/foo';
$formParams = [];
$queryParams = [];
@ -311,16 +324,11 @@ class DefaultApi
if ($multipart) {
$headers = $this->headerSelector->selectHeadersForMultipart(
['application/json']
);
} else {
$headers = $this->headerSelector->selectHeaders(
['application/json'],
[]
['application/json', ],
$contentType,
$multipart
);
}
// for model (json/xml)
if (count($formParams) > 0) {
@ -338,9 +346,9 @@ class DefaultApi
// for HTTP post (form)
$httpBody = new MultipartStream($multipartContents);
} elseif ($headers['Content-Type'] === 'application/json') {
} elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
# if Content-Type contains "application/json", json_encode the form parameters
$httpBody = \GuzzleHttp\json_encode($formParams);
} else {
// for HTTP post (form)
$httpBody = ObjectSerializer::buildQuery($formParams);

View File

@ -69,6 +69,13 @@ class FakeClassnameTags123Api
*/
protected $hostIndex;
/** @var string[] $contentTypes **/
public const contentTypes = [
'testClassname' => [
'application/json',
],
];
/**
* @param ClientInterface $client
* @param Configuration $config
@ -121,14 +128,15 @@ class FakeClassnameTags123Api
* To test class name in snake case
*
* @param \OpenAPI\Client\Model\Client $client client model (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['testClassname'] to see the possible values for this operation
*
* @throws \OpenAPI\Client\ApiException on non-2xx response
* @throws \InvalidArgumentException
* @return \OpenAPI\Client\Model\Client
*/
public function testClassname($client)
public function testClassname($client, string $contentType = self::contentTypes['testClassname'][0])
{
list($response) = $this->testClassnameWithHttpInfo($client);
list($response) = $this->testClassnameWithHttpInfo($client, $contentType);
return $response;
}
@ -138,14 +146,15 @@ class FakeClassnameTags123Api
* To test class name in snake case
*
* @param \OpenAPI\Client\Model\Client $client client model (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['testClassname'] to see the possible values for this operation
*
* @throws \OpenAPI\Client\ApiException on non-2xx response
* @throws \InvalidArgumentException
* @return array of \OpenAPI\Client\Model\Client, HTTP status code, HTTP response headers (array of strings)
*/
public function testClassnameWithHttpInfo($client)
public function testClassnameWithHttpInfo($client, string $contentType = self::contentTypes['testClassname'][0])
{
$request = $this->testClassnameRequest($client);
$request = $this->testClassnameRequest($client, $contentType);
try {
$options = $this->createHttpClientOption();
@ -237,13 +246,14 @@ class FakeClassnameTags123Api
* To test class name in snake case
*
* @param \OpenAPI\Client\Model\Client $client client model (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['testClassname'] to see the possible values for this operation
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Promise\PromiseInterface
*/
public function testClassnameAsync($client)
public function testClassnameAsync($client, string $contentType = self::contentTypes['testClassname'][0])
{
return $this->testClassnameAsyncWithHttpInfo($client)
return $this->testClassnameAsyncWithHttpInfo($client, $contentType)
->then(
function ($response) {
return $response[0];
@ -257,14 +267,15 @@ class FakeClassnameTags123Api
* To test class name in snake case
*
* @param \OpenAPI\Client\Model\Client $client client model (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['testClassname'] to see the possible values for this operation
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Promise\PromiseInterface
*/
public function testClassnameAsyncWithHttpInfo($client)
public function testClassnameAsyncWithHttpInfo($client, string $contentType = self::contentTypes['testClassname'][0])
{
$returnType = '\OpenAPI\Client\Model\Client';
$request = $this->testClassnameRequest($client);
$request = $this->testClassnameRequest($client, $contentType);
return $this->client
->sendAsync($request, $this->createHttpClientOption())
@ -306,11 +317,12 @@ class FakeClassnameTags123Api
* Create request for operation 'testClassname'
*
* @param \OpenAPI\Client\Model\Client $client client model (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['testClassname'] to see the possible values for this operation
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Psr7\Request
*/
public function testClassnameRequest($client)
public function testClassnameRequest($client, string $contentType = self::contentTypes['testClassname'][0])
{
// verify the required parameter 'client' is set
@ -320,6 +332,7 @@ class FakeClassnameTags123Api
);
}
$resourcePath = '/fake_classname_test';
$formParams = [];
$queryParams = [];
@ -331,20 +344,16 @@ class FakeClassnameTags123Api
if ($multipart) {
$headers = $this->headerSelector->selectHeadersForMultipart(
['application/json']
);
} else {
$headers = $this->headerSelector->selectHeaders(
['application/json'],
['application/json']
['application/json', ],
$contentType,
$multipart
);
}
// for model (json/xml)
if (isset($client)) {
if ($headers['Content-Type'] === 'application/json') {
if (stripos($headers['Content-Type'], 'application/json') !== false) {
# if Content-Type contains "application/json", json_encode the body
$httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($client));
} else {
$httpBody = $client;
@ -364,9 +373,9 @@ class FakeClassnameTags123Api
// for HTTP post (form)
$httpBody = new MultipartStream($multipartContents);
} elseif ($headers['Content-Type'] === 'application/json') {
} elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
# if Content-Type contains "application/json", json_encode the form parameters
$httpBody = \GuzzleHttp\json_encode($formParams);
} else {
// for HTTP post (form)
$httpBody = ObjectSerializer::buildQuery($formParams);

View File

@ -69,6 +69,22 @@ class StoreApi
*/
protected $hostIndex;
/** @var string[] $contentTypes **/
public const contentTypes = [
'deleteOrder' => [
'application/json',
],
'getInventory' => [
'application/json',
],
'getOrderById' => [
'application/json',
],
'placeOrder' => [
'application/json',
],
];
/**
* @param ClientInterface $client
* @param Configuration $config
@ -121,14 +137,15 @@ class StoreApi
* Delete purchase order by ID
*
* @param string $order_id ID of the order that needs to be deleted (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['deleteOrder'] to see the possible values for this operation
*
* @throws \OpenAPI\Client\ApiException on non-2xx response
* @throws \InvalidArgumentException
* @return void
*/
public function deleteOrder($order_id)
public function deleteOrder($order_id, string $contentType = self::contentTypes['deleteOrder'][0])
{
$this->deleteOrderWithHttpInfo($order_id);
$this->deleteOrderWithHttpInfo($order_id, $contentType);
}
/**
@ -137,14 +154,15 @@ class StoreApi
* Delete purchase order by ID
*
* @param string $order_id ID of the order that needs to be deleted (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['deleteOrder'] to see the possible values for this operation
*
* @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 deleteOrderWithHttpInfo($order_id)
public function deleteOrderWithHttpInfo($order_id, string $contentType = self::contentTypes['deleteOrder'][0])
{
$request = $this->deleteOrderRequest($order_id);
$request = $this->deleteOrderRequest($order_id, $contentType);
try {
$options = $this->createHttpClientOption();
@ -196,13 +214,14 @@ class StoreApi
* Delete purchase order by ID
*
* @param string $order_id ID of the order that needs to be deleted (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['deleteOrder'] to see the possible values for this operation
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Promise\PromiseInterface
*/
public function deleteOrderAsync($order_id)
public function deleteOrderAsync($order_id, string $contentType = self::contentTypes['deleteOrder'][0])
{
return $this->deleteOrderAsyncWithHttpInfo($order_id)
return $this->deleteOrderAsyncWithHttpInfo($order_id, $contentType)
->then(
function ($response) {
return $response[0];
@ -216,14 +235,15 @@ class StoreApi
* Delete purchase order by ID
*
* @param string $order_id ID of the order that needs to be deleted (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['deleteOrder'] to see the possible values for this operation
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Promise\PromiseInterface
*/
public function deleteOrderAsyncWithHttpInfo($order_id)
public function deleteOrderAsyncWithHttpInfo($order_id, string $contentType = self::contentTypes['deleteOrder'][0])
{
$returnType = '';
$request = $this->deleteOrderRequest($order_id);
$request = $this->deleteOrderRequest($order_id, $contentType);
return $this->client
->sendAsync($request, $this->createHttpClientOption())
@ -252,11 +272,12 @@ class StoreApi
* Create request for operation 'deleteOrder'
*
* @param string $order_id ID of the order that needs to be deleted (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['deleteOrder'] to see the possible values for this operation
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Psr7\Request
*/
public function deleteOrderRequest($order_id)
public function deleteOrderRequest($order_id, string $contentType = self::contentTypes['deleteOrder'][0])
{
// verify the required parameter 'order_id' is set
@ -266,6 +287,7 @@ class StoreApi
);
}
$resourcePath = '/store/order/{order_id}';
$formParams = [];
$queryParams = [];
@ -285,16 +307,11 @@ class StoreApi
}
if ($multipart) {
$headers = $this->headerSelector->selectHeadersForMultipart(
[]
);
} else {
$headers = $this->headerSelector->selectHeaders(
[],
[]
$contentType,
$multipart
);
}
// for model (json/xml)
if (count($formParams) > 0) {
@ -312,9 +329,9 @@ class StoreApi
// for HTTP post (form)
$httpBody = new MultipartStream($multipartContents);
} elseif ($headers['Content-Type'] === 'application/json') {
} elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
# if Content-Type contains "application/json", json_encode the form parameters
$httpBody = \GuzzleHttp\json_encode($formParams);
} else {
// for HTTP post (form)
$httpBody = ObjectSerializer::buildQuery($formParams);
@ -348,14 +365,15 @@ class StoreApi
*
* Returns pet inventories by status
*
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['getInventory'] to see the possible values for this operation
*
* @throws \OpenAPI\Client\ApiException on non-2xx response
* @throws \InvalidArgumentException
* @return array<string,int>
*/
public function getInventory()
public function getInventory(string $contentType = self::contentTypes['getInventory'][0])
{
list($response) = $this->getInventoryWithHttpInfo();
list($response) = $this->getInventoryWithHttpInfo($contentType);
return $response;
}
@ -364,14 +382,15 @@ class StoreApi
*
* Returns pet inventories by status
*
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['getInventory'] to see the possible values for this operation
*
* @throws \OpenAPI\Client\ApiException on non-2xx response
* @throws \InvalidArgumentException
* @return array of array<string,int>, HTTP status code, HTTP response headers (array of strings)
*/
public function getInventoryWithHttpInfo()
public function getInventoryWithHttpInfo(string $contentType = self::contentTypes['getInventory'][0])
{
$request = $this->getInventoryRequest();
$request = $this->getInventoryRequest($contentType);
try {
$options = $this->createHttpClientOption();
@ -462,13 +481,14 @@ class StoreApi
*
* Returns pet inventories by status
*
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['getInventory'] to see the possible values for this operation
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Promise\PromiseInterface
*/
public function getInventoryAsync()
public function getInventoryAsync(string $contentType = self::contentTypes['getInventory'][0])
{
return $this->getInventoryAsyncWithHttpInfo()
return $this->getInventoryAsyncWithHttpInfo($contentType)
->then(
function ($response) {
return $response[0];
@ -481,14 +501,15 @@ class StoreApi
*
* Returns pet inventories by status
*
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['getInventory'] to see the possible values for this operation
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Promise\PromiseInterface
*/
public function getInventoryAsyncWithHttpInfo()
public function getInventoryAsyncWithHttpInfo(string $contentType = self::contentTypes['getInventory'][0])
{
$returnType = 'array<string,int>';
$request = $this->getInventoryRequest();
$request = $this->getInventoryRequest($contentType);
return $this->client
->sendAsync($request, $this->createHttpClientOption())
@ -529,13 +550,15 @@ class StoreApi
/**
* Create request for operation 'getInventory'
*
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['getInventory'] to see the possible values for this operation
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Psr7\Request
*/
public function getInventoryRequest()
public function getInventoryRequest(string $contentType = self::contentTypes['getInventory'][0])
{
$resourcePath = '/store/inventory';
$formParams = [];
$queryParams = [];
@ -547,16 +570,11 @@ class StoreApi
if ($multipart) {
$headers = $this->headerSelector->selectHeadersForMultipart(
['application/json']
);
} else {
$headers = $this->headerSelector->selectHeaders(
['application/json'],
[]
['application/json', ],
$contentType,
$multipart
);
}
// for model (json/xml)
if (count($formParams) > 0) {
@ -574,9 +592,9 @@ class StoreApi
// for HTTP post (form)
$httpBody = new MultipartStream($multipartContents);
} elseif ($headers['Content-Type'] === 'application/json') {
} elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
# if Content-Type contains "application/json", json_encode the form parameters
$httpBody = \GuzzleHttp\json_encode($formParams);
} else {
// for HTTP post (form)
$httpBody = ObjectSerializer::buildQuery($formParams);
@ -616,14 +634,15 @@ class StoreApi
* Find purchase order by ID
*
* @param int $order_id ID of pet that needs to be fetched (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['getOrderById'] to see the possible values for this operation
*
* @throws \OpenAPI\Client\ApiException on non-2xx response
* @throws \InvalidArgumentException
* @return \OpenAPI\Client\Model\Order
*/
public function getOrderById($order_id)
public function getOrderById($order_id, string $contentType = self::contentTypes['getOrderById'][0])
{
list($response) = $this->getOrderByIdWithHttpInfo($order_id);
list($response) = $this->getOrderByIdWithHttpInfo($order_id, $contentType);
return $response;
}
@ -633,14 +652,15 @@ class StoreApi
* Find purchase order by ID
*
* @param int $order_id ID of pet that needs to be fetched (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['getOrderById'] to see the possible values for this operation
*
* @throws \OpenAPI\Client\ApiException on non-2xx response
* @throws \InvalidArgumentException
* @return array of \OpenAPI\Client\Model\Order, HTTP status code, HTTP response headers (array of strings)
*/
public function getOrderByIdWithHttpInfo($order_id)
public function getOrderByIdWithHttpInfo($order_id, string $contentType = self::contentTypes['getOrderById'][0])
{
$request = $this->getOrderByIdRequest($order_id);
$request = $this->getOrderByIdRequest($order_id, $contentType);
try {
$options = $this->createHttpClientOption();
@ -732,13 +752,14 @@ class StoreApi
* Find purchase order by ID
*
* @param int $order_id ID of pet that needs to be fetched (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['getOrderById'] to see the possible values for this operation
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Promise\PromiseInterface
*/
public function getOrderByIdAsync($order_id)
public function getOrderByIdAsync($order_id, string $contentType = self::contentTypes['getOrderById'][0])
{
return $this->getOrderByIdAsyncWithHttpInfo($order_id)
return $this->getOrderByIdAsyncWithHttpInfo($order_id, $contentType)
->then(
function ($response) {
return $response[0];
@ -752,14 +773,15 @@ class StoreApi
* Find purchase order by ID
*
* @param int $order_id ID of pet that needs to be fetched (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['getOrderById'] to see the possible values for this operation
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Promise\PromiseInterface
*/
public function getOrderByIdAsyncWithHttpInfo($order_id)
public function getOrderByIdAsyncWithHttpInfo($order_id, string $contentType = self::contentTypes['getOrderById'][0])
{
$returnType = '\OpenAPI\Client\Model\Order';
$request = $this->getOrderByIdRequest($order_id);
$request = $this->getOrderByIdRequest($order_id, $contentType);
return $this->client
->sendAsync($request, $this->createHttpClientOption())
@ -801,11 +823,12 @@ class StoreApi
* Create request for operation 'getOrderById'
*
* @param int $order_id ID of pet that needs to be fetched (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['getOrderById'] to see the possible values for this operation
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Psr7\Request
*/
public function getOrderByIdRequest($order_id)
public function getOrderByIdRequest($order_id, string $contentType = self::contentTypes['getOrderById'][0])
{
// verify the required parameter 'order_id' is set
@ -841,16 +864,11 @@ class StoreApi
}
if ($multipart) {
$headers = $this->headerSelector->selectHeadersForMultipart(
['application/xml', 'application/json']
);
} else {
$headers = $this->headerSelector->selectHeaders(
['application/xml', 'application/json'],
[]
['application/xml', 'application/json', ],
$contentType,
$multipart
);
}
// for model (json/xml)
if (count($formParams) > 0) {
@ -868,9 +886,9 @@ class StoreApi
// for HTTP post (form)
$httpBody = new MultipartStream($multipartContents);
} elseif ($headers['Content-Type'] === 'application/json') {
} elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
# if Content-Type contains "application/json", json_encode the form parameters
$httpBody = \GuzzleHttp\json_encode($formParams);
} else {
// for HTTP post (form)
$httpBody = ObjectSerializer::buildQuery($formParams);
@ -905,14 +923,15 @@ class StoreApi
* Place an order for a pet
*
* @param \OpenAPI\Client\Model\Order $order order placed for purchasing the pet (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['placeOrder'] to see the possible values for this operation
*
* @throws \OpenAPI\Client\ApiException on non-2xx response
* @throws \InvalidArgumentException
* @return \OpenAPI\Client\Model\Order
*/
public function placeOrder($order)
public function placeOrder($order, string $contentType = self::contentTypes['placeOrder'][0])
{
list($response) = $this->placeOrderWithHttpInfo($order);
list($response) = $this->placeOrderWithHttpInfo($order, $contentType);
return $response;
}
@ -922,14 +941,15 @@ class StoreApi
* Place an order for a pet
*
* @param \OpenAPI\Client\Model\Order $order order placed for purchasing the pet (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['placeOrder'] to see the possible values for this operation
*
* @throws \OpenAPI\Client\ApiException on non-2xx response
* @throws \InvalidArgumentException
* @return array of \OpenAPI\Client\Model\Order, HTTP status code, HTTP response headers (array of strings)
*/
public function placeOrderWithHttpInfo($order)
public function placeOrderWithHttpInfo($order, string $contentType = self::contentTypes['placeOrder'][0])
{
$request = $this->placeOrderRequest($order);
$request = $this->placeOrderRequest($order, $contentType);
try {
$options = $this->createHttpClientOption();
@ -1021,13 +1041,14 @@ class StoreApi
* Place an order for a pet
*
* @param \OpenAPI\Client\Model\Order $order order placed for purchasing the pet (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['placeOrder'] to see the possible values for this operation
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Promise\PromiseInterface
*/
public function placeOrderAsync($order)
public function placeOrderAsync($order, string $contentType = self::contentTypes['placeOrder'][0])
{
return $this->placeOrderAsyncWithHttpInfo($order)
return $this->placeOrderAsyncWithHttpInfo($order, $contentType)
->then(
function ($response) {
return $response[0];
@ -1041,14 +1062,15 @@ class StoreApi
* Place an order for a pet
*
* @param \OpenAPI\Client\Model\Order $order order placed for purchasing the pet (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['placeOrder'] to see the possible values for this operation
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Promise\PromiseInterface
*/
public function placeOrderAsyncWithHttpInfo($order)
public function placeOrderAsyncWithHttpInfo($order, string $contentType = self::contentTypes['placeOrder'][0])
{
$returnType = '\OpenAPI\Client\Model\Order';
$request = $this->placeOrderRequest($order);
$request = $this->placeOrderRequest($order, $contentType);
return $this->client
->sendAsync($request, $this->createHttpClientOption())
@ -1090,11 +1112,12 @@ class StoreApi
* Create request for operation 'placeOrder'
*
* @param \OpenAPI\Client\Model\Order $order order placed for purchasing the pet (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['placeOrder'] to see the possible values for this operation
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Psr7\Request
*/
public function placeOrderRequest($order)
public function placeOrderRequest($order, string $contentType = self::contentTypes['placeOrder'][0])
{
// verify the required parameter 'order' is set
@ -1104,6 +1127,7 @@ class StoreApi
);
}
$resourcePath = '/store/order';
$formParams = [];
$queryParams = [];
@ -1115,20 +1139,16 @@ class StoreApi
if ($multipart) {
$headers = $this->headerSelector->selectHeadersForMultipart(
['application/xml', 'application/json']
);
} else {
$headers = $this->headerSelector->selectHeaders(
['application/xml', 'application/json'],
['application/json']
['application/xml', 'application/json', ],
$contentType,
$multipart
);
}
// for model (json/xml)
if (isset($order)) {
if ($headers['Content-Type'] === 'application/json') {
if (stripos($headers['Content-Type'], 'application/json') !== false) {
# if Content-Type contains "application/json", json_encode the body
$httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($order));
} else {
$httpBody = $order;
@ -1148,9 +1168,9 @@ class StoreApi
// for HTTP post (form)
$httpBody = new MultipartStream($multipartContents);
} elseif ($headers['Content-Type'] === 'application/json') {
} elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
# if Content-Type contains "application/json", json_encode the form parameters
$httpBody = \GuzzleHttp\json_encode($formParams);
} else {
// for HTTP post (form)
$httpBody = ObjectSerializer::buildQuery($formParams);

View File

@ -69,6 +69,34 @@ class UserApi
*/
protected $hostIndex;
/** @var string[] $contentTypes **/
public const contentTypes = [
'createUser' => [
'application/json',
],
'createUsersWithArrayInput' => [
'application/json',
],
'createUsersWithListInput' => [
'application/json',
],
'deleteUser' => [
'application/json',
],
'getUserByName' => [
'application/json',
],
'loginUser' => [
'application/json',
],
'logoutUser' => [
'application/json',
],
'updateUser' => [
'application/json',
],
];
/**
* @param ClientInterface $client
* @param Configuration $config
@ -121,14 +149,15 @@ class UserApi
* Create user
*
* @param \OpenAPI\Client\Model\User $user Created user object (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['createUser'] to see the possible values for this operation
*
* @throws \OpenAPI\Client\ApiException on non-2xx response
* @throws \InvalidArgumentException
* @return void
*/
public function createUser($user)
public function createUser($user, string $contentType = self::contentTypes['createUser'][0])
{
$this->createUserWithHttpInfo($user);
$this->createUserWithHttpInfo($user, $contentType);
}
/**
@ -137,14 +166,15 @@ class UserApi
* Create user
*
* @param \OpenAPI\Client\Model\User $user Created user object (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['createUser'] to see the possible values for this operation
*
* @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 createUserWithHttpInfo($user)
public function createUserWithHttpInfo($user, string $contentType = self::contentTypes['createUser'][0])
{
$request = $this->createUserRequest($user);
$request = $this->createUserRequest($user, $contentType);
try {
$options = $this->createHttpClientOption();
@ -196,13 +226,14 @@ class UserApi
* Create user
*
* @param \OpenAPI\Client\Model\User $user Created user object (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['createUser'] to see the possible values for this operation
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Promise\PromiseInterface
*/
public function createUserAsync($user)
public function createUserAsync($user, string $contentType = self::contentTypes['createUser'][0])
{
return $this->createUserAsyncWithHttpInfo($user)
return $this->createUserAsyncWithHttpInfo($user, $contentType)
->then(
function ($response) {
return $response[0];
@ -216,14 +247,15 @@ class UserApi
* Create user
*
* @param \OpenAPI\Client\Model\User $user Created user object (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['createUser'] to see the possible values for this operation
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Promise\PromiseInterface
*/
public function createUserAsyncWithHttpInfo($user)
public function createUserAsyncWithHttpInfo($user, string $contentType = self::contentTypes['createUser'][0])
{
$returnType = '';
$request = $this->createUserRequest($user);
$request = $this->createUserRequest($user, $contentType);
return $this->client
->sendAsync($request, $this->createHttpClientOption())
@ -252,11 +284,12 @@ class UserApi
* Create request for operation 'createUser'
*
* @param \OpenAPI\Client\Model\User $user Created user object (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['createUser'] to see the possible values for this operation
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Psr7\Request
*/
public function createUserRequest($user)
public function createUserRequest($user, string $contentType = self::contentTypes['createUser'][0])
{
// verify the required parameter 'user' is set
@ -266,6 +299,7 @@ class UserApi
);
}
$resourcePath = '/user';
$formParams = [];
$queryParams = [];
@ -277,20 +311,16 @@ class UserApi
if ($multipart) {
$headers = $this->headerSelector->selectHeadersForMultipart(
[]
);
} else {
$headers = $this->headerSelector->selectHeaders(
[],
['application/json']
$contentType,
$multipart
);
}
// for model (json/xml)
if (isset($user)) {
if ($headers['Content-Type'] === 'application/json') {
if (stripos($headers['Content-Type'], 'application/json') !== false) {
# if Content-Type contains "application/json", json_encode the body
$httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($user));
} else {
$httpBody = $user;
@ -310,9 +340,9 @@ class UserApi
// for HTTP post (form)
$httpBody = new MultipartStream($multipartContents);
} elseif ($headers['Content-Type'] === 'application/json') {
} elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
# if Content-Type contains "application/json", json_encode the form parameters
$httpBody = \GuzzleHttp\json_encode($formParams);
} else {
// for HTTP post (form)
$httpBody = ObjectSerializer::buildQuery($formParams);
@ -347,14 +377,15 @@ class UserApi
* Creates list of users with given input array
*
* @param \OpenAPI\Client\Model\User[] $user List of user object (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['createUsersWithArrayInput'] to see the possible values for this operation
*
* @throws \OpenAPI\Client\ApiException on non-2xx response
* @throws \InvalidArgumentException
* @return void
*/
public function createUsersWithArrayInput($user)
public function createUsersWithArrayInput($user, string $contentType = self::contentTypes['createUsersWithArrayInput'][0])
{
$this->createUsersWithArrayInputWithHttpInfo($user);
$this->createUsersWithArrayInputWithHttpInfo($user, $contentType);
}
/**
@ -363,14 +394,15 @@ class UserApi
* Creates list of users with given input array
*
* @param \OpenAPI\Client\Model\User[] $user List of user object (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['createUsersWithArrayInput'] to see the possible values for this operation
*
* @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 createUsersWithArrayInputWithHttpInfo($user)
public function createUsersWithArrayInputWithHttpInfo($user, string $contentType = self::contentTypes['createUsersWithArrayInput'][0])
{
$request = $this->createUsersWithArrayInputRequest($user);
$request = $this->createUsersWithArrayInputRequest($user, $contentType);
try {
$options = $this->createHttpClientOption();
@ -422,13 +454,14 @@ class UserApi
* Creates list of users with given input array
*
* @param \OpenAPI\Client\Model\User[] $user List of user object (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['createUsersWithArrayInput'] to see the possible values for this operation
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Promise\PromiseInterface
*/
public function createUsersWithArrayInputAsync($user)
public function createUsersWithArrayInputAsync($user, string $contentType = self::contentTypes['createUsersWithArrayInput'][0])
{
return $this->createUsersWithArrayInputAsyncWithHttpInfo($user)
return $this->createUsersWithArrayInputAsyncWithHttpInfo($user, $contentType)
->then(
function ($response) {
return $response[0];
@ -442,14 +475,15 @@ class UserApi
* Creates list of users with given input array
*
* @param \OpenAPI\Client\Model\User[] $user List of user object (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['createUsersWithArrayInput'] to see the possible values for this operation
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Promise\PromiseInterface
*/
public function createUsersWithArrayInputAsyncWithHttpInfo($user)
public function createUsersWithArrayInputAsyncWithHttpInfo($user, string $contentType = self::contentTypes['createUsersWithArrayInput'][0])
{
$returnType = '';
$request = $this->createUsersWithArrayInputRequest($user);
$request = $this->createUsersWithArrayInputRequest($user, $contentType);
return $this->client
->sendAsync($request, $this->createHttpClientOption())
@ -478,11 +512,12 @@ class UserApi
* Create request for operation 'createUsersWithArrayInput'
*
* @param \OpenAPI\Client\Model\User[] $user List of user object (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['createUsersWithArrayInput'] to see the possible values for this operation
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Psr7\Request
*/
public function createUsersWithArrayInputRequest($user)
public function createUsersWithArrayInputRequest($user, string $contentType = self::contentTypes['createUsersWithArrayInput'][0])
{
// verify the required parameter 'user' is set
@ -492,6 +527,7 @@ class UserApi
);
}
$resourcePath = '/user/createWithArray';
$formParams = [];
$queryParams = [];
@ -503,20 +539,16 @@ class UserApi
if ($multipart) {
$headers = $this->headerSelector->selectHeadersForMultipart(
[]
);
} else {
$headers = $this->headerSelector->selectHeaders(
[],
['application/json']
$contentType,
$multipart
);
}
// for model (json/xml)
if (isset($user)) {
if ($headers['Content-Type'] === 'application/json') {
if (stripos($headers['Content-Type'], 'application/json') !== false) {
# if Content-Type contains "application/json", json_encode the body
$httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($user));
} else {
$httpBody = $user;
@ -536,9 +568,9 @@ class UserApi
// for HTTP post (form)
$httpBody = new MultipartStream($multipartContents);
} elseif ($headers['Content-Type'] === 'application/json') {
} elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
# if Content-Type contains "application/json", json_encode the form parameters
$httpBody = \GuzzleHttp\json_encode($formParams);
} else {
// for HTTP post (form)
$httpBody = ObjectSerializer::buildQuery($formParams);
@ -573,14 +605,15 @@ class UserApi
* Creates list of users with given input array
*
* @param \OpenAPI\Client\Model\User[] $user List of user object (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['createUsersWithListInput'] to see the possible values for this operation
*
* @throws \OpenAPI\Client\ApiException on non-2xx response
* @throws \InvalidArgumentException
* @return void
*/
public function createUsersWithListInput($user)
public function createUsersWithListInput($user, string $contentType = self::contentTypes['createUsersWithListInput'][0])
{
$this->createUsersWithListInputWithHttpInfo($user);
$this->createUsersWithListInputWithHttpInfo($user, $contentType);
}
/**
@ -589,14 +622,15 @@ class UserApi
* Creates list of users with given input array
*
* @param \OpenAPI\Client\Model\User[] $user List of user object (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['createUsersWithListInput'] to see the possible values for this operation
*
* @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 createUsersWithListInputWithHttpInfo($user)
public function createUsersWithListInputWithHttpInfo($user, string $contentType = self::contentTypes['createUsersWithListInput'][0])
{
$request = $this->createUsersWithListInputRequest($user);
$request = $this->createUsersWithListInputRequest($user, $contentType);
try {
$options = $this->createHttpClientOption();
@ -648,13 +682,14 @@ class UserApi
* Creates list of users with given input array
*
* @param \OpenAPI\Client\Model\User[] $user List of user object (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['createUsersWithListInput'] to see the possible values for this operation
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Promise\PromiseInterface
*/
public function createUsersWithListInputAsync($user)
public function createUsersWithListInputAsync($user, string $contentType = self::contentTypes['createUsersWithListInput'][0])
{
return $this->createUsersWithListInputAsyncWithHttpInfo($user)
return $this->createUsersWithListInputAsyncWithHttpInfo($user, $contentType)
->then(
function ($response) {
return $response[0];
@ -668,14 +703,15 @@ class UserApi
* Creates list of users with given input array
*
* @param \OpenAPI\Client\Model\User[] $user List of user object (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['createUsersWithListInput'] to see the possible values for this operation
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Promise\PromiseInterface
*/
public function createUsersWithListInputAsyncWithHttpInfo($user)
public function createUsersWithListInputAsyncWithHttpInfo($user, string $contentType = self::contentTypes['createUsersWithListInput'][0])
{
$returnType = '';
$request = $this->createUsersWithListInputRequest($user);
$request = $this->createUsersWithListInputRequest($user, $contentType);
return $this->client
->sendAsync($request, $this->createHttpClientOption())
@ -704,11 +740,12 @@ class UserApi
* Create request for operation 'createUsersWithListInput'
*
* @param \OpenAPI\Client\Model\User[] $user List of user object (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['createUsersWithListInput'] to see the possible values for this operation
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Psr7\Request
*/
public function createUsersWithListInputRequest($user)
public function createUsersWithListInputRequest($user, string $contentType = self::contentTypes['createUsersWithListInput'][0])
{
// verify the required parameter 'user' is set
@ -718,6 +755,7 @@ class UserApi
);
}
$resourcePath = '/user/createWithList';
$formParams = [];
$queryParams = [];
@ -729,20 +767,16 @@ class UserApi
if ($multipart) {
$headers = $this->headerSelector->selectHeadersForMultipart(
[]
);
} else {
$headers = $this->headerSelector->selectHeaders(
[],
['application/json']
$contentType,
$multipart
);
}
// for model (json/xml)
if (isset($user)) {
if ($headers['Content-Type'] === 'application/json') {
if (stripos($headers['Content-Type'], 'application/json') !== false) {
# if Content-Type contains "application/json", json_encode the body
$httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($user));
} else {
$httpBody = $user;
@ -762,9 +796,9 @@ class UserApi
// for HTTP post (form)
$httpBody = new MultipartStream($multipartContents);
} elseif ($headers['Content-Type'] === 'application/json') {
} elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
# if Content-Type contains "application/json", json_encode the form parameters
$httpBody = \GuzzleHttp\json_encode($formParams);
} else {
// for HTTP post (form)
$httpBody = ObjectSerializer::buildQuery($formParams);
@ -799,14 +833,15 @@ class UserApi
* Delete user
*
* @param string $username The name that needs to be deleted (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['deleteUser'] to see the possible values for this operation
*
* @throws \OpenAPI\Client\ApiException on non-2xx response
* @throws \InvalidArgumentException
* @return void
*/
public function deleteUser($username)
public function deleteUser($username, string $contentType = self::contentTypes['deleteUser'][0])
{
$this->deleteUserWithHttpInfo($username);
$this->deleteUserWithHttpInfo($username, $contentType);
}
/**
@ -815,14 +850,15 @@ class UserApi
* Delete user
*
* @param string $username The name that needs to be deleted (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['deleteUser'] to see the possible values for this operation
*
* @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 deleteUserWithHttpInfo($username)
public function deleteUserWithHttpInfo($username, string $contentType = self::contentTypes['deleteUser'][0])
{
$request = $this->deleteUserRequest($username);
$request = $this->deleteUserRequest($username, $contentType);
try {
$options = $this->createHttpClientOption();
@ -874,13 +910,14 @@ class UserApi
* Delete user
*
* @param string $username The name that needs to be deleted (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['deleteUser'] to see the possible values for this operation
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Promise\PromiseInterface
*/
public function deleteUserAsync($username)
public function deleteUserAsync($username, string $contentType = self::contentTypes['deleteUser'][0])
{
return $this->deleteUserAsyncWithHttpInfo($username)
return $this->deleteUserAsyncWithHttpInfo($username, $contentType)
->then(
function ($response) {
return $response[0];
@ -894,14 +931,15 @@ class UserApi
* Delete user
*
* @param string $username The name that needs to be deleted (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['deleteUser'] to see the possible values for this operation
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Promise\PromiseInterface
*/
public function deleteUserAsyncWithHttpInfo($username)
public function deleteUserAsyncWithHttpInfo($username, string $contentType = self::contentTypes['deleteUser'][0])
{
$returnType = '';
$request = $this->deleteUserRequest($username);
$request = $this->deleteUserRequest($username, $contentType);
return $this->client
->sendAsync($request, $this->createHttpClientOption())
@ -930,11 +968,12 @@ class UserApi
* Create request for operation 'deleteUser'
*
* @param string $username The name that needs to be deleted (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['deleteUser'] to see the possible values for this operation
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Psr7\Request
*/
public function deleteUserRequest($username)
public function deleteUserRequest($username, string $contentType = self::contentTypes['deleteUser'][0])
{
// verify the required parameter 'username' is set
@ -944,6 +983,7 @@ class UserApi
);
}
$resourcePath = '/user/{username}';
$formParams = [];
$queryParams = [];
@ -963,16 +1003,11 @@ class UserApi
}
if ($multipart) {
$headers = $this->headerSelector->selectHeadersForMultipart(
[]
);
} else {
$headers = $this->headerSelector->selectHeaders(
[],
[]
$contentType,
$multipart
);
}
// for model (json/xml)
if (count($formParams) > 0) {
@ -990,9 +1025,9 @@ class UserApi
// for HTTP post (form)
$httpBody = new MultipartStream($multipartContents);
} elseif ($headers['Content-Type'] === 'application/json') {
} elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
# if Content-Type contains "application/json", json_encode the form parameters
$httpBody = \GuzzleHttp\json_encode($formParams);
} else {
// for HTTP post (form)
$httpBody = ObjectSerializer::buildQuery($formParams);
@ -1027,14 +1062,15 @@ class UserApi
* Get user by user name
*
* @param string $username The name that needs to be fetched. Use user1 for testing. (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['getUserByName'] to see the possible values for this operation
*
* @throws \OpenAPI\Client\ApiException on non-2xx response
* @throws \InvalidArgumentException
* @return \OpenAPI\Client\Model\User
*/
public function getUserByName($username)
public function getUserByName($username, string $contentType = self::contentTypes['getUserByName'][0])
{
list($response) = $this->getUserByNameWithHttpInfo($username);
list($response) = $this->getUserByNameWithHttpInfo($username, $contentType);
return $response;
}
@ -1044,14 +1080,15 @@ class UserApi
* Get user by user name
*
* @param string $username The name that needs to be fetched. Use user1 for testing. (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['getUserByName'] to see the possible values for this operation
*
* @throws \OpenAPI\Client\ApiException on non-2xx response
* @throws \InvalidArgumentException
* @return array of \OpenAPI\Client\Model\User, HTTP status code, HTTP response headers (array of strings)
*/
public function getUserByNameWithHttpInfo($username)
public function getUserByNameWithHttpInfo($username, string $contentType = self::contentTypes['getUserByName'][0])
{
$request = $this->getUserByNameRequest($username);
$request = $this->getUserByNameRequest($username, $contentType);
try {
$options = $this->createHttpClientOption();
@ -1143,13 +1180,14 @@ class UserApi
* Get user by user name
*
* @param string $username The name that needs to be fetched. Use user1 for testing. (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['getUserByName'] to see the possible values for this operation
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Promise\PromiseInterface
*/
public function getUserByNameAsync($username)
public function getUserByNameAsync($username, string $contentType = self::contentTypes['getUserByName'][0])
{
return $this->getUserByNameAsyncWithHttpInfo($username)
return $this->getUserByNameAsyncWithHttpInfo($username, $contentType)
->then(
function ($response) {
return $response[0];
@ -1163,14 +1201,15 @@ class UserApi
* Get user by user name
*
* @param string $username The name that needs to be fetched. Use user1 for testing. (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['getUserByName'] to see the possible values for this operation
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Promise\PromiseInterface
*/
public function getUserByNameAsyncWithHttpInfo($username)
public function getUserByNameAsyncWithHttpInfo($username, string $contentType = self::contentTypes['getUserByName'][0])
{
$returnType = '\OpenAPI\Client\Model\User';
$request = $this->getUserByNameRequest($username);
$request = $this->getUserByNameRequest($username, $contentType);
return $this->client
->sendAsync($request, $this->createHttpClientOption())
@ -1212,11 +1251,12 @@ class UserApi
* Create request for operation 'getUserByName'
*
* @param string $username The name that needs to be fetched. Use user1 for testing. (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['getUserByName'] to see the possible values for this operation
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Psr7\Request
*/
public function getUserByNameRequest($username)
public function getUserByNameRequest($username, string $contentType = self::contentTypes['getUserByName'][0])
{
// verify the required parameter 'username' is set
@ -1226,6 +1266,7 @@ class UserApi
);
}
$resourcePath = '/user/{username}';
$formParams = [];
$queryParams = [];
@ -1245,16 +1286,11 @@ class UserApi
}
if ($multipart) {
$headers = $this->headerSelector->selectHeadersForMultipart(
['application/xml', 'application/json']
);
} else {
$headers = $this->headerSelector->selectHeaders(
['application/xml', 'application/json'],
[]
['application/xml', 'application/json', ],
$contentType,
$multipart
);
}
// for model (json/xml)
if (count($formParams) > 0) {
@ -1272,9 +1308,9 @@ class UserApi
// for HTTP post (form)
$httpBody = new MultipartStream($multipartContents);
} elseif ($headers['Content-Type'] === 'application/json') {
} elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
# if Content-Type contains "application/json", json_encode the form parameters
$httpBody = \GuzzleHttp\json_encode($formParams);
} else {
// for HTTP post (form)
$httpBody = ObjectSerializer::buildQuery($formParams);
@ -1310,14 +1346,15 @@ class UserApi
*
* @param string $username The user name for login (required)
* @param string $password The password for login in clear text (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['loginUser'] to see the possible values for this operation
*
* @throws \OpenAPI\Client\ApiException on non-2xx response
* @throws \InvalidArgumentException
* @return string
*/
public function loginUser($username, $password)
public function loginUser($username, $password, string $contentType = self::contentTypes['loginUser'][0])
{
list($response) = $this->loginUserWithHttpInfo($username, $password);
list($response) = $this->loginUserWithHttpInfo($username, $password, $contentType);
return $response;
}
@ -1328,14 +1365,15 @@ class UserApi
*
* @param string $username The user name for login (required)
* @param string $password The password for login in clear text (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['loginUser'] to see the possible values for this operation
*
* @throws \OpenAPI\Client\ApiException on non-2xx response
* @throws \InvalidArgumentException
* @return array of string, HTTP status code, HTTP response headers (array of strings)
*/
public function loginUserWithHttpInfo($username, $password)
public function loginUserWithHttpInfo($username, $password, string $contentType = self::contentTypes['loginUser'][0])
{
$request = $this->loginUserRequest($username, $password);
$request = $this->loginUserRequest($username, $password, $contentType);
try {
$options = $this->createHttpClientOption();
@ -1428,13 +1466,14 @@ class UserApi
*
* @param string $username The user name for login (required)
* @param string $password The password for login in clear text (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['loginUser'] to see the possible values for this operation
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Promise\PromiseInterface
*/
public function loginUserAsync($username, $password)
public function loginUserAsync($username, $password, string $contentType = self::contentTypes['loginUser'][0])
{
return $this->loginUserAsyncWithHttpInfo($username, $password)
return $this->loginUserAsyncWithHttpInfo($username, $password, $contentType)
->then(
function ($response) {
return $response[0];
@ -1449,14 +1488,15 @@ class UserApi
*
* @param string $username The user name for login (required)
* @param string $password The password for login in clear text (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['loginUser'] to see the possible values for this operation
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Promise\PromiseInterface
*/
public function loginUserAsyncWithHttpInfo($username, $password)
public function loginUserAsyncWithHttpInfo($username, $password, string $contentType = self::contentTypes['loginUser'][0])
{
$returnType = 'string';
$request = $this->loginUserRequest($username, $password);
$request = $this->loginUserRequest($username, $password, $contentType);
return $this->client
->sendAsync($request, $this->createHttpClientOption())
@ -1499,11 +1539,12 @@ class UserApi
*
* @param string $username The user name for login (required)
* @param string $password The password for login in clear text (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['loginUser'] to see the possible values for this operation
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Psr7\Request
*/
public function loginUserRequest($username, $password)
public function loginUserRequest($username, $password, string $contentType = self::contentTypes['loginUser'][0])
{
// verify the required parameter 'username' is set
@ -1520,6 +1561,7 @@ class UserApi
);
}
$resourcePath = '/user/login';
$formParams = [];
$queryParams = [];
@ -1549,16 +1591,11 @@ class UserApi
if ($multipart) {
$headers = $this->headerSelector->selectHeadersForMultipart(
['application/xml', 'application/json']
);
} else {
$headers = $this->headerSelector->selectHeaders(
['application/xml', 'application/json'],
[]
['application/xml', 'application/json', ],
$contentType,
$multipart
);
}
// for model (json/xml)
if (count($formParams) > 0) {
@ -1576,9 +1613,9 @@ class UserApi
// for HTTP post (form)
$httpBody = new MultipartStream($multipartContents);
} elseif ($headers['Content-Type'] === 'application/json') {
} elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
# if Content-Type contains "application/json", json_encode the form parameters
$httpBody = \GuzzleHttp\json_encode($formParams);
} else {
// for HTTP post (form)
$httpBody = ObjectSerializer::buildQuery($formParams);
@ -1612,14 +1649,15 @@ class UserApi
*
* Logs out current logged in user session
*
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['logoutUser'] to see the possible values for this operation
*
* @throws \OpenAPI\Client\ApiException on non-2xx response
* @throws \InvalidArgumentException
* @return void
*/
public function logoutUser()
public function logoutUser(string $contentType = self::contentTypes['logoutUser'][0])
{
$this->logoutUserWithHttpInfo();
$this->logoutUserWithHttpInfo($contentType);
}
/**
@ -1627,14 +1665,15 @@ class UserApi
*
* Logs out current logged in user session
*
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['logoutUser'] to see the possible values for this operation
*
* @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 logoutUserWithHttpInfo()
public function logoutUserWithHttpInfo(string $contentType = self::contentTypes['logoutUser'][0])
{
$request = $this->logoutUserRequest();
$request = $this->logoutUserRequest($contentType);
try {
$options = $this->createHttpClientOption();
@ -1685,13 +1724,14 @@ class UserApi
*
* Logs out current logged in user session
*
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['logoutUser'] to see the possible values for this operation
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Promise\PromiseInterface
*/
public function logoutUserAsync()
public function logoutUserAsync(string $contentType = self::contentTypes['logoutUser'][0])
{
return $this->logoutUserAsyncWithHttpInfo()
return $this->logoutUserAsyncWithHttpInfo($contentType)
->then(
function ($response) {
return $response[0];
@ -1704,14 +1744,15 @@ class UserApi
*
* Logs out current logged in user session
*
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['logoutUser'] to see the possible values for this operation
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Promise\PromiseInterface
*/
public function logoutUserAsyncWithHttpInfo()
public function logoutUserAsyncWithHttpInfo(string $contentType = self::contentTypes['logoutUser'][0])
{
$returnType = '';
$request = $this->logoutUserRequest();
$request = $this->logoutUserRequest($contentType);
return $this->client
->sendAsync($request, $this->createHttpClientOption())
@ -1739,13 +1780,15 @@ class UserApi
/**
* Create request for operation 'logoutUser'
*
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['logoutUser'] to see the possible values for this operation
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Psr7\Request
*/
public function logoutUserRequest()
public function logoutUserRequest(string $contentType = self::contentTypes['logoutUser'][0])
{
$resourcePath = '/user/logout';
$formParams = [];
$queryParams = [];
@ -1757,16 +1800,11 @@ class UserApi
if ($multipart) {
$headers = $this->headerSelector->selectHeadersForMultipart(
[]
);
} else {
$headers = $this->headerSelector->selectHeaders(
[],
[]
$contentType,
$multipart
);
}
// for model (json/xml)
if (count($formParams) > 0) {
@ -1784,9 +1822,9 @@ class UserApi
// for HTTP post (form)
$httpBody = new MultipartStream($multipartContents);
} elseif ($headers['Content-Type'] === 'application/json') {
} elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
# if Content-Type contains "application/json", json_encode the form parameters
$httpBody = \GuzzleHttp\json_encode($formParams);
} else {
// for HTTP post (form)
$httpBody = ObjectSerializer::buildQuery($formParams);
@ -1822,14 +1860,15 @@ class UserApi
*
* @param string $username name that need to be deleted (required)
* @param \OpenAPI\Client\Model\User $user Updated user object (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['updateUser'] to see the possible values for this operation
*
* @throws \OpenAPI\Client\ApiException on non-2xx response
* @throws \InvalidArgumentException
* @return void
*/
public function updateUser($username, $user)
public function updateUser($username, $user, string $contentType = self::contentTypes['updateUser'][0])
{
$this->updateUserWithHttpInfo($username, $user);
$this->updateUserWithHttpInfo($username, $user, $contentType);
}
/**
@ -1839,14 +1878,15 @@ class UserApi
*
* @param string $username name that need to be deleted (required)
* @param \OpenAPI\Client\Model\User $user Updated user object (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['updateUser'] to see the possible values for this operation
*
* @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 updateUserWithHttpInfo($username, $user)
public function updateUserWithHttpInfo($username, $user, string $contentType = self::contentTypes['updateUser'][0])
{
$request = $this->updateUserRequest($username, $user);
$request = $this->updateUserRequest($username, $user, $contentType);
try {
$options = $this->createHttpClientOption();
@ -1899,13 +1939,14 @@ class UserApi
*
* @param string $username name that need to be deleted (required)
* @param \OpenAPI\Client\Model\User $user Updated user object (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['updateUser'] to see the possible values for this operation
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Promise\PromiseInterface
*/
public function updateUserAsync($username, $user)
public function updateUserAsync($username, $user, string $contentType = self::contentTypes['updateUser'][0])
{
return $this->updateUserAsyncWithHttpInfo($username, $user)
return $this->updateUserAsyncWithHttpInfo($username, $user, $contentType)
->then(
function ($response) {
return $response[0];
@ -1920,14 +1961,15 @@ class UserApi
*
* @param string $username name that need to be deleted (required)
* @param \OpenAPI\Client\Model\User $user Updated user object (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['updateUser'] to see the possible values for this operation
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Promise\PromiseInterface
*/
public function updateUserAsyncWithHttpInfo($username, $user)
public function updateUserAsyncWithHttpInfo($username, $user, string $contentType = self::contentTypes['updateUser'][0])
{
$returnType = '';
$request = $this->updateUserRequest($username, $user);
$request = $this->updateUserRequest($username, $user, $contentType);
return $this->client
->sendAsync($request, $this->createHttpClientOption())
@ -1957,11 +1999,12 @@ class UserApi
*
* @param string $username name that need to be deleted (required)
* @param \OpenAPI\Client\Model\User $user Updated user object (required)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['updateUser'] to see the possible values for this operation
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Psr7\Request
*/
public function updateUserRequest($username, $user)
public function updateUserRequest($username, $user, string $contentType = self::contentTypes['updateUser'][0])
{
// verify the required parameter 'username' is set
@ -1978,6 +2021,7 @@ class UserApi
);
}
$resourcePath = '/user/{username}';
$formParams = [];
$queryParams = [];
@ -1997,20 +2041,16 @@ class UserApi
}
if ($multipart) {
$headers = $this->headerSelector->selectHeadersForMultipart(
[]
);
} else {
$headers = $this->headerSelector->selectHeaders(
[],
['application/json']
$contentType,
$multipart
);
}
// for model (json/xml)
if (isset($user)) {
if ($headers['Content-Type'] === 'application/json') {
if (stripos($headers['Content-Type'], 'application/json') !== false) {
# if Content-Type contains "application/json", json_encode the body
$httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($user));
} else {
$httpBody = $user;
@ -2030,9 +2070,9 @@ class UserApi
// for HTTP post (form)
$httpBody = new MultipartStream($multipartContents);
} elseif ($headers['Content-Type'] === 'application/json') {
} elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
# if Content-Type contains "application/json", json_encode the form parameters
$httpBody = \GuzzleHttp\json_encode($formParams);
} else {
// for HTTP post (form)
$httpBody = ObjectSerializer::buildQuery($formParams);

View File

@ -1,6 +1,6 @@
<?php
/**
* ApiException
* HeaderSelector
* PHP version 7.4
*
* @category Class
@ -27,10 +27,8 @@
namespace OpenAPI\Client;
use \Exception;
/**
* ApiException Class Doc Comment
* HeaderSelector Class Doc Comment
*
* @category Class
* @package OpenAPI\Client
@ -41,10 +39,11 @@ class HeaderSelector
{
/**
* @param string[] $accept
* @param string[] $contentTypes
* @return array
* @param string $contentType
* @param bool $isMultipart
* @return string[]
*/
public function selectHeaders($accept, $contentTypes)
public function selectHeaders(array $accept, string $contentType, bool $isMultipart): array
{
$headers = [];
@ -52,20 +51,13 @@ class HeaderSelector
if ($accept !== null) {
$headers['Accept'] = $accept;
}
$headers['Content-Type'] = $this->selectContentTypeHeader($contentTypes);
return $headers;
if(!$isMultipart) {
if($contentType === '') {
$contentType = 'application/json';
}
$headers['Content-Type'] = $contentType;
}
/**
* @param string[] $accept
* @return array
*/
public function selectHeadersForMultipart($accept)
{
$headers = $this->selectHeaders($accept, []);
unset($headers['Content-Type']);
return $headers;
}
@ -86,22 +78,4 @@ class HeaderSelector
return implode(',', $accept);
}
}
/**
* Return the content type based on an array of content-type provided
*
* @param string[] $contentType Array fo content-type
*
* @return string Content-Type (e.g. application/json)
*/
private function selectContentTypeHeader($contentType)
{
if (count($contentType) === 0 || (count($contentType) === 1 && $contentType[0] === '')) {
return 'application/json';
} elseif (preg_grep("/application\/json/i", $contentType)) {
return 'application/json';
} else {
return implode(',', $contentType);
}
}
}

View File

@ -1,58 +1,70 @@
<?php
namespace OpenAPI\Client;
use PHPUnit\Framework\TestCase;
/**
* class HeaderSelectorTest
*
* @package OpenAPI\Client
*/
class HeaderSelectorTest extends TestCase
{
public function testSelectingHeaders()
/**
* @dataProvider headersProvider
* @param string[] $accept
* @param string $contentType
* @param bool $isMultiple
* @param string[] $expectedHeaders
*/
public function testSelectHeaders(array $accept, string $contentType, bool $isMultiple, array $expectedHeaders): void
{
$selector = new HeaderSelector();
$headers = $selector->selectHeaders([
'application/xml',
'application/json'
], []);
$this->assertSame('application/json', $headers['Accept']);
$headers = $selector->selectHeaders([], []);
$this->assertArrayNotHasKey('Accept', $headers);
$header = $selector->selectHeaders([
'application/yaml',
'application/xml'
], []);
$this->assertSame('application/yaml,application/xml', $header['Accept']);
// test selectHeaderContentType
$headers = $selector->selectHeaders([], [
'application/xml',
'application/json'
]);
$this->assertSame('application/json', $headers['Content-Type']);
$headers = $selector->selectHeaders([], []);
$this->assertSame('application/json', $headers['Content-Type']);
$headers = $selector->selectHeaders([], [
'application/yaml',
'application/xml'
]);
$this->assertSame('application/yaml,application/xml', $headers['Content-Type']);
$headers = $selector->selectHeaders($accept, $contentType, $isMultiple);
$this->assertEquals($expectedHeaders, $headers);
}
public function testSelectingHeadersForMultipartBody()
/**
* @return array[][]
*/
public function headersProvider(): array
{
// test selectHeaderAccept
$selector = new HeaderSelector();
$headers = $selector->selectHeadersForMultipart([
'application/xml',
'application/json'
]);
$this->assertSame('application/json', $headers['Accept']);
$this->assertArrayNotHasKey('Content-Type', $headers);
$headers = $selector->selectHeadersForMultipart([]);
$this->assertArrayNotHasKey('Accept', $headers);
$this->assertArrayNotHasKey('Content-Type', $headers);
return [
// array $accept, string $contentType, bool $isMultipart, array $expectedHeaders
[
[], 'application/xml', false, ['Content-Type' => 'application/xml'],
],
[
[], 'application/xml', true, [],
],
[
['application/xml'], '', false, ['Accept' => 'application/xml', 'Content-Type' => 'application/json'],
],
[
['application/xml'], '', true, ['Accept' => 'application/xml'],
],
[
['application/xml'], 'application/xml', false, ['Accept' => 'application/xml', 'Content-Type' => 'application/xml'],
],
[
['application/xml'], 'application/xml', true, ['Accept' => 'application/xml'],
],
[
['application/xml', 'text/html'], 'application/xml', false, ['Accept' => 'application/xml,text/html', 'Content-Type' => 'application/xml'],
],
[
['application/json', 'text/html'], 'application/xml', false, ['Accept' => 'application/json', 'Content-Type' => 'application/xml'],
],
[
['text/html', 'application/json'], 'application/xml', false, ['Accept' => 'application/json', 'Content-Type' => 'application/xml'],
],
[
['application/json;format=flowed'], 'text/plain;format=fixed', false, ['Accept' => 'application/json;format=flowed', 'Content-Type' => 'text/plain;format=fixed'],
],
[
['text/html', 'application/json;format=flowed'], 'text/plain;format=fixed', false, ['Accept' => 'application/json;format=flowed', 'Content-Type' => 'text/plain;format=fixed'],
],
];
}
}