Merge pull request #22 from ackintosh/fix-yaml

Fix request content-type for '/fake/jsonFormData'
This commit is contained in:
William Cheng
2018-04-08 16:56:22 +08:00
committed by GitHub
8 changed files with 57 additions and 71 deletions

View File

@@ -848,7 +848,7 @@ paths:
description: successful operation
requestBody:
content:
application/x-www-form-urlencoded:
application/json:
schema:
type: object
properties:

View File

@@ -294,8 +294,8 @@ $int64 = 56; // int | None
$float = 3.4; // float | None
$string = "string_example"; // string | None
$binary = "binary_example"; // string | None
$date = "date_example"; // \DateTime | None
$date_time = "date_time_example"; // \DateTime | None
$date = new \DateTime("2013-10-20T19:20:30+01:00"); // \DateTime | None
$date_time = new \DateTime("2013-10-20T19:20:30+01:00"); // \DateTime | None
$password = "password_example"; // string | None
$callback = "callback_example"; // string | None
@@ -314,13 +314,13 @@ Name | Type | Description | Notes
**number** | **BigDecimal**| None |
**double** | **double**| None |
**pattern_without_delimiter** | **string**| None |
**byte** | **string**| None |
**byte** | **string****string**| None |
**integer** | **int**| None | [optional]
**int32** | **int**| None | [optional]
**int64** | **int**| None | [optional]
**float** | **float**| None | [optional]
**string** | **string**| None | [optional]
**binary** | **string**| None | [optional]
**binary** | **string****string**| None | [optional]
**date** | **\DateTime**| None | [optional]
**date_time** | **\DateTime**| None | [optional]
**password** | **string**| None | [optional]
@@ -450,7 +450,7 @@ No authorization required
[[Back to top]](#) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to Model list]](../../README.md#documentation-for-models) [[Back to README]](../../README.md)
# **testJsonFormData**
> testJsonFormData($param, $param2)
> testJsonFormData($body_4)
test json serialization of form data
@@ -464,11 +464,10 @@ $apiInstance = new Swagger\Client\Api\FakeApi(
// This is optional, `GuzzleHttp\Client` will be used as default.
new GuzzleHttp\Client()
);
$param = "param_example"; // string | field1
$param2 = "param2_example"; // string | field2
$body_4 = new \Swagger\Client\Model\Body4(); // \Swagger\Client\Model\Body4 |
try {
$apiInstance->testJsonFormData($param, $param2);
$apiInstance->testJsonFormData($body_4);
} catch (Exception $e) {
echo 'Exception when calling FakeApi->testJsonFormData: ', $e->getMessage(), PHP_EOL;
}
@@ -479,8 +478,7 @@ try {
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**param** | **string**| field1 |
**param2** | **string**| field2 |
**body_4** | [**\Swagger\Client\Model\Body4**](../Model/Body4.md)| | [optional]
### Return type
@@ -492,7 +490,7 @@ No authorization required
### HTTP request headers
- **Content-Type**: application/x-www-form-urlencoded
- **Content-Type**: application/json
- **Accept**: Not defined
[[Back to top]](#) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to Model list]](../../README.md#documentation-for-models) [[Back to README]](../../README.md)

View File

@@ -419,7 +419,7 @@ Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**pet_id** | **int**| ID of pet to update |
**additional_metadata** | **string**| Additional data to pass to server | [optional]
**file** | **string**| file to upload | [optional]
**file** | **string****string**| file to upload | [optional]
### Return type

View File

@@ -1641,11 +1641,13 @@ class FakeApi
}
// form params
if ($byte !== null) {
$formParams['byte'] = ObjectSerializer::toFormValue($byte);
$multipart = true;
$formParams['byte'] = \GuzzleHttp\Psr7\try_fopen(ObjectSerializer::toFormValue($byte), 'rb');
}
// form params
if ($binary !== null) {
$formParams['binary'] = ObjectSerializer::toFormValue($binary);
$multipart = true;
$formParams['binary'] = \GuzzleHttp\Psr7\try_fopen(ObjectSerializer::toFormValue($binary), 'rb');
}
// form params
if ($date !== null) {
@@ -2237,16 +2239,15 @@ class FakeApi
*
* test json serialization of form data
*
* @param string $param field1 (required)
* @param string $param2 field2 (required)
* @param \Swagger\Client\Model\Body4 $body_4 body_4 (optional)
*
* @throws \Swagger\Client\ApiException on non-2xx response
* @throws \InvalidArgumentException
* @return void
*/
public function testJsonFormData($param, $param2)
public function testJsonFormData($body_4 = null)
{
$this->testJsonFormDataWithHttpInfo($param, $param2);
$this->testJsonFormDataWithHttpInfo($body_4);
}
/**
@@ -2254,17 +2255,16 @@ class FakeApi
*
* test json serialization of form data
*
* @param string $param field1 (required)
* @param string $param2 field2 (required)
* @param \Swagger\Client\Model\Body4 $body_4 (optional)
*
* @throws \Swagger\Client\ApiException on non-2xx response
* @throws \InvalidArgumentException
* @return array of null, HTTP status code, HTTP response headers (array of strings)
*/
public function testJsonFormDataWithHttpInfo($param, $param2)
public function testJsonFormDataWithHttpInfo($body_4 = null)
{
$returnType = '';
$request = $this->testJsonFormDataRequest($param, $param2);
$request = $this->testJsonFormDataRequest($body_4);
try {
$options = $this->createHttpClientOption();
@@ -2308,15 +2308,14 @@ class FakeApi
*
* test json serialization of form data
*
* @param string $param field1 (required)
* @param string $param2 field2 (required)
* @param \Swagger\Client\Model\Body4 $body_4 (optional)
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Promise\PromiseInterface
*/
public function testJsonFormDataAsync($param, $param2)
public function testJsonFormDataAsync($body_4 = null)
{
return $this->testJsonFormDataAsyncWithHttpInfo($param, $param2)
return $this->testJsonFormDataAsyncWithHttpInfo($body_4)
->then(
function ($response) {
return $response[0];
@@ -2329,16 +2328,15 @@ class FakeApi
*
* test json serialization of form data
*
* @param string $param field1 (required)
* @param string $param2 field2 (required)
* @param \Swagger\Client\Model\Body4 $body_4 (optional)
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Promise\PromiseInterface
*/
public function testJsonFormDataAsyncWithHttpInfo($param, $param2)
public function testJsonFormDataAsyncWithHttpInfo($body_4 = null)
{
$returnType = '';
$request = $this->testJsonFormDataRequest($param, $param2);
$request = $this->testJsonFormDataRequest($body_4);
return $this->client
->sendAsync($request, $this->createHttpClientOption())
@@ -2366,26 +2364,13 @@ class FakeApi
/**
* Create request for operation 'testJsonFormData'
*
* @param string $param field1 (required)
* @param string $param2 field2 (required)
* @param \Swagger\Client\Model\Body4 $body_4 (optional)
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Psr7\Request
*/
protected function testJsonFormDataRequest($param, $param2)
protected function testJsonFormDataRequest($body_4 = null)
{
// verify the required parameter 'param' is set
if ($param === null || (is_array($param) && count($param) === 0)) {
throw new \InvalidArgumentException(
'Missing the required parameter $param when calling testJsonFormData'
);
}
// verify the required parameter 'param2' is set
if ($param2 === null || (is_array($param2) && count($param2) === 0)) {
throw new \InvalidArgumentException(
'Missing the required parameter $param2 when calling testJsonFormData'
);
}
$resourcePath = '/fake/jsonFormData';
$formParams = [];
@@ -2396,16 +2381,11 @@ class FakeApi
// form params
if ($param !== null) {
$formParams['param'] = ObjectSerializer::toFormValue($param);
}
// form params
if ($param2 !== null) {
$formParams['param2'] = ObjectSerializer::toFormValue($param2);
}
// body params
$_tempBody = null;
if (isset($body_4)) {
$_tempBody = $body_4;
}
if ($multipart) {
$headers = $this->headerSelector->selectHeadersForMultipart(
@@ -2414,7 +2394,7 @@ class FakeApi
} else {
$headers = $this->headerSelector->selectHeaders(
[],
['application/x-www-form-urlencoded']
['application/json']
);
}

View File

@@ -2031,7 +2031,8 @@ class PetApi
}
// form params
if ($file !== null) {
$formParams['file'] = ObjectSerializer::toFormValue($file);
$multipart = true;
$formParams['file'] = \GuzzleHttp\Psr7\try_fopen(ObjectSerializer::toFormValue($file), 'rb');
}
// body params
$_tempBody = null;

View File

@@ -295,11 +295,11 @@ class Body3 implements ModelInterface, ArrayAccess
if ($this->container['byte'] === null) {
$invalidProperties[] = "'byte' can't be null";
}
if (!is_null($this->container['password']) && (strlen($this->container['password']) > 64)) {
if (!is_null($this->container['password']) && (mb_strlen($this->container['password']) > 64)) {
$invalidProperties[] = "invalid value for 'password', the character length must be smaller than or equal to 64.";
}
if (!is_null($this->container['password']) && (strlen($this->container['password']) < 10)) {
if (!is_null($this->container['password']) && (mb_strlen($this->container['password']) < 10)) {
$invalidProperties[] = "invalid value for 'password', the character length must be bigger than or equal to 10.";
}
@@ -339,10 +339,10 @@ class Body3 implements ModelInterface, ArrayAccess
if ($this->container['byte'] === null) {
return false;
}
if (strlen($this->container['password']) > 64) {
if (mb_strlen($this->container['password']) > 64) {
return false;
}
if (strlen($this->container['password']) < 10) {
if (mb_strlen($this->container['password']) < 10) {
return false;
}
return true;
@@ -672,10 +672,10 @@ class Body3 implements ModelInterface, ArrayAccess
*/
public function setPassword($password)
{
if (!is_null($password) && (strlen($password) > 64)) {
if (!is_null($password) && (mb_strlen($password) > 64)) {
throw new \InvalidArgumentException('invalid length for $password when calling Body3., must be smaller than or equal to 64.');
}
if (!is_null($password) && (strlen($password) < 10)) {
if (!is_null($password) && (mb_strlen($password) < 10)) {
throw new \InvalidArgumentException('invalid length for $password when calling Body3., must be bigger than or equal to 10.');
}

View File

@@ -289,11 +289,11 @@ class FormatTest implements ModelInterface, ArrayAccess
if ($this->container['password'] === null) {
$invalidProperties[] = "'password' can't be null";
}
if ((strlen($this->container['password']) > 64)) {
if ((mb_strlen($this->container['password']) > 64)) {
$invalidProperties[] = "invalid value for 'password', the character length must be smaller than or equal to 64.";
}
if ((strlen($this->container['password']) < 10)) {
if ((mb_strlen($this->container['password']) < 10)) {
$invalidProperties[] = "invalid value for 'password', the character length must be bigger than or equal to 10.";
}
@@ -333,10 +333,10 @@ class FormatTest implements ModelInterface, ArrayAccess
if ($this->container['password'] === null) {
return false;
}
if (strlen($this->container['password']) > 64) {
if (mb_strlen($this->container['password']) > 64) {
return false;
}
if (strlen($this->container['password']) < 10) {
if (mb_strlen($this->container['password']) < 10) {
return false;
}
return true;
@@ -666,10 +666,10 @@ class FormatTest implements ModelInterface, ArrayAccess
*/
public function setPassword($password)
{
if ((strlen($password) > 64)) {
if ((mb_strlen($password) > 64)) {
throw new \InvalidArgumentException('invalid length for $password when calling FormatTest., must be smaller than or equal to 64.');
}
if ((strlen($password) < 10)) {
if ((mb_strlen($password) < 10)) {
throw new \InvalidArgumentException('invalid length for $password when calling FormatTest., must be bigger than or equal to 10.');
}

View File

@@ -3,12 +3,12 @@
namespace Swagger\Client;
use Swagger\Client\Api\FakeApi;
use Swagger\Client\Model\Body4;
require_once __DIR__ . '/FakeHttpClient.php';
class RequestTest extends \PHPUnit_Framework_TestCase
{
/** @var FakeApi */
private $api;
/** @var FakeHttpClient */
@@ -22,15 +22,22 @@ class RequestTest extends \PHPUnit_Framework_TestCase
public function testFormDataEncodingToJson()
{
$this->api->testJsonFormData('value', 'value2');
$this->api->testJsonFormData(
new Body4(['param' => 'value', 'param2' => 'value2'])
);
$request = $this->fakeClient->getLastRequest();
$contentType = $request->getHeader('Content-Type');
$this->assertEquals(['application/json'], $contentType);
$requestContent = $request->getBody()->getContents();
$expected = <<<__EOS__
{
"param": "value",
"param2": "value2"
}
__EOS__;
$expected = json_encode(['param' => 'value', 'param2' => 'value2']);
$this->assertEquals($expected, $requestContent);
}
}