Better logic to handle tags with special characters (#6466)

* better logic to handle tag with special characters

* update test cases

* comment out swift test cases

* restore the swift tests
This commit is contained in:
wing328
2017-09-12 11:41:14 +08:00
committed by GitHub
parent 9e0911b376
commit 591149bcb7
16 changed files with 736 additions and 40 deletions

View File

@@ -0,0 +1,309 @@
<?php
/**
* AnotherFakeApi
* PHP version 5
*
* @category Class
* @package Swagger\Client
* @author Swagger Codegen team
* @link https://github.com/swagger-api/swagger-codegen
*/
/**
* Swagger Petstore
*
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
*
* OpenAPI spec version: 1.0.0
* Contact: apiteam@swagger.io
* Generated by: https://github.com/swagger-api/swagger-codegen.git
*
*/
/**
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen
* Do not edit the class manually.
*/
namespace Swagger\Client\Api;
use GuzzleHttp\Client;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Psr7\MultipartStream;
use GuzzleHttp\Psr7\Request;
use Swagger\Client\ApiException;
use Swagger\Client\Configuration;
use Swagger\Client\HeaderSelector;
use Swagger\Client\ObjectSerializer;
/**
* AnotherFakeApi Class Doc Comment
*
* @category Class
* @package Swagger\Client
* @author Swagger Codegen team
* @link https://github.com/swagger-api/swagger-codegen
*/
class AnotherFakeApi
{
/**
* @var ClientInterface
*/
protected $client;
/**
* @var Configuration
*/
protected $config;
/**
* @param ClientInterface $client
* @param Configuration $config
* @param HeaderSelector $selector
*/
public function __construct(
ClientInterface $client = null,
Configuration $config = null,
HeaderSelector $selector = null
) {
$this->client = $client ?: new Client();
$this->config = $config ?: new Configuration();
$this->headerSelector = $selector ?: new HeaderSelector();
}
/**
* @return Configuration
*/
public function getConfig()
{
return $this->config;
}
/**
* Operation testSpecialTags
*
* To test special tags
*
* @param \Swagger\Client\Model\Client $body client model (required)
* @throws \Swagger\Client\ApiException on non-2xx response
* @throws \InvalidArgumentException
* @return \Swagger\Client\Model\Client
*/
public function testSpecialTags($body)
{
list($response) = $this->testSpecialTagsWithHttpInfo($body);
return $response;
}
/**
* Operation testSpecialTagsWithHttpInfo
*
* To test special tags
*
* @param \Swagger\Client\Model\Client $body client model (required)
* @throws \Swagger\Client\ApiException on non-2xx response
* @throws \InvalidArgumentException
* @return array of \Swagger\Client\Model\Client, HTTP status code, HTTP response headers (array of strings)
*/
public function testSpecialTagsWithHttpInfo($body)
{
$returnType = '\Swagger\Client\Model\Client';
$request = $this->testSpecialTagsRequest($body);
try {
try {
$response = $this->client->send($request);
} catch (RequestException $e) {
throw new ApiException(
"[{$e->getCode()}] {$e->getMessage()}",
$e->getCode(),
$e->getResponse() ? $e->getResponse()->getHeaders() : null
);
}
$statusCode = $response->getStatusCode();
if ($statusCode < 200 || $statusCode > 299) {
throw new ApiException(
"[$statusCode] Error connecting to the API ({$request->getUri()})",
$statusCode,
$response->getHeaders(),
$response->getBody()
);
}
$responseBody = $response->getBody();
if ($returnType === '\SplFileObject') {
$content = $responseBody; //stream goes to serializer
} else {
$content = $responseBody->getContents();
if ($returnType !== 'string') {
$content = json_decode($content);
}
}
return [
ObjectSerializer::deserialize($content, $returnType, []),
$response->getStatusCode(),
$response->getHeaders()
];
} catch (ApiException $e) {
switch ($e->getCode()) {
case 200:
$data = ObjectSerializer::deserialize($e->getResponseBody(), '\Swagger\Client\Model\Client', $e->getResponseHeaders());
$e->setResponseObject($data);
break;
}
throw $e;
}
}
/**
* Operation testSpecialTagsAsync
*
* To test special tags
*
* @param \Swagger\Client\Model\Client $body client model (required)
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Promise\PromiseInterface
*/
public function testSpecialTagsAsync($body)
{
return $this->testSpecialTagsAsyncWithHttpInfo($body)->then(function ($response) {
return $response[0];
});
}
/**
* Operation testSpecialTagsAsyncWithHttpInfo
*
* To test special tags
*
* @param \Swagger\Client\Model\Client $body client model (required)
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Promise\PromiseInterface
*/
public function testSpecialTagsAsyncWithHttpInfo($body)
{
$returnType = '\Swagger\Client\Model\Client';
$request = $this->testSpecialTagsRequest($body);
return $this->client->sendAsync($request)->then(function ($response) use ($returnType) {
$responseBody = $response->getBody();
if ($returnType === '\SplFileObject') {
$content = $responseBody; //stream goes to serializer
} else {
$content = $responseBody->getContents();
if ($returnType !== 'string') {
$content = json_decode($content);
}
}
return [
ObjectSerializer::deserialize($content, $returnType, []),
$response->getStatusCode(),
$response->getHeaders()
];
}, function ($exception) {
$response = $exception->getResponse();
$statusCode = $response->getStatusCode();
throw new ApiException(
"[$statusCode] Error connecting to the API ({$exception->getRequest()->getUri()})",
$statusCode,
$response->getHeaders(),
$response->getBody()
);
});
}
/**
* Create request for operation 'testSpecialTags'
*
* @param \Swagger\Client\Model\Client $body client model (required)
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Psr7\Request
*/
protected function testSpecialTagsRequest($body)
{
// verify the required parameter 'body' is set
if ($body === null) {
throw new \InvalidArgumentException('Missing the required parameter $body when calling testSpecialTags');
}
$resourcePath = '/another-fake/dummy';
$formParams = [];
$queryParams = [];
$headerParams = [];
$httpBody = '';
$multipart = false;
// body params
$_tempBody = null;
if (isset($body)) {
$_tempBody = $body;
}
if ($multipart) {
$headers= $this->headerSelector->selectHeadersForMultipart(
['application/json']
);
} else {
$headers = $this->headerSelector->selectHeaders(
['application/json'],
['application/json']
);
}
// for model (json/xml)
if (isset($_tempBody)) {
$httpBody = $_tempBody; // $_tempBody is the method argument, if present
} elseif (count($formParams) > 0) {
if ($multipart) {
$multipartContents = [];
foreach ($formParams as $formParamName => $formParamValue) {
$multipartContents[] = [
'name' => $formParamName,
'contents' => $formParamValue
];
}
$httpBody = new MultipartStream($multipartContents); // for HTTP post (form)
} elseif ($headers['Content-Type'] === 'application/json') {
$httpBody = \GuzzleHttp\json_encode($formParams);
} else {
$httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form)
}
}
$query = \GuzzleHttp\Psr7\build_query($queryParams);
$url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : '');
$defaultHeaders = [];
if ($this->config->getUserAgent()) {
$defaultHeaders['User-Agent'] = $this->config->getUserAgent();
}
$headers = array_merge(
$defaultHeaders,
$headerParams,
$headers
);
return new Request(
'PATCH',
$url,
$headers,
$httpBody
);
}
}

View File

@@ -1,6 +1,6 @@
<?php
/**
* Fake_classname_tags123Api
* FakeClassnameTags123Api
* PHP version 5
*
* @category Class
@@ -39,14 +39,14 @@ use Swagger\Client\HeaderSelector;
use Swagger\Client\ObjectSerializer;
/**
* Fake_classname_tags123Api Class Doc Comment
* FakeClassnameTags123Api Class Doc Comment
*
* @category Class
* @package Swagger\Client
* @author Swagger Codegen team
* @link https://github.com/swagger-api/swagger-codegen
*/
class Fake_classname_tags123Api
class FakeClassnameTags123Api
{
/**
* @var ClientInterface