From 4612c1256094e2587c0e0b05040ce1c3ea7b0f72 Mon Sep 17 00:00:00 2001 From: Akihito Nakano Date: Wed, 7 Jun 2017 21:35:28 +0900 Subject: [PATCH] [PHP] Add support for async requests (#5771) * Add xxxAsyncWithHttpInfo * Add xxxAsync * Tweak doc comment * apply DRY principle to the creation process for request * Fix undefined variable $statusCode * error handling * Fix undefined variable $url * Tweak syntax * Update samples run './bin/php-petstore.sh' * Update samples (security) run './bin/security/php-petstore.sh' * Fix doc comment xxx(Async|AsyncWithHttpInfo) returns \GuzzleHttp\Promise\PromiseInterface * Update samples (./bin/php-petstore.sh) * Update samples (./bin/security/php-petstore.sh) * Add AsyncTest --- .../src/main/resources/php/api.mustache | 210 ++- .../php/SwaggerClient-php/lib/Api/FakeApi.php | 123 +- .../php/SwaggerClient-php/lib/Api/FakeApi.php | 1129 ++++++++++++---- .../lib/Api/Fake_classname_tags123Api.php | 173 ++- .../php/SwaggerClient-php/lib/Api/PetApi.php | 1123 +++++++++++----- .../SwaggerClient-php/lib/Api/StoreApi.php | 563 +++++--- .../php/SwaggerClient-php/lib/Api/UserApi.php | 1135 ++++++++++++----- .../php/SwaggerClient-php/tests/AsyncTest.php | 85 ++ 8 files changed, 3357 insertions(+), 1184 deletions(-) create mode 100644 samples/client/petstore/php/SwaggerClient-php/tests/AsyncTest.php diff --git a/modules/swagger-codegen/src/main/resources/php/api.mustache b/modules/swagger-codegen/src/main/resources/php/api.mustache index 4f3a8aee2aae..b473bdcd04f6 100644 --- a/modules/swagger-codegen/src/main/resources/php/api.mustache +++ b/modules/swagger-codegen/src/main/resources/php/api.mustache @@ -115,6 +115,154 @@ use {{invokerPackage}}\ObjectSerializer; * @return array of {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}null{{/returnType}}, HTTP status code, HTTP response headers (array of strings) */ public function {{operationId}}WithHttpInfo({{#allParams}}${{paramName}}{{^required}} = {{#defaultValue}}'{{{.}}}'{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) + { + $returnType = '{{returnType}}'; + $request = $this->{{operationId}}Request({{#allParams}}${{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}); + + 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() + ); + } + + {{#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() + ]; + {{/returnType}} + {{^returnType}} + return [null, $statusCode, $response->getHeaders()]; + {{/returnType}} + + } catch (ApiException $e) { + switch ($e->getCode()) { + {{#responses}} + {{#dataType}} + {{^isWildcard}}case {{code}}:{{/isWildcard}}{{#isWildcard}}default:{{/isWildcard}} + $data = ObjectSerializer::deserialize($e->getResponseBody(), '{{dataType}}', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + {{/dataType}} + {{/responses}} + } + throw $e; + } + } + + /** + * Operation {{{operationId}}}Async + * + * {{{summary}}} + * +{{#description}} + * {{.}} + * +{{/description}} +{{#allParams}} + * @param {{dataType}} ${{paramName}} {{description}} {{#required}}(required){{/required}}{{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}} +{{/allParams}} + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function {{operationId}}Async({{#allParams}}${{paramName}}{{^required}} = {{#defaultValue}}'{{{.}}}'{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) + { + return $this->{{operationId}}AsyncWithHttpInfo({{#allParams}}${{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}})->then(function ($response) { + return $response[0]; + }); + } + + /** + * Operation {{{operationId}}}AsyncWithHttpInfo + * + * {{{summary}}} + * +{{#description}} + * {{.}} + * +{{/description}} +{{#allParams}} + * @param {{dataType}} ${{paramName}} {{description}} {{#required}}(required){{/required}}{{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}} +{{/allParams}} + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function {{operationId}}AsyncWithHttpInfo({{#allParams}}${{paramName}}{{^required}} = {{#defaultValue}}'{{{.}}}'{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) + { + $returnType = '{{returnType}}'; + $request = $this->{{operationId}}Request({{#allParams}}${{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + {{#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() + ]; + {{/returnType}} + {{^returnType}} + return [null, $response->getStatusCode(), $response->getHeaders()]; + {{/returnType}} + }, 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 '{{{operationId}}}' + * +{{#allParams}} + * @param {{dataType}} ${{paramName}} {{description}} {{#required}}(required){{/required}}{{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}} +{{/allParams}} + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function {{operationId}}Request({{#allParams}}${{paramName}}{{^required}} = {{#defaultValue}}'{{{.}}}'{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) { {{#allParams}} {{#required}} @@ -169,7 +317,6 @@ use {{invokerPackage}}\ObjectSerializer; $headerParams = []; $httpBody = ''; $multipart = false; - $returnType = '{{returnType}}'; {{#queryParams}} // query params @@ -296,71 +443,14 @@ use {{invokerPackage}}\ObjectSerializer; $headers ); - $request = new Request( + return new Request( '{{httpMethod}}', $url, $headers, $httpBody ); - - 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 ($url)", - $statusCode, - $response->getHeaders(), - $response->getBody() - ); - } - - {{#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() - ]; - {{/returnType}} - {{^returnType}} - return [null, $statusCode, $response->getHeaders()]; - {{/returnType}} - - } catch (ApiException $e) { - switch ($e->getCode()) { - {{#responses}} - {{#dataType}} - {{^isWildcard}}case {{code}}:{{/isWildcard}}{{#isWildcard}}default:{{/isWildcard}} - $data = ObjectSerializer::deserialize($e->getResponseBody(), '{{dataType}}', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - {{/dataType}} - {{/responses}} - } - throw $e; - } } + {{/operation}} } {{/operations}} diff --git a/samples/client/petstore-security-test/php/SwaggerClient-php/lib/Api/FakeApi.php b/samples/client/petstore-security-test/php/SwaggerClient-php/lib/Api/FakeApi.php index 2c6ad2528525..b5ea03148110 100644 --- a/samples/client/petstore-security-test/php/SwaggerClient-php/lib/Api/FakeApi.php +++ b/samples/client/petstore-security-test/php/SwaggerClient-php/lib/Api/FakeApi.php @@ -107,6 +107,94 @@ class FakeApi * @return array of null, HTTP status code, HTTP response headers (array of strings) */ public function testCodeInjectEndRnNRWithHttpInfo($test_code_inject____end____rn_n_r = null) + { + $returnType = ''; + $request = $this->testCodeInjectEndRnNRRequest($test_code_inject____end____rn_n_r); + + 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() + ); + } + + return [null, $statusCode, $response->getHeaders()]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + } + throw $e; + } + } + + /** + * Operation testCodeInjectEndRnNRAsync + * + * To test code injection *_/ ' \" =end -- \\r\\n \\n \\r + * + * @param string $test_code_inject____end____rn_n_r To test code injection *_/ ' \" =end -- \\r\\n \\n \\r (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function testCodeInjectEndRnNRAsync($test_code_inject____end____rn_n_r = null) + { + return $this->testCodeInjectEndRnNRAsyncWithHttpInfo($test_code_inject____end____rn_n_r)->then(function ($response) { + return $response[0]; + }); + } + + /** + * Operation testCodeInjectEndRnNRAsyncWithHttpInfo + * + * To test code injection *_/ ' \" =end -- \\r\\n \\n \\r + * + * @param string $test_code_inject____end____rn_n_r To test code injection *_/ ' \" =end -- \\r\\n \\n \\r (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function testCodeInjectEndRnNRAsyncWithHttpInfo($test_code_inject____end____rn_n_r = null) + { + $returnType = ''; + $request = $this->testCodeInjectEndRnNRRequest($test_code_inject____end____rn_n_r); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + return [null, $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 'testCodeInjectEndRnNR' + * + * @param string $test_code_inject____end____rn_n_r To test code injection *_/ ' \" =end -- \\r\\n \\n \\r (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function testCodeInjectEndRnNRRequest($test_code_inject____end____rn_n_r = null) { $resourcePath = '/fake'; @@ -115,7 +203,6 @@ class FakeApi $headerParams = []; $httpBody = ''; $multipart = false; - $returnType = ''; @@ -173,42 +260,12 @@ class FakeApi $headers ); - $request = new Request( + return new Request( 'PUT', $url, $headers, $httpBody ); - - 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 ($url)", - $statusCode, - $response->getHeaders(), - $response->getBody() - ); - } - - return [null, $statusCode, $response->getHeaders()]; - - } catch (ApiException $e) { - switch ($e->getCode()) { - } - throw $e; - } } + } diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Api/FakeApi.php b/samples/client/petstore/php/SwaggerClient-php/lib/Api/FakeApi.php index 715e2ac62a04..a2f91408104a 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/FakeApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/FakeApi.php @@ -105,78 +105,8 @@ class FakeApi */ public function fakeOuterBooleanSerializeWithHttpInfo($body = null) { - - $resourcePath = '/fake/outer/boolean'; - $formParams = []; - $queryParams = []; - $headerParams = []; - $httpBody = ''; - $multipart = false; $returnType = '\Swagger\Client\Model\OuterBoolean'; - - - - // body params - $_tempBody = null; - if (isset($body)) { - $_tempBody = $body; - } - - if ($multipart) { - $headers= $this->headerSelector->selectHeadersForMultipart( - [] - ); - } else { - $headers = $this->headerSelector->selectHeaders( - [], - [] - ); - } - - // 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 - ); - - $request = new Request( - 'POST', - $url, - $headers, - $httpBody - ); + $request = $this->fakeOuterBooleanSerializeRequest($body); try { @@ -194,7 +124,7 @@ class FakeApi if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( - "[$statusCode] Error connecting to the API ($url)", + "[$statusCode] Error connecting to the API ({$request->getUri()})", $statusCode, $response->getHeaders(), $response->getBody() @@ -227,38 +157,81 @@ class FakeApi throw $e; } } + /** - * Operation fakeOuterCompositeSerialize + * Operation fakeOuterBooleanSerializeAsync * - * @param \Swagger\Client\Model\OuterComposite $body Input composite as post body (optional) - * @throws \Swagger\Client\ApiException on non-2xx response + * + * + * @param \Swagger\Client\Model\OuterBoolean $body Input boolean as post body (optional) * @throws \InvalidArgumentException - * @return \Swagger\Client\Model\OuterComposite + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function fakeOuterCompositeSerialize($body = null) + public function fakeOuterBooleanSerializeAsync($body = null) { - list($response) = $this->fakeOuterCompositeSerializeWithHttpInfo($body); - return $response; + return $this->fakeOuterBooleanSerializeAsyncWithHttpInfo($body)->then(function ($response) { + return $response[0]; + }); } /** - * Operation fakeOuterCompositeSerializeWithHttpInfo + * Operation fakeOuterBooleanSerializeAsyncWithHttpInfo * - * @param \Swagger\Client\Model\OuterComposite $body Input composite as post body (optional) - * @throws \Swagger\Client\ApiException on non-2xx response + * + * + * @param \Swagger\Client\Model\OuterBoolean $body Input boolean as post body (optional) * @throws \InvalidArgumentException - * @return array of \Swagger\Client\Model\OuterComposite, HTTP status code, HTTP response headers (array of strings) + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function fakeOuterCompositeSerializeWithHttpInfo($body = null) + public function fakeOuterBooleanSerializeAsyncWithHttpInfo($body = null) + { + $returnType = '\Swagger\Client\Model\OuterBoolean'; + $request = $this->fakeOuterBooleanSerializeRequest($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 'fakeOuterBooleanSerialize' + * + * @param \Swagger\Client\Model\OuterBoolean $body Input boolean as post body (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function fakeOuterBooleanSerializeRequest($body = null) { - $resourcePath = '/fake/outer/composite'; + $resourcePath = '/fake/outer/boolean'; $formParams = []; $queryParams = []; $headerParams = []; $httpBody = ''; $multipart = false; - $returnType = '\Swagger\Client\Model\OuterComposite'; @@ -317,12 +290,44 @@ class FakeApi $headers ); - $request = new Request( + return new Request( 'POST', $url, $headers, $httpBody ); + } + + /** + * Operation fakeOuterCompositeSerialize + * + * + * + * @param \Swagger\Client\Model\OuterComposite $body Input composite as post body (optional) + * @throws \Swagger\Client\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return \Swagger\Client\Model\OuterComposite + */ + public function fakeOuterCompositeSerialize($body = null) + { + list($response) = $this->fakeOuterCompositeSerializeWithHttpInfo($body); + return $response; + } + + /** + * Operation fakeOuterCompositeSerializeWithHttpInfo + * + * + * + * @param \Swagger\Client\Model\OuterComposite $body Input composite as post body (optional) + * @throws \Swagger\Client\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of \Swagger\Client\Model\OuterComposite, HTTP status code, HTTP response headers (array of strings) + */ + public function fakeOuterCompositeSerializeWithHttpInfo($body = null) + { + $returnType = '\Swagger\Client\Model\OuterComposite'; + $request = $this->fakeOuterCompositeSerializeRequest($body); try { @@ -340,7 +345,7 @@ class FakeApi if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( - "[$statusCode] Error connecting to the API ($url)", + "[$statusCode] Error connecting to the API ({$request->getUri()})", $statusCode, $response->getHeaders(), $response->getBody() @@ -373,38 +378,77 @@ class FakeApi throw $e; } } + /** - * Operation fakeOuterNumberSerialize + * Operation fakeOuterCompositeSerializeAsync * - * @param \Swagger\Client\Model\OuterNumber $body Input number as post body (optional) - * @throws \Swagger\Client\ApiException on non-2xx response + * @param \Swagger\Client\Model\OuterComposite $body Input composite as post body (optional) * @throws \InvalidArgumentException - * @return \Swagger\Client\Model\OuterNumber + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function fakeOuterNumberSerialize($body = null) + public function fakeOuterCompositeSerializeAsync($body = null) { - list($response) = $this->fakeOuterNumberSerializeWithHttpInfo($body); - return $response; + return $this->fakeOuterCompositeSerializeAsyncWithHttpInfo($body)->then(function ($response) { + return $response[0]; + }); } /** - * Operation fakeOuterNumberSerializeWithHttpInfo + * Operation fakeOuterCompositeSerializeAsyncWithHttpInfo * - * @param \Swagger\Client\Model\OuterNumber $body Input number as post body (optional) - * @throws \Swagger\Client\ApiException on non-2xx response + * @param \Swagger\Client\Model\OuterComposite $body Input composite as post body (optional) * @throws \InvalidArgumentException - * @return array of \Swagger\Client\Model\OuterNumber, HTTP status code, HTTP response headers (array of strings) + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function fakeOuterNumberSerializeWithHttpInfo($body = null) + public function fakeOuterCompositeSerializeAsyncWithHttpInfo($body = null) + { + $returnType = '\Swagger\Client\Model\OuterComposite'; + $request = $this->fakeOuterCompositeSerializeRequest($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 'fakeOuterCompositeSerialize' + * + * @param \Swagger\Client\Model\OuterComposite $body Input composite as post body (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function fakeOuterCompositeSerializeRequest($body = null) { - $resourcePath = '/fake/outer/number'; + $resourcePath = '/fake/outer/composite'; $formParams = []; $queryParams = []; $headerParams = []; $httpBody = ''; $multipart = false; - $returnType = '\Swagger\Client\Model\OuterNumber'; @@ -463,12 +507,44 @@ class FakeApi $headers ); - $request = new Request( + return new Request( 'POST', $url, $headers, $httpBody ); + } + + /** + * Operation fakeOuterNumberSerialize + * + * + * + * @param \Swagger\Client\Model\OuterNumber $body Input number as post body (optional) + * @throws \Swagger\Client\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return \Swagger\Client\Model\OuterNumber + */ + public function fakeOuterNumberSerialize($body = null) + { + list($response) = $this->fakeOuterNumberSerializeWithHttpInfo($body); + return $response; + } + + /** + * Operation fakeOuterNumberSerializeWithHttpInfo + * + * + * + * @param \Swagger\Client\Model\OuterNumber $body Input number as post body (optional) + * @throws \Swagger\Client\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of \Swagger\Client\Model\OuterNumber, HTTP status code, HTTP response headers (array of strings) + */ + public function fakeOuterNumberSerializeWithHttpInfo($body = null) + { + $returnType = '\Swagger\Client\Model\OuterNumber'; + $request = $this->fakeOuterNumberSerializeRequest($body); try { @@ -486,7 +562,7 @@ class FakeApi if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( - "[$statusCode] Error connecting to the API ($url)", + "[$statusCode] Error connecting to the API ({$request->getUri()})", $statusCode, $response->getHeaders(), $response->getBody() @@ -519,38 +595,77 @@ class FakeApi throw $e; } } + /** - * Operation fakeOuterStringSerialize + * Operation fakeOuterNumberSerializeAsync * - * @param \Swagger\Client\Model\OuterString $body Input string as post body (optional) - * @throws \Swagger\Client\ApiException on non-2xx response + * @param \Swagger\Client\Model\OuterNumber $body Input number as post body (optional) * @throws \InvalidArgumentException - * @return \Swagger\Client\Model\OuterString + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function fakeOuterStringSerialize($body = null) + public function fakeOuterNumberSerializeAsync($body = null) { - list($response) = $this->fakeOuterStringSerializeWithHttpInfo($body); - return $response; + return $this->fakeOuterNumberSerializeAsyncWithHttpInfo($body)->then(function ($response) { + return $response[0]; + }); } /** - * Operation fakeOuterStringSerializeWithHttpInfo + * Operation fakeOuterNumberSerializeAsyncWithHttpInfo * - * @param \Swagger\Client\Model\OuterString $body Input string as post body (optional) - * @throws \Swagger\Client\ApiException on non-2xx response + * @param \Swagger\Client\Model\OuterNumber $body Input number as post body (optional) * @throws \InvalidArgumentException - * @return array of \Swagger\Client\Model\OuterString, HTTP status code, HTTP response headers (array of strings) + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function fakeOuterStringSerializeWithHttpInfo($body = null) + public function fakeOuterNumberSerializeAsyncWithHttpInfo($body = null) + { + $returnType = '\Swagger\Client\Model\OuterNumber'; + $request = $this->fakeOuterNumberSerializeRequest($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 'fakeOuterNumberSerialize' + * + * @param \Swagger\Client\Model\OuterNumber $body Input number as post body (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function fakeOuterNumberSerializeRequest($body = null) { - $resourcePath = '/fake/outer/string'; + $resourcePath = '/fake/outer/number'; $formParams = []; $queryParams = []; $headerParams = []; $httpBody = ''; $multipart = false; - $returnType = '\Swagger\Client\Model\OuterString'; @@ -609,12 +724,44 @@ class FakeApi $headers ); - $request = new Request( + return new Request( 'POST', $url, $headers, $httpBody ); + } + + /** + * Operation fakeOuterStringSerialize + * + * + * + * @param \Swagger\Client\Model\OuterString $body Input string as post body (optional) + * @throws \Swagger\Client\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return \Swagger\Client\Model\OuterString + */ + public function fakeOuterStringSerialize($body = null) + { + list($response) = $this->fakeOuterStringSerializeWithHttpInfo($body); + return $response; + } + + /** + * Operation fakeOuterStringSerializeWithHttpInfo + * + * + * + * @param \Swagger\Client\Model\OuterString $body Input string as post body (optional) + * @throws \Swagger\Client\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of \Swagger\Client\Model\OuterString, HTTP status code, HTTP response headers (array of strings) + */ + public function fakeOuterStringSerializeWithHttpInfo($body = null) + { + $returnType = '\Swagger\Client\Model\OuterString'; + $request = $this->fakeOuterStringSerializeRequest($body); try { @@ -632,7 +779,7 @@ class FakeApi if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( - "[$statusCode] Error connecting to the API ($url)", + "[$statusCode] Error connecting to the API ({$request->getUri()})", $statusCode, $response->getHeaders(), $response->getBody() @@ -665,6 +812,143 @@ class FakeApi throw $e; } } + + /** + * Operation fakeOuterStringSerializeAsync + * + * @param \Swagger\Client\Model\OuterString $body Input string as post body (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function fakeOuterStringSerializeAsync($body = null) + { + return $this->fakeOuterStringSerializeAsyncWithHttpInfo($body)->then(function ($response) { + return $response[0]; + }); + } + + /** + * Operation fakeOuterStringSerializeAsyncWithHttpInfo + * + * @param \Swagger\Client\Model\OuterString $body Input string as post body (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function fakeOuterStringSerializeAsyncWithHttpInfo($body = null) + { + $returnType = '\Swagger\Client\Model\OuterString'; + $request = $this->fakeOuterStringSerializeRequest($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 'fakeOuterStringSerialize' + * + * @param \Swagger\Client\Model\OuterString $body Input string as post body (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function fakeOuterStringSerializeRequest($body = null) + { + + $resourcePath = '/fake/outer/string'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + + + // body params + $_tempBody = null; + if (isset($body)) { + $_tempBody = $body; + } + + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + [] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + [], + [] + ); + } + + // 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( + 'POST', + $url, + $headers, + $httpBody + ); + } + /** * Operation testClientModel * @@ -692,6 +976,126 @@ class FakeApi * @return array of \Swagger\Client\Model\Client, HTTP status code, HTTP response headers (array of strings) */ public function testClientModelWithHttpInfo($body) + { + $returnType = '\Swagger\Client\Model\Client'; + $request = $this->testClientModelRequest($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 testClientModelAsync + * + * To test \"client\" model + * + * @param \Swagger\Client\Model\Client $body client model (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function testClientModelAsync($body) + { + return $this->testClientModelAsyncWithHttpInfo($body)->then(function ($response) { + return $response[0]; + }); + } + + /** + * Operation testClientModelAsyncWithHttpInfo + * + * To test \"client\" model + * + * @param \Swagger\Client\Model\Client $body client model (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function testClientModelAsyncWithHttpInfo($body) + { + $returnType = '\Swagger\Client\Model\Client'; + $request = $this->testClientModelRequest($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 'testClientModel' + * + * @param \Swagger\Client\Model\Client $body client model (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function testClientModelRequest($body) { // verify the required parameter 'body' is set if ($body === null) { @@ -704,7 +1108,6 @@ class FakeApi $headerParams = []; $httpBody = ''; $multipart = false; - $returnType = '\Swagger\Client\Model\Client'; @@ -763,62 +1166,14 @@ class FakeApi $headers ); - $request = new Request( + return new Request( 'PATCH', $url, $headers, $httpBody ); - - 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 ($url)", - $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 testEndpointParameters * @@ -871,6 +1226,133 @@ class FakeApi * @return array of null, HTTP status code, HTTP response headers (array of strings) */ public function testEndpointParametersWithHttpInfo($number, $double, $pattern_without_delimiter, $byte, $integer = null, $int32 = null, $int64 = null, $float = null, $string = null, $binary = null, $date = null, $date_time = null, $password = null, $callback = null) + { + $returnType = ''; + $request = $this->testEndpointParametersRequest($number, $double, $pattern_without_delimiter, $byte, $integer, $int32, $int64, $float, $string, $binary, $date, $date_time, $password, $callback); + + 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() + ); + } + + return [null, $statusCode, $response->getHeaders()]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + } + throw $e; + } + } + + /** + * Operation testEndpointParametersAsync + * + * Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 + * + * @param float $number None (required) + * @param double $double None (required) + * @param string $pattern_without_delimiter None (required) + * @param string $byte None (required) + * @param int $integer None (optional) + * @param int $int32 None (optional) + * @param int $int64 None (optional) + * @param float $float None (optional) + * @param string $string None (optional) + * @param string $binary None (optional) + * @param \DateTime $date None (optional) + * @param \DateTime $date_time None (optional) + * @param string $password None (optional) + * @param string $callback None (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function testEndpointParametersAsync($number, $double, $pattern_without_delimiter, $byte, $integer = null, $int32 = null, $int64 = null, $float = null, $string = null, $binary = null, $date = null, $date_time = null, $password = null, $callback = null) + { + return $this->testEndpointParametersAsyncWithHttpInfo($number, $double, $pattern_without_delimiter, $byte, $integer, $int32, $int64, $float, $string, $binary, $date, $date_time, $password, $callback)->then(function ($response) { + return $response[0]; + }); + } + + /** + * Operation testEndpointParametersAsyncWithHttpInfo + * + * Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 + * + * @param float $number None (required) + * @param double $double None (required) + * @param string $pattern_without_delimiter None (required) + * @param string $byte None (required) + * @param int $integer None (optional) + * @param int $int32 None (optional) + * @param int $int64 None (optional) + * @param float $float None (optional) + * @param string $string None (optional) + * @param string $binary None (optional) + * @param \DateTime $date None (optional) + * @param \DateTime $date_time None (optional) + * @param string $password None (optional) + * @param string $callback None (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function testEndpointParametersAsyncWithHttpInfo($number, $double, $pattern_without_delimiter, $byte, $integer = null, $int32 = null, $int64 = null, $float = null, $string = null, $binary = null, $date = null, $date_time = null, $password = null, $callback = null) + { + $returnType = ''; + $request = $this->testEndpointParametersRequest($number, $double, $pattern_without_delimiter, $byte, $integer, $int32, $int64, $float, $string, $binary, $date, $date_time, $password, $callback); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + return [null, $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 'testEndpointParameters' + * + * @param float $number None (required) + * @param double $double None (required) + * @param string $pattern_without_delimiter None (required) + * @param string $byte None (required) + * @param int $integer None (optional) + * @param int $int32 None (optional) + * @param int $int64 None (optional) + * @param float $float None (optional) + * @param string $string None (optional) + * @param string $binary None (optional) + * @param \DateTime $date None (optional) + * @param \DateTime $date_time None (optional) + * @param string $password None (optional) + * @param string $callback None (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function testEndpointParametersRequest($number, $double, $pattern_without_delimiter, $byte, $integer = null, $int32 = null, $int64 = null, $float = null, $string = null, $binary = null, $date = null, $date_time = null, $password = null, $callback = null) { // verify the required parameter 'number' is set if ($number === null) { @@ -942,7 +1424,6 @@ class FakeApi $headerParams = []; $httpBody = ''; $multipart = false; - $returnType = ''; @@ -1056,44 +1537,14 @@ class FakeApi $headers ); - $request = new Request( + return new Request( 'POST', $url, $headers, $httpBody ); - - 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 ($url)", - $statusCode, - $response->getHeaders(), - $response->getBody() - ); - } - - return [null, $statusCode, $response->getHeaders()]; - - } catch (ApiException $e) { - switch ($e->getCode()) { - } - throw $e; - } } + /** * Operation testEnumParameters * @@ -1134,6 +1585,115 @@ class FakeApi * @return array of null, HTTP status code, HTTP response headers (array of strings) */ public function testEnumParametersWithHttpInfo($enum_form_string_array = null, $enum_form_string = '-efg', $enum_header_string_array = null, $enum_header_string = '-efg', $enum_query_string_array = null, $enum_query_string = '-efg', $enum_query_integer = null, $enum_query_double = null) + { + $returnType = ''; + $request = $this->testEnumParametersRequest($enum_form_string_array, $enum_form_string, $enum_header_string_array, $enum_header_string, $enum_query_string_array, $enum_query_string, $enum_query_integer, $enum_query_double); + + 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() + ); + } + + return [null, $statusCode, $response->getHeaders()]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + } + throw $e; + } + } + + /** + * Operation testEnumParametersAsync + * + * To test enum parameters + * + * @param string[] $enum_form_string_array Form parameter enum test (string array) (optional) + * @param string $enum_form_string Form parameter enum test (string) (optional, default to -efg) + * @param string[] $enum_header_string_array Header parameter enum test (string array) (optional) + * @param string $enum_header_string Header parameter enum test (string) (optional, default to -efg) + * @param string[] $enum_query_string_array Query parameter enum test (string array) (optional) + * @param string $enum_query_string Query parameter enum test (string) (optional, default to -efg) + * @param int $enum_query_integer Query parameter enum test (double) (optional) + * @param double $enum_query_double Query parameter enum test (double) (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function testEnumParametersAsync($enum_form_string_array = null, $enum_form_string = '-efg', $enum_header_string_array = null, $enum_header_string = '-efg', $enum_query_string_array = null, $enum_query_string = '-efg', $enum_query_integer = null, $enum_query_double = null) + { + return $this->testEnumParametersAsyncWithHttpInfo($enum_form_string_array, $enum_form_string, $enum_header_string_array, $enum_header_string, $enum_query_string_array, $enum_query_string, $enum_query_integer, $enum_query_double)->then(function ($response) { + return $response[0]; + }); + } + + /** + * Operation testEnumParametersAsyncWithHttpInfo + * + * To test enum parameters + * + * @param string[] $enum_form_string_array Form parameter enum test (string array) (optional) + * @param string $enum_form_string Form parameter enum test (string) (optional, default to -efg) + * @param string[] $enum_header_string_array Header parameter enum test (string array) (optional) + * @param string $enum_header_string Header parameter enum test (string) (optional, default to -efg) + * @param string[] $enum_query_string_array Query parameter enum test (string array) (optional) + * @param string $enum_query_string Query parameter enum test (string) (optional, default to -efg) + * @param int $enum_query_integer Query parameter enum test (double) (optional) + * @param double $enum_query_double Query parameter enum test (double) (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function testEnumParametersAsyncWithHttpInfo($enum_form_string_array = null, $enum_form_string = '-efg', $enum_header_string_array = null, $enum_header_string = '-efg', $enum_query_string_array = null, $enum_query_string = '-efg', $enum_query_integer = null, $enum_query_double = null) + { + $returnType = ''; + $request = $this->testEnumParametersRequest($enum_form_string_array, $enum_form_string, $enum_header_string_array, $enum_header_string, $enum_query_string_array, $enum_query_string, $enum_query_integer, $enum_query_double); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + return [null, $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 'testEnumParameters' + * + * @param string[] $enum_form_string_array Form parameter enum test (string array) (optional) + * @param string $enum_form_string Form parameter enum test (string) (optional, default to -efg) + * @param string[] $enum_header_string_array Header parameter enum test (string array) (optional) + * @param string $enum_header_string Header parameter enum test (string) (optional, default to -efg) + * @param string[] $enum_query_string_array Query parameter enum test (string array) (optional) + * @param string $enum_query_string Query parameter enum test (string) (optional, default to -efg) + * @param int $enum_query_integer Query parameter enum test (double) (optional) + * @param double $enum_query_double Query parameter enum test (double) (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function testEnumParametersRequest($enum_form_string_array = null, $enum_form_string = '-efg', $enum_header_string_array = null, $enum_header_string = '-efg', $enum_query_string_array = null, $enum_query_string = '-efg', $enum_query_integer = null, $enum_query_double = null) { $resourcePath = '/fake'; @@ -1142,7 +1702,6 @@ class FakeApi $headerParams = []; $httpBody = ''; $multipart = false; - $returnType = ''; // query params if (is_array($enum_query_string_array)) { @@ -1234,44 +1793,14 @@ class FakeApi $headers ); - $request = new Request( + return new Request( 'GET', $url, $headers, $httpBody ); - - 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 ($url)", - $statusCode, - $response->getHeaders(), - $response->getBody() - ); - } - - return [null, $statusCode, $response->getHeaders()]; - - } catch (ApiException $e) { - switch ($e->getCode()) { - } - throw $e; - } } + /** * Operation testJsonFormData * @@ -1300,6 +1829,97 @@ class FakeApi * @return array of null, HTTP status code, HTTP response headers (array of strings) */ public function testJsonFormDataWithHttpInfo($param, $param2) + { + $returnType = ''; + $request = $this->testJsonFormDataRequest($param, $param2); + + 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() + ); + } + + return [null, $statusCode, $response->getHeaders()]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + } + throw $e; + } + } + + /** + * Operation testJsonFormDataAsync + * + * test json serialization of form data + * + * @param string $param field1 (required) + * @param string $param2 field2 (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function testJsonFormDataAsync($param, $param2) + { + return $this->testJsonFormDataAsyncWithHttpInfo($param, $param2)->then(function ($response) { + return $response[0]; + }); + } + + /** + * Operation testJsonFormDataAsyncWithHttpInfo + * + * test json serialization of form data + * + * @param string $param field1 (required) + * @param string $param2 field2 (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function testJsonFormDataAsyncWithHttpInfo($param, $param2) + { + $returnType = ''; + $request = $this->testJsonFormDataRequest($param, $param2); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + return [null, $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 'testJsonFormData' + * + * @param string $param field1 (required) + * @param string $param2 field2 (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function testJsonFormDataRequest($param, $param2) { // verify the required parameter 'param' is set if ($param === null) { @@ -1316,7 +1936,6 @@ class FakeApi $headerParams = []; $httpBody = ''; $multipart = false; - $returnType = ''; @@ -1378,42 +1997,12 @@ class FakeApi $headers ); - $request = new Request( + return new Request( 'GET', $url, $headers, $httpBody ); - - 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 ($url)", - $statusCode, - $response->getHeaders(), - $response->getBody() - ); - } - - return [null, $statusCode, $response->getHeaders()]; - - } catch (ApiException $e) { - switch ($e->getCode()) { - } - throw $e; - } } + } diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Api/Fake_classname_tags123Api.php b/samples/client/petstore/php/SwaggerClient-php/lib/Api/Fake_classname_tags123Api.php index d501d730bbd0..6687f851f1bc 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/Fake_classname_tags123Api.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/Fake_classname_tags123Api.php @@ -108,6 +108,126 @@ class Fake_classname_tags123Api * @return array of \Swagger\Client\Model\Client, HTTP status code, HTTP response headers (array of strings) */ public function testClassnameWithHttpInfo($body) + { + $returnType = '\Swagger\Client\Model\Client'; + $request = $this->testClassnameRequest($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 testClassnameAsync + * + * To test class name in snake case + * + * @param \Swagger\Client\Model\Client $body client model (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function testClassnameAsync($body) + { + return $this->testClassnameAsyncWithHttpInfo($body)->then(function ($response) { + return $response[0]; + }); + } + + /** + * Operation testClassnameAsyncWithHttpInfo + * + * To test class name in snake case + * + * @param \Swagger\Client\Model\Client $body client model (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function testClassnameAsyncWithHttpInfo($body) + { + $returnType = '\Swagger\Client\Model\Client'; + $request = $this->testClassnameRequest($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 'testClassname' + * + * @param \Swagger\Client\Model\Client $body client model (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function testClassnameRequest($body) { // verify the required parameter 'body' is set if ($body === null) { @@ -120,7 +240,6 @@ class Fake_classname_tags123Api $headerParams = []; $httpBody = ''; $multipart = false; - $returnType = '\Swagger\Client\Model\Client'; @@ -179,60 +298,12 @@ class Fake_classname_tags123Api $headers ); - $request = new Request( + return new Request( 'PATCH', $url, $headers, $httpBody ); - - 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 ($url)", - $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; - } } + } diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php b/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php index e1c7f0beeee7..e2ab3e4713fa 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php @@ -107,6 +107,94 @@ class PetApi * @return array of null, HTTP status code, HTTP response headers (array of strings) */ public function addPetWithHttpInfo($body) + { + $returnType = ''; + $request = $this->addPetRequest($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() + ); + } + + return [null, $statusCode, $response->getHeaders()]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + } + throw $e; + } + } + + /** + * Operation addPetAsync + * + * Add a new pet to the store + * + * @param \Swagger\Client\Model\Pet $body Pet object that needs to be added to the store (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function addPetAsync($body) + { + return $this->addPetAsyncWithHttpInfo($body)->then(function ($response) { + return $response[0]; + }); + } + + /** + * Operation addPetAsyncWithHttpInfo + * + * Add a new pet to the store + * + * @param \Swagger\Client\Model\Pet $body Pet object that needs to be added to the store (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function addPetAsyncWithHttpInfo($body) + { + $returnType = ''; + $request = $this->addPetRequest($body); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + return [null, $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 'addPet' + * + * @param \Swagger\Client\Model\Pet $body Pet object that needs to be added to the store (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function addPetRequest($body) { // verify the required parameter 'body' is set if ($body === null) { @@ -119,7 +207,6 @@ class PetApi $headerParams = []; $httpBody = ''; $multipart = false; - $returnType = ''; @@ -182,44 +269,14 @@ class PetApi $headers ); - $request = new Request( + return new Request( 'POST', $url, $headers, $httpBody ); - - 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 ($url)", - $statusCode, - $response->getHeaders(), - $response->getBody() - ); - } - - return [null, $statusCode, $response->getHeaders()]; - - } catch (ApiException $e) { - switch ($e->getCode()) { - } - throw $e; - } } + /** * Operation deletePet * @@ -248,6 +305,97 @@ class PetApi * @return array of null, HTTP status code, HTTP response headers (array of strings) */ public function deletePetWithHttpInfo($pet_id, $api_key = null) + { + $returnType = ''; + $request = $this->deletePetRequest($pet_id, $api_key); + + 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() + ); + } + + return [null, $statusCode, $response->getHeaders()]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + } + throw $e; + } + } + + /** + * Operation deletePetAsync + * + * Deletes a pet + * + * @param int $pet_id Pet id to delete (required) + * @param string $api_key (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function deletePetAsync($pet_id, $api_key = null) + { + return $this->deletePetAsyncWithHttpInfo($pet_id, $api_key)->then(function ($response) { + return $response[0]; + }); + } + + /** + * Operation deletePetAsyncWithHttpInfo + * + * Deletes a pet + * + * @param int $pet_id Pet id to delete (required) + * @param string $api_key (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function deletePetAsyncWithHttpInfo($pet_id, $api_key = null) + { + $returnType = ''; + $request = $this->deletePetRequest($pet_id, $api_key); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + return [null, $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 'deletePet' + * + * @param int $pet_id Pet id to delete (required) + * @param string $api_key (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function deletePetRequest($pet_id, $api_key = null) { // verify the required parameter 'pet_id' is set if ($pet_id === null) { @@ -260,7 +408,6 @@ class PetApi $headerParams = []; $httpBody = ''; $multipart = false; - $returnType = ''; // header params if ($api_key !== null) { @@ -326,44 +473,14 @@ class PetApi $headers ); - $request = new Request( + return new Request( 'DELETE', $url, $headers, $httpBody ); - - 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 ($url)", - $statusCode, - $response->getHeaders(), - $response->getBody() - ); - } - - return [null, $statusCode, $response->getHeaders()]; - - } catch (ApiException $e) { - switch ($e->getCode()) { - } - throw $e; - } } + /** * Operation findPetsByStatus * @@ -391,6 +508,126 @@ class PetApi * @return array of \Swagger\Client\Model\Pet[], HTTP status code, HTTP response headers (array of strings) */ public function findPetsByStatusWithHttpInfo($status) + { + $returnType = '\Swagger\Client\Model\Pet[]'; + $request = $this->findPetsByStatusRequest($status); + + 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\Pet[]', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + } + throw $e; + } + } + + /** + * Operation findPetsByStatusAsync + * + * Finds Pets by status + * + * @param string[] $status Status values that need to be considered for filter (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function findPetsByStatusAsync($status) + { + return $this->findPetsByStatusAsyncWithHttpInfo($status)->then(function ($response) { + return $response[0]; + }); + } + + /** + * Operation findPetsByStatusAsyncWithHttpInfo + * + * Finds Pets by status + * + * @param string[] $status Status values that need to be considered for filter (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function findPetsByStatusAsyncWithHttpInfo($status) + { + $returnType = '\Swagger\Client\Model\Pet[]'; + $request = $this->findPetsByStatusRequest($status); + + 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 'findPetsByStatus' + * + * @param string[] $status Status values that need to be considered for filter (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function findPetsByStatusRequest($status) { // verify the required parameter 'status' is set if ($status === null) { @@ -403,7 +640,6 @@ class PetApi $headerParams = []; $httpBody = ''; $multipart = false; - $returnType = '\Swagger\Client\Model\Pet[]'; // query params if (is_array($status)) { @@ -468,12 +704,44 @@ class PetApi $headers ); - $request = new Request( + return new Request( 'GET', $url, $headers, $httpBody ); + } + + /** + * Operation findPetsByTags + * + * Finds Pets by tags + * + * @param string[] $tags Tags to filter by (required) + * @throws \Swagger\Client\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return \Swagger\Client\Model\Pet[] + */ + public function findPetsByTags($tags) + { + list($response) = $this->findPetsByTagsWithHttpInfo($tags); + return $response; + } + + /** + * Operation findPetsByTagsWithHttpInfo + * + * Finds Pets by tags + * + * @param string[] $tags Tags to filter by (required) + * @throws \Swagger\Client\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of \Swagger\Client\Model\Pet[], HTTP status code, HTTP response headers (array of strings) + */ + public function findPetsByTagsWithHttpInfo($tags) + { + $returnType = '\Swagger\Client\Model\Pet[]'; + $request = $this->findPetsByTagsRequest($tags); try { @@ -491,7 +759,7 @@ class PetApi if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( - "[$statusCode] Error connecting to the API ($url)", + "[$statusCode] Error connecting to the API ({$request->getUri()})", $statusCode, $response->getHeaders(), $response->getBody() @@ -524,33 +792,73 @@ class PetApi throw $e; } } + /** - * Operation findPetsByTags + * Operation findPetsByTagsAsync * * Finds Pets by tags * * @param string[] $tags Tags to filter by (required) - * @throws \Swagger\Client\ApiException on non-2xx response * @throws \InvalidArgumentException - * @return \Swagger\Client\Model\Pet[] + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function findPetsByTags($tags) + public function findPetsByTagsAsync($tags) { - list($response) = $this->findPetsByTagsWithHttpInfo($tags); - return $response; + return $this->findPetsByTagsAsyncWithHttpInfo($tags)->then(function ($response) { + return $response[0]; + }); } /** - * Operation findPetsByTagsWithHttpInfo + * Operation findPetsByTagsAsyncWithHttpInfo * * Finds Pets by tags * * @param string[] $tags Tags to filter by (required) - * @throws \Swagger\Client\ApiException on non-2xx response * @throws \InvalidArgumentException - * @return array of \Swagger\Client\Model\Pet[], HTTP status code, HTTP response headers (array of strings) + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function findPetsByTagsWithHttpInfo($tags) + public function findPetsByTagsAsyncWithHttpInfo($tags) + { + $returnType = '\Swagger\Client\Model\Pet[]'; + $request = $this->findPetsByTagsRequest($tags); + + 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 'findPetsByTags' + * + * @param string[] $tags Tags to filter by (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function findPetsByTagsRequest($tags) { // verify the required parameter 'tags' is set if ($tags === null) { @@ -563,7 +871,6 @@ class PetApi $headerParams = []; $httpBody = ''; $multipart = false; - $returnType = '\Swagger\Client\Model\Pet[]'; // query params if (is_array($tags)) { @@ -628,62 +935,14 @@ class PetApi $headers ); - $request = new Request( + return new Request( 'GET', $url, $headers, $httpBody ); - - 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 ($url)", - $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\Pet[]', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - } - throw $e; - } } + /** * Operation getPetById * @@ -711,6 +970,126 @@ class PetApi * @return array of \Swagger\Client\Model\Pet, HTTP status code, HTTP response headers (array of strings) */ public function getPetByIdWithHttpInfo($pet_id) + { + $returnType = '\Swagger\Client\Model\Pet'; + $request = $this->getPetByIdRequest($pet_id); + + 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\Pet', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + } + throw $e; + } + } + + /** + * Operation getPetByIdAsync + * + * Find pet by ID + * + * @param int $pet_id ID of pet to return (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function getPetByIdAsync($pet_id) + { + return $this->getPetByIdAsyncWithHttpInfo($pet_id)->then(function ($response) { + return $response[0]; + }); + } + + /** + * Operation getPetByIdAsyncWithHttpInfo + * + * Find pet by ID + * + * @param int $pet_id ID of pet to return (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function getPetByIdAsyncWithHttpInfo($pet_id) + { + $returnType = '\Swagger\Client\Model\Pet'; + $request = $this->getPetByIdRequest($pet_id); + + 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 'getPetById' + * + * @param int $pet_id ID of pet to return (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function getPetByIdRequest($pet_id) { // verify the required parameter 'pet_id' is set if ($pet_id === null) { @@ -723,7 +1102,6 @@ class PetApi $headerParams = []; $httpBody = ''; $multipart = false; - $returnType = '\Swagger\Client\Model\Pet'; // path params @@ -786,62 +1164,14 @@ class PetApi $headers ); - $request = new Request( + return new Request( 'GET', $url, $headers, $httpBody ); - - 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 ($url)", - $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\Pet', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - } - throw $e; - } } + /** * Operation updatePet * @@ -868,6 +1198,94 @@ class PetApi * @return array of null, HTTP status code, HTTP response headers (array of strings) */ public function updatePetWithHttpInfo($body) + { + $returnType = ''; + $request = $this->updatePetRequest($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() + ); + } + + return [null, $statusCode, $response->getHeaders()]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + } + throw $e; + } + } + + /** + * Operation updatePetAsync + * + * Update an existing pet + * + * @param \Swagger\Client\Model\Pet $body Pet object that needs to be added to the store (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function updatePetAsync($body) + { + return $this->updatePetAsyncWithHttpInfo($body)->then(function ($response) { + return $response[0]; + }); + } + + /** + * Operation updatePetAsyncWithHttpInfo + * + * Update an existing pet + * + * @param \Swagger\Client\Model\Pet $body Pet object that needs to be added to the store (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function updatePetAsyncWithHttpInfo($body) + { + $returnType = ''; + $request = $this->updatePetRequest($body); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + return [null, $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 'updatePet' + * + * @param \Swagger\Client\Model\Pet $body Pet object that needs to be added to the store (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function updatePetRequest($body) { // verify the required parameter 'body' is set if ($body === null) { @@ -880,7 +1298,6 @@ class PetApi $headerParams = []; $httpBody = ''; $multipart = false; - $returnType = ''; @@ -943,44 +1360,14 @@ class PetApi $headers ); - $request = new Request( + return new Request( 'PUT', $url, $headers, $httpBody ); - - 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 ($url)", - $statusCode, - $response->getHeaders(), - $response->getBody() - ); - } - - return [null, $statusCode, $response->getHeaders()]; - - } catch (ApiException $e) { - switch ($e->getCode()) { - } - throw $e; - } } + /** * Operation updatePetWithForm * @@ -1011,6 +1398,100 @@ class PetApi * @return array of null, HTTP status code, HTTP response headers (array of strings) */ public function updatePetWithFormWithHttpInfo($pet_id, $name = null, $status = null) + { + $returnType = ''; + $request = $this->updatePetWithFormRequest($pet_id, $name, $status); + + 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() + ); + } + + return [null, $statusCode, $response->getHeaders()]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + } + throw $e; + } + } + + /** + * Operation updatePetWithFormAsync + * + * Updates a pet in the store with form data + * + * @param int $pet_id ID of pet that needs to be updated (required) + * @param string $name Updated name of the pet (optional) + * @param string $status Updated status of the pet (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function updatePetWithFormAsync($pet_id, $name = null, $status = null) + { + return $this->updatePetWithFormAsyncWithHttpInfo($pet_id, $name, $status)->then(function ($response) { + return $response[0]; + }); + } + + /** + * Operation updatePetWithFormAsyncWithHttpInfo + * + * Updates a pet in the store with form data + * + * @param int $pet_id ID of pet that needs to be updated (required) + * @param string $name Updated name of the pet (optional) + * @param string $status Updated status of the pet (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function updatePetWithFormAsyncWithHttpInfo($pet_id, $name = null, $status = null) + { + $returnType = ''; + $request = $this->updatePetWithFormRequest($pet_id, $name, $status); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + return [null, $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 'updatePetWithForm' + * + * @param int $pet_id ID of pet that needs to be updated (required) + * @param string $name Updated name of the pet (optional) + * @param string $status Updated status of the pet (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function updatePetWithFormRequest($pet_id, $name = null, $status = null) { // verify the required parameter 'pet_id' is set if ($pet_id === null) { @@ -1023,7 +1504,6 @@ class PetApi $headerParams = []; $httpBody = ''; $multipart = false; - $returnType = ''; // path params @@ -1093,44 +1573,14 @@ class PetApi $headers ); - $request = new Request( + return new Request( 'POST', $url, $headers, $httpBody ); - - 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 ($url)", - $statusCode, - $response->getHeaders(), - $response->getBody() - ); - } - - return [null, $statusCode, $response->getHeaders()]; - - } catch (ApiException $e) { - switch ($e->getCode()) { - } - throw $e; - } } + /** * Operation uploadFile * @@ -1162,6 +1612,132 @@ class PetApi * @return array of \Swagger\Client\Model\ApiResponse, HTTP status code, HTTP response headers (array of strings) */ public function uploadFileWithHttpInfo($pet_id, $additional_metadata = null, $file = null) + { + $returnType = '\Swagger\Client\Model\ApiResponse'; + $request = $this->uploadFileRequest($pet_id, $additional_metadata, $file); + + 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\ApiResponse', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + } + throw $e; + } + } + + /** + * Operation uploadFileAsync + * + * uploads an image + * + * @param int $pet_id ID of pet to update (required) + * @param string $additional_metadata Additional data to pass to server (optional) + * @param \SplFileObject $file file to upload (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function uploadFileAsync($pet_id, $additional_metadata = null, $file = null) + { + return $this->uploadFileAsyncWithHttpInfo($pet_id, $additional_metadata, $file)->then(function ($response) { + return $response[0]; + }); + } + + /** + * Operation uploadFileAsyncWithHttpInfo + * + * uploads an image + * + * @param int $pet_id ID of pet to update (required) + * @param string $additional_metadata Additional data to pass to server (optional) + * @param \SplFileObject $file file to upload (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function uploadFileAsyncWithHttpInfo($pet_id, $additional_metadata = null, $file = null) + { + $returnType = '\Swagger\Client\Model\ApiResponse'; + $request = $this->uploadFileRequest($pet_id, $additional_metadata, $file); + + 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 'uploadFile' + * + * @param int $pet_id ID of pet to update (required) + * @param string $additional_metadata Additional data to pass to server (optional) + * @param \SplFileObject $file file to upload (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function uploadFileRequest($pet_id, $additional_metadata = null, $file = null) { // verify the required parameter 'pet_id' is set if ($pet_id === null) { @@ -1174,7 +1750,6 @@ class PetApi $headerParams = []; $httpBody = ''; $multipart = false; - $returnType = '\Swagger\Client\Model\ApiResponse'; // path params @@ -1245,60 +1820,12 @@ class PetApi $headers ); - $request = new Request( + return new Request( 'POST', $url, $headers, $httpBody ); - - 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 ($url)", - $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\ApiResponse', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - } - throw $e; - } } + } diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php b/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php index 35908a206713..56ad01aa62fc 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php @@ -107,6 +107,94 @@ class StoreApi * @return array of null, HTTP status code, HTTP response headers (array of strings) */ public function deleteOrderWithHttpInfo($order_id) + { + $returnType = ''; + $request = $this->deleteOrderRequest($order_id); + + 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() + ); + } + + return [null, $statusCode, $response->getHeaders()]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + } + throw $e; + } + } + + /** + * Operation deleteOrderAsync + * + * Delete purchase order by ID + * + * @param string $order_id ID of the order that needs to be deleted (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function deleteOrderAsync($order_id) + { + return $this->deleteOrderAsyncWithHttpInfo($order_id)->then(function ($response) { + return $response[0]; + }); + } + + /** + * Operation deleteOrderAsyncWithHttpInfo + * + * Delete purchase order by ID + * + * @param string $order_id ID of the order that needs to be deleted (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function deleteOrderAsyncWithHttpInfo($order_id) + { + $returnType = ''; + $request = $this->deleteOrderRequest($order_id); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + return [null, $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 'deleteOrder' + * + * @param string $order_id ID of the order that needs to be deleted (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function deleteOrderRequest($order_id) { // verify the required parameter 'order_id' is set if ($order_id === null) { @@ -119,7 +207,6 @@ class StoreApi $headerParams = []; $httpBody = ''; $multipart = false; - $returnType = ''; // path params @@ -177,44 +264,14 @@ class StoreApi $headers ); - $request = new Request( + return new Request( 'DELETE', $url, $headers, $httpBody ); - - 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 ($url)", - $statusCode, - $response->getHeaders(), - $response->getBody() - ); - } - - return [null, $statusCode, $response->getHeaders()]; - - } catch (ApiException $e) { - switch ($e->getCode()) { - } - throw $e; - } } + /** * Operation getInventory * @@ -240,6 +297,123 @@ class StoreApi * @return array of map[string,int], HTTP status code, HTTP response headers (array of strings) */ public function getInventoryWithHttpInfo() + { + $returnType = 'map[string,int]'; + $request = $this->getInventoryRequest(); + + 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(), 'map[string,int]', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + } + throw $e; + } + } + + /** + * Operation getInventoryAsync + * + * Returns pet inventories by status + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function getInventoryAsync() + { + return $this->getInventoryAsyncWithHttpInfo()->then(function ($response) { + return $response[0]; + }); + } + + /** + * Operation getInventoryAsyncWithHttpInfo + * + * Returns pet inventories by status + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function getInventoryAsyncWithHttpInfo() + { + $returnType = 'map[string,int]'; + $request = $this->getInventoryRequest(); + + 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 'getInventory' + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function getInventoryRequest() { $resourcePath = '/store/inventory'; @@ -248,7 +422,6 @@ class StoreApi $headerParams = []; $httpBody = ''; $multipart = false; - $returnType = 'map[string,int]'; @@ -307,62 +480,14 @@ class StoreApi $headers ); - $request = new Request( + return new Request( 'GET', $url, $headers, $httpBody ); - - 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 ($url)", - $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(), 'map[string,int]', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - } - throw $e; - } } + /** * Operation getOrderById * @@ -390,6 +515,126 @@ class StoreApi * @return array of \Swagger\Client\Model\Order, HTTP status code, HTTP response headers (array of strings) */ public function getOrderByIdWithHttpInfo($order_id) + { + $returnType = '\Swagger\Client\Model\Order'; + $request = $this->getOrderByIdRequest($order_id); + + 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\Order', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + } + throw $e; + } + } + + /** + * Operation getOrderByIdAsync + * + * Find purchase order by ID + * + * @param int $order_id ID of pet that needs to be fetched (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function getOrderByIdAsync($order_id) + { + return $this->getOrderByIdAsyncWithHttpInfo($order_id)->then(function ($response) { + return $response[0]; + }); + } + + /** + * Operation getOrderByIdAsyncWithHttpInfo + * + * Find purchase order by ID + * + * @param int $order_id ID of pet that needs to be fetched (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function getOrderByIdAsyncWithHttpInfo($order_id) + { + $returnType = '\Swagger\Client\Model\Order'; + $request = $this->getOrderByIdRequest($order_id); + + 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 'getOrderById' + * + * @param int $order_id ID of pet that needs to be fetched (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function getOrderByIdRequest($order_id) { // verify the required parameter 'order_id' is set if ($order_id === null) { @@ -409,7 +654,6 @@ class StoreApi $headerParams = []; $httpBody = ''; $multipart = false; - $returnType = '\Swagger\Client\Model\Order'; // path params @@ -467,12 +711,44 @@ class StoreApi $headers ); - $request = new Request( + return new Request( 'GET', $url, $headers, $httpBody ); + } + + /** + * Operation placeOrder + * + * Place an order for a pet + * + * @param \Swagger\Client\Model\Order $body order placed for purchasing the pet (required) + * @throws \Swagger\Client\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return \Swagger\Client\Model\Order + */ + public function placeOrder($body) + { + list($response) = $this->placeOrderWithHttpInfo($body); + return $response; + } + + /** + * Operation placeOrderWithHttpInfo + * + * Place an order for a pet + * + * @param \Swagger\Client\Model\Order $body order placed for purchasing the pet (required) + * @throws \Swagger\Client\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of \Swagger\Client\Model\Order, HTTP status code, HTTP response headers (array of strings) + */ + public function placeOrderWithHttpInfo($body) + { + $returnType = '\Swagger\Client\Model\Order'; + $request = $this->placeOrderRequest($body); try { @@ -490,7 +766,7 @@ class StoreApi if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( - "[$statusCode] Error connecting to the API ($url)", + "[$statusCode] Error connecting to the API ({$request->getUri()})", $statusCode, $response->getHeaders(), $response->getBody() @@ -523,33 +799,73 @@ class StoreApi throw $e; } } + /** - * Operation placeOrder + * Operation placeOrderAsync * * Place an order for a pet * * @param \Swagger\Client\Model\Order $body order placed for purchasing the pet (required) - * @throws \Swagger\Client\ApiException on non-2xx response * @throws \InvalidArgumentException - * @return \Swagger\Client\Model\Order + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function placeOrder($body) + public function placeOrderAsync($body) { - list($response) = $this->placeOrderWithHttpInfo($body); - return $response; + return $this->placeOrderAsyncWithHttpInfo($body)->then(function ($response) { + return $response[0]; + }); } /** - * Operation placeOrderWithHttpInfo + * Operation placeOrderAsyncWithHttpInfo * * Place an order for a pet * * @param \Swagger\Client\Model\Order $body order placed for purchasing the pet (required) - * @throws \Swagger\Client\ApiException on non-2xx response * @throws \InvalidArgumentException - * @return array of \Swagger\Client\Model\Order, HTTP status code, HTTP response headers (array of strings) + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function placeOrderWithHttpInfo($body) + public function placeOrderAsyncWithHttpInfo($body) + { + $returnType = '\Swagger\Client\Model\Order'; + $request = $this->placeOrderRequest($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 'placeOrder' + * + * @param \Swagger\Client\Model\Order $body order placed for purchasing the pet (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function placeOrderRequest($body) { // verify the required parameter 'body' is set if ($body === null) { @@ -562,7 +878,6 @@ class StoreApi $headerParams = []; $httpBody = ''; $multipart = false; - $returnType = '\Swagger\Client\Model\Order'; @@ -621,60 +936,12 @@ class StoreApi $headers ); - $request = new Request( + return new Request( 'POST', $url, $headers, $httpBody ); - - 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 ($url)", - $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\Order', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - } - throw $e; - } } + } diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Api/UserApi.php b/samples/client/petstore/php/SwaggerClient-php/lib/Api/UserApi.php index 5cd4cab7bb16..27f7220ed8ae 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/UserApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/UserApi.php @@ -107,6 +107,94 @@ class UserApi * @return array of null, HTTP status code, HTTP response headers (array of strings) */ public function createUserWithHttpInfo($body) + { + $returnType = ''; + $request = $this->createUserRequest($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() + ); + } + + return [null, $statusCode, $response->getHeaders()]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + } + throw $e; + } + } + + /** + * Operation createUserAsync + * + * Create user + * + * @param \Swagger\Client\Model\User $body Created user object (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function createUserAsync($body) + { + return $this->createUserAsyncWithHttpInfo($body)->then(function ($response) { + return $response[0]; + }); + } + + /** + * Operation createUserAsyncWithHttpInfo + * + * Create user + * + * @param \Swagger\Client\Model\User $body Created user object (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function createUserAsyncWithHttpInfo($body) + { + $returnType = ''; + $request = $this->createUserRequest($body); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + return [null, $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 'createUser' + * + * @param \Swagger\Client\Model\User $body Created user object (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function createUserRequest($body) { // verify the required parameter 'body' is set if ($body === null) { @@ -119,7 +207,6 @@ class UserApi $headerParams = []; $httpBody = ''; $multipart = false; - $returnType = ''; @@ -178,44 +265,14 @@ class UserApi $headers ); - $request = new Request( + return new Request( 'POST', $url, $headers, $httpBody ); - - 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 ($url)", - $statusCode, - $response->getHeaders(), - $response->getBody() - ); - } - - return [null, $statusCode, $response->getHeaders()]; - - } catch (ApiException $e) { - switch ($e->getCode()) { - } - throw $e; - } } + /** * Operation createUsersWithArrayInput * @@ -242,6 +299,94 @@ class UserApi * @return array of null, HTTP status code, HTTP response headers (array of strings) */ public function createUsersWithArrayInputWithHttpInfo($body) + { + $returnType = ''; + $request = $this->createUsersWithArrayInputRequest($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() + ); + } + + return [null, $statusCode, $response->getHeaders()]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + } + throw $e; + } + } + + /** + * Operation createUsersWithArrayInputAsync + * + * Creates list of users with given input array + * + * @param \Swagger\Client\Model\User[] $body List of user object (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function createUsersWithArrayInputAsync($body) + { + return $this->createUsersWithArrayInputAsyncWithHttpInfo($body)->then(function ($response) { + return $response[0]; + }); + } + + /** + * Operation createUsersWithArrayInputAsyncWithHttpInfo + * + * Creates list of users with given input array + * + * @param \Swagger\Client\Model\User[] $body List of user object (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function createUsersWithArrayInputAsyncWithHttpInfo($body) + { + $returnType = ''; + $request = $this->createUsersWithArrayInputRequest($body); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + return [null, $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 'createUsersWithArrayInput' + * + * @param \Swagger\Client\Model\User[] $body List of user object (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function createUsersWithArrayInputRequest($body) { // verify the required parameter 'body' is set if ($body === null) { @@ -254,7 +399,6 @@ class UserApi $headerParams = []; $httpBody = ''; $multipart = false; - $returnType = ''; @@ -313,44 +457,14 @@ class UserApi $headers ); - $request = new Request( + return new Request( 'POST', $url, $headers, $httpBody ); - - 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 ($url)", - $statusCode, - $response->getHeaders(), - $response->getBody() - ); - } - - return [null, $statusCode, $response->getHeaders()]; - - } catch (ApiException $e) { - switch ($e->getCode()) { - } - throw $e; - } } + /** * Operation createUsersWithListInput * @@ -377,6 +491,94 @@ class UserApi * @return array of null, HTTP status code, HTTP response headers (array of strings) */ public function createUsersWithListInputWithHttpInfo($body) + { + $returnType = ''; + $request = $this->createUsersWithListInputRequest($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() + ); + } + + return [null, $statusCode, $response->getHeaders()]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + } + throw $e; + } + } + + /** + * Operation createUsersWithListInputAsync + * + * Creates list of users with given input array + * + * @param \Swagger\Client\Model\User[] $body List of user object (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function createUsersWithListInputAsync($body) + { + return $this->createUsersWithListInputAsyncWithHttpInfo($body)->then(function ($response) { + return $response[0]; + }); + } + + /** + * Operation createUsersWithListInputAsyncWithHttpInfo + * + * Creates list of users with given input array + * + * @param \Swagger\Client\Model\User[] $body List of user object (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function createUsersWithListInputAsyncWithHttpInfo($body) + { + $returnType = ''; + $request = $this->createUsersWithListInputRequest($body); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + return [null, $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 'createUsersWithListInput' + * + * @param \Swagger\Client\Model\User[] $body List of user object (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function createUsersWithListInputRequest($body) { // verify the required parameter 'body' is set if ($body === null) { @@ -389,7 +591,6 @@ class UserApi $headerParams = []; $httpBody = ''; $multipart = false; - $returnType = ''; @@ -448,44 +649,14 @@ class UserApi $headers ); - $request = new Request( + return new Request( 'POST', $url, $headers, $httpBody ); - - 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 ($url)", - $statusCode, - $response->getHeaders(), - $response->getBody() - ); - } - - return [null, $statusCode, $response->getHeaders()]; - - } catch (ApiException $e) { - switch ($e->getCode()) { - } - throw $e; - } } + /** * Operation deleteUser * @@ -512,6 +683,94 @@ class UserApi * @return array of null, HTTP status code, HTTP response headers (array of strings) */ public function deleteUserWithHttpInfo($username) + { + $returnType = ''; + $request = $this->deleteUserRequest($username); + + 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() + ); + } + + return [null, $statusCode, $response->getHeaders()]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + } + throw $e; + } + } + + /** + * Operation deleteUserAsync + * + * Delete user + * + * @param string $username The name that needs to be deleted (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function deleteUserAsync($username) + { + return $this->deleteUserAsyncWithHttpInfo($username)->then(function ($response) { + return $response[0]; + }); + } + + /** + * Operation deleteUserAsyncWithHttpInfo + * + * Delete user + * + * @param string $username The name that needs to be deleted (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function deleteUserAsyncWithHttpInfo($username) + { + $returnType = ''; + $request = $this->deleteUserRequest($username); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + return [null, $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 'deleteUser' + * + * @param string $username The name that needs to be deleted (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function deleteUserRequest($username) { // verify the required parameter 'username' is set if ($username === null) { @@ -524,7 +783,6 @@ class UserApi $headerParams = []; $httpBody = ''; $multipart = false; - $returnType = ''; // path params @@ -582,44 +840,14 @@ class UserApi $headers ); - $request = new Request( + return new Request( 'DELETE', $url, $headers, $httpBody ); - - 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 ($url)", - $statusCode, - $response->getHeaders(), - $response->getBody() - ); - } - - return [null, $statusCode, $response->getHeaders()]; - - } catch (ApiException $e) { - switch ($e->getCode()) { - } - throw $e; - } } + /** * Operation getUserByName * @@ -648,81 +876,8 @@ class UserApi */ public function getUserByNameWithHttpInfo($username) { - // verify the required parameter 'username' is set - if ($username === null) { - throw new \InvalidArgumentException('Missing the required parameter $username when calling getUserByName'); - } - - $resourcePath = '/user/{username}'; - $formParams = []; - $queryParams = []; - $headerParams = []; - $httpBody = ''; - $multipart = false; $returnType = '\Swagger\Client\Model\User'; - - - // path params - if ($username !== null) { - $resourcePath = str_replace('{' . 'username' . '}', ObjectSerializer::toPathValue($username), $resourcePath); - } - - - if ($multipart) { - $headers= $this->headerSelector->selectHeadersForMultipart( - ['application/xml', 'application/json'] - ); - } else { - $headers = $this->headerSelector->selectHeaders( - ['application/xml', '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 - ); - - $request = new Request( - 'GET', - $url, - $headers, - $httpBody - ); + $request = $this->getUserByNameRequest($username); try { @@ -740,7 +895,7 @@ class UserApi if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( - "[$statusCode] Error connecting to the API ($url)", + "[$statusCode] Error connecting to the API ({$request->getUri()})", $statusCode, $response->getHeaders(), $response->getBody() @@ -773,6 +928,150 @@ class UserApi throw $e; } } + + /** + * Operation getUserByNameAsync + * + * Get user by user name + * + * @param string $username The name that needs to be fetched. Use user1 for testing. (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function getUserByNameAsync($username) + { + return $this->getUserByNameAsyncWithHttpInfo($username)->then(function ($response) { + return $response[0]; + }); + } + + /** + * Operation getUserByNameAsyncWithHttpInfo + * + * Get user by user name + * + * @param string $username The name that needs to be fetched. Use user1 for testing. (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function getUserByNameAsyncWithHttpInfo($username) + { + $returnType = '\Swagger\Client\Model\User'; + $request = $this->getUserByNameRequest($username); + + 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 'getUserByName' + * + * @param string $username The name that needs to be fetched. Use user1 for testing. (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function getUserByNameRequest($username) + { + // verify the required parameter 'username' is set + if ($username === null) { + throw new \InvalidArgumentException('Missing the required parameter $username when calling getUserByName'); + } + + $resourcePath = '/user/{username}'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + + // path params + if ($username !== null) { + $resourcePath = str_replace('{' . 'username' . '}', ObjectSerializer::toPathValue($username), $resourcePath); + } + + + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/xml', 'application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/xml', '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( + 'GET', + $url, + $headers, + $httpBody + ); + } + /** * Operation loginUser * @@ -802,6 +1101,129 @@ class UserApi * @return array of string, HTTP status code, HTTP response headers (array of strings) */ public function loginUserWithHttpInfo($username, $password) + { + $returnType = 'string'; + $request = $this->loginUserRequest($username, $password); + + 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(), 'string', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + } + throw $e; + } + } + + /** + * Operation loginUserAsync + * + * Logs user into the system + * + * @param string $username The user name for login (required) + * @param string $password The password for login in clear text (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function loginUserAsync($username, $password) + { + return $this->loginUserAsyncWithHttpInfo($username, $password)->then(function ($response) { + return $response[0]; + }); + } + + /** + * Operation loginUserAsyncWithHttpInfo + * + * Logs user into the system + * + * @param string $username The user name for login (required) + * @param string $password The password for login in clear text (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function loginUserAsyncWithHttpInfo($username, $password) + { + $returnType = 'string'; + $request = $this->loginUserRequest($username, $password); + + 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 'loginUser' + * + * @param string $username The user name for login (required) + * @param string $password The password for login in clear text (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function loginUserRequest($username, $password) { // verify the required parameter 'username' is set if ($username === null) { @@ -818,7 +1240,6 @@ class UserApi $headerParams = []; $httpBody = ''; $multipart = false; - $returnType = 'string'; // query params if ($username !== null) { @@ -880,62 +1301,14 @@ class UserApi $headers ); - $request = new Request( + return new Request( 'GET', $url, $headers, $httpBody ); - - 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 ($url)", - $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(), 'string', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - } - throw $e; - } } + /** * Operation logoutUser * @@ -960,6 +1333,91 @@ class UserApi * @return array of null, HTTP status code, HTTP response headers (array of strings) */ public function logoutUserWithHttpInfo() + { + $returnType = ''; + $request = $this->logoutUserRequest(); + + 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() + ); + } + + return [null, $statusCode, $response->getHeaders()]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + } + throw $e; + } + } + + /** + * Operation logoutUserAsync + * + * Logs out current logged in user session + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function logoutUserAsync() + { + return $this->logoutUserAsyncWithHttpInfo()->then(function ($response) { + return $response[0]; + }); + } + + /** + * Operation logoutUserAsyncWithHttpInfo + * + * Logs out current logged in user session + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function logoutUserAsyncWithHttpInfo() + { + $returnType = ''; + $request = $this->logoutUserRequest(); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + return [null, $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 'logoutUser' + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function logoutUserRequest() { $resourcePath = '/user/logout'; @@ -968,7 +1426,6 @@ class UserApi $headerParams = []; $httpBody = ''; $multipart = false; - $returnType = ''; @@ -1022,44 +1479,14 @@ class UserApi $headers ); - $request = new Request( + return new Request( 'GET', $url, $headers, $httpBody ); - - 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 ($url)", - $statusCode, - $response->getHeaders(), - $response->getBody() - ); - } - - return [null, $statusCode, $response->getHeaders()]; - - } catch (ApiException $e) { - switch ($e->getCode()) { - } - throw $e; - } } + /** * Operation updateUser * @@ -1088,6 +1515,97 @@ class UserApi * @return array of null, HTTP status code, HTTP response headers (array of strings) */ public function updateUserWithHttpInfo($username, $body) + { + $returnType = ''; + $request = $this->updateUserRequest($username, $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() + ); + } + + return [null, $statusCode, $response->getHeaders()]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + } + throw $e; + } + } + + /** + * Operation updateUserAsync + * + * Updated user + * + * @param string $username name that need to be deleted (required) + * @param \Swagger\Client\Model\User $body Updated user object (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function updateUserAsync($username, $body) + { + return $this->updateUserAsyncWithHttpInfo($username, $body)->then(function ($response) { + return $response[0]; + }); + } + + /** + * Operation updateUserAsyncWithHttpInfo + * + * Updated user + * + * @param string $username name that need to be deleted (required) + * @param \Swagger\Client\Model\User $body Updated user object (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function updateUserAsyncWithHttpInfo($username, $body) + { + $returnType = ''; + $request = $this->updateUserRequest($username, $body); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + return [null, $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 'updateUser' + * + * @param string $username name that need to be deleted (required) + * @param \Swagger\Client\Model\User $body Updated user object (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function updateUserRequest($username, $body) { // verify the required parameter 'username' is set if ($username === null) { @@ -1104,7 +1622,6 @@ class UserApi $headerParams = []; $httpBody = ''; $multipart = false; - $returnType = ''; // path params @@ -1167,42 +1684,12 @@ class UserApi $headers ); - $request = new Request( + return new Request( 'PUT', $url, $headers, $httpBody ); - - 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 ($url)", - $statusCode, - $response->getHeaders(), - $response->getBody() - ); - } - - return [null, $statusCode, $response->getHeaders()]; - - } catch (ApiException $e) { - switch ($e->getCode()) { - } - throw $e; - } } + } diff --git a/samples/client/petstore/php/SwaggerClient-php/tests/AsyncTest.php b/samples/client/petstore/php/SwaggerClient-php/tests/AsyncTest.php new file mode 100644 index 000000000000..049869c357d4 --- /dev/null +++ b/samples/client/petstore/php/SwaggerClient-php/tests/AsyncTest.php @@ -0,0 +1,85 @@ +api = new Api\PetApi(); + + $this->petId = 10005; + $pet = new Model\Pet; + $pet->setId($this->petId); + $pet->setName("PHP Unit Test"); + $pet->setPhotoUrls(array("http://test_php_unit_test.com")); + // new tag + $tag= new Model\Tag; + $tag->setId($this->petId); // use the same id as pet + $tag->setName("test php tag"); + // new category + $category = new Model\Category; + $category->setId($this->petId); // use the same id as pet + $category->setName("test php category"); + + $pet->setTags(array($tag)); + $pet->setCategory($category); + + $pet_api = new Api\PetApi(); + // add a new pet (model) + $add_response = $pet_api->addPet($pet); + } + + public function testAsyncRequest() + { + $promise = $this->api->getPetByIdAsync(10005); + + $promise2 = $this->api->getPetByIdAsync(10005); + + $pet = $promise->wait(); + $pet2 = $promise2->wait(); + $this->assertInstanceOf(Pet::class, $pet); + $this->assertInstanceOf(Pet::class, $pet2); + } + + public function testAsyncRequestWithHttpInfo() + { + $promise = $this->api->getPetByIdAsyncWithHttpInfo($this->petId); + + list($pet, $status, $headers) = $promise->wait(); + $this->assertEquals(200, $status); + $this->assertInternalType('array', $headers); + $this->assertInstanceOf(Pet::class, $pet); + } + + public function testAsyncThrowingException() + { + $this->setExpectedException(ApiException::class); + + $promise = $this->api->getPetByIdAsync(0); + $promise->wait(); + } + + public function testAsyncApiExceptionWithoutWaitIsNotThrown() + { + $promise = $this->api->getPetByIdAsync(0); + sleep(1); + } + + public function testAsyncHttpInfoThrowingException() + { + $this->setExpectedException(ApiException::class); + + $promise = $this->api->getPetByIdAsyncWithHttpInfo(0); + $promise->wait(); + } +}