Skip to content

Commit d2e7818

Browse files
committed
updated php petstore client
1 parent dd1df7a commit d2e7818

File tree

10 files changed

+314
-103
lines changed

10 files changed

+314
-103
lines changed
Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
<?php
22

3-
return Symfony\CS\Config::create()
4-
->level(Symfony\CS\FixerInterface::PSR2_LEVEL)
3+
return PhpCsFixer\Config::create()
54
->setUsingCache(true)
6-
->fixers(
7-
[
8-
'ordered_use',
9-
'phpdoc_order',
10-
'short_array_syntax',
11-
'strict',
12-
'strict_param'
13-
]
14-
)
15-
->finder(
16-
Symfony\CS\Finder\DefaultFinder::create()
17-
->in(__DIR__)
5+
->setRules([
6+
'@PSR2' => true,
7+
'ordered_imports' => true,
8+
'phpdoc_order' => true,
9+
'array_syntax' => [ 'syntax' => 'short' ],
10+
'strict_comparison' => true,
11+
'strict_param' => true,
12+
'no_trailing_whitespace' => false,
13+
'no_trailing_whitespace_in_comment' => false,
14+
'braces' => false,
15+
'single_blank_line_at_eof' => false,
16+
'blank_line_after_namespace' => false,
17+
])
18+
->setFinder(
19+
PhpCsFixer\Finder::create()
20+
->exclude('test')
21+
->exclude('tests')
22+
->in(__DIR__)
1823
);

samples/client/petstore/php/SwaggerClient-php/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,11 @@ All URIs are relative to *http://petstore.swagger.io:80/v2*
8080
Class | Method | HTTP request | Description
8181
------------ | ------------- | ------------- | -------------
8282
*AnotherFakeApi* | [**testSpecialTags**](docs/Api/AnotherFakeApi.md#testspecialtags) | **PATCH** /another-fake/dummy | To test special tags
83-
*DefaultApi* | [**testBodyWithQueryParams**](docs/Api/DefaultApi.md#testbodywithqueryparams) | **PUT** /fake/body-with-query-params |
8483
*FakeApi* | [**fakeOuterBooleanSerialize**](docs/Api/FakeApi.md#fakeouterbooleanserialize) | **POST** /fake/outer/boolean |
8584
*FakeApi* | [**fakeOuterCompositeSerialize**](docs/Api/FakeApi.md#fakeoutercompositeserialize) | **POST** /fake/outer/composite |
8685
*FakeApi* | [**fakeOuterNumberSerialize**](docs/Api/FakeApi.md#fakeouternumberserialize) | **POST** /fake/outer/number |
8786
*FakeApi* | [**fakeOuterStringSerialize**](docs/Api/FakeApi.md#fakeouterstringserialize) | **POST** /fake/outer/string |
87+
*FakeApi* | [**testBodyWithQueryParams**](docs/Api/FakeApi.md#testbodywithqueryparams) | **PUT** /fake/body-with-query-params |
8888
*FakeApi* | [**testClientModel**](docs/Api/FakeApi.md#testclientmodel) | **PATCH** /fake | To test \&quot;client\&quot; model
8989
*FakeApi* | [**testEndpointParameters**](docs/Api/FakeApi.md#testendpointparameters) | **POST** /fake | Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
9090
*FakeApi* | [**testEnumParameters**](docs/Api/FakeApi.md#testenumparameters) | **GET** /fake | To test enum parameters

samples/client/petstore/php/SwaggerClient-php/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"require-dev": {
2626
"phpunit/phpunit": "^4.8",
2727
"squizlabs/php_codesniffer": "~2.6",
28-
"friendsofphp/php-cs-fixer": "~1.12"
28+
"friendsofphp/php-cs-fixer": "~2.12"
2929
},
3030
"autoload": {
3131
"psr-4": { "Swagger\\Client\\" : "lib/" }

samples/client/petstore/php/SwaggerClient-php/docs/Api/FakeApi.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Method | HTTP request | Description
88
[**fakeOuterCompositeSerialize**](FakeApi.md#fakeOuterCompositeSerialize) | **POST** /fake/outer/composite |
99
[**fakeOuterNumberSerialize**](FakeApi.md#fakeOuterNumberSerialize) | **POST** /fake/outer/number |
1010
[**fakeOuterStringSerialize**](FakeApi.md#fakeOuterStringSerialize) | **POST** /fake/outer/string |
11+
[**testBodyWithQueryParams**](FakeApi.md#testBodyWithQueryParams) | **PUT** /fake/body-with-query-params |
1112
[**testClientModel**](FakeApi.md#testClientModel) | **PATCH** /fake | To test \&quot;client\&quot; model
1213
[**testEndpointParameters**](FakeApi.md#testEndpointParameters) | **POST** /fake | Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
1314
[**testEnumParameters**](FakeApi.md#testEnumParameters) | **GET** /fake | To test enum parameters
@@ -211,6 +212,54 @@ No authorization required
211212

212213
[[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)
213214

215+
# **testBodyWithQueryParams**
216+
> testBodyWithQueryParams($body, $query)
217+
218+
219+
220+
### Example
221+
```php
222+
<?php
223+
require_once(__DIR__ . '/vendor/autoload.php');
224+
225+
$apiInstance = new Swagger\Client\Api\FakeApi(
226+
// If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.
227+
// This is optional, `GuzzleHttp\Client` will be used as default.
228+
new GuzzleHttp\Client()
229+
);
230+
$body = new \Swagger\Client\Model\User(); // \Swagger\Client\Model\User |
231+
$query = "query_example"; // string |
232+
233+
try {
234+
$apiInstance->testBodyWithQueryParams($body, $query);
235+
} catch (Exception $e) {
236+
echo 'Exception when calling FakeApi->testBodyWithQueryParams: ', $e->getMessage(), PHP_EOL;
237+
}
238+
?>
239+
```
240+
241+
### Parameters
242+
243+
Name | Type | Description | Notes
244+
------------- | ------------- | ------------- | -------------
245+
**body** | [**\Swagger\Client\Model\User**](../Model/User.md)| |
246+
**query** | **string**| |
247+
248+
### Return type
249+
250+
void (empty response body)
251+
252+
### Authorization
253+
254+
No authorization required
255+
256+
### HTTP request headers
257+
258+
- **Content-Type**: application/json
259+
- **Accept**: Not defined
260+
261+
[[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)
262+
214263
# **testClientModel**
215264
> \Swagger\Client\Model\Client testClientModel($body)
216265

samples/client/petstore/php/SwaggerClient-php/lib/Api/FakeApi.php

Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,6 +1075,237 @@ protected function fakeOuterStringSerializeRequest($body = null)
10751075
);
10761076
}
10771077

1078+
/**
1079+
* Operation testBodyWithQueryParams
1080+
*
1081+
* @param \Swagger\Client\Model\User $body body (required)
1082+
* @param string $query query (required)
1083+
*
1084+
* @throws \Swagger\Client\ApiException on non-2xx response
1085+
* @throws \InvalidArgumentException
1086+
* @return void
1087+
*/
1088+
public function testBodyWithQueryParams($body, $query)
1089+
{
1090+
$this->testBodyWithQueryParamsWithHttpInfo($body, $query);
1091+
}
1092+
1093+
/**
1094+
* Operation testBodyWithQueryParamsWithHttpInfo
1095+
*
1096+
* @param \Swagger\Client\Model\User $body (required)
1097+
* @param string $query (required)
1098+
*
1099+
* @throws \Swagger\Client\ApiException on non-2xx response
1100+
* @throws \InvalidArgumentException
1101+
* @return array of null, HTTP status code, HTTP response headers (array of strings)
1102+
*/
1103+
public function testBodyWithQueryParamsWithHttpInfo($body, $query)
1104+
{
1105+
$returnType = '';
1106+
$request = $this->testBodyWithQueryParamsRequest($body, $query);
1107+
1108+
try {
1109+
$options = $this->createHttpClientOption();
1110+
try {
1111+
$response = $this->client->send($request, $options);
1112+
} catch (RequestException $e) {
1113+
throw new ApiException(
1114+
"[{$e->getCode()}] {$e->getMessage()}",
1115+
$e->getCode(),
1116+
$e->getResponse() ? $e->getResponse()->getHeaders() : null,
1117+
$e->getResponse() ? $e->getResponse()->getBody()->getContents() : null
1118+
);
1119+
}
1120+
1121+
$statusCode = $response->getStatusCode();
1122+
1123+
if ($statusCode < 200 || $statusCode > 299) {
1124+
throw new ApiException(
1125+
sprintf(
1126+
'[%d] Error connecting to the API (%s)',
1127+
$statusCode,
1128+
$request->getUri()
1129+
),
1130+
$statusCode,
1131+
$response->getHeaders(),
1132+
$response->getBody()
1133+
);
1134+
}
1135+
1136+
return [null, $statusCode, $response->getHeaders()];
1137+
1138+
} catch (ApiException $e) {
1139+
switch ($e->getCode()) {
1140+
}
1141+
throw $e;
1142+
}
1143+
}
1144+
1145+
/**
1146+
* Operation testBodyWithQueryParamsAsync
1147+
*
1148+
*
1149+
*
1150+
* @param \Swagger\Client\Model\User $body (required)
1151+
* @param string $query (required)
1152+
*
1153+
* @throws \InvalidArgumentException
1154+
* @return \GuzzleHttp\Promise\PromiseInterface
1155+
*/
1156+
public function testBodyWithQueryParamsAsync($body, $query)
1157+
{
1158+
return $this->testBodyWithQueryParamsAsyncWithHttpInfo($body, $query)
1159+
->then(
1160+
function ($response) {
1161+
return $response[0];
1162+
}
1163+
);
1164+
}
1165+
1166+
/**
1167+
* Operation testBodyWithQueryParamsAsyncWithHttpInfo
1168+
*
1169+
*
1170+
*
1171+
* @param \Swagger\Client\Model\User $body (required)
1172+
* @param string $query (required)
1173+
*
1174+
* @throws \InvalidArgumentException
1175+
* @return \GuzzleHttp\Promise\PromiseInterface
1176+
*/
1177+
public function testBodyWithQueryParamsAsyncWithHttpInfo($body, $query)
1178+
{
1179+
$returnType = '';
1180+
$request = $this->testBodyWithQueryParamsRequest($body, $query);
1181+
1182+
return $this->client
1183+
->sendAsync($request, $this->createHttpClientOption())
1184+
->then(
1185+
function ($response) use ($returnType) {
1186+
return [null, $response->getStatusCode(), $response->getHeaders()];
1187+
},
1188+
function ($exception) {
1189+
$response = $exception->getResponse();
1190+
$statusCode = $response->getStatusCode();
1191+
throw new ApiException(
1192+
sprintf(
1193+
'[%d] Error connecting to the API (%s)',
1194+
$statusCode,
1195+
$exception->getRequest()->getUri()
1196+
),
1197+
$statusCode,
1198+
$response->getHeaders(),
1199+
$response->getBody()
1200+
);
1201+
}
1202+
);
1203+
}
1204+
1205+
/**
1206+
* Create request for operation 'testBodyWithQueryParams'
1207+
*
1208+
* @param \Swagger\Client\Model\User $body (required)
1209+
* @param string $query (required)
1210+
*
1211+
* @throws \InvalidArgumentException
1212+
* @return \GuzzleHttp\Psr7\Request
1213+
*/
1214+
protected function testBodyWithQueryParamsRequest($body, $query)
1215+
{
1216+
// verify the required parameter 'body' is set
1217+
if ($body === null || (is_array($body) && count($body) === 0)) {
1218+
throw new \InvalidArgumentException(
1219+
'Missing the required parameter $body when calling testBodyWithQueryParams'
1220+
);
1221+
}
1222+
// verify the required parameter 'query' is set
1223+
if ($query === null || (is_array($query) && count($query) === 0)) {
1224+
throw new \InvalidArgumentException(
1225+
'Missing the required parameter $query when calling testBodyWithQueryParams'
1226+
);
1227+
}
1228+
1229+
$resourcePath = '/fake/body-with-query-params';
1230+
$formParams = [];
1231+
$queryParams = [];
1232+
$headerParams = [];
1233+
$httpBody = '';
1234+
$multipart = false;
1235+
1236+
// query params
1237+
if ($query !== null) {
1238+
$queryParams['query'] = ObjectSerializer::toQueryValue($query);
1239+
}
1240+
1241+
1242+
// body params
1243+
$_tempBody = null;
1244+
if (isset($body)) {
1245+
$_tempBody = $body;
1246+
}
1247+
1248+
if ($multipart) {
1249+
$headers = $this->headerSelector->selectHeadersForMultipart(
1250+
[]
1251+
);
1252+
} else {
1253+
$headers = $this->headerSelector->selectHeaders(
1254+
[],
1255+
['application/json']
1256+
);
1257+
}
1258+
1259+
// for model (json/xml)
1260+
if (isset($_tempBody)) {
1261+
// $_tempBody is the method argument, if present
1262+
$httpBody = $_tempBody;
1263+
// \stdClass has no __toString(), so we should encode it manually
1264+
if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') {
1265+
$httpBody = \GuzzleHttp\json_encode($httpBody);
1266+
}
1267+
} elseif (count($formParams) > 0) {
1268+
if ($multipart) {
1269+
$multipartContents = [];
1270+
foreach ($formParams as $formParamName => $formParamValue) {
1271+
$multipartContents[] = [
1272+
'name' => $formParamName,
1273+
'contents' => $formParamValue
1274+
];
1275+
}
1276+
// for HTTP post (form)
1277+
$httpBody = new MultipartStream($multipartContents);
1278+
1279+
} elseif ($headers['Content-Type'] === 'application/json') {
1280+
$httpBody = \GuzzleHttp\json_encode($formParams);
1281+
1282+
} else {
1283+
// for HTTP post (form)
1284+
$httpBody = \GuzzleHttp\Psr7\build_query($formParams);
1285+
}
1286+
}
1287+
1288+
1289+
$defaultHeaders = [];
1290+
if ($this->config->getUserAgent()) {
1291+
$defaultHeaders['User-Agent'] = $this->config->getUserAgent();
1292+
}
1293+
1294+
$headers = array_merge(
1295+
$defaultHeaders,
1296+
$headerParams,
1297+
$headers
1298+
);
1299+
1300+
$query = \GuzzleHttp\Psr7\build_query($queryParams);
1301+
return new Request(
1302+
'PUT',
1303+
$this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
1304+
$headers,
1305+
$httpBody
1306+
);
1307+
}
1308+
10781309
/**
10791310
* Operation testClientModel
10801311
*

samples/client/petstore/php/SwaggerClient-php/lib/HeaderSelector.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,3 @@ private function selectContentTypeHeader($contentType)
107107
}
108108
}
109109
}
110-

samples/client/petstore/php/SwaggerClient-php/lib/Model/Animal.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ public function __construct(array $data = null)
186186
$this->container['color'] = isset($data['color']) ? $data['color'] : 'red';
187187

188188
// Initialize discriminator property with the model name.
189-
$discriminator = array_search('className', self::$attributeMap);
189+
$discriminator = array_search('className', self::$attributeMap, true);
190190
$this->container[$discriminator] = static::$swaggerModelName;
191191
}
192192

samples/client/petstore/php/SwaggerClient-php/lib/ObjectSerializer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public static function sanitizeForSerialization($data, $type = null, $format = n
6868
if ($value !== null
6969
&& !in_array($swaggerType, ['DateTime', 'bool', 'boolean', 'byte', 'double', 'float', 'int', 'integer', 'mixed', 'number', 'object', 'string', 'void'], true)
7070
&& method_exists($swaggerType, 'getAllowableEnumValues')
71-
&& !in_array($value, $swaggerType::getAllowableEnumValues())) {
71+
&& !in_array($value, $swaggerType::getAllowableEnumValues(), true)) {
7272
$imploded = implode("', '", $swaggerType::getAllowableEnumValues());
7373
throw new \InvalidArgumentException("Invalid value for enum '$swaggerType', must be one of: '$imploded'");
7474
}
@@ -284,7 +284,7 @@ public static function deserialize($data, $class, $httpHeaders = null)
284284

285285
return new \SplFileObject($filename, 'r');
286286
} elseif (method_exists($class, 'getAllowableEnumValues')) {
287-
if (!in_array($data, $class::getAllowableEnumValues())) {
287+
if (!in_array($data, $class::getAllowableEnumValues(), true)) {
288288
$imploded = implode("', '", $class::getAllowableEnumValues());
289289
throw new \InvalidArgumentException("Invalid value for enum '$class', must be one of: '$imploded'");
290290
}

0 commit comments

Comments
 (0)