From a45d1587103cf924b99e0e37337bc7385c7f5fc7 Mon Sep 17 00:00:00 2001 From: Juan Treminio Date: Sat, 29 Mar 2025 12:47:29 -0500 Subject: [PATCH 1/8] [PHP] - Add range HTTP code support --- .../main/resources/php-nextgen/api.mustache | 125 +- .../src/main/resources/php/api.mustache | 125 +- .../php/libraries/psr-18/api.mustache | 109 +- ...ith-fake-endpoints-models-for-testing.yaml | 64 + .../php-nextgen-streaming/src/Api/AuthApi.php | 177 +- .../php-nextgen-streaming/src/Api/BodyApi.php | 713 ++------ .../php-nextgen-streaming/src/Api/FormApi.php | 244 +-- .../src/Api/HeaderApi.php | 110 +- .../php-nextgen-streaming/src/Api/PathApi.php | 110 +- .../src/Api/QueryApi.php | 713 ++------ .../echo_api/php-nextgen/src/Api/AuthApi.php | 177 +- .../echo_api/php-nextgen/src/Api/BodyApi.php | 713 ++------ .../echo_api/php-nextgen/src/Api/FormApi.php | 244 +-- .../php-nextgen/src/Api/HeaderApi.php | 110 +- .../echo_api/php-nextgen/src/Api/PathApi.php | 110 +- .../echo_api/php-nextgen/src/Api/QueryApi.php | 713 ++------ .../src/Api/AnotherFakeApi.php | 110 +- .../OpenAPIClient-php/src/Api/DefaultApi.php | 110 +- .../OpenAPIClient-php/src/Api/FakeApi.php | 674 ++----- .../src/Api/FakeClassnameTags123Api.php | 110 +- .../OpenAPIClient-php/src/Api/PetApi.php | 386 ++-- .../OpenAPIClient-php/src/Api/StoreApi.php | 246 +-- .../OpenAPIClient-php/src/Api/UserApi.php | 189 +- .../.openapi-generator/FILES | 3 + .../petstore/php/OpenAPIClient-php/README.md | 4 + .../php/OpenAPIClient-php/docs/Api/FakeApi.md | 162 ++ .../docs/Model/ErrorRangeResponse.md | 10 + .../docs/Model/ErrorResponse.md | 10 + .../lib/Api/AnotherFakeApi.php | 111 +- .../OpenAPIClient-php/lib/Api/DefaultApi.php | 111 +- .../php/OpenAPIClient-php/lib/Api/FakeApi.php | 1610 ++++++++++------- .../lib/Api/FakeClassnameTags123Api.php | 111 +- .../php/OpenAPIClient-php/lib/Api/PetApi.php | 463 ++--- .../OpenAPIClient-php/lib/Api/StoreApi.php | 250 +-- .../php/OpenAPIClient-php/lib/Api/UserApi.php | 197 +- .../lib/Model/ErrorRangeResponse.php | 443 +++++ .../lib/Model/ErrorResponse.php | 443 +++++ .../test/Model/ErrorRangeResponseTest.php | 99 + .../test/Model/ErrorResponseTest.php | 99 + .../php/psr-18/.openapi-generator/FILES | 3 + samples/client/petstore/php/psr-18/README.md | 4 + .../petstore/php/psr-18/docs/Api/FakeApi.md | 162 ++ .../psr-18/docs/Model/ErrorRangeResponse.md | 10 + .../php/psr-18/docs/Model/ErrorResponse.md | 10 + .../php/psr-18/lib/Api/AnotherFakeApi.php | 91 +- .../php/psr-18/lib/Api/DefaultApi.php | 91 +- .../petstore/php/psr-18/lib/Api/FakeApi.php | 1404 ++++++++++---- .../lib/Api/FakeClassnameTags123Api.php | 91 +- .../petstore/php/psr-18/lib/Api/PetApi.php | 347 ++-- .../petstore/php/psr-18/lib/Api/StoreApi.php | 191 +- .../petstore/php/psr-18/lib/Api/UserApi.php | 163 +- .../psr-18/lib/Model/ErrorRangeResponse.php | 443 +++++ .../php/psr-18/lib/Model/ErrorResponse.php | 443 +++++ .../test/Model/ErrorRangeResponseTest.php | 99 + .../psr-18/test/Model/ErrorResponseTest.php | 99 + 55 files changed, 7686 insertions(+), 6473 deletions(-) create mode 100644 samples/client/petstore/php/OpenAPIClient-php/docs/Model/ErrorRangeResponse.md create mode 100644 samples/client/petstore/php/OpenAPIClient-php/docs/Model/ErrorResponse.md create mode 100644 samples/client/petstore/php/OpenAPIClient-php/lib/Model/ErrorRangeResponse.php create mode 100644 samples/client/petstore/php/OpenAPIClient-php/lib/Model/ErrorResponse.php create mode 100644 samples/client/petstore/php/OpenAPIClient-php/test/Model/ErrorRangeResponseTest.php create mode 100644 samples/client/petstore/php/OpenAPIClient-php/test/Model/ErrorResponseTest.php create mode 100644 samples/client/petstore/php/psr-18/docs/Model/ErrorRangeResponse.md create mode 100644 samples/client/petstore/php/psr-18/docs/Model/ErrorResponse.md create mode 100644 samples/client/petstore/php/psr-18/lib/Model/ErrorRangeResponse.php create mode 100644 samples/client/petstore/php/psr-18/lib/Model/ErrorResponse.php create mode 100644 samples/client/petstore/php/psr-18/test/Model/ErrorRangeResponseTest.php create mode 100644 samples/client/petstore/php/psr-18/test/Model/ErrorResponseTest.php diff --git a/modules/openapi-generator/src/main/resources/php-nextgen/api.mustache b/modules/openapi-generator/src/main/resources/php-nextgen/api.mustache index 96c394a31bb0..99e6ed4d250d 100644 --- a/modules/openapi-generator/src/main/resources/php-nextgen/api.mustache +++ b/modules/openapi-generator/src/main/resources/php-nextgen/api.mustache @@ -26,6 +26,7 @@ use GuzzleHttp\Psr7\MultipartStream; use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; use GuzzleHttp\Promise\PromiseInterface; +use Psr\Http\Message\ResponseInterface; use {{invokerPackage}}\ApiException; use {{invokerPackage}}\Configuration; use {{invokerPackage}}\HeaderSelector; @@ -289,42 +290,26 @@ use {{invokerPackage}}\ObjectSerializer; {{#returnType}} {{#responses}} {{#-first}} - switch($statusCode) { {{/-first}} {{#dataType}} {{^isRange}}{{^isWildcard}}case {{code}}:{{/isWildcard}}{{#isWildcard}}default:{{/isWildcard}} - if (in_array('{{{dataType}}}', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('{{{dataType}}}' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, '{{{dataType}}}', []), - $response->getStatusCode(), - $response->getHeaders() - ];{{/isRange}} + return $this->handleResponseWithDataType( + '{{{dataType}}}', + $response, + );{{/isRange}} {{/dataType}} {{#-last}} } {{/-last}} {{/responses}} + {{#responses}}{{#dataType}}{{#isRange}}{{^isWildcard}} + if ($this->responseWithinRangeCode('{{code}}', $statusCode)) { + return $this->handleResponseWithDataType( + '{{{dataType}}}', + $response, + ); + }{{/isWildcard}}{{/isRange}}{{/dataType}}{{/responses}} if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -339,39 +324,15 @@ use {{invokerPackage}}\ObjectSerializer; ); } - $returnType = '{{{returnType}}}'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + '{{{returnType}}}', + $response, + ); {{/returnType}} {{^returnType}} return [null, $statusCode, $response->getHeaders()]; {{/returnType}} - } catch (ApiException $e) { switch ($e->getCode()) { {{#responses}} @@ -383,10 +344,20 @@ use {{invokerPackage}}\ObjectSerializer; $e->getResponseHeaders() ); $e->setResponseObject($data); - break;{{/isRange}} + throw $e;{{/isRange}} {{/dataType}} {{/responses}} } + {{#responses}}{{#dataType}}{{#isRange}}{{^isWildcard}} + if ($this->responseWithinRangeCode('{{code}}', $e->getCode())) { + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '{{{dataType}}}', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + throw $e; + }{{/isWildcard}}{{/isRange}}{{/dataType}}{{/responses}} throw $e; } } @@ -938,5 +909,47 @@ use {{invokerPackage}}\ObjectSerializer; return $options; } + + private function handleResponseWithDataType( + string $dataType, + ResponseInterface $response, + ): array { + if (in_array($dataType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ($dataType !== 'string') { + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $response->getStatusCode(), + $response->getHeaders(), + $content + ); + } + } + } + + return [ + ObjectSerializer::deserialize($content, $dataType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + private function responseWithinRangeCode( + string $rangeCode, + int $statusCode, + ): bool { + $left = (int) ($rangeCode[0].'00'); + $right = (int) ($rangeCode[0].'99'); + + return $statusCode >= $left && $statusCode <= $right; + } } {{/operations}} diff --git a/modules/openapi-generator/src/main/resources/php/api.mustache b/modules/openapi-generator/src/main/resources/php/api.mustache index 9acfcd42797f..da502f43680a 100644 --- a/modules/openapi-generator/src/main/resources/php/api.mustache +++ b/modules/openapi-generator/src/main/resources/php/api.mustache @@ -25,6 +25,7 @@ use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Psr7\MultipartStream; use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; +use Psr\Http\Message\ResponseInterface; use {{invokerPackage}}\ApiException; use {{invokerPackage}}\Configuration; use {{invokerPackage}}\HeaderSelector; @@ -262,38 +263,23 @@ use {{invokerPackage}}\ObjectSerializer; {{/-first}} {{#dataType}} {{^isRange}}{{^isWildcard}}case {{code}}:{{/isWildcard}}{{#isWildcard}}default:{{/isWildcard}} - if ('{{{dataType}}}' === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('{{{dataType}}}' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, '{{{dataType}}}', []), - $response->getStatusCode(), - $response->getHeaders() - ];{{/isRange}} + return $this->handleResponseWithDataType( + '{{{dataType}}}', + $response, + );{{/isRange}} {{/dataType}} {{#-last}} } {{/-last}} {{/responses}} + {{#responses}}{{#dataType}}{{#isRange}}{{^isWildcard}}if ($this->responseWithinRangeCode('{{code}}', $statusCode)) { + return $this->handleResponseWithDataType( + '{{{dataType}}}', + $response, + ); + }{{/isWildcard}}{{/isRange}}{{/dataType}}{{/responses}} + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( sprintf( @@ -307,39 +293,15 @@ use {{invokerPackage}}\ObjectSerializer; ); } - $returnType = '{{{returnType}}}'; - if ($returnType === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + '{{{returnType}}}', + $response, + ); {{/returnType}} {{^returnType}} return [null, $statusCode, $response->getHeaders()]; {{/returnType}} - } catch (ApiException $e) { switch ($e->getCode()) { {{#responses}} @@ -351,10 +313,21 @@ use {{invokerPackage}}\ObjectSerializer; $e->getResponseHeaders() ); $e->setResponseObject($data); - break;{{/isRange}} + throw $e;{{/isRange}} {{/dataType}} {{/responses}} } + {{#responses}}{{#dataType}}{{#isRange}}{{^isWildcard}} + if ($this->responseWithinRangeCode('{{code}}', $e->getCode())) { + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '{{{dataType}}}', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + throw $e; + }{{/isWildcard}}{{/isRange}}{{/dataType}}{{/responses}} + throw $e; } } @@ -859,5 +832,47 @@ use {{invokerPackage}}\ObjectSerializer; return $options; } + + private function handleResponseWithDataType( + string $dataType, + ResponseInterface $response + ): array { + if ($dataType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ($dataType !== 'string') { + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $response->getStatusCode(), + $response->getHeaders(), + $content + ); + } + } + } + + return [ + ObjectSerializer::deserialize($content, $dataType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + private function responseWithinRangeCode( + string $rangeCode, + int $statusCode + ): bool { + $left = (int) ($rangeCode[0].'00'); + $right = (int) ($rangeCode[0].'99'); + + return $statusCode >= $left && $statusCode <= $right; + } } {{/operations}} diff --git a/modules/openapi-generator/src/main/resources/php/libraries/psr-18/api.mustache b/modules/openapi-generator/src/main/resources/php/libraries/psr-18/api.mustache index 16e76da9074c..14ec231659d7 100644 --- a/modules/openapi-generator/src/main/resources/php/libraries/psr-18/api.mustache +++ b/modules/openapi-generator/src/main/resources/php/libraries/psr-18/api.mustache @@ -39,6 +39,7 @@ use Psr\Http\Client\ClientExceptionInterface; use Psr\Http\Client\ClientInterface; use Psr\Http\Message\RequestFactoryInterface; use Psr\Http\Message\RequestInterface; +use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\StreamFactoryInterface; use Psr\Http\Message\UriFactoryInterface; use Psr\Http\Message\UriInterface; @@ -263,6 +264,7 @@ use function sprintf; } $statusCode = $response->getStatusCode(); + {{#returnType}} {{#responses}} {{#-first}} @@ -270,57 +272,72 @@ use function sprintf; switch($statusCode) { {{/-first}} {{#dataType}} - {{^isWildcard}}case {{code}}:{{/isWildcard}}{{#isWildcard}}default:{{/isWildcard}} - if ('{{{dataType}}}' === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - } - - return [ - ObjectSerializer::deserialize($content, '{{{dataType}}}', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + {{^isRange}}{{^isWildcard}}case {{code}}:{{/isWildcard}}{{#isWildcard}}default:{{/isWildcard}} + return $this->handleResponseWithDataType( + '{{{dataType}}}', + $response, + );{{/isRange}} {{/dataType}} {{#-last}} } {{/-last}} {{/responses}} - $returnType = '{{{returnType}}}'; - if ($returnType === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); + {{#responses}}{{#dataType}}{{#isRange}}{{^isWildcard}}if ($this->responseWithinRangeCode('{{code}}', $statusCode)) { + return $this->handleResponseWithDataType( + '{{{dataType}}}', + $response, + ); + }{{/isWildcard}}{{/isRange}}{{/dataType}}{{/responses}} + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); } - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + '{{{returnType}}}', + $response, + ); {{/returnType}} {{^returnType}} return [null, $statusCode, $response->getHeaders()]; {{/returnType}} - } catch (ApiException $e) { switch ($e->getCode()) { {{#responses}} {{#dataType}} - {{^isWildcard}}case {{code}}:{{/isWildcard}}{{#isWildcard}}default:{{/isWildcard}} + {{^isRange}}{{^isWildcard}}case {{code}}:{{/isWildcard}}{{#isWildcard}}default:{{/isWildcard}} $data = ObjectSerializer::deserialize( $e->getResponseBody(), '{{{dataType}}}', $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e;{{/isRange}} {{/dataType}} {{/responses}} } + {{#responses}}{{#dataType}}{{#isRange}}{{^isWildcard}} + if ($this->responseWithinRangeCode('{{code}}', $e->getCode())) { + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '{{{dataType}}}', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + throw $e; + }{{/isWildcard}}{{/isRange}}{{/dataType}}{{/responses}} + throw $e; } } @@ -769,5 +786,47 @@ use function sprintf; return $uri; } + + private function handleResponseWithDataType( + string $dataType, + ResponseInterface $response + ): array { + if ($dataType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ($dataType !== 'string') { + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $response->getStatusCode(), + $response->getHeaders(), + $content + ); + } + } + } + + return [ + ObjectSerializer::deserialize($content, $dataType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + private function responseWithinRangeCode( + string $rangeCode, + int $statusCode + ): bool { + $left = (int) ($rangeCode[0].'00'); + $right = (int) ($rangeCode[0].'99'); + + return $statusCode >= $left && $statusCode <= $right; + } } {{/operations}} diff --git a/modules/openapi-generator/src/test/resources/3_0/php/petstore-with-fake-endpoints-models-for-testing.yaml b/modules/openapi-generator/src/test/resources/3_0/php/petstore-with-fake-endpoints-models-for-testing.yaml index e971a99dc261..c716c5b6fadb 100644 --- a/modules/openapi-generator/src/test/resources/3_0/php/petstore-with-fake-endpoints-models-for-testing.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/php/petstore-with-fake-endpoints-models-for-testing.yaml @@ -1394,6 +1394,63 @@ paths: application/json: schema: $ref: '#/components/schemas/EnumClass' + /fake/with_400_response/endpoint: + post: + tags: + - fake + summary: test endpoint with 400 response http code with dataType + operationId: fake-with_400_response-endpoint + responses: + 200: + description: Valid status value + '400': + description: Invalid status value + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorResponse' + requestBody: + $ref: '#/components/requestBodies/Pet' + /fake/with_4xx_range_response/endpoint: + post: + tags: + - fake + summary: test endpoint with 400-499 range response http code with dataType + operationId: fake-with_4xx_range_response-endpoint + responses: + 200: + description: Valid status value + '4xx': + description: Range of HTTP code 400-499 + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorResponse' + requestBody: + $ref: '#/components/requestBodies/Pet' + /fake/with_400_and_4xx_range_response/endpoint: + post: + tags: + - fake + summary: test endpoint with 400 and 400-499 range response http code with dataType + operationId: fake-with_400_and_4xx_range_response-endpoint + responses: + 200: + description: Valid status value + '400': + description: Invalid status value + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorResponse' + '4xx': + description: Range of HTTP code 400-499 + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorResponse' + requestBody: + $ref: '#/components/requestBodies/Pet' servers: - url: 'http://{server}.swagger.io:{port}/v2' description: petstore server @@ -2206,3 +2263,10 @@ components: - The word one - The digit two - The digit three prefixed by a space + ErrorResponse: + type: object + properties: + response_code: + type: integer + error: + type: string diff --git a/samples/client/echo_api/php-nextgen-streaming/src/Api/AuthApi.php b/samples/client/echo_api/php-nextgen-streaming/src/Api/AuthApi.php index 2ab4f17c90c4..740aeab82ba8 100644 --- a/samples/client/echo_api/php-nextgen-streaming/src/Api/AuthApi.php +++ b/samples/client/echo_api/php-nextgen-streaming/src/Api/AuthApi.php @@ -36,6 +36,7 @@ use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; use GuzzleHttp\Promise\PromiseInterface; +use Psr\Http\Message\ResponseInterface; use OpenAPI\Client\ApiException; use OpenAPI\Client\Configuration; use OpenAPI\Client\HeaderSelector; @@ -184,36 +185,14 @@ public function testAuthHttpBasicWithHttpInfo( $statusCode = $response->getStatusCode(); - switch($statusCode) { case 200: - if (in_array('string', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('string' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, 'string', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + 'string', + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -228,34 +207,10 @@ public function testAuthHttpBasicWithHttpInfo( ); } - $returnType = 'string'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + 'string', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -265,8 +220,9 @@ public function testAuthHttpBasicWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -486,36 +442,14 @@ public function testAuthHttpBearerWithHttpInfo( $statusCode = $response->getStatusCode(); - switch($statusCode) { case 200: - if (in_array('string', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('string' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, 'string', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + 'string', + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -530,34 +464,10 @@ public function testAuthHttpBearerWithHttpInfo( ); } - $returnType = 'string'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + 'string', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -567,8 +477,9 @@ public function testAuthHttpBearerWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -748,4 +659,46 @@ protected function createHttpClientOption(): array return $options; } + + private function handleResponseWithDataType( + string $dataType, + ResponseInterface $response, + ): array { + if (in_array($dataType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ($dataType !== 'string') { + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $response->getStatusCode(), + $response->getHeaders(), + $content + ); + } + } + } + + return [ + ObjectSerializer::deserialize($content, $dataType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + private function responseWithinRangeCode( + string $rangeCode, + int $statusCode, + ): bool { + $left = (int) ($rangeCode[0].'00'); + $right = (int) ($rangeCode[0].'99'); + + return $statusCode >= $left && $statusCode <= $right; + } } diff --git a/samples/client/echo_api/php-nextgen-streaming/src/Api/BodyApi.php b/samples/client/echo_api/php-nextgen-streaming/src/Api/BodyApi.php index 78c0645f1ad0..d55ea687ea37 100644 --- a/samples/client/echo_api/php-nextgen-streaming/src/Api/BodyApi.php +++ b/samples/client/echo_api/php-nextgen-streaming/src/Api/BodyApi.php @@ -36,6 +36,7 @@ use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; use GuzzleHttp\Promise\PromiseInterface; +use Psr\Http\Message\ResponseInterface; use OpenAPI\Client\ApiException; use OpenAPI\Client\Configuration; use OpenAPI\Client\HeaderSelector; @@ -208,36 +209,14 @@ public function testBinaryGifWithHttpInfo( $statusCode = $response->getStatusCode(); - switch($statusCode) { case 200: - if (in_array('\Psr\Http\Message\StreamInterface', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('\Psr\Http\Message\StreamInterface' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, '\Psr\Http\Message\StreamInterface', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + '\Psr\Http\Message\StreamInterface', + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -252,34 +231,10 @@ public function testBinaryGifWithHttpInfo( ); } - $returnType = '\Psr\Http\Message\StreamInterface'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + '\Psr\Http\Message\StreamInterface', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -289,8 +244,9 @@ public function testBinaryGifWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -510,36 +466,14 @@ public function testBodyApplicationOctetstreamBinaryWithHttpInfo( $statusCode = $response->getStatusCode(); - switch($statusCode) { case 200: - if (in_array('string', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('string' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, 'string', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + 'string', + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -554,34 +488,10 @@ public function testBodyApplicationOctetstreamBinaryWithHttpInfo( ); } - $returnType = 'string'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + 'string', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -591,8 +501,9 @@ public function testBodyApplicationOctetstreamBinaryWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -826,36 +737,14 @@ public function testBodyMultipartFormdataArrayOfBinaryWithHttpInfo( $statusCode = $response->getStatusCode(); - switch($statusCode) { case 200: - if (in_array('string', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('string' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, 'string', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + 'string', + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -870,34 +759,10 @@ public function testBodyMultipartFormdataArrayOfBinaryWithHttpInfo( ); } - $returnType = 'string'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + 'string', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -907,8 +772,9 @@ public function testBodyMultipartFormdataArrayOfBinaryWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -1155,36 +1021,14 @@ public function testBodyMultipartFormdataSingleBinaryWithHttpInfo( $statusCode = $response->getStatusCode(); - switch($statusCode) { case 200: - if (in_array('string', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('string' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, 'string', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + 'string', + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -1199,34 +1043,10 @@ public function testBodyMultipartFormdataSingleBinaryWithHttpInfo( ); } - $returnType = 'string'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + 'string', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -1236,8 +1056,9 @@ public function testBodyMultipartFormdataSingleBinaryWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -1478,36 +1299,14 @@ public function testEchoBodyAllOfPetWithHttpInfo( $statusCode = $response->getStatusCode(); - switch($statusCode) { case 200: - if (in_array('\OpenAPI\Client\Model\Pet', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('\OpenAPI\Client\Model\Pet' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, '\OpenAPI\Client\Model\Pet', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Pet', + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -1522,34 +1321,10 @@ public function testEchoBodyAllOfPetWithHttpInfo( ); } - $returnType = '\OpenAPI\Client\Model\Pet'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Pet', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -1559,8 +1334,9 @@ public function testEchoBodyAllOfPetWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -1794,36 +1570,14 @@ public function testEchoBodyFreeFormObjectResponseStringWithHttpInfo( $statusCode = $response->getStatusCode(); - switch($statusCode) { case 200: - if (in_array('string', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('string' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, 'string', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + 'string', + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -1838,34 +1592,10 @@ public function testEchoBodyFreeFormObjectResponseStringWithHttpInfo( ); } - $returnType = 'string'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + 'string', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -1875,8 +1605,9 @@ public function testEchoBodyFreeFormObjectResponseStringWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -2110,36 +1841,14 @@ public function testEchoBodyPetWithHttpInfo( $statusCode = $response->getStatusCode(); - switch($statusCode) { case 200: - if (in_array('\OpenAPI\Client\Model\Pet', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('\OpenAPI\Client\Model\Pet' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, '\OpenAPI\Client\Model\Pet', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Pet', + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -2154,34 +1863,10 @@ public function testEchoBodyPetWithHttpInfo( ); } - $returnType = '\OpenAPI\Client\Model\Pet'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Pet', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -2191,8 +1876,9 @@ public function testEchoBodyPetWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -2426,36 +2112,14 @@ public function testEchoBodyPetResponseStringWithHttpInfo( $statusCode = $response->getStatusCode(); - switch($statusCode) { case 200: - if (in_array('string', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('string' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, 'string', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + 'string', + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -2470,34 +2134,10 @@ public function testEchoBodyPetResponseStringWithHttpInfo( ); } - $returnType = 'string'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + 'string', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -2507,8 +2147,9 @@ public function testEchoBodyPetResponseStringWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -2742,36 +2383,14 @@ public function testEchoBodyStringEnumWithHttpInfo( $statusCode = $response->getStatusCode(); - switch($statusCode) { case 200: - if (in_array('\OpenAPI\Client\Model\StringEnumRef', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('\OpenAPI\Client\Model\StringEnumRef' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, '\OpenAPI\Client\Model\StringEnumRef', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\StringEnumRef', + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -2786,34 +2405,10 @@ public function testEchoBodyStringEnumWithHttpInfo( ); } - $returnType = '\OpenAPI\Client\Model\StringEnumRef'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\StringEnumRef', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -2823,8 +2418,9 @@ public function testEchoBodyStringEnumWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -3058,36 +2654,14 @@ public function testEchoBodyTagResponseStringWithHttpInfo( $statusCode = $response->getStatusCode(); - switch($statusCode) { case 200: - if (in_array('string', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('string' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, 'string', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + 'string', + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -3102,34 +2676,10 @@ public function testEchoBodyTagResponseStringWithHttpInfo( ); } - $returnType = 'string'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + 'string', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -3139,8 +2689,9 @@ public function testEchoBodyTagResponseStringWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -3330,4 +2881,46 @@ protected function createHttpClientOption(): array return $options; } + + private function handleResponseWithDataType( + string $dataType, + ResponseInterface $response, + ): array { + if (in_array($dataType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ($dataType !== 'string') { + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $response->getStatusCode(), + $response->getHeaders(), + $content + ); + } + } + } + + return [ + ObjectSerializer::deserialize($content, $dataType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + private function responseWithinRangeCode( + string $rangeCode, + int $statusCode, + ): bool { + $left = (int) ($rangeCode[0].'00'); + $right = (int) ($rangeCode[0].'99'); + + return $statusCode >= $left && $statusCode <= $right; + } } diff --git a/samples/client/echo_api/php-nextgen-streaming/src/Api/FormApi.php b/samples/client/echo_api/php-nextgen-streaming/src/Api/FormApi.php index 193033455ace..1b1bb8aecaa2 100644 --- a/samples/client/echo_api/php-nextgen-streaming/src/Api/FormApi.php +++ b/samples/client/echo_api/php-nextgen-streaming/src/Api/FormApi.php @@ -36,6 +36,7 @@ use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; use GuzzleHttp\Promise\PromiseInterface; +use Psr\Http\Message\ResponseInterface; use OpenAPI\Client\ApiException; use OpenAPI\Client\Configuration; use OpenAPI\Client\HeaderSelector; @@ -199,36 +200,14 @@ public function testFormIntegerBooleanStringWithHttpInfo( $statusCode = $response->getStatusCode(); - switch($statusCode) { case 200: - if (in_array('string', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('string' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, 'string', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + 'string', + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -243,34 +222,10 @@ public function testFormIntegerBooleanStringWithHttpInfo( ); } - $returnType = 'string'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + 'string', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -280,8 +235,9 @@ public function testFormIntegerBooleanStringWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -534,36 +490,14 @@ public function testFormObjectMultipartWithHttpInfo( $statusCode = $response->getStatusCode(); - switch($statusCode) { case 200: - if (in_array('string', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('string' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, 'string', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + 'string', + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -578,34 +512,10 @@ public function testFormObjectMultipartWithHttpInfo( ); } - $returnType = 'string'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + 'string', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -615,8 +525,9 @@ public function testFormObjectMultipartWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -873,36 +784,14 @@ public function testFormOneofWithHttpInfo( $statusCode = $response->getStatusCode(); - switch($statusCode) { case 200: - if (in_array('string', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('string' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, 'string', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + 'string', + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -917,34 +806,10 @@ public function testFormOneofWithHttpInfo( ); } - $returnType = 'string'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + 'string', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -954,8 +819,9 @@ public function testFormOneofWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -1197,4 +1063,46 @@ protected function createHttpClientOption(): array return $options; } + + private function handleResponseWithDataType( + string $dataType, + ResponseInterface $response, + ): array { + if (in_array($dataType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ($dataType !== 'string') { + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $response->getStatusCode(), + $response->getHeaders(), + $content + ); + } + } + } + + return [ + ObjectSerializer::deserialize($content, $dataType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + private function responseWithinRangeCode( + string $rangeCode, + int $statusCode, + ): bool { + $left = (int) ($rangeCode[0].'00'); + $right = (int) ($rangeCode[0].'99'); + + return $statusCode >= $left && $statusCode <= $right; + } } diff --git a/samples/client/echo_api/php-nextgen-streaming/src/Api/HeaderApi.php b/samples/client/echo_api/php-nextgen-streaming/src/Api/HeaderApi.php index aa4c1fcbdc9a..3d18038f17eb 100644 --- a/samples/client/echo_api/php-nextgen-streaming/src/Api/HeaderApi.php +++ b/samples/client/echo_api/php-nextgen-streaming/src/Api/HeaderApi.php @@ -36,6 +36,7 @@ use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; use GuzzleHttp\Promise\PromiseInterface; +use Psr\Http\Message\ResponseInterface; use OpenAPI\Client\ApiException; use OpenAPI\Client\Configuration; use OpenAPI\Client\HeaderSelector; @@ -201,36 +202,14 @@ public function testHeaderIntegerBooleanStringEnumsWithHttpInfo( $statusCode = $response->getStatusCode(); - switch($statusCode) { case 200: - if (in_array('string', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('string' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, 'string', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + 'string', + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -245,34 +224,10 @@ public function testHeaderIntegerBooleanStringEnumsWithHttpInfo( ); } - $returnType = 'string'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + 'string', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -282,8 +237,9 @@ public function testHeaderIntegerBooleanStringEnumsWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -514,4 +470,46 @@ protected function createHttpClientOption(): array return $options; } + + private function handleResponseWithDataType( + string $dataType, + ResponseInterface $response, + ): array { + if (in_array($dataType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ($dataType !== 'string') { + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $response->getStatusCode(), + $response->getHeaders(), + $content + ); + } + } + } + + return [ + ObjectSerializer::deserialize($content, $dataType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + private function responseWithinRangeCode( + string $rangeCode, + int $statusCode, + ): bool { + $left = (int) ($rangeCode[0].'00'); + $right = (int) ($rangeCode[0].'99'); + + return $statusCode >= $left && $statusCode <= $right; + } } diff --git a/samples/client/echo_api/php-nextgen-streaming/src/Api/PathApi.php b/samples/client/echo_api/php-nextgen-streaming/src/Api/PathApi.php index 5fb253899d02..0842612e45a9 100644 --- a/samples/client/echo_api/php-nextgen-streaming/src/Api/PathApi.php +++ b/samples/client/echo_api/php-nextgen-streaming/src/Api/PathApi.php @@ -36,6 +36,7 @@ use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; use GuzzleHttp\Promise\PromiseInterface; +use Psr\Http\Message\ResponseInterface; use OpenAPI\Client\ApiException; use OpenAPI\Client\Configuration; use OpenAPI\Client\HeaderSelector; @@ -197,36 +198,14 @@ public function testsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathE $statusCode = $response->getStatusCode(); - switch($statusCode) { case 200: - if (in_array('string', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('string' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, 'string', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + 'string', + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -241,34 +220,10 @@ public function testsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathE ); } - $returnType = 'string'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + 'string', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -278,8 +233,9 @@ public function testsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathE $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -539,4 +495,46 @@ protected function createHttpClientOption(): array return $options; } + + private function handleResponseWithDataType( + string $dataType, + ResponseInterface $response, + ): array { + if (in_array($dataType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ($dataType !== 'string') { + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $response->getStatusCode(), + $response->getHeaders(), + $content + ); + } + } + } + + return [ + ObjectSerializer::deserialize($content, $dataType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + private function responseWithinRangeCode( + string $rangeCode, + int $statusCode, + ): bool { + $left = (int) ($rangeCode[0].'00'); + $right = (int) ($rangeCode[0].'99'); + + return $statusCode >= $left && $statusCode <= $right; + } } diff --git a/samples/client/echo_api/php-nextgen-streaming/src/Api/QueryApi.php b/samples/client/echo_api/php-nextgen-streaming/src/Api/QueryApi.php index 12169d7ef19b..cd1a249558a9 100644 --- a/samples/client/echo_api/php-nextgen-streaming/src/Api/QueryApi.php +++ b/samples/client/echo_api/php-nextgen-streaming/src/Api/QueryApi.php @@ -36,6 +36,7 @@ use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; use GuzzleHttp\Promise\PromiseInterface; +use Psr\Http\Message\ResponseInterface; use OpenAPI\Client\ApiException; use OpenAPI\Client\Configuration; use OpenAPI\Client\HeaderSelector; @@ -216,36 +217,14 @@ public function testEnumRefStringWithHttpInfo( $statusCode = $response->getStatusCode(); - switch($statusCode) { case 200: - if (in_array('string', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('string' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, 'string', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + 'string', + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -260,34 +239,10 @@ public function testEnumRefStringWithHttpInfo( ); } - $returnType = 'string'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + 'string', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -297,8 +252,9 @@ public function testEnumRefStringWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -558,36 +514,14 @@ public function testQueryDatetimeDateStringWithHttpInfo( $statusCode = $response->getStatusCode(); - switch($statusCode) { case 200: - if (in_array('string', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('string' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, 'string', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + 'string', + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -602,34 +536,10 @@ public function testQueryDatetimeDateStringWithHttpInfo( ); } - $returnType = 'string'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + 'string', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -639,8 +549,9 @@ public function testQueryDatetimeDateStringWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -916,36 +827,14 @@ public function testQueryIntegerBooleanStringWithHttpInfo( $statusCode = $response->getStatusCode(); - switch($statusCode) { case 200: - if (in_array('string', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('string' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, 'string', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + 'string', + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -960,34 +849,10 @@ public function testQueryIntegerBooleanStringWithHttpInfo( ); } - $returnType = 'string'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + 'string', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -997,8 +862,9 @@ public function testQueryIntegerBooleanStringWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -1266,36 +1132,14 @@ public function testQueryStyleDeepObjectExplodeTrueObjectWithHttpInfo( $statusCode = $response->getStatusCode(); - switch($statusCode) { case 200: - if (in_array('string', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('string' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, 'string', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + 'string', + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -1310,34 +1154,10 @@ public function testQueryStyleDeepObjectExplodeTrueObjectWithHttpInfo( ); } - $returnType = 'string'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + 'string', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -1347,8 +1167,9 @@ public function testQueryStyleDeepObjectExplodeTrueObjectWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -1584,36 +1405,14 @@ public function testQueryStyleDeepObjectExplodeTrueObjectAllOfWithHttpInfo( $statusCode = $response->getStatusCode(); - switch($statusCode) { case 200: - if (in_array('string', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('string' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, 'string', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + 'string', + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -1628,34 +1427,10 @@ public function testQueryStyleDeepObjectExplodeTrueObjectAllOfWithHttpInfo( ); } - $returnType = 'string'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + 'string', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -1665,8 +1440,9 @@ public function testQueryStyleDeepObjectExplodeTrueObjectAllOfWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -1902,36 +1678,14 @@ public function testQueryStyleFormExplodeFalseArrayIntegerWithHttpInfo( $statusCode = $response->getStatusCode(); - switch($statusCode) { case 200: - if (in_array('string', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('string' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, 'string', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + 'string', + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -1946,34 +1700,10 @@ public function testQueryStyleFormExplodeFalseArrayIntegerWithHttpInfo( ); } - $returnType = 'string'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + 'string', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -1983,8 +1713,9 @@ public function testQueryStyleFormExplodeFalseArrayIntegerWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -2220,36 +1951,14 @@ public function testQueryStyleFormExplodeFalseArrayStringWithHttpInfo( $statusCode = $response->getStatusCode(); - switch($statusCode) { case 200: - if (in_array('string', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('string' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, 'string', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + 'string', + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -2264,34 +1973,10 @@ public function testQueryStyleFormExplodeFalseArrayStringWithHttpInfo( ); } - $returnType = 'string'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + 'string', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -2301,8 +1986,9 @@ public function testQueryStyleFormExplodeFalseArrayStringWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -2538,36 +2224,14 @@ public function testQueryStyleFormExplodeTrueArrayStringWithHttpInfo( $statusCode = $response->getStatusCode(); - switch($statusCode) { case 200: - if (in_array('string', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('string' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, 'string', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + 'string', + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -2582,34 +2246,10 @@ public function testQueryStyleFormExplodeTrueArrayStringWithHttpInfo( ); } - $returnType = 'string'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + 'string', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -2619,8 +2259,9 @@ public function testQueryStyleFormExplodeTrueArrayStringWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -2856,36 +2497,14 @@ public function testQueryStyleFormExplodeTrueObjectWithHttpInfo( $statusCode = $response->getStatusCode(); - switch($statusCode) { case 200: - if (in_array('string', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('string' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, 'string', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + 'string', + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -2900,34 +2519,10 @@ public function testQueryStyleFormExplodeTrueObjectWithHttpInfo( ); } - $returnType = 'string'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + 'string', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -2937,8 +2532,9 @@ public function testQueryStyleFormExplodeTrueObjectWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -3174,36 +2770,14 @@ public function testQueryStyleFormExplodeTrueObjectAllOfWithHttpInfo( $statusCode = $response->getStatusCode(); - switch($statusCode) { case 200: - if (in_array('string', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('string' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, 'string', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + 'string', + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -3218,34 +2792,10 @@ public function testQueryStyleFormExplodeTrueObjectAllOfWithHttpInfo( ); } - $returnType = 'string'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + 'string', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -3255,8 +2805,9 @@ public function testQueryStyleFormExplodeTrueObjectAllOfWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -3448,4 +2999,46 @@ protected function createHttpClientOption(): array return $options; } + + private function handleResponseWithDataType( + string $dataType, + ResponseInterface $response, + ): array { + if (in_array($dataType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ($dataType !== 'string') { + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $response->getStatusCode(), + $response->getHeaders(), + $content + ); + } + } + } + + return [ + ObjectSerializer::deserialize($content, $dataType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + private function responseWithinRangeCode( + string $rangeCode, + int $statusCode, + ): bool { + $left = (int) ($rangeCode[0].'00'); + $right = (int) ($rangeCode[0].'99'); + + return $statusCode >= $left && $statusCode <= $right; + } } diff --git a/samples/client/echo_api/php-nextgen/src/Api/AuthApi.php b/samples/client/echo_api/php-nextgen/src/Api/AuthApi.php index 2ab4f17c90c4..740aeab82ba8 100644 --- a/samples/client/echo_api/php-nextgen/src/Api/AuthApi.php +++ b/samples/client/echo_api/php-nextgen/src/Api/AuthApi.php @@ -36,6 +36,7 @@ use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; use GuzzleHttp\Promise\PromiseInterface; +use Psr\Http\Message\ResponseInterface; use OpenAPI\Client\ApiException; use OpenAPI\Client\Configuration; use OpenAPI\Client\HeaderSelector; @@ -184,36 +185,14 @@ public function testAuthHttpBasicWithHttpInfo( $statusCode = $response->getStatusCode(); - switch($statusCode) { case 200: - if (in_array('string', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('string' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, 'string', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + 'string', + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -228,34 +207,10 @@ public function testAuthHttpBasicWithHttpInfo( ); } - $returnType = 'string'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + 'string', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -265,8 +220,9 @@ public function testAuthHttpBasicWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -486,36 +442,14 @@ public function testAuthHttpBearerWithHttpInfo( $statusCode = $response->getStatusCode(); - switch($statusCode) { case 200: - if (in_array('string', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('string' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, 'string', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + 'string', + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -530,34 +464,10 @@ public function testAuthHttpBearerWithHttpInfo( ); } - $returnType = 'string'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + 'string', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -567,8 +477,9 @@ public function testAuthHttpBearerWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -748,4 +659,46 @@ protected function createHttpClientOption(): array return $options; } + + private function handleResponseWithDataType( + string $dataType, + ResponseInterface $response, + ): array { + if (in_array($dataType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ($dataType !== 'string') { + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $response->getStatusCode(), + $response->getHeaders(), + $content + ); + } + } + } + + return [ + ObjectSerializer::deserialize($content, $dataType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + private function responseWithinRangeCode( + string $rangeCode, + int $statusCode, + ): bool { + $left = (int) ($rangeCode[0].'00'); + $right = (int) ($rangeCode[0].'99'); + + return $statusCode >= $left && $statusCode <= $right; + } } diff --git a/samples/client/echo_api/php-nextgen/src/Api/BodyApi.php b/samples/client/echo_api/php-nextgen/src/Api/BodyApi.php index c2459f1777eb..be8394f36b5f 100644 --- a/samples/client/echo_api/php-nextgen/src/Api/BodyApi.php +++ b/samples/client/echo_api/php-nextgen/src/Api/BodyApi.php @@ -36,6 +36,7 @@ use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; use GuzzleHttp\Promise\PromiseInterface; +use Psr\Http\Message\ResponseInterface; use OpenAPI\Client\ApiException; use OpenAPI\Client\Configuration; use OpenAPI\Client\HeaderSelector; @@ -208,36 +209,14 @@ public function testBinaryGifWithHttpInfo( $statusCode = $response->getStatusCode(); - switch($statusCode) { case 200: - if (in_array('\SplFileObject', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('\SplFileObject' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, '\SplFileObject', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + '\SplFileObject', + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -252,34 +231,10 @@ public function testBinaryGifWithHttpInfo( ); } - $returnType = '\SplFileObject'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + '\SplFileObject', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -289,8 +244,9 @@ public function testBinaryGifWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -510,36 +466,14 @@ public function testBodyApplicationOctetstreamBinaryWithHttpInfo( $statusCode = $response->getStatusCode(); - switch($statusCode) { case 200: - if (in_array('string', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('string' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, 'string', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + 'string', + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -554,34 +488,10 @@ public function testBodyApplicationOctetstreamBinaryWithHttpInfo( ); } - $returnType = 'string'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + 'string', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -591,8 +501,9 @@ public function testBodyApplicationOctetstreamBinaryWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -826,36 +737,14 @@ public function testBodyMultipartFormdataArrayOfBinaryWithHttpInfo( $statusCode = $response->getStatusCode(); - switch($statusCode) { case 200: - if (in_array('string', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('string' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, 'string', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + 'string', + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -870,34 +759,10 @@ public function testBodyMultipartFormdataArrayOfBinaryWithHttpInfo( ); } - $returnType = 'string'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + 'string', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -907,8 +772,9 @@ public function testBodyMultipartFormdataArrayOfBinaryWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -1155,36 +1021,14 @@ public function testBodyMultipartFormdataSingleBinaryWithHttpInfo( $statusCode = $response->getStatusCode(); - switch($statusCode) { case 200: - if (in_array('string', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('string' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, 'string', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + 'string', + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -1199,34 +1043,10 @@ public function testBodyMultipartFormdataSingleBinaryWithHttpInfo( ); } - $returnType = 'string'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + 'string', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -1236,8 +1056,9 @@ public function testBodyMultipartFormdataSingleBinaryWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -1478,36 +1299,14 @@ public function testEchoBodyAllOfPetWithHttpInfo( $statusCode = $response->getStatusCode(); - switch($statusCode) { case 200: - if (in_array('\OpenAPI\Client\Model\Pet', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('\OpenAPI\Client\Model\Pet' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, '\OpenAPI\Client\Model\Pet', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Pet', + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -1522,34 +1321,10 @@ public function testEchoBodyAllOfPetWithHttpInfo( ); } - $returnType = '\OpenAPI\Client\Model\Pet'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Pet', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -1559,8 +1334,9 @@ public function testEchoBodyAllOfPetWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -1794,36 +1570,14 @@ public function testEchoBodyFreeFormObjectResponseStringWithHttpInfo( $statusCode = $response->getStatusCode(); - switch($statusCode) { case 200: - if (in_array('string', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('string' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, 'string', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + 'string', + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -1838,34 +1592,10 @@ public function testEchoBodyFreeFormObjectResponseStringWithHttpInfo( ); } - $returnType = 'string'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + 'string', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -1875,8 +1605,9 @@ public function testEchoBodyFreeFormObjectResponseStringWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -2110,36 +1841,14 @@ public function testEchoBodyPetWithHttpInfo( $statusCode = $response->getStatusCode(); - switch($statusCode) { case 200: - if (in_array('\OpenAPI\Client\Model\Pet', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('\OpenAPI\Client\Model\Pet' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, '\OpenAPI\Client\Model\Pet', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Pet', + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -2154,34 +1863,10 @@ public function testEchoBodyPetWithHttpInfo( ); } - $returnType = '\OpenAPI\Client\Model\Pet'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Pet', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -2191,8 +1876,9 @@ public function testEchoBodyPetWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -2426,36 +2112,14 @@ public function testEchoBodyPetResponseStringWithHttpInfo( $statusCode = $response->getStatusCode(); - switch($statusCode) { case 200: - if (in_array('string', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('string' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, 'string', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + 'string', + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -2470,34 +2134,10 @@ public function testEchoBodyPetResponseStringWithHttpInfo( ); } - $returnType = 'string'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + 'string', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -2507,8 +2147,9 @@ public function testEchoBodyPetResponseStringWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -2742,36 +2383,14 @@ public function testEchoBodyStringEnumWithHttpInfo( $statusCode = $response->getStatusCode(); - switch($statusCode) { case 200: - if (in_array('\OpenAPI\Client\Model\StringEnumRef', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('\OpenAPI\Client\Model\StringEnumRef' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, '\OpenAPI\Client\Model\StringEnumRef', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\StringEnumRef', + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -2786,34 +2405,10 @@ public function testEchoBodyStringEnumWithHttpInfo( ); } - $returnType = '\OpenAPI\Client\Model\StringEnumRef'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\StringEnumRef', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -2823,8 +2418,9 @@ public function testEchoBodyStringEnumWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -3058,36 +2654,14 @@ public function testEchoBodyTagResponseStringWithHttpInfo( $statusCode = $response->getStatusCode(); - switch($statusCode) { case 200: - if (in_array('string', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('string' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, 'string', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + 'string', + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -3102,34 +2676,10 @@ public function testEchoBodyTagResponseStringWithHttpInfo( ); } - $returnType = 'string'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + 'string', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -3139,8 +2689,9 @@ public function testEchoBodyTagResponseStringWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -3330,4 +2881,46 @@ protected function createHttpClientOption(): array return $options; } + + private function handleResponseWithDataType( + string $dataType, + ResponseInterface $response, + ): array { + if (in_array($dataType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ($dataType !== 'string') { + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $response->getStatusCode(), + $response->getHeaders(), + $content + ); + } + } + } + + return [ + ObjectSerializer::deserialize($content, $dataType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + private function responseWithinRangeCode( + string $rangeCode, + int $statusCode, + ): bool { + $left = (int) ($rangeCode[0].'00'); + $right = (int) ($rangeCode[0].'99'); + + return $statusCode >= $left && $statusCode <= $right; + } } diff --git a/samples/client/echo_api/php-nextgen/src/Api/FormApi.php b/samples/client/echo_api/php-nextgen/src/Api/FormApi.php index 193033455ace..1b1bb8aecaa2 100644 --- a/samples/client/echo_api/php-nextgen/src/Api/FormApi.php +++ b/samples/client/echo_api/php-nextgen/src/Api/FormApi.php @@ -36,6 +36,7 @@ use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; use GuzzleHttp\Promise\PromiseInterface; +use Psr\Http\Message\ResponseInterface; use OpenAPI\Client\ApiException; use OpenAPI\Client\Configuration; use OpenAPI\Client\HeaderSelector; @@ -199,36 +200,14 @@ public function testFormIntegerBooleanStringWithHttpInfo( $statusCode = $response->getStatusCode(); - switch($statusCode) { case 200: - if (in_array('string', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('string' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, 'string', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + 'string', + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -243,34 +222,10 @@ public function testFormIntegerBooleanStringWithHttpInfo( ); } - $returnType = 'string'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + 'string', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -280,8 +235,9 @@ public function testFormIntegerBooleanStringWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -534,36 +490,14 @@ public function testFormObjectMultipartWithHttpInfo( $statusCode = $response->getStatusCode(); - switch($statusCode) { case 200: - if (in_array('string', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('string' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, 'string', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + 'string', + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -578,34 +512,10 @@ public function testFormObjectMultipartWithHttpInfo( ); } - $returnType = 'string'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + 'string', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -615,8 +525,9 @@ public function testFormObjectMultipartWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -873,36 +784,14 @@ public function testFormOneofWithHttpInfo( $statusCode = $response->getStatusCode(); - switch($statusCode) { case 200: - if (in_array('string', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('string' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, 'string', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + 'string', + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -917,34 +806,10 @@ public function testFormOneofWithHttpInfo( ); } - $returnType = 'string'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + 'string', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -954,8 +819,9 @@ public function testFormOneofWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -1197,4 +1063,46 @@ protected function createHttpClientOption(): array return $options; } + + private function handleResponseWithDataType( + string $dataType, + ResponseInterface $response, + ): array { + if (in_array($dataType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ($dataType !== 'string') { + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $response->getStatusCode(), + $response->getHeaders(), + $content + ); + } + } + } + + return [ + ObjectSerializer::deserialize($content, $dataType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + private function responseWithinRangeCode( + string $rangeCode, + int $statusCode, + ): bool { + $left = (int) ($rangeCode[0].'00'); + $right = (int) ($rangeCode[0].'99'); + + return $statusCode >= $left && $statusCode <= $right; + } } diff --git a/samples/client/echo_api/php-nextgen/src/Api/HeaderApi.php b/samples/client/echo_api/php-nextgen/src/Api/HeaderApi.php index aa4c1fcbdc9a..3d18038f17eb 100644 --- a/samples/client/echo_api/php-nextgen/src/Api/HeaderApi.php +++ b/samples/client/echo_api/php-nextgen/src/Api/HeaderApi.php @@ -36,6 +36,7 @@ use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; use GuzzleHttp\Promise\PromiseInterface; +use Psr\Http\Message\ResponseInterface; use OpenAPI\Client\ApiException; use OpenAPI\Client\Configuration; use OpenAPI\Client\HeaderSelector; @@ -201,36 +202,14 @@ public function testHeaderIntegerBooleanStringEnumsWithHttpInfo( $statusCode = $response->getStatusCode(); - switch($statusCode) { case 200: - if (in_array('string', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('string' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, 'string', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + 'string', + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -245,34 +224,10 @@ public function testHeaderIntegerBooleanStringEnumsWithHttpInfo( ); } - $returnType = 'string'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + 'string', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -282,8 +237,9 @@ public function testHeaderIntegerBooleanStringEnumsWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -514,4 +470,46 @@ protected function createHttpClientOption(): array return $options; } + + private function handleResponseWithDataType( + string $dataType, + ResponseInterface $response, + ): array { + if (in_array($dataType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ($dataType !== 'string') { + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $response->getStatusCode(), + $response->getHeaders(), + $content + ); + } + } + } + + return [ + ObjectSerializer::deserialize($content, $dataType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + private function responseWithinRangeCode( + string $rangeCode, + int $statusCode, + ): bool { + $left = (int) ($rangeCode[0].'00'); + $right = (int) ($rangeCode[0].'99'); + + return $statusCode >= $left && $statusCode <= $right; + } } diff --git a/samples/client/echo_api/php-nextgen/src/Api/PathApi.php b/samples/client/echo_api/php-nextgen/src/Api/PathApi.php index 5fb253899d02..0842612e45a9 100644 --- a/samples/client/echo_api/php-nextgen/src/Api/PathApi.php +++ b/samples/client/echo_api/php-nextgen/src/Api/PathApi.php @@ -36,6 +36,7 @@ use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; use GuzzleHttp\Promise\PromiseInterface; +use Psr\Http\Message\ResponseInterface; use OpenAPI\Client\ApiException; use OpenAPI\Client\Configuration; use OpenAPI\Client\HeaderSelector; @@ -197,36 +198,14 @@ public function testsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathE $statusCode = $response->getStatusCode(); - switch($statusCode) { case 200: - if (in_array('string', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('string' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, 'string', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + 'string', + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -241,34 +220,10 @@ public function testsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathE ); } - $returnType = 'string'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + 'string', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -278,8 +233,9 @@ public function testsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathE $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -539,4 +495,46 @@ protected function createHttpClientOption(): array return $options; } + + private function handleResponseWithDataType( + string $dataType, + ResponseInterface $response, + ): array { + if (in_array($dataType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ($dataType !== 'string') { + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $response->getStatusCode(), + $response->getHeaders(), + $content + ); + } + } + } + + return [ + ObjectSerializer::deserialize($content, $dataType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + private function responseWithinRangeCode( + string $rangeCode, + int $statusCode, + ): bool { + $left = (int) ($rangeCode[0].'00'); + $right = (int) ($rangeCode[0].'99'); + + return $statusCode >= $left && $statusCode <= $right; + } } diff --git a/samples/client/echo_api/php-nextgen/src/Api/QueryApi.php b/samples/client/echo_api/php-nextgen/src/Api/QueryApi.php index 12169d7ef19b..cd1a249558a9 100644 --- a/samples/client/echo_api/php-nextgen/src/Api/QueryApi.php +++ b/samples/client/echo_api/php-nextgen/src/Api/QueryApi.php @@ -36,6 +36,7 @@ use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; use GuzzleHttp\Promise\PromiseInterface; +use Psr\Http\Message\ResponseInterface; use OpenAPI\Client\ApiException; use OpenAPI\Client\Configuration; use OpenAPI\Client\HeaderSelector; @@ -216,36 +217,14 @@ public function testEnumRefStringWithHttpInfo( $statusCode = $response->getStatusCode(); - switch($statusCode) { case 200: - if (in_array('string', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('string' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, 'string', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + 'string', + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -260,34 +239,10 @@ public function testEnumRefStringWithHttpInfo( ); } - $returnType = 'string'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + 'string', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -297,8 +252,9 @@ public function testEnumRefStringWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -558,36 +514,14 @@ public function testQueryDatetimeDateStringWithHttpInfo( $statusCode = $response->getStatusCode(); - switch($statusCode) { case 200: - if (in_array('string', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('string' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, 'string', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + 'string', + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -602,34 +536,10 @@ public function testQueryDatetimeDateStringWithHttpInfo( ); } - $returnType = 'string'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + 'string', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -639,8 +549,9 @@ public function testQueryDatetimeDateStringWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -916,36 +827,14 @@ public function testQueryIntegerBooleanStringWithHttpInfo( $statusCode = $response->getStatusCode(); - switch($statusCode) { case 200: - if (in_array('string', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('string' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, 'string', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + 'string', + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -960,34 +849,10 @@ public function testQueryIntegerBooleanStringWithHttpInfo( ); } - $returnType = 'string'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + 'string', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -997,8 +862,9 @@ public function testQueryIntegerBooleanStringWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -1266,36 +1132,14 @@ public function testQueryStyleDeepObjectExplodeTrueObjectWithHttpInfo( $statusCode = $response->getStatusCode(); - switch($statusCode) { case 200: - if (in_array('string', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('string' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, 'string', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + 'string', + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -1310,34 +1154,10 @@ public function testQueryStyleDeepObjectExplodeTrueObjectWithHttpInfo( ); } - $returnType = 'string'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + 'string', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -1347,8 +1167,9 @@ public function testQueryStyleDeepObjectExplodeTrueObjectWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -1584,36 +1405,14 @@ public function testQueryStyleDeepObjectExplodeTrueObjectAllOfWithHttpInfo( $statusCode = $response->getStatusCode(); - switch($statusCode) { case 200: - if (in_array('string', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('string' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, 'string', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + 'string', + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -1628,34 +1427,10 @@ public function testQueryStyleDeepObjectExplodeTrueObjectAllOfWithHttpInfo( ); } - $returnType = 'string'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + 'string', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -1665,8 +1440,9 @@ public function testQueryStyleDeepObjectExplodeTrueObjectAllOfWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -1902,36 +1678,14 @@ public function testQueryStyleFormExplodeFalseArrayIntegerWithHttpInfo( $statusCode = $response->getStatusCode(); - switch($statusCode) { case 200: - if (in_array('string', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('string' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, 'string', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + 'string', + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -1946,34 +1700,10 @@ public function testQueryStyleFormExplodeFalseArrayIntegerWithHttpInfo( ); } - $returnType = 'string'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + 'string', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -1983,8 +1713,9 @@ public function testQueryStyleFormExplodeFalseArrayIntegerWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -2220,36 +1951,14 @@ public function testQueryStyleFormExplodeFalseArrayStringWithHttpInfo( $statusCode = $response->getStatusCode(); - switch($statusCode) { case 200: - if (in_array('string', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('string' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, 'string', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + 'string', + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -2264,34 +1973,10 @@ public function testQueryStyleFormExplodeFalseArrayStringWithHttpInfo( ); } - $returnType = 'string'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + 'string', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -2301,8 +1986,9 @@ public function testQueryStyleFormExplodeFalseArrayStringWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -2538,36 +2224,14 @@ public function testQueryStyleFormExplodeTrueArrayStringWithHttpInfo( $statusCode = $response->getStatusCode(); - switch($statusCode) { case 200: - if (in_array('string', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('string' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, 'string', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + 'string', + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -2582,34 +2246,10 @@ public function testQueryStyleFormExplodeTrueArrayStringWithHttpInfo( ); } - $returnType = 'string'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + 'string', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -2619,8 +2259,9 @@ public function testQueryStyleFormExplodeTrueArrayStringWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -2856,36 +2497,14 @@ public function testQueryStyleFormExplodeTrueObjectWithHttpInfo( $statusCode = $response->getStatusCode(); - switch($statusCode) { case 200: - if (in_array('string', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('string' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, 'string', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + 'string', + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -2900,34 +2519,10 @@ public function testQueryStyleFormExplodeTrueObjectWithHttpInfo( ); } - $returnType = 'string'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + 'string', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -2937,8 +2532,9 @@ public function testQueryStyleFormExplodeTrueObjectWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -3174,36 +2770,14 @@ public function testQueryStyleFormExplodeTrueObjectAllOfWithHttpInfo( $statusCode = $response->getStatusCode(); - switch($statusCode) { case 200: - if (in_array('string', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('string' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, 'string', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + 'string', + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -3218,34 +2792,10 @@ public function testQueryStyleFormExplodeTrueObjectAllOfWithHttpInfo( ); } - $returnType = 'string'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + 'string', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -3255,8 +2805,9 @@ public function testQueryStyleFormExplodeTrueObjectAllOfWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -3448,4 +2999,46 @@ protected function createHttpClientOption(): array return $options; } + + private function handleResponseWithDataType( + string $dataType, + ResponseInterface $response, + ): array { + if (in_array($dataType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ($dataType !== 'string') { + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $response->getStatusCode(), + $response->getHeaders(), + $content + ); + } + } + } + + return [ + ObjectSerializer::deserialize($content, $dataType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + private function responseWithinRangeCode( + string $rangeCode, + int $statusCode, + ): bool { + $left = (int) ($rangeCode[0].'00'); + $right = (int) ($rangeCode[0].'99'); + + return $statusCode >= $left && $statusCode <= $right; + } } diff --git a/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/AnotherFakeApi.php b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/AnotherFakeApi.php index c69a68e49f40..811f1aaf63c8 100644 --- a/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/AnotherFakeApi.php +++ b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/AnotherFakeApi.php @@ -35,6 +35,7 @@ use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; use GuzzleHttp\Promise\PromiseInterface; +use Psr\Http\Message\ResponseInterface; use OpenAPI\Client\ApiException; use OpenAPI\Client\Configuration; use OpenAPI\Client\HeaderSelector; @@ -184,36 +185,14 @@ public function call123TestSpecialTagsWithHttpInfo( $statusCode = $response->getStatusCode(); - switch($statusCode) { case 200: - if (in_array('\OpenAPI\Client\Model\Client', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('\OpenAPI\Client\Model\Client' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, '\OpenAPI\Client\Model\Client', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Client', + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -228,34 +207,10 @@ public function call123TestSpecialTagsWithHttpInfo( ); } - $returnType = '\OpenAPI\Client\Model\Client'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Client', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -265,8 +220,9 @@ public function call123TestSpecialTagsWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -462,4 +418,46 @@ protected function createHttpClientOption(): array return $options; } + + private function handleResponseWithDataType( + string $dataType, + ResponseInterface $response, + ): array { + if (in_array($dataType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ($dataType !== 'string') { + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $response->getStatusCode(), + $response->getHeaders(), + $content + ); + } + } + } + + return [ + ObjectSerializer::deserialize($content, $dataType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + private function responseWithinRangeCode( + string $rangeCode, + int $statusCode, + ): bool { + $left = (int) ($rangeCode[0].'00'); + $right = (int) ($rangeCode[0].'99'); + + return $statusCode >= $left && $statusCode <= $right; + } } diff --git a/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/DefaultApi.php b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/DefaultApi.php index aeff9f7c541a..435f979780e6 100644 --- a/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/DefaultApi.php +++ b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/DefaultApi.php @@ -35,6 +35,7 @@ use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; use GuzzleHttp\Promise\PromiseInterface; +use Psr\Http\Message\ResponseInterface; use OpenAPI\Client\ApiException; use OpenAPI\Client\Configuration; use OpenAPI\Client\HeaderSelector; @@ -176,36 +177,14 @@ public function fooGetWithHttpInfo( $statusCode = $response->getStatusCode(); - switch($statusCode) { default: - if (in_array('\OpenAPI\Client\Model\FooGetDefaultResponse', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('\OpenAPI\Client\Model\FooGetDefaultResponse' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, '\OpenAPI\Client\Model\FooGetDefaultResponse', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\FooGetDefaultResponse', + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -220,34 +199,10 @@ public function fooGetWithHttpInfo( ); } - $returnType = '\OpenAPI\Client\Model\FooGetDefaultResponse'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\FooGetDefaultResponse', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { default: @@ -257,8 +212,9 @@ public function fooGetWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -430,4 +386,46 @@ protected function createHttpClientOption(): array return $options; } + + private function handleResponseWithDataType( + string $dataType, + ResponseInterface $response, + ): array { + if (in_array($dataType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ($dataType !== 'string') { + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $response->getStatusCode(), + $response->getHeaders(), + $content + ); + } + } + } + + return [ + ObjectSerializer::deserialize($content, $dataType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + private function responseWithinRangeCode( + string $rangeCode, + int $statusCode, + ): bool { + $left = (int) ($rangeCode[0].'00'); + $right = (int) ($rangeCode[0].'99'); + + return $statusCode >= $left && $statusCode <= $right; + } } diff --git a/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/FakeApi.php b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/FakeApi.php index 07ed43c9eaaf..3d64c0790964 100644 --- a/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/FakeApi.php +++ b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/FakeApi.php @@ -35,6 +35,7 @@ use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; use GuzzleHttp\Promise\PromiseInterface; +use Psr\Http\Message\ResponseInterface; use OpenAPI\Client\ApiException; use OpenAPI\Client\Configuration; use OpenAPI\Client\HeaderSelector; @@ -243,36 +244,14 @@ public function fakeBigDecimalMapWithHttpInfo( $statusCode = $response->getStatusCode(); - switch($statusCode) { case 200: - if (in_array('\OpenAPI\Client\Model\FakeBigDecimalMap200Response', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('\OpenAPI\Client\Model\FakeBigDecimalMap200Response' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, '\OpenAPI\Client\Model\FakeBigDecimalMap200Response', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\FakeBigDecimalMap200Response', + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -287,34 +266,10 @@ public function fakeBigDecimalMapWithHttpInfo( ); } - $returnType = '\OpenAPI\Client\Model\FakeBigDecimalMap200Response'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\FakeBigDecimalMap200Response', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -324,8 +279,9 @@ public function fakeBigDecimalMapWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -549,36 +505,14 @@ public function fakeEnumEndpointWithHttpInfo( $statusCode = $response->getStatusCode(); - switch($statusCode) { case 200: - if (in_array('\OpenAPI\Client\Model\EnumClass', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('\OpenAPI\Client\Model\EnumClass' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, '\OpenAPI\Client\Model\EnumClass', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\EnumClass', + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -593,34 +527,10 @@ public function fakeEnumEndpointWithHttpInfo( ); } - $returnType = '\OpenAPI\Client\Model\EnumClass'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\EnumClass', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -630,8 +540,9 @@ public function fakeEnumEndpointWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -913,36 +824,14 @@ public function fakeHealthGetWithHttpInfo( $statusCode = $response->getStatusCode(); - switch($statusCode) { case 200: - if (in_array('\OpenAPI\Client\Model\HealthCheckResult', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('\OpenAPI\Client\Model\HealthCheckResult' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, '\OpenAPI\Client\Model\HealthCheckResult', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\HealthCheckResult', + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -957,34 +846,10 @@ public function fakeHealthGetWithHttpInfo( ); } - $returnType = '\OpenAPI\Client\Model\HealthCheckResult'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\HealthCheckResult', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -994,8 +859,9 @@ public function fakeHealthGetWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -1224,10 +1090,10 @@ public function fakeHttpSignatureTestWithHttpInfo( return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + throw $e; } } @@ -1477,36 +1343,14 @@ public function fakeOuterBooleanSerializeWithHttpInfo( $statusCode = $response->getStatusCode(); - switch($statusCode) { case 200: - if (in_array('bool', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('bool' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, 'bool', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + 'bool', + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -1521,34 +1365,10 @@ public function fakeOuterBooleanSerializeWithHttpInfo( ); } - $returnType = 'bool'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + 'bool', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -1558,8 +1378,9 @@ public function fakeOuterBooleanSerializeWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -1785,36 +1606,14 @@ public function fakeOuterCompositeSerializeWithHttpInfo( $statusCode = $response->getStatusCode(); - switch($statusCode) { case 200: - if (in_array('\OpenAPI\Client\Model\OuterComposite', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('\OpenAPI\Client\Model\OuterComposite' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, '\OpenAPI\Client\Model\OuterComposite', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\OuterComposite', + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -1829,34 +1628,10 @@ public function fakeOuterCompositeSerializeWithHttpInfo( ); } - $returnType = '\OpenAPI\Client\Model\OuterComposite'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\OuterComposite', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -1866,8 +1641,9 @@ public function fakeOuterCompositeSerializeWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -2093,36 +1869,14 @@ public function fakeOuterNumberSerializeWithHttpInfo( $statusCode = $response->getStatusCode(); - switch($statusCode) { case 200: - if (in_array('float', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('float' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, 'float', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + 'float', + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -2137,34 +1891,10 @@ public function fakeOuterNumberSerializeWithHttpInfo( ); } - $returnType = 'float'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + 'float', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -2174,8 +1904,9 @@ public function fakeOuterNumberSerializeWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -2401,36 +2132,14 @@ public function fakeOuterStringSerializeWithHttpInfo( $statusCode = $response->getStatusCode(); - switch($statusCode) { case 200: - if (in_array('string', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('string' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, 'string', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + 'string', + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -2445,34 +2154,10 @@ public function fakeOuterStringSerializeWithHttpInfo( ); } - $returnType = 'string'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + 'string', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -2482,8 +2167,9 @@ public function fakeOuterStringSerializeWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -2709,36 +2395,14 @@ public function fakePropertyEnumIntegerSerializeWithHttpInfo( $statusCode = $response->getStatusCode(); - switch($statusCode) { case 200: - if (in_array('\OpenAPI\Client\Model\OuterObjectWithEnumProperty', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('\OpenAPI\Client\Model\OuterObjectWithEnumProperty' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, '\OpenAPI\Client\Model\OuterObjectWithEnumProperty', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\OuterObjectWithEnumProperty', + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -2753,34 +2417,10 @@ public function fakePropertyEnumIntegerSerializeWithHttpInfo( ); } - $returnType = '\OpenAPI\Client\Model\OuterObjectWithEnumProperty'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\OuterObjectWithEnumProperty', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -2790,8 +2430,9 @@ public function fakePropertyEnumIntegerSerializeWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -3028,10 +2669,10 @@ public function testAdditionalPropertiesReferenceWithHttpInfo( return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + throw $e; } } @@ -3255,10 +2896,10 @@ public function testBodyWithBinaryWithHttpInfo( return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + throw $e; } } @@ -3478,10 +3119,10 @@ public function testBodyWithFileSchemaWithHttpInfo( return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + throw $e; } } @@ -3705,10 +3346,10 @@ public function testBodyWithQueryParamsWithHttpInfo( return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + throw $e; } } @@ -3953,36 +3594,14 @@ public function testClientModelWithHttpInfo( $statusCode = $response->getStatusCode(); - switch($statusCode) { case 200: - if (in_array('\OpenAPI\Client\Model\Client', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('\OpenAPI\Client\Model\Client' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, '\OpenAPI\Client\Model\Client', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Client', + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -3997,34 +3616,10 @@ public function testClientModelWithHttpInfo( ); } - $returnType = '\OpenAPI\Client\Model\Client'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Client', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -4034,8 +3629,9 @@ public function testClientModelWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -4328,10 +3924,10 @@ public function testEndpointParametersWithHttpInfo( return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + throw $e; } } @@ -4802,10 +4398,10 @@ public function testEnumParametersWithHttpInfo( return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + throw $e; } } @@ -5152,10 +4748,10 @@ public function testGroupParametersWithHttpInfo( return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + throw $e; } } @@ -5467,10 +5063,10 @@ public function testInlineAdditionalPropertiesWithHttpInfo( return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + throw $e; } } @@ -5698,10 +5294,10 @@ public function testInlineFreeformAdditionalPropertiesWithHttpInfo( return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + throw $e; } } @@ -5933,10 +5529,10 @@ public function testJsonFormDataWithHttpInfo( return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + throw $e; } } @@ -6178,10 +5774,10 @@ public function testNullableWithHttpInfo( return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + throw $e; } } @@ -6429,10 +6025,10 @@ public function testQueryParameterCollectionFormatWithHttpInfo( return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + throw $e; } } @@ -6784,10 +6380,10 @@ public function testStringMapReferenceWithHttpInfo( return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + throw $e; } } @@ -6970,4 +6566,46 @@ protected function createHttpClientOption(): array return $options; } + + private function handleResponseWithDataType( + string $dataType, + ResponseInterface $response, + ): array { + if (in_array($dataType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ($dataType !== 'string') { + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $response->getStatusCode(), + $response->getHeaders(), + $content + ); + } + } + } + + return [ + ObjectSerializer::deserialize($content, $dataType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + private function responseWithinRangeCode( + string $rangeCode, + int $statusCode, + ): bool { + $left = (int) ($rangeCode[0].'00'); + $right = (int) ($rangeCode[0].'99'); + + return $statusCode >= $left && $statusCode <= $right; + } } diff --git a/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/FakeClassnameTags123Api.php b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/FakeClassnameTags123Api.php index 2324371fccd7..c9b4667ecb3a 100644 --- a/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/FakeClassnameTags123Api.php +++ b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/FakeClassnameTags123Api.php @@ -35,6 +35,7 @@ use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; use GuzzleHttp\Promise\PromiseInterface; +use Psr\Http\Message\ResponseInterface; use OpenAPI\Client\ApiException; use OpenAPI\Client\Configuration; use OpenAPI\Client\HeaderSelector; @@ -184,36 +185,14 @@ public function testClassnameWithHttpInfo( $statusCode = $response->getStatusCode(); - switch($statusCode) { case 200: - if (in_array('\OpenAPI\Client\Model\Client', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('\OpenAPI\Client\Model\Client' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, '\OpenAPI\Client\Model\Client', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Client', + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -228,34 +207,10 @@ public function testClassnameWithHttpInfo( ); } - $returnType = '\OpenAPI\Client\Model\Client'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Client', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -265,8 +220,9 @@ public function testClassnameWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -467,4 +423,46 @@ protected function createHttpClientOption(): array return $options; } + + private function handleResponseWithDataType( + string $dataType, + ResponseInterface $response, + ): array { + if (in_array($dataType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ($dataType !== 'string') { + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $response->getStatusCode(), + $response->getHeaders(), + $content + ); + } + } + } + + return [ + ObjectSerializer::deserialize($content, $dataType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + private function responseWithinRangeCode( + string $rangeCode, + int $statusCode, + ): bool { + $left = (int) ($rangeCode[0].'00'); + $right = (int) ($rangeCode[0].'99'); + + return $statusCode >= $left && $statusCode <= $right; + } } diff --git a/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/PetApi.php b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/PetApi.php index 564d43a7150e..00de4eba4a38 100644 --- a/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/PetApi.php +++ b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/PetApi.php @@ -35,6 +35,7 @@ use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; use GuzzleHttp\Promise\PromiseInterface; +use Psr\Http\Message\ResponseInterface; use OpenAPI\Client\ApiException; use OpenAPI\Client\Configuration; use OpenAPI\Client\HeaderSelector; @@ -251,10 +252,10 @@ public function addPetWithHttpInfo( return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + throw $e; } } @@ -602,10 +603,10 @@ public function deletePetWithHttpInfo( return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + throw $e; } } @@ -848,36 +849,14 @@ public function findPetsByStatusWithHttpInfo( $statusCode = $response->getStatusCode(); - switch($statusCode) { case 200: - if (in_array('\OpenAPI\Client\Model\Pet[]', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('\OpenAPI\Client\Model\Pet[]' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, '\OpenAPI\Client\Model\Pet[]', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Pet[]', + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -892,34 +871,10 @@ public function findPetsByStatusWithHttpInfo( ); } - $returnType = '\OpenAPI\Client\Model\Pet[]'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Pet[]', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -929,8 +884,9 @@ public function findPetsByStatusWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -1178,36 +1134,14 @@ public function findPetsByTagsWithHttpInfo( $statusCode = $response->getStatusCode(); - switch($statusCode) { case 200: - if (in_array('\OpenAPI\Client\Model\Pet[]', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('\OpenAPI\Client\Model\Pet[]' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, '\OpenAPI\Client\Model\Pet[]', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Pet[]', + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -1222,34 +1156,10 @@ public function findPetsByTagsWithHttpInfo( ); } - $returnType = '\OpenAPI\Client\Model\Pet[]'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Pet[]', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -1259,8 +1169,9 @@ public function findPetsByTagsWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -1509,36 +1420,14 @@ public function getPetByIdWithHttpInfo( $statusCode = $response->getStatusCode(); - switch($statusCode) { case 200: - if (in_array('\OpenAPI\Client\Model\Pet', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('\OpenAPI\Client\Model\Pet' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, '\OpenAPI\Client\Model\Pet', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Pet', + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -1553,34 +1442,10 @@ public function getPetByIdWithHttpInfo( ); } - $returnType = '\OpenAPI\Client\Model\Pet'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Pet', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -1590,8 +1455,9 @@ public function getPetByIdWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -1878,10 +1744,10 @@ public function updatePetWithHttpInfo( return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + throw $e; } } @@ -2233,10 +2099,10 @@ public function updatePetWithFormWithHttpInfo( return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + throw $e; } } @@ -2498,36 +2364,14 @@ public function uploadFileWithHttpInfo( $statusCode = $response->getStatusCode(); - switch($statusCode) { case 200: - if (in_array('\OpenAPI\Client\Model\ApiResponse', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('\OpenAPI\Client\Model\ApiResponse' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, '\OpenAPI\Client\Model\ApiResponse', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\ApiResponse', + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -2542,34 +2386,10 @@ public function uploadFileWithHttpInfo( ); } - $returnType = '\OpenAPI\Client\Model\ApiResponse'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\ApiResponse', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -2579,8 +2399,9 @@ public function uploadFileWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -2865,36 +2686,14 @@ public function uploadFileWithRequiredFileWithHttpInfo( $statusCode = $response->getStatusCode(); - switch($statusCode) { case 200: - if (in_array('\OpenAPI\Client\Model\ApiResponse', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('\OpenAPI\Client\Model\ApiResponse' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, '\OpenAPI\Client\Model\ApiResponse', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\ApiResponse', + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -2909,34 +2708,10 @@ public function uploadFileWithRequiredFileWithHttpInfo( ); } - $returnType = '\OpenAPI\Client\Model\ApiResponse'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\ApiResponse', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -2946,8 +2721,9 @@ public function uploadFileWithRequiredFileWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -3186,4 +2962,46 @@ protected function createHttpClientOption(): array return $options; } + + private function handleResponseWithDataType( + string $dataType, + ResponseInterface $response, + ): array { + if (in_array($dataType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ($dataType !== 'string') { + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $response->getStatusCode(), + $response->getHeaders(), + $content + ); + } + } + } + + return [ + ObjectSerializer::deserialize($content, $dataType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + private function responseWithinRangeCode( + string $rangeCode, + int $statusCode, + ): bool { + $left = (int) ($rangeCode[0].'00'); + $right = (int) ($rangeCode[0].'99'); + + return $statusCode >= $left && $statusCode <= $right; + } } diff --git a/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/StoreApi.php b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/StoreApi.php index 705302d06141..81a3e408f22e 100644 --- a/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/StoreApi.php +++ b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/StoreApi.php @@ -35,6 +35,7 @@ use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; use GuzzleHttp\Promise\PromiseInterface; +use Psr\Http\Message\ResponseInterface; use OpenAPI\Client\ApiException; use OpenAPI\Client\Configuration; use OpenAPI\Client\HeaderSelector; @@ -194,10 +195,10 @@ public function deleteOrderWithHttpInfo( return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + throw $e; } } @@ -421,36 +422,14 @@ public function getInventoryWithHttpInfo( $statusCode = $response->getStatusCode(); - switch($statusCode) { case 200: - if (in_array('array', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('array' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, 'array', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + 'array', + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -465,34 +444,10 @@ public function getInventoryWithHttpInfo( ); } - $returnType = 'array'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + 'array', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -502,8 +457,9 @@ public function getInventoryWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -728,36 +684,14 @@ public function getOrderByIdWithHttpInfo( $statusCode = $response->getStatusCode(); - switch($statusCode) { case 200: - if (in_array('\OpenAPI\Client\Model\Order', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('\OpenAPI\Client\Model\Order' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, '\OpenAPI\Client\Model\Order', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Order', + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -772,34 +706,10 @@ public function getOrderByIdWithHttpInfo( ); } - $returnType = '\OpenAPI\Client\Model\Order'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Order', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -809,8 +719,9 @@ public function getOrderByIdWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -1057,36 +968,14 @@ public function placeOrderWithHttpInfo( $statusCode = $response->getStatusCode(); - switch($statusCode) { case 200: - if (in_array('\OpenAPI\Client\Model\Order', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('\OpenAPI\Client\Model\Order' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, '\OpenAPI\Client\Model\Order', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Order', + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -1101,34 +990,10 @@ public function placeOrderWithHttpInfo( ); } - $returnType = '\OpenAPI\Client\Model\Order'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Order', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -1138,8 +1003,9 @@ public function placeOrderWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -1335,4 +1201,46 @@ protected function createHttpClientOption(): array return $options; } + + private function handleResponseWithDataType( + string $dataType, + ResponseInterface $response, + ): array { + if (in_array($dataType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ($dataType !== 'string') { + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $response->getStatusCode(), + $response->getHeaders(), + $content + ); + } + } + } + + return [ + ObjectSerializer::deserialize($content, $dataType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + private function responseWithinRangeCode( + string $rangeCode, + int $statusCode, + ): bool { + $left = (int) ($rangeCode[0].'00'); + $right = (int) ($rangeCode[0].'99'); + + return $statusCode >= $left && $statusCode <= $right; + } } diff --git a/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/UserApi.php b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/UserApi.php index 97e46e3bf84d..85f2087f21d2 100644 --- a/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/UserApi.php +++ b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/UserApi.php @@ -35,6 +35,7 @@ use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; use GuzzleHttp\Promise\PromiseInterface; +use Psr\Http\Message\ResponseInterface; use OpenAPI\Client\ApiException; use OpenAPI\Client\Configuration; use OpenAPI\Client\HeaderSelector; @@ -206,10 +207,10 @@ public function createUserWithHttpInfo( return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + throw $e; } } @@ -437,10 +438,10 @@ public function createUsersWithArrayInputWithHttpInfo( return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + throw $e; } } @@ -668,10 +669,10 @@ public function createUsersWithListInputWithHttpInfo( return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + throw $e; } } @@ -899,10 +900,10 @@ public function deleteUserWithHttpInfo( return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + throw $e; } } @@ -1130,36 +1131,14 @@ public function getUserByNameWithHttpInfo( $statusCode = $response->getStatusCode(); - switch($statusCode) { case 200: - if (in_array('\OpenAPI\Client\Model\User', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('\OpenAPI\Client\Model\User' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, '\OpenAPI\Client\Model\User', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\User', + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -1174,34 +1153,10 @@ public function getUserByNameWithHttpInfo( ); } - $returnType = '\OpenAPI\Client\Model\User'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\User', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -1211,8 +1166,9 @@ public function getUserByNameWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -1457,36 +1413,14 @@ public function loginUserWithHttpInfo( $statusCode = $response->getStatusCode(); - switch($statusCode) { case 200: - if (in_array('string', ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('string' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, 'string', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + 'string', + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -1501,34 +1435,10 @@ public function loginUserWithHttpInfo( ); } - $returnType = 'string'; - if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + 'string', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -1538,8 +1448,9 @@ public function loginUserWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -1800,10 +1711,10 @@ public function logoutUserWithHttpInfo( return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + throw $e; } } @@ -2015,10 +1926,10 @@ public function updateUserWithHttpInfo( return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + throw $e; } } @@ -2222,4 +2133,46 @@ protected function createHttpClientOption(): array return $options; } + + private function handleResponseWithDataType( + string $dataType, + ResponseInterface $response, + ): array { + if (in_array($dataType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ($dataType !== 'string') { + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $response->getStatusCode(), + $response->getHeaders(), + $content + ); + } + } + } + + return [ + ObjectSerializer::deserialize($content, $dataType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + private function responseWithinRangeCode( + string $rangeCode, + int $statusCode, + ): bool { + $left = (int) ($rangeCode[0].'00'); + $right = (int) ($rangeCode[0].'99'); + + return $statusCode >= $left && $statusCode <= $right; + } } diff --git a/samples/client/petstore/php/OpenAPIClient-php/.openapi-generator/FILES b/samples/client/petstore/php/OpenAPIClient-php/.openapi-generator/FILES index 163723370d10..fa5b51302970 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/.openapi-generator/FILES +++ b/samples/client/petstore/php/OpenAPIClient-php/.openapi-generator/FILES @@ -28,6 +28,7 @@ docs/Model/EnumArrays.md docs/Model/EnumClass.md docs/Model/EnumTest.md docs/Model/EnumWithNameAndDescription.md +docs/Model/ErrorResponse.md docs/Model/FakeBigDecimalMap200Response.md docs/Model/File.md docs/Model/FileSchemaTestClass.md @@ -89,6 +90,7 @@ lib/Model/EnumArrays.php lib/Model/EnumClass.php lib/Model/EnumTest.php lib/Model/EnumWithNameAndDescription.php +lib/Model/ErrorResponse.php lib/Model/FakeBigDecimalMap200Response.php lib/Model/File.php lib/Model/FileSchemaTestClass.php @@ -124,3 +126,4 @@ lib/Model/TestInlineFreeformAdditionalPropertiesRequest.php lib/Model/User.php lib/ObjectSerializer.php phpunit.xml.dist +test/Model/ErrorResponseTest.php diff --git a/samples/client/petstore/php/OpenAPIClient-php/README.md b/samples/client/petstore/php/OpenAPIClient-php/README.md index 81f5c4bf3639..f23a92463d7c 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/README.md +++ b/samples/client/petstore/php/OpenAPIClient-php/README.md @@ -82,6 +82,9 @@ Class | Method | HTTP request | Description *FakeApi* | [**fakeOuterNumberSerialize**](docs/Api/FakeApi.md#fakeouternumberserialize) | **POST** /fake/outer/number | *FakeApi* | [**fakeOuterStringSerialize**](docs/Api/FakeApi.md#fakeouterstringserialize) | **POST** /fake/outer/string | *FakeApi* | [**fakePropertyEnumIntegerSerialize**](docs/Api/FakeApi.md#fakepropertyenumintegerserialize) | **POST** /fake/property/enum-int | +*FakeApi* | [**fakeWith400And4xxRangeResponseEndpoint**](docs/Api/FakeApi.md#fakewith400and4xxrangeresponseendpoint) | **POST** /fake/with_400_and_4xx_range_response/endpoint | test endpoint with 400 and 400-499 range response http code with dataType +*FakeApi* | [**fakeWith400ResponseEndpoint**](docs/Api/FakeApi.md#fakewith400responseendpoint) | **POST** /fake/with_400_response/endpoint | test endpoint with 400 response http code with dataType +*FakeApi* | [**fakeWith4xxRangeResponseEndpoint**](docs/Api/FakeApi.md#fakewith4xxrangeresponseendpoint) | **POST** /fake/with_4xx_range_response/endpoint | test endpoint with 400-499 range response http code with dataType *FakeApi* | [**getParameterNameMapping**](docs/Api/FakeApi.md#getparameternamemapping) | **GET** /fake/parameter-name-mapping | parameter name mapping test *FakeApi* | [**testAdditionalPropertiesReference**](docs/Api/FakeApi.md#testadditionalpropertiesreference) | **POST** /fake/additionalProperties-reference | test referenced additionalProperties *FakeApi* | [**testBodyWithBinary**](docs/Api/FakeApi.md#testbodywithbinary) | **PUT** /fake/body-with-binary | @@ -140,6 +143,7 @@ Class | Method | HTTP request | Description - [EnumClass](docs/Model/EnumClass.md) - [EnumTest](docs/Model/EnumTest.md) - [EnumWithNameAndDescription](docs/Model/EnumWithNameAndDescription.md) +- [ErrorResponse](docs/Model/ErrorResponse.md) - [FakeBigDecimalMap200Response](docs/Model/FakeBigDecimalMap200Response.md) - [File](docs/Model/File.md) - [FileSchemaTestClass](docs/Model/FileSchemaTestClass.md) diff --git a/samples/client/petstore/php/OpenAPIClient-php/docs/Api/FakeApi.md b/samples/client/petstore/php/OpenAPIClient-php/docs/Api/FakeApi.md index 48d5bad2c164..c7f1fa71c1d2 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/docs/Api/FakeApi.md +++ b/samples/client/petstore/php/OpenAPIClient-php/docs/Api/FakeApi.md @@ -13,6 +13,9 @@ All URIs are relative to http://petstore.swagger.io:80/v2, except if the operati | [**fakeOuterNumberSerialize()**](FakeApi.md#fakeOuterNumberSerialize) | **POST** /fake/outer/number | | | [**fakeOuterStringSerialize()**](FakeApi.md#fakeOuterStringSerialize) | **POST** /fake/outer/string | | | [**fakePropertyEnumIntegerSerialize()**](FakeApi.md#fakePropertyEnumIntegerSerialize) | **POST** /fake/property/enum-int | | +| [**fakeWith400And4xxRangeResponseEndpoint()**](FakeApi.md#fakeWith400And4xxRangeResponseEndpoint) | **POST** /fake/with_400_and_4xx_range_response/endpoint | test endpoint with 400 and 400-499 range response http code with dataType | +| [**fakeWith400ResponseEndpoint()**](FakeApi.md#fakeWith400ResponseEndpoint) | **POST** /fake/with_400_response/endpoint | test endpoint with 400 response http code with dataType | +| [**fakeWith4xxRangeResponseEndpoint()**](FakeApi.md#fakeWith4xxRangeResponseEndpoint) | **POST** /fake/with_4xx_range_response/endpoint | test endpoint with 400-499 range response http code with dataType | | [**getParameterNameMapping()**](FakeApi.md#getParameterNameMapping) | **GET** /fake/parameter-name-mapping | parameter name mapping test | | [**testAdditionalPropertiesReference()**](FakeApi.md#testAdditionalPropertiesReference) | **POST** /fake/additionalProperties-reference | test referenced additionalProperties | | [**testBodyWithBinary()**](FakeApi.md#testBodyWithBinary) | **PUT** /fake/body-with-binary | | @@ -530,6 +533,165 @@ No authorization required [[Back to Model list]](../../README.md#models) [[Back to README]](../../README.md) +## `fakeWith400And4xxRangeResponseEndpoint()` + +```php +fakeWith400And4xxRangeResponseEndpoint($pet) +``` + +test endpoint with 400 and 400-499 range response http code with dataType + +### Example + +```php +fakeWith400And4xxRangeResponseEndpoint($pet); +} catch (Exception $e) { + echo 'Exception when calling FakeApi->fakeWith400And4xxRangeResponseEndpoint: ', $e->getMessage(), PHP_EOL; +} +``` + +### Parameters + +| Name | Type | Description | Notes | +| ------------- | ------------- | ------------- | ------------- | +| **pet** | [**\OpenAPI\Client\Model\Pet**](../Model/Pet.md)| Pet object that needs to be added to the store | | + +### Return type + +void (empty response body) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: `application/json`, `application/xml` +- **Accept**: `application/json` + +[[Back to top]](#) [[Back to API list]](../../README.md#endpoints) +[[Back to Model list]](../../README.md#models) +[[Back to README]](../../README.md) + +## `fakeWith400ResponseEndpoint()` + +```php +fakeWith400ResponseEndpoint($pet) +``` + +test endpoint with 400 response http code with dataType + +### Example + +```php +fakeWith400ResponseEndpoint($pet); +} catch (Exception $e) { + echo 'Exception when calling FakeApi->fakeWith400ResponseEndpoint: ', $e->getMessage(), PHP_EOL; +} +``` + +### Parameters + +| Name | Type | Description | Notes | +| ------------- | ------------- | ------------- | ------------- | +| **pet** | [**\OpenAPI\Client\Model\Pet**](../Model/Pet.md)| Pet object that needs to be added to the store | | + +### Return type + +void (empty response body) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: `application/json`, `application/xml` +- **Accept**: `application/json` + +[[Back to top]](#) [[Back to API list]](../../README.md#endpoints) +[[Back to Model list]](../../README.md#models) +[[Back to README]](../../README.md) + +## `fakeWith4xxRangeResponseEndpoint()` + +```php +fakeWith4xxRangeResponseEndpoint($pet) +``` + +test endpoint with 400-499 range response http code with dataType + +### Example + +```php +fakeWith4xxRangeResponseEndpoint($pet); +} catch (Exception $e) { + echo 'Exception when calling FakeApi->fakeWith4xxRangeResponseEndpoint: ', $e->getMessage(), PHP_EOL; +} +``` + +### Parameters + +| Name | Type | Description | Notes | +| ------------- | ------------- | ------------- | ------------- | +| **pet** | [**\OpenAPI\Client\Model\Pet**](../Model/Pet.md)| Pet object that needs to be added to the store | | + +### Return type + +void (empty response body) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: `application/json`, `application/xml` +- **Accept**: `application/json` + +[[Back to top]](#) [[Back to API list]](../../README.md#endpoints) +[[Back to Model list]](../../README.md#models) +[[Back to README]](../../README.md) + ## `getParameterNameMapping()` ```php diff --git a/samples/client/petstore/php/OpenAPIClient-php/docs/Model/ErrorRangeResponse.md b/samples/client/petstore/php/OpenAPIClient-php/docs/Model/ErrorRangeResponse.md new file mode 100644 index 000000000000..25a8fe846fba --- /dev/null +++ b/samples/client/petstore/php/OpenAPIClient-php/docs/Model/ErrorRangeResponse.md @@ -0,0 +1,10 @@ +# # ErrorRangeResponse + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**response_code** | **int** | | [optional] +**error** | **string** | | [optional] + +[[Back to Model list]](../../README.md#models) [[Back to API list]](../../README.md#endpoints) [[Back to README]](../../README.md) diff --git a/samples/client/petstore/php/OpenAPIClient-php/docs/Model/ErrorResponse.md b/samples/client/petstore/php/OpenAPIClient-php/docs/Model/ErrorResponse.md new file mode 100644 index 000000000000..a6db5fe293ef --- /dev/null +++ b/samples/client/petstore/php/OpenAPIClient-php/docs/Model/ErrorResponse.md @@ -0,0 +1,10 @@ +# # ErrorResponse + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**response_code** | **int** | | [optional] +**error** | **string** | | [optional] + +[[Back to Model list]](../../README.md#models) [[Back to API list]](../../README.md#endpoints) [[Back to README]](../../README.md) diff --git a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/AnotherFakeApi.php b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/AnotherFakeApi.php index d97d060f866c..9af2ab03bef1 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/AnotherFakeApi.php +++ b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/AnotherFakeApi.php @@ -34,6 +34,7 @@ use GuzzleHttp\Psr7\MultipartStream; use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; +use Psr\Http\Message\ResponseInterface; use OpenAPI\Client\ApiException; use OpenAPI\Client\Configuration; use OpenAPI\Client\HeaderSelector; @@ -181,34 +182,14 @@ public function call123TestSpecialTagsWithHttpInfo($client, string $contentType switch($statusCode) { case 200: - if ('\OpenAPI\Client\Model\Client' === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('\OpenAPI\Client\Model\Client' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, '\OpenAPI\Client\Model\Client', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Client', + $response, + ); } + + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( sprintf( @@ -222,34 +203,10 @@ public function call123TestSpecialTagsWithHttpInfo($client, string $contentType ); } - $returnType = '\OpenAPI\Client\Model\Client'; - if ($returnType === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Client', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -259,8 +216,10 @@ public function call123TestSpecialTagsWithHttpInfo($client, string $contentType $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -447,4 +406,46 @@ protected function createHttpClientOption() return $options; } + + private function handleResponseWithDataType( + string $dataType, + ResponseInterface $response + ): array { + if ($dataType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ($dataType !== 'string') { + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $response->getStatusCode(), + $response->getHeaders(), + $content + ); + } + } + } + + return [ + ObjectSerializer::deserialize($content, $dataType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + private function responseWithinRangeCode( + string $rangeCode, + int $statusCode + ): bool { + $left = (int) ($rangeCode[0].'00'); + $right = (int) ($rangeCode[0].'99'); + + return $statusCode >= $left && $statusCode <= $right; + } } diff --git a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/DefaultApi.php b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/DefaultApi.php index 2a3996d403cb..3c17b07a4bc4 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/DefaultApi.php +++ b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/DefaultApi.php @@ -34,6 +34,7 @@ use GuzzleHttp\Psr7\MultipartStream; use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; +use Psr\Http\Message\ResponseInterface; use OpenAPI\Client\ApiException; use OpenAPI\Client\Configuration; use OpenAPI\Client\HeaderSelector; @@ -175,34 +176,14 @@ public function fooGetWithHttpInfo(string $contentType = self::contentTypes['foo switch($statusCode) { default: - if ('\OpenAPI\Client\Model\FooGetDefaultResponse' === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('\OpenAPI\Client\Model\FooGetDefaultResponse' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, '\OpenAPI\Client\Model\FooGetDefaultResponse', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\FooGetDefaultResponse', + $response, + ); } + + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( sprintf( @@ -216,34 +197,10 @@ public function fooGetWithHttpInfo(string $contentType = self::contentTypes['foo ); } - $returnType = '\OpenAPI\Client\Model\FooGetDefaultResponse'; - if ($returnType === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\FooGetDefaultResponse', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { default: @@ -253,8 +210,10 @@ public function fooGetWithHttpInfo(string $contentType = self::contentTypes['foo $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -420,4 +379,46 @@ protected function createHttpClientOption() return $options; } + + private function handleResponseWithDataType( + string $dataType, + ResponseInterface $response + ): array { + if ($dataType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ($dataType !== 'string') { + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $response->getStatusCode(), + $response->getHeaders(), + $content + ); + } + } + } + + return [ + ObjectSerializer::deserialize($content, $dataType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + private function responseWithinRangeCode( + string $rangeCode, + int $statusCode + ): bool { + $left = (int) ($rangeCode[0].'00'); + $right = (int) ($rangeCode[0].'99'); + + return $statusCode >= $left && $statusCode <= $right; + } } diff --git a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/FakeApi.php b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/FakeApi.php index f1349de63575..bd829d3699d7 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/FakeApi.php +++ b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/FakeApi.php @@ -34,6 +34,7 @@ use GuzzleHttp\Psr7\MultipartStream; use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; +use Psr\Http\Message\ResponseInterface; use OpenAPI\Client\ApiException; use OpenAPI\Client\Configuration; use OpenAPI\Client\HeaderSelector; @@ -99,6 +100,18 @@ class FakeApi 'fakePropertyEnumIntegerSerialize' => [ 'application/json', ], + 'fakeWith400And4xxRangeResponseEndpoint' => [ + 'application/json', + 'application/xml', + ], + 'fakeWith400ResponseEndpoint' => [ + 'application/json', + 'application/xml', + ], + 'fakeWith4xxRangeResponseEndpoint' => [ + 'application/json', + 'application/xml', + ], 'getParameterNameMapping' => [ 'application/json', ], @@ -242,34 +255,14 @@ public function fakeBigDecimalMapWithHttpInfo(string $contentType = self::conten switch($statusCode) { case 200: - if ('\OpenAPI\Client\Model\FakeBigDecimalMap200Response' === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('\OpenAPI\Client\Model\FakeBigDecimalMap200Response' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, '\OpenAPI\Client\Model\FakeBigDecimalMap200Response', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\FakeBigDecimalMap200Response', + $response, + ); } + + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( sprintf( @@ -283,34 +276,10 @@ public function fakeBigDecimalMapWithHttpInfo(string $contentType = self::conten ); } - $returnType = '\OpenAPI\Client\Model\FakeBigDecimalMap200Response'; - if ($returnType === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\FakeBigDecimalMap200Response', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -320,8 +289,10 @@ public function fakeBigDecimalMapWithHttpInfo(string $contentType = self::conten $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -532,34 +503,14 @@ public function fakeEnumEndpointWithHttpInfo($enum_class, $enum_class_array, $en switch($statusCode) { case 200: - if ('\OpenAPI\Client\Model\EnumClass' === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('\OpenAPI\Client\Model\EnumClass' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, '\OpenAPI\Client\Model\EnumClass', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\EnumClass', + $response, + ); } + + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( sprintf( @@ -573,34 +524,10 @@ public function fakeEnumEndpointWithHttpInfo($enum_class, $enum_class_array, $en ); } - $returnType = '\OpenAPI\Client\Model\EnumClass'; - if ($returnType === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\EnumClass', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -610,8 +537,10 @@ public function fakeEnumEndpointWithHttpInfo($enum_class, $enum_class_array, $en $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -877,34 +806,14 @@ public function fakeHealthGetWithHttpInfo(string $contentType = self::contentTyp switch($statusCode) { case 200: - if ('\OpenAPI\Client\Model\HealthCheckResult' === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('\OpenAPI\Client\Model\HealthCheckResult' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, '\OpenAPI\Client\Model\HealthCheckResult', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\HealthCheckResult', + $response, + ); } + + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( sprintf( @@ -918,34 +827,10 @@ public function fakeHealthGetWithHttpInfo(string $contentType = self::contentTyp ); } - $returnType = '\OpenAPI\Client\Model\HealthCheckResult'; - if ($returnType === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\HealthCheckResult', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -955,8 +840,10 @@ public function fakeHealthGetWithHttpInfo(string $contentType = self::contentTyp $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -1169,10 +1056,11 @@ public function fakeHttpSignatureTestWithHttpInfo($pet, $query_1 = null, $header return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + + throw $e; } } @@ -1404,34 +1292,14 @@ public function fakeOuterBooleanSerializeWithHttpInfo($body = null, string $cont switch($statusCode) { case 200: - if ('bool' === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('bool' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, 'bool', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + 'bool', + $response, + ); } + + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( sprintf( @@ -1445,34 +1313,10 @@ public function fakeOuterBooleanSerializeWithHttpInfo($body = null, string $cont ); } - $returnType = 'bool'; - if ($returnType === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + 'bool', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -1482,8 +1326,10 @@ public function fakeOuterBooleanSerializeWithHttpInfo($body = null, string $cont $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -1697,34 +1543,14 @@ public function fakeOuterCompositeSerializeWithHttpInfo($outer_composite = null, switch($statusCode) { case 200: - if ('\OpenAPI\Client\Model\OuterComposite' === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('\OpenAPI\Client\Model\OuterComposite' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, '\OpenAPI\Client\Model\OuterComposite', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\OuterComposite', + $response, + ); } + + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( sprintf( @@ -1738,34 +1564,10 @@ public function fakeOuterCompositeSerializeWithHttpInfo($outer_composite = null, ); } - $returnType = '\OpenAPI\Client\Model\OuterComposite'; - if ($returnType === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\OuterComposite', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -1775,8 +1577,10 @@ public function fakeOuterCompositeSerializeWithHttpInfo($outer_composite = null, $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -1990,34 +1794,14 @@ public function fakeOuterNumberSerializeWithHttpInfo($body = null, string $conte switch($statusCode) { case 200: - if ('float' === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('float' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, 'float', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + 'float', + $response, + ); } + + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( sprintf( @@ -2031,34 +1815,10 @@ public function fakeOuterNumberSerializeWithHttpInfo($body = null, string $conte ); } - $returnType = 'float'; - if ($returnType === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + 'float', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -2068,8 +1828,10 @@ public function fakeOuterNumberSerializeWithHttpInfo($body = null, string $conte $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -2283,34 +2045,14 @@ public function fakeOuterStringSerializeWithHttpInfo($body = null, string $conte switch($statusCode) { case 200: - if ('string' === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('string' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, 'string', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + 'string', + $response, + ); } + + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( sprintf( @@ -2324,61 +2066,761 @@ public function fakeOuterStringSerializeWithHttpInfo($body = null, string $conte ); } - $returnType = 'string'; - if ($returnType === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } + return $this->handleResponseWithDataType( + 'string', + $response, + ); + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + 'string', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + throw $e; + } + + + throw $e; + } + } + + /** + * Operation fakeOuterStringSerializeAsync + * + * @param string|null $body Input string as post body (optional) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeOuterStringSerialize'] to see the possible values for this operation + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function fakeOuterStringSerializeAsync($body = null, string $contentType = self::contentTypes['fakeOuterStringSerialize'][0]) + { + return $this->fakeOuterStringSerializeAsyncWithHttpInfo($body, $contentType) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation fakeOuterStringSerializeAsyncWithHttpInfo + * + * @param string|null $body Input string as post body (optional) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeOuterStringSerialize'] to see the possible values for this operation + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function fakeOuterStringSerializeAsyncWithHttpInfo($body = null, string $contentType = self::contentTypes['fakeOuterStringSerialize'][0]) + { + $returnType = 'string'; + $request = $this->fakeOuterStringSerializeRequest($body, $contentType); + + return $this->client + ->sendAsync($request, $this->createHttpClientOption()) + ->then( + function ($response) use ($returnType) { + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + 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( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $exception->getRequest()->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + ); + } + + /** + * Create request for operation 'fakeOuterStringSerialize' + * + * @param string|null $body Input string as post body (optional) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeOuterStringSerialize'] to see the possible values for this operation + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + public function fakeOuterStringSerializeRequest($body = null, string $contentType = self::contentTypes['fakeOuterStringSerialize'][0]) + { + + + + $resourcePath = '/fake/outer/string'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + + + + + $headers = $this->headerSelector->selectHeaders( + ['*/*', ], + $contentType, + $multipart + ); + + // for model (json/xml) + if (isset($body)) { + if (stripos($headers['Content-Type'], 'application/json') !== false) { + # if Content-Type contains "application/json", json_encode the body + $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($body)); + } else { + $httpBody = $body; + } + } elseif (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; + foreach ($formParamValueItems as $formParamValueItem) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValueItem + ]; + } + } + // for HTTP post (form) + $httpBody = new MultipartStream($multipartContents); + + } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { + # if Content-Type contains "application/json", json_encode the form parameters + $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + } else { + // for HTTP post (form) + $httpBody = ObjectSerializer::buildQuery($formParams); + } + } + + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $operationHost = $this->config->getHost(); + $query = ObjectSerializer::buildQuery($queryParams); + return new Request( + 'POST', + $operationHost . $resourcePath . ($query ? "?{$query}" : ''), + $headers, + $httpBody + ); + } + + /** + * Operation fakePropertyEnumIntegerSerialize + * + * @param \OpenAPI\Client\Model\OuterObjectWithEnumProperty $outer_object_with_enum_property Input enum (int) as post body (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakePropertyEnumIntegerSerialize'] to see the possible values for this operation + * + * @throws \OpenAPI\Client\ApiException on non-2xx response or if the response body is not in the expected format + * @throws \InvalidArgumentException + * @return \OpenAPI\Client\Model\OuterObjectWithEnumProperty + */ + public function fakePropertyEnumIntegerSerialize($outer_object_with_enum_property, string $contentType = self::contentTypes['fakePropertyEnumIntegerSerialize'][0]) + { + list($response) = $this->fakePropertyEnumIntegerSerializeWithHttpInfo($outer_object_with_enum_property, $contentType); + return $response; + } + + /** + * Operation fakePropertyEnumIntegerSerializeWithHttpInfo + * + * @param \OpenAPI\Client\Model\OuterObjectWithEnumProperty $outer_object_with_enum_property Input enum (int) as post body (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakePropertyEnumIntegerSerialize'] to see the possible values for this operation + * + * @throws \OpenAPI\Client\ApiException on non-2xx response or if the response body is not in the expected format + * @throws \InvalidArgumentException + * @return array of \OpenAPI\Client\Model\OuterObjectWithEnumProperty, HTTP status code, HTTP response headers (array of strings) + */ + public function fakePropertyEnumIntegerSerializeWithHttpInfo($outer_object_with_enum_property, string $contentType = self::contentTypes['fakePropertyEnumIntegerSerialize'][0]) + { + $request = $this->fakePropertyEnumIntegerSerializeRequest($outer_object_with_enum_property, $contentType); + + try { + $options = $this->createHttpClientOption(); + try { + $response = $this->client->send($request, $options); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null, + $e->getResponse() ? (string) $e->getResponse()->getBody() : null + ); + } catch (ConnectException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + null, + null + ); + } + + $statusCode = $response->getStatusCode(); + + + switch($statusCode) { + case 200: + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\OuterObjectWithEnumProperty', + $response, + ); + } + + + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\OuterObjectWithEnumProperty', + $response, + ); + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\OpenAPI\Client\Model\OuterObjectWithEnumProperty', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + throw $e; + } + + + throw $e; + } + } + + /** + * Operation fakePropertyEnumIntegerSerializeAsync + * + * @param \OpenAPI\Client\Model\OuterObjectWithEnumProperty $outer_object_with_enum_property Input enum (int) as post body (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakePropertyEnumIntegerSerialize'] to see the possible values for this operation + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function fakePropertyEnumIntegerSerializeAsync($outer_object_with_enum_property, string $contentType = self::contentTypes['fakePropertyEnumIntegerSerialize'][0]) + { + return $this->fakePropertyEnumIntegerSerializeAsyncWithHttpInfo($outer_object_with_enum_property, $contentType) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation fakePropertyEnumIntegerSerializeAsyncWithHttpInfo + * + * @param \OpenAPI\Client\Model\OuterObjectWithEnumProperty $outer_object_with_enum_property Input enum (int) as post body (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakePropertyEnumIntegerSerialize'] to see the possible values for this operation + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function fakePropertyEnumIntegerSerializeAsyncWithHttpInfo($outer_object_with_enum_property, string $contentType = self::contentTypes['fakePropertyEnumIntegerSerialize'][0]) + { + $returnType = '\OpenAPI\Client\Model\OuterObjectWithEnumProperty'; + $request = $this->fakePropertyEnumIntegerSerializeRequest($outer_object_with_enum_property, $contentType); + + return $this->client + ->sendAsync($request, $this->createHttpClientOption()) + ->then( + function ($response) use ($returnType) { + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + 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( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $exception->getRequest()->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + ); + } + + /** + * Create request for operation 'fakePropertyEnumIntegerSerialize' + * + * @param \OpenAPI\Client\Model\OuterObjectWithEnumProperty $outer_object_with_enum_property Input enum (int) as post body (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakePropertyEnumIntegerSerialize'] to see the possible values for this operation + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + public function fakePropertyEnumIntegerSerializeRequest($outer_object_with_enum_property, string $contentType = self::contentTypes['fakePropertyEnumIntegerSerialize'][0]) + { + + // verify the required parameter 'outer_object_with_enum_property' is set + if ($outer_object_with_enum_property === null || (is_array($outer_object_with_enum_property) && count($outer_object_with_enum_property) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $outer_object_with_enum_property when calling fakePropertyEnumIntegerSerialize' + ); + } + + + $resourcePath = '/fake/property/enum-int'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + + + + + $headers = $this->headerSelector->selectHeaders( + ['*/*', ], + $contentType, + $multipart + ); + + // for model (json/xml) + if (isset($outer_object_with_enum_property)) { + if (stripos($headers['Content-Type'], 'application/json') !== false) { + # if Content-Type contains "application/json", json_encode the body + $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($outer_object_with_enum_property)); + } else { + $httpBody = $outer_object_with_enum_property; + } + } elseif (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; + foreach ($formParamValueItems as $formParamValueItem) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValueItem + ]; + } + } + // for HTTP post (form) + $httpBody = new MultipartStream($multipartContents); + + } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { + # if Content-Type contains "application/json", json_encode the form parameters + $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + } else { + // for HTTP post (form) + $httpBody = ObjectSerializer::buildQuery($formParams); + } + } + + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $operationHost = $this->config->getHost(); + $query = ObjectSerializer::buildQuery($queryParams); + return new Request( + 'POST', + $operationHost . $resourcePath . ($query ? "?{$query}" : ''), + $headers, + $httpBody + ); + } + + /** + * Operation fakeWith400And4xxRangeResponseEndpoint + * + * test endpoint with 400 and 400-499 range response http code with dataType + * + * @param \OpenAPI\Client\Model\Pet $pet Pet object that needs to be added to the store (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeWith400And4xxRangeResponseEndpoint'] to see the possible values for this operation + * + * @throws \OpenAPI\Client\ApiException on non-2xx response or if the response body is not in the expected format + * @throws \InvalidArgumentException + * @return void + */ + public function fakeWith400And4xxRangeResponseEndpoint($pet, string $contentType = self::contentTypes['fakeWith400And4xxRangeResponseEndpoint'][0]) + { + $this->fakeWith400And4xxRangeResponseEndpointWithHttpInfo($pet, $contentType); + } + + /** + * Operation fakeWith400And4xxRangeResponseEndpointWithHttpInfo + * + * test endpoint with 400 and 400-499 range response http code with dataType + * + * @param \OpenAPI\Client\Model\Pet $pet Pet object that needs to be added to the store (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeWith400And4xxRangeResponseEndpoint'] to see the possible values for this operation + * + * @throws \OpenAPI\Client\ApiException on non-2xx response or if the response body is not in the expected format + * @throws \InvalidArgumentException + * @return array of null, HTTP status code, HTTP response headers (array of strings) + */ + public function fakeWith400And4xxRangeResponseEndpointWithHttpInfo($pet, string $contentType = self::contentTypes['fakeWith400And4xxRangeResponseEndpoint'][0]) + { + $request = $this->fakeWith400And4xxRangeResponseEndpointRequest($pet, $contentType); + + try { + $options = $this->createHttpClientOption(); + try { + $response = $this->client->send($request, $options); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null, + $e->getResponse() ? (string) $e->getResponse()->getBody() : null + ); + } catch (ConnectException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + null, + null + ); + } + + $statusCode = $response->getStatusCode(); + + + return [null, $statusCode, $response->getHeaders()]; + } catch (ApiException $e) { + switch ($e->getCode()) { + case 400: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\OpenAPI\Client\Model\ErrorResponse', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + throw $e; + + } + + if ($this->responseWithinRangeCode('4xx', $e->getCode())) { + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\OpenAPI\Client\Model\ErrorResponse', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + throw $e; + } + + throw $e; + } + } + + /** + * Operation fakeWith400And4xxRangeResponseEndpointAsync + * + * test endpoint with 400 and 400-499 range response http code with dataType + * + * @param \OpenAPI\Client\Model\Pet $pet Pet object that needs to be added to the store (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeWith400And4xxRangeResponseEndpoint'] to see the possible values for this operation + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function fakeWith400And4xxRangeResponseEndpointAsync($pet, string $contentType = self::contentTypes['fakeWith400And4xxRangeResponseEndpoint'][0]) + { + return $this->fakeWith400And4xxRangeResponseEndpointAsyncWithHttpInfo($pet, $contentType) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation fakeWith400And4xxRangeResponseEndpointAsyncWithHttpInfo + * + * test endpoint with 400 and 400-499 range response http code with dataType + * + * @param \OpenAPI\Client\Model\Pet $pet Pet object that needs to be added to the store (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeWith400And4xxRangeResponseEndpoint'] to see the possible values for this operation + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function fakeWith400And4xxRangeResponseEndpointAsyncWithHttpInfo($pet, string $contentType = self::contentTypes['fakeWith400And4xxRangeResponseEndpoint'][0]) + { + $returnType = ''; + $request = $this->fakeWith400And4xxRangeResponseEndpointRequest($pet, $contentType); + + return $this->client + ->sendAsync($request, $this->createHttpClientOption()) + ->then( + function ($response) use ($returnType) { + return [null, $response->getStatusCode(), $response->getHeaders()]; + }, + function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $exception->getRequest()->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + ); + } + + /** + * Create request for operation 'fakeWith400And4xxRangeResponseEndpoint' + * + * @param \OpenAPI\Client\Model\Pet $pet Pet object that needs to be added to the store (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeWith400And4xxRangeResponseEndpoint'] to see the possible values for this operation + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + public function fakeWith400And4xxRangeResponseEndpointRequest($pet, string $contentType = self::contentTypes['fakeWith400And4xxRangeResponseEndpoint'][0]) + { + + // verify the required parameter 'pet' is set + if ($pet === null || (is_array($pet) && count($pet) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $pet when calling fakeWith400And4xxRangeResponseEndpoint' + ); + } + + + $resourcePath = '/fake/with_400_and_4xx_range_response/endpoint'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + + + + + $headers = $this->headerSelector->selectHeaders( + ['application/json', ], + $contentType, + $multipart + ); + + // for model (json/xml) + if (isset($pet)) { + if (stripos($headers['Content-Type'], 'application/json') !== false) { + # if Content-Type contains "application/json", json_encode the body + $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($pet)); + } else { + $httpBody = $pet; + } + } elseif (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; + foreach ($formParamValueItems as $formParamValueItem) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValueItem + ]; + } + } + // for HTTP post (form) + $httpBody = new MultipartStream($multipartContents); + + } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { + # if Content-Type contains "application/json", json_encode the form parameters + $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + } else { + // for HTTP post (form) + $httpBody = ObjectSerializer::buildQuery($formParams); + } + } + + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $operationHost = $this->config->getHost(); + $query = ObjectSerializer::buildQuery($queryParams); + return new Request( + 'POST', + $operationHost . $resourcePath . ($query ? "?{$query}" : ''), + $headers, + $httpBody + ); + } + + /** + * Operation fakeWith400ResponseEndpoint + * + * test endpoint with 400 response http code with dataType + * + * @param \OpenAPI\Client\Model\Pet $pet Pet object that needs to be added to the store (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeWith400ResponseEndpoint'] to see the possible values for this operation + * + * @throws \OpenAPI\Client\ApiException on non-2xx response or if the response body is not in the expected format + * @throws \InvalidArgumentException + * @return void + */ + public function fakeWith400ResponseEndpoint($pet, string $contentType = self::contentTypes['fakeWith400ResponseEndpoint'][0]) + { + $this->fakeWith400ResponseEndpointWithHttpInfo($pet, $contentType); + } + + /** + * Operation fakeWith400ResponseEndpointWithHttpInfo + * + * test endpoint with 400 response http code with dataType + * + * @param \OpenAPI\Client\Model\Pet $pet Pet object that needs to be added to the store (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeWith400ResponseEndpoint'] to see the possible values for this operation + * + * @throws \OpenAPI\Client\ApiException on non-2xx response or if the response body is not in the expected format + * @throws \InvalidArgumentException + * @return array of null, HTTP status code, HTTP response headers (array of strings) + */ + public function fakeWith400ResponseEndpointWithHttpInfo($pet, string $contentType = self::contentTypes['fakeWith400ResponseEndpoint'][0]) + { + $request = $this->fakeWith400ResponseEndpointRequest($pet, $contentType); + + try { + $options = $this->createHttpClientOption(); + try { + $response = $this->client->send($request, $options); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null, + $e->getResponse() ? (string) $e->getResponse()->getBody() : null + ); + } catch (ConnectException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + null, + null + ); + } + + $statusCode = $response->getStatusCode(); - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return [null, $statusCode, $response->getHeaders()]; } catch (ApiException $e) { switch ($e->getCode()) { - case 200: + case 400: $data = ObjectSerializer::deserialize( $e->getResponseBody(), - 'string', + '\OpenAPI\Client\Model\ErrorResponse', $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } /** - * Operation fakeOuterStringSerializeAsync + * Operation fakeWith400ResponseEndpointAsync * - * @param string|null $body Input string as post body (optional) - * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeOuterStringSerialize'] to see the possible values for this operation + * test endpoint with 400 response http code with dataType + * + * @param \OpenAPI\Client\Model\Pet $pet Pet object that needs to be added to the store (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeWith400ResponseEndpoint'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ - public function fakeOuterStringSerializeAsync($body = null, string $contentType = self::contentTypes['fakeOuterStringSerialize'][0]) + public function fakeWith400ResponseEndpointAsync($pet, string $contentType = self::contentTypes['fakeWith400ResponseEndpoint'][0]) { - return $this->fakeOuterStringSerializeAsyncWithHttpInfo($body, $contentType) + return $this->fakeWith400ResponseEndpointAsyncWithHttpInfo($pet, $contentType) ->then( function ($response) { return $response[0]; @@ -2387,37 +2829,26 @@ function ($response) { } /** - * Operation fakeOuterStringSerializeAsyncWithHttpInfo + * Operation fakeWith400ResponseEndpointAsyncWithHttpInfo * - * @param string|null $body Input string as post body (optional) - * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeOuterStringSerialize'] to see the possible values for this operation + * test endpoint with 400 response http code with dataType + * + * @param \OpenAPI\Client\Model\Pet $pet Pet object that needs to be added to the store (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeWith400ResponseEndpoint'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ - public function fakeOuterStringSerializeAsyncWithHttpInfo($body = null, string $contentType = self::contentTypes['fakeOuterStringSerialize'][0]) + public function fakeWith400ResponseEndpointAsyncWithHttpInfo($pet, string $contentType = self::contentTypes['fakeWith400ResponseEndpoint'][0]) { - $returnType = 'string'; - $request = $this->fakeOuterStringSerializeRequest($body, $contentType); + $returnType = ''; + $request = $this->fakeWith400ResponseEndpointRequest($pet, $contentType); return $this->client ->sendAsync($request, $this->createHttpClientOption()) ->then( function ($response) use ($returnType) { - if ($returnType === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - $content = json_decode($content); - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { $response = $exception->getResponse(); @@ -2437,20 +2868,26 @@ function ($exception) { } /** - * Create request for operation 'fakeOuterStringSerialize' + * Create request for operation 'fakeWith400ResponseEndpoint' * - * @param string|null $body Input string as post body (optional) - * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeOuterStringSerialize'] to see the possible values for this operation + * @param \OpenAPI\Client\Model\Pet $pet Pet object that needs to be added to the store (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeWith400ResponseEndpoint'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Psr7\Request */ - public function fakeOuterStringSerializeRequest($body = null, string $contentType = self::contentTypes['fakeOuterStringSerialize'][0]) + public function fakeWith400ResponseEndpointRequest($pet, string $contentType = self::contentTypes['fakeWith400ResponseEndpoint'][0]) { + // verify the required parameter 'pet' is set + if ($pet === null || (is_array($pet) && count($pet) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $pet when calling fakeWith400ResponseEndpoint' + ); + } - $resourcePath = '/fake/outer/string'; + $resourcePath = '/fake/with_400_response/endpoint'; $formParams = []; $queryParams = []; $headerParams = []; @@ -2462,18 +2899,18 @@ public function fakeOuterStringSerializeRequest($body = null, string $contentTyp $headers = $this->headerSelector->selectHeaders( - ['*/*', ], + ['application/json', ], $contentType, $multipart ); // for model (json/xml) - if (isset($body)) { + if (isset($pet)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($body)); + $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($pet)); } else { - $httpBody = $body; + $httpBody = $pet; } } elseif (count($formParams) > 0) { if ($multipart) { @@ -2522,34 +2959,37 @@ public function fakeOuterStringSerializeRequest($body = null, string $contentTyp } /** - * Operation fakePropertyEnumIntegerSerialize + * Operation fakeWith4xxRangeResponseEndpoint * - * @param \OpenAPI\Client\Model\OuterObjectWithEnumProperty $outer_object_with_enum_property Input enum (int) as post body (required) - * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakePropertyEnumIntegerSerialize'] to see the possible values for this operation + * test endpoint with 400-499 range response http code with dataType + * + * @param \OpenAPI\Client\Model\Pet $pet Pet object that needs to be added to the store (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeWith4xxRangeResponseEndpoint'] to see the possible values for this operation * * @throws \OpenAPI\Client\ApiException on non-2xx response or if the response body is not in the expected format * @throws \InvalidArgumentException - * @return \OpenAPI\Client\Model\OuterObjectWithEnumProperty + * @return void */ - public function fakePropertyEnumIntegerSerialize($outer_object_with_enum_property, string $contentType = self::contentTypes['fakePropertyEnumIntegerSerialize'][0]) + public function fakeWith4xxRangeResponseEndpoint($pet, string $contentType = self::contentTypes['fakeWith4xxRangeResponseEndpoint'][0]) { - list($response) = $this->fakePropertyEnumIntegerSerializeWithHttpInfo($outer_object_with_enum_property, $contentType); - return $response; + $this->fakeWith4xxRangeResponseEndpointWithHttpInfo($pet, $contentType); } /** - * Operation fakePropertyEnumIntegerSerializeWithHttpInfo + * Operation fakeWith4xxRangeResponseEndpointWithHttpInfo * - * @param \OpenAPI\Client\Model\OuterObjectWithEnumProperty $outer_object_with_enum_property Input enum (int) as post body (required) - * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakePropertyEnumIntegerSerialize'] to see the possible values for this operation + * test endpoint with 400-499 range response http code with dataType + * + * @param \OpenAPI\Client\Model\Pet $pet Pet object that needs to be added to the store (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeWith4xxRangeResponseEndpoint'] to see the possible values for this operation * * @throws \OpenAPI\Client\ApiException on non-2xx response or if the response body is not in the expected format * @throws \InvalidArgumentException - * @return array of \OpenAPI\Client\Model\OuterObjectWithEnumProperty, HTTP status code, HTTP response headers (array of strings) + * @return array of null, HTTP status code, HTTP response headers (array of strings) */ - public function fakePropertyEnumIntegerSerializeWithHttpInfo($outer_object_with_enum_property, string $contentType = self::contentTypes['fakePropertyEnumIntegerSerialize'][0]) + public function fakeWith4xxRangeResponseEndpointWithHttpInfo($pet, string $contentType = self::contentTypes['fakeWith4xxRangeResponseEndpoint'][0]) { - $request = $this->fakePropertyEnumIntegerSerializeRequest($outer_object_with_enum_property, $contentType); + $request = $this->fakeWith4xxRangeResponseEndpointRequest($pet, $contentType); try { $options = $this->createHttpClientOption(); @@ -2574,104 +3014,40 @@ public function fakePropertyEnumIntegerSerializeWithHttpInfo($outer_object_with_ $statusCode = $response->getStatusCode(); - switch($statusCode) { - case 200: - if ('\OpenAPI\Client\Model\OuterObjectWithEnumProperty' === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('\OpenAPI\Client\Model\OuterObjectWithEnumProperty' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, '\OpenAPI\Client\Model\OuterObjectWithEnumProperty', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return [null, $statusCode, $response->getHeaders()]; + } catch (ApiException $e) { + switch ($e->getCode()) { + } - - if ($statusCode < 200 || $statusCode > 299) { - throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - (string) $request->getUri() - ), - $statusCode, - $response->getHeaders(), - (string) $response->getBody() + + if ($this->responseWithinRangeCode('4xx', $e->getCode())) { + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\OpenAPI\Client\Model\ErrorResponse', + $e->getResponseHeaders() ); + $e->setResponseObject($data); + throw $e; } - $returnType = '\OpenAPI\Client\Model\OuterObjectWithEnumProperty'; - if ($returnType === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - - } catch (ApiException $e) { - switch ($e->getCode()) { - case 200: - $data = ObjectSerializer::deserialize( - $e->getResponseBody(), - '\OpenAPI\Client\Model\OuterObjectWithEnumProperty', - $e->getResponseHeaders() - ); - $e->setResponseObject($data); - break; - } throw $e; } } /** - * Operation fakePropertyEnumIntegerSerializeAsync + * Operation fakeWith4xxRangeResponseEndpointAsync * - * @param \OpenAPI\Client\Model\OuterObjectWithEnumProperty $outer_object_with_enum_property Input enum (int) as post body (required) - * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakePropertyEnumIntegerSerialize'] to see the possible values for this operation + * test endpoint with 400-499 range response http code with dataType + * + * @param \OpenAPI\Client\Model\Pet $pet Pet object that needs to be added to the store (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeWith4xxRangeResponseEndpoint'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ - public function fakePropertyEnumIntegerSerializeAsync($outer_object_with_enum_property, string $contentType = self::contentTypes['fakePropertyEnumIntegerSerialize'][0]) + public function fakeWith4xxRangeResponseEndpointAsync($pet, string $contentType = self::contentTypes['fakeWith4xxRangeResponseEndpoint'][0]) { - return $this->fakePropertyEnumIntegerSerializeAsyncWithHttpInfo($outer_object_with_enum_property, $contentType) + return $this->fakeWith4xxRangeResponseEndpointAsyncWithHttpInfo($pet, $contentType) ->then( function ($response) { return $response[0]; @@ -2680,37 +3056,26 @@ function ($response) { } /** - * Operation fakePropertyEnumIntegerSerializeAsyncWithHttpInfo + * Operation fakeWith4xxRangeResponseEndpointAsyncWithHttpInfo * - * @param \OpenAPI\Client\Model\OuterObjectWithEnumProperty $outer_object_with_enum_property Input enum (int) as post body (required) - * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakePropertyEnumIntegerSerialize'] to see the possible values for this operation + * test endpoint with 400-499 range response http code with dataType + * + * @param \OpenAPI\Client\Model\Pet $pet Pet object that needs to be added to the store (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeWith4xxRangeResponseEndpoint'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ - public function fakePropertyEnumIntegerSerializeAsyncWithHttpInfo($outer_object_with_enum_property, string $contentType = self::contentTypes['fakePropertyEnumIntegerSerialize'][0]) + public function fakeWith4xxRangeResponseEndpointAsyncWithHttpInfo($pet, string $contentType = self::contentTypes['fakeWith4xxRangeResponseEndpoint'][0]) { - $returnType = '\OpenAPI\Client\Model\OuterObjectWithEnumProperty'; - $request = $this->fakePropertyEnumIntegerSerializeRequest($outer_object_with_enum_property, $contentType); + $returnType = ''; + $request = $this->fakeWith4xxRangeResponseEndpointRequest($pet, $contentType); return $this->client ->sendAsync($request, $this->createHttpClientOption()) ->then( function ($response) use ($returnType) { - if ($returnType === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - $content = json_decode($content); - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { $response = $exception->getResponse(); @@ -2730,26 +3095,26 @@ function ($exception) { } /** - * Create request for operation 'fakePropertyEnumIntegerSerialize' + * Create request for operation 'fakeWith4xxRangeResponseEndpoint' * - * @param \OpenAPI\Client\Model\OuterObjectWithEnumProperty $outer_object_with_enum_property Input enum (int) as post body (required) - * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakePropertyEnumIntegerSerialize'] to see the possible values for this operation + * @param \OpenAPI\Client\Model\Pet $pet Pet object that needs to be added to the store (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeWith4xxRangeResponseEndpoint'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Psr7\Request */ - public function fakePropertyEnumIntegerSerializeRequest($outer_object_with_enum_property, string $contentType = self::contentTypes['fakePropertyEnumIntegerSerialize'][0]) + public function fakeWith4xxRangeResponseEndpointRequest($pet, string $contentType = self::contentTypes['fakeWith4xxRangeResponseEndpoint'][0]) { - // verify the required parameter 'outer_object_with_enum_property' is set - if ($outer_object_with_enum_property === null || (is_array($outer_object_with_enum_property) && count($outer_object_with_enum_property) === 0)) { + // verify the required parameter 'pet' is set + if ($pet === null || (is_array($pet) && count($pet) === 0)) { throw new \InvalidArgumentException( - 'Missing the required parameter $outer_object_with_enum_property when calling fakePropertyEnumIntegerSerialize' + 'Missing the required parameter $pet when calling fakeWith4xxRangeResponseEndpoint' ); } - $resourcePath = '/fake/property/enum-int'; + $resourcePath = '/fake/with_4xx_range_response/endpoint'; $formParams = []; $queryParams = []; $headerParams = []; @@ -2761,18 +3126,18 @@ public function fakePropertyEnumIntegerSerializeRequest($outer_object_with_enum_ $headers = $this->headerSelector->selectHeaders( - ['*/*', ], + ['application/json', ], $contentType, $multipart ); // for model (json/xml) - if (isset($outer_object_with_enum_property)) { + if (isset($pet)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($outer_object_with_enum_property)); + $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($pet)); } else { - $httpBody = $outer_object_with_enum_property; + $httpBody = $pet; } } elseif (count($formParams) > 0) { if ($multipart) { @@ -2885,10 +3250,11 @@ public function getParameterNameMappingWithHttpInfo($underscore_type, $type, $ty return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + + throw $e; } } @@ -3164,10 +3530,11 @@ public function testAdditionalPropertiesReferenceWithHttpInfo($request_body, str return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + + throw $e; } } @@ -3376,10 +3743,11 @@ public function testBodyWithBinaryWithHttpInfo($body, string $contentType = self return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + + throw $e; } } @@ -3584,10 +3952,11 @@ public function testBodyWithFileSchemaWithHttpInfo($file_schema_test_class, stri return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + + throw $e; } } @@ -3794,10 +4163,11 @@ public function testBodyWithQueryParamsWithHttpInfo($query, $user, string $conte return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + + throw $e; } } @@ -4027,34 +4397,14 @@ public function testClientModelWithHttpInfo($client, string $contentType = self: switch($statusCode) { case 200: - if ('\OpenAPI\Client\Model\Client' === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('\OpenAPI\Client\Model\Client' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, '\OpenAPI\Client\Model\Client', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Client', + $response, + ); } + + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( sprintf( @@ -4068,34 +4418,10 @@ public function testClientModelWithHttpInfo($client, string $contentType = self: ); } - $returnType = '\OpenAPI\Client\Model\Client'; - if ($returnType === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Client', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -4105,8 +4431,10 @@ public function testClientModelWithHttpInfo($client, string $contentType = self: $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -4358,10 +4686,11 @@ public function testEndpointParametersWithHttpInfo($number, $double, $pattern_wi return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + + throw $e; } } @@ -4760,10 +5089,11 @@ public function testEnumParametersWithHttpInfo($enum_header_string_array = null, return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + + throw $e; } } @@ -5073,10 +5403,11 @@ public function testGroupParametersWithHttpInfo($associative_array) return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + + throw $e; } } @@ -5376,10 +5707,11 @@ public function testInlineAdditionalPropertiesWithHttpInfo($request_body, string return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + + throw $e; } } @@ -5592,10 +5924,11 @@ public function testInlineFreeformAdditionalPropertiesWithHttpInfo($test_inline_ return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + + throw $e; } } @@ -5810,10 +6143,11 @@ public function testJsonFormDataWithHttpInfo($param, $param2, string $contentTyp return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + + throw $e; } } @@ -6045,10 +6379,11 @@ public function testQueryParameterCollectionFormatWithHttpInfo($pipe, $ioutil, $ return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + + throw $e; } } @@ -6367,10 +6702,11 @@ public function testStringMapReferenceWithHttpInfo($request_body, string $conten return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + + throw $e; } } @@ -6544,4 +6880,46 @@ protected function createHttpClientOption() return $options; } + + private function handleResponseWithDataType( + string $dataType, + ResponseInterface $response + ): array { + if ($dataType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ($dataType !== 'string') { + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $response->getStatusCode(), + $response->getHeaders(), + $content + ); + } + } + } + + return [ + ObjectSerializer::deserialize($content, $dataType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + private function responseWithinRangeCode( + string $rangeCode, + int $statusCode + ): bool { + $left = (int) ($rangeCode[0].'00'); + $right = (int) ($rangeCode[0].'99'); + + return $statusCode >= $left && $statusCode <= $right; + } } diff --git a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/FakeClassnameTags123Api.php b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/FakeClassnameTags123Api.php index d2215d53885d..4f60c0adbc34 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/FakeClassnameTags123Api.php +++ b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/FakeClassnameTags123Api.php @@ -34,6 +34,7 @@ use GuzzleHttp\Psr7\MultipartStream; use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; +use Psr\Http\Message\ResponseInterface; use OpenAPI\Client\ApiException; use OpenAPI\Client\Configuration; use OpenAPI\Client\HeaderSelector; @@ -181,34 +182,14 @@ public function testClassnameWithHttpInfo($client, string $contentType = self::c switch($statusCode) { case 200: - if ('\OpenAPI\Client\Model\Client' === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('\OpenAPI\Client\Model\Client' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, '\OpenAPI\Client\Model\Client', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Client', + $response, + ); } + + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( sprintf( @@ -222,34 +203,10 @@ public function testClassnameWithHttpInfo($client, string $contentType = self::c ); } - $returnType = '\OpenAPI\Client\Model\Client'; - if ($returnType === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Client', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -259,8 +216,10 @@ public function testClassnameWithHttpInfo($client, string $contentType = self::c $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -452,4 +411,46 @@ protected function createHttpClientOption() return $options; } + + private function handleResponseWithDataType( + string $dataType, + ResponseInterface $response + ): array { + if ($dataType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ($dataType !== 'string') { + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $response->getStatusCode(), + $response->getHeaders(), + $content + ); + } + } + } + + return [ + ObjectSerializer::deserialize($content, $dataType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + private function responseWithinRangeCode( + string $rangeCode, + int $statusCode + ): bool { + $left = (int) ($rangeCode[0].'00'); + $right = (int) ($rangeCode[0].'99'); + + return $statusCode >= $left && $statusCode <= $right; + } } diff --git a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/PetApi.php b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/PetApi.php index 3f3f7049302a..2695796312f9 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/PetApi.php +++ b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/PetApi.php @@ -34,6 +34,7 @@ use GuzzleHttp\Psr7\MultipartStream; use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; +use Psr\Http\Message\ResponseInterface; use OpenAPI\Client\ApiException; use OpenAPI\Client\Configuration; use OpenAPI\Client\HeaderSelector; @@ -244,10 +245,11 @@ public function addPetWithHttpInfo($pet, ?int $hostIndex = null, array $variable return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + + throw $e; } } @@ -572,10 +574,11 @@ public function deletePetWithHttpInfo($pet_id, $api_key = null, string $contentT return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + + throw $e; } } @@ -803,34 +806,14 @@ public function findPetsByStatusWithHttpInfo($status, string $contentType = self switch($statusCode) { case 200: - if ('\OpenAPI\Client\Model\Pet[]' === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('\OpenAPI\Client\Model\Pet[]' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, '\OpenAPI\Client\Model\Pet[]', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Pet[]', + $response, + ); } + + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( sprintf( @@ -844,34 +827,10 @@ public function findPetsByStatusWithHttpInfo($status, string $contentType = self ); } - $returnType = '\OpenAPI\Client\Model\Pet[]'; - if ($returnType === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Pet[]', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -881,8 +840,10 @@ public function findPetsByStatusWithHttpInfo($status, string $contentType = self $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -1118,34 +1079,14 @@ public function findPetsByTagsWithHttpInfo($tags, string $contentType = self::co switch($statusCode) { case 200: - if ('\OpenAPI\Client\Model\Pet[]' === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('\OpenAPI\Client\Model\Pet[]' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, '\OpenAPI\Client\Model\Pet[]', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Pet[]', + $response, + ); } + + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( sprintf( @@ -1159,34 +1100,10 @@ public function findPetsByTagsWithHttpInfo($tags, string $contentType = self::co ); } - $returnType = '\OpenAPI\Client\Model\Pet[]'; - if ($returnType === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Pet[]', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -1196,8 +1113,10 @@ public function findPetsByTagsWithHttpInfo($tags, string $contentType = self::co $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -1434,34 +1353,14 @@ public function getPetByIdWithHttpInfo($pet_id, string $contentType = self::cont switch($statusCode) { case 200: - if ('\OpenAPI\Client\Model\Pet' === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('\OpenAPI\Client\Model\Pet' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, '\OpenAPI\Client\Model\Pet', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Pet', + $response, + ); } + + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( sprintf( @@ -1475,34 +1374,10 @@ public function getPetByIdWithHttpInfo($pet_id, string $contentType = self::cont ); } - $returnType = '\OpenAPI\Client\Model\Pet'; - if ($returnType === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Pet', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -1512,8 +1387,10 @@ public function getPetByIdWithHttpInfo($pet_id, string $contentType = self::cont $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -1781,10 +1658,11 @@ public function updatePetWithHttpInfo($pet, ?int $hostIndex = null, array $varia return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + + throw $e; } } @@ -2111,10 +1989,11 @@ public function updatePetWithFormWithHttpInfo($pet_id, $name = null, $status = n return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + + throw $e; } } @@ -2354,34 +2233,14 @@ public function uploadFileWithHttpInfo($pet_id, $additional_metadata = null, $fi switch($statusCode) { case 200: - if ('\OpenAPI\Client\Model\ApiResponse' === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('\OpenAPI\Client\Model\ApiResponse' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, '\OpenAPI\Client\Model\ApiResponse', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\ApiResponse', + $response, + ); } + + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( sprintf( @@ -2395,34 +2254,10 @@ public function uploadFileWithHttpInfo($pet_id, $additional_metadata = null, $fi ); } - $returnType = '\OpenAPI\Client\Model\ApiResponse'; - if ($returnType === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\ApiResponse', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -2432,8 +2267,10 @@ public function uploadFileWithHttpInfo($pet_id, $additional_metadata = null, $fi $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -2695,34 +2532,14 @@ public function uploadFileWithRequiredFileWithHttpInfo($pet_id, $required_file, switch($statusCode) { case 200: - if ('\OpenAPI\Client\Model\ApiResponse' === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('\OpenAPI\Client\Model\ApiResponse' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, '\OpenAPI\Client\Model\ApiResponse', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\ApiResponse', + $response, + ); } + + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( sprintf( @@ -2736,34 +2553,10 @@ public function uploadFileWithRequiredFileWithHttpInfo($pet_id, $required_file, ); } - $returnType = '\OpenAPI\Client\Model\ApiResponse'; - if ($returnType === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\ApiResponse', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -2773,8 +2566,10 @@ public function uploadFileWithRequiredFileWithHttpInfo($pet_id, $required_file, $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -3054,34 +2849,14 @@ public function uploadImageFullFormDataWithHttpInfo($pet_id, $name, $photo_urls, switch($statusCode) { case 200: - if ('\OpenAPI\Client\Model\ApiResponse' === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('\OpenAPI\Client\Model\ApiResponse' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, '\OpenAPI\Client\Model\ApiResponse', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\ApiResponse', + $response, + ); } + + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( sprintf( @@ -3095,34 +2870,10 @@ public function uploadImageFullFormDataWithHttpInfo($pet_id, $name, $photo_urls, ); } - $returnType = '\OpenAPI\Client\Model\ApiResponse'; - if ($returnType === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\ApiResponse', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -3132,8 +2883,10 @@ public function uploadImageFullFormDataWithHttpInfo($pet_id, $name, $photo_urls, $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -3418,4 +3171,46 @@ protected function createHttpClientOption() return $options; } + + private function handleResponseWithDataType( + string $dataType, + ResponseInterface $response + ): array { + if ($dataType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ($dataType !== 'string') { + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $response->getStatusCode(), + $response->getHeaders(), + $content + ); + } + } + } + + return [ + ObjectSerializer::deserialize($content, $dataType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + private function responseWithinRangeCode( + string $rangeCode, + int $statusCode + ): bool { + $left = (int) ($rangeCode[0].'00'); + $right = (int) ($rangeCode[0].'99'); + + return $statusCode >= $left && $statusCode <= $right; + } } diff --git a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/StoreApi.php b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/StoreApi.php index 25196cc8e363..cfa1cfd5443e 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/StoreApi.php +++ b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/StoreApi.php @@ -34,6 +34,7 @@ use GuzzleHttp\Psr7\MultipartStream; use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; +use Psr\Http\Message\ResponseInterface; use OpenAPI\Client\ApiException; use OpenAPI\Client\Configuration; use OpenAPI\Client\HeaderSelector; @@ -188,10 +189,11 @@ public function deleteOrderWithHttpInfo($order_id, string $contentType = self::c return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + + throw $e; } } @@ -405,34 +407,14 @@ public function getInventoryWithHttpInfo(string $contentType = self::contentType switch($statusCode) { case 200: - if ('array' === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('array' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, 'array', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + 'array', + $response, + ); } + + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( sprintf( @@ -446,34 +428,10 @@ public function getInventoryWithHttpInfo(string $contentType = self::contentType ); } - $returnType = 'array'; - if ($returnType === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + 'array', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -483,8 +441,10 @@ public function getInventoryWithHttpInfo(string $contentType = self::contentType $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -700,34 +660,14 @@ public function getOrderByIdWithHttpInfo($order_id, string $contentType = self:: switch($statusCode) { case 200: - if ('\OpenAPI\Client\Model\Order' === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('\OpenAPI\Client\Model\Order' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, '\OpenAPI\Client\Model\Order', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Order', + $response, + ); } + + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( sprintf( @@ -741,34 +681,10 @@ public function getOrderByIdWithHttpInfo($order_id, string $contentType = self:: ); } - $returnType = '\OpenAPI\Client\Model\Order'; - if ($returnType === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Order', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -778,8 +694,10 @@ public function getOrderByIdWithHttpInfo($order_id, string $contentType = self:: $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -1014,34 +932,14 @@ public function placeOrderWithHttpInfo($order, string $contentType = self::conte switch($statusCode) { case 200: - if ('\OpenAPI\Client\Model\Order' === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('\OpenAPI\Client\Model\Order' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, '\OpenAPI\Client\Model\Order', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Order', + $response, + ); } + + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( sprintf( @@ -1055,34 +953,10 @@ public function placeOrderWithHttpInfo($order, string $contentType = self::conte ); } - $returnType = '\OpenAPI\Client\Model\Order'; - if ($returnType === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Order', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -1092,8 +966,10 @@ public function placeOrderWithHttpInfo($order, string $contentType = self::conte $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -1280,4 +1156,46 @@ protected function createHttpClientOption() return $options; } + + private function handleResponseWithDataType( + string $dataType, + ResponseInterface $response + ): array { + if ($dataType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ($dataType !== 'string') { + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $response->getStatusCode(), + $response->getHeaders(), + $content + ); + } + } + } + + return [ + ObjectSerializer::deserialize($content, $dataType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + private function responseWithinRangeCode( + string $rangeCode, + int $statusCode + ): bool { + $left = (int) ($rangeCode[0].'00'); + $right = (int) ($rangeCode[0].'99'); + + return $statusCode >= $left && $statusCode <= $right; + } } diff --git a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/UserApi.php b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/UserApi.php index 580ea06e9c4a..f8d871661371 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/UserApi.php +++ b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/UserApi.php @@ -34,6 +34,7 @@ use GuzzleHttp\Psr7\MultipartStream; use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; +use Psr\Http\Message\ResponseInterface; use OpenAPI\Client\ApiException; use OpenAPI\Client\Configuration; use OpenAPI\Client\HeaderSelector; @@ -200,10 +201,11 @@ public function createUserWithHttpInfo($user, string $contentType = self::conten return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + + throw $e; } } @@ -416,10 +418,11 @@ public function createUsersWithArrayInputWithHttpInfo($user, string $contentType return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + + throw $e; } } @@ -632,10 +635,11 @@ public function createUsersWithListInputWithHttpInfo($user, string $contentType return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + + throw $e; } } @@ -848,10 +852,11 @@ public function deleteUserWithHttpInfo($username, string $contentType = self::co return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + + throw $e; } } @@ -1067,34 +1072,14 @@ public function getUserByNameWithHttpInfo($username, string $contentType = self: switch($statusCode) { case 200: - if ('\OpenAPI\Client\Model\User' === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('\OpenAPI\Client\Model\User' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, '\OpenAPI\Client\Model\User', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\User', + $response, + ); } + + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( sprintf( @@ -1108,34 +1093,10 @@ public function getUserByNameWithHttpInfo($username, string $contentType = self: ); } - $returnType = '\OpenAPI\Client\Model\User'; - if ($returnType === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\User', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -1145,8 +1106,10 @@ public function getUserByNameWithHttpInfo($username, string $contentType = self: $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -1377,34 +1340,14 @@ public function loginUserWithHttpInfo($username, $password, string $contentType switch($statusCode) { case 200: - if ('string' === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('string' !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, 'string', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + 'string', + $response, + ); } + + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( sprintf( @@ -1418,34 +1361,10 @@ public function loginUserWithHttpInfo($username, $password, string $contentType ); } - $returnType = 'string'; - if ($returnType === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - try { - $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new ApiException( - sprintf( - 'Error JSON decoding server response (%s)', - $request->getUri() - ), - $statusCode, - $response->getHeaders(), - $content - ); - } - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + 'string', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -1455,8 +1374,10 @@ public function loginUserWithHttpInfo($username, $password, string $contentType $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -1701,10 +1622,11 @@ public function logoutUserWithHttpInfo(string $contentType = self::contentTypes[ return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + + throw $e; } } @@ -1902,10 +1824,11 @@ public function updateUserWithHttpInfo($username, $user, string $contentType = s return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + + throw $e; } } @@ -2097,4 +2020,46 @@ protected function createHttpClientOption() return $options; } + + private function handleResponseWithDataType( + string $dataType, + ResponseInterface $response + ): array { + if ($dataType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ($dataType !== 'string') { + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $response->getStatusCode(), + $response->getHeaders(), + $content + ); + } + } + } + + return [ + ObjectSerializer::deserialize($content, $dataType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + private function responseWithinRangeCode( + string $rangeCode, + int $statusCode + ): bool { + $left = (int) ($rangeCode[0].'00'); + $right = (int) ($rangeCode[0].'99'); + + return $statusCode >= $left && $statusCode <= $right; + } } diff --git a/samples/client/petstore/php/OpenAPIClient-php/lib/Model/ErrorRangeResponse.php b/samples/client/petstore/php/OpenAPIClient-php/lib/Model/ErrorRangeResponse.php new file mode 100644 index 000000000000..8fef20574d1a --- /dev/null +++ b/samples/client/petstore/php/OpenAPIClient-php/lib/Model/ErrorRangeResponse.php @@ -0,0 +1,443 @@ + + */ +class ErrorRangeResponse implements ModelInterface, ArrayAccess, \JsonSerializable +{ + public const DISCRIMINATOR = null; + + /** + * The original name of the model. + * + * @var string + */ + protected static $openAPIModelName = 'ErrorRangeResponse'; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @var string[] + */ + protected static $openAPITypes = [ + 'response_code' => 'int', + 'error' => 'string' + ]; + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @var string[] + * @phpstan-var array + * @psalm-var array + */ + protected static $openAPIFormats = [ + 'response_code' => null, + 'error' => null + ]; + + /** + * Array of nullable properties. Used for (de)serialization + * + * @var boolean[] + */ + protected static array $openAPINullables = [ + 'response_code' => false, + 'error' => false + ]; + + /** + * If a nullable field gets set to null, insert it here + * + * @var boolean[] + */ + protected array $openAPINullablesSetToNull = []; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPITypes() + { + return self::$openAPITypes; + } + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPIFormats() + { + return self::$openAPIFormats; + } + + /** + * Array of nullable properties + * + * @return array + */ + protected static function openAPINullables(): array + { + return self::$openAPINullables; + } + + /** + * Array of nullable field names deliberately set to null + * + * @return boolean[] + */ + private function getOpenAPINullablesSetToNull(): array + { + return $this->openAPINullablesSetToNull; + } + + /** + * Setter - Array of nullable field names deliberately set to null + * + * @param boolean[] $openAPINullablesSetToNull + */ + private function setOpenAPINullablesSetToNull(array $openAPINullablesSetToNull): void + { + $this->openAPINullablesSetToNull = $openAPINullablesSetToNull; + } + + /** + * Checks if a property is nullable + * + * @param string $property + * @return bool + */ + public static function isNullable(string $property): bool + { + return self::openAPINullables()[$property] ?? false; + } + + /** + * Checks if a nullable property is set to null. + * + * @param string $property + * @return bool + */ + public function isNullableSetToNull(string $property): bool + { + return in_array($property, $this->getOpenAPINullablesSetToNull(), true); + } + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @var string[] + */ + protected static $attributeMap = [ + 'response_code' => 'response_code', + 'error' => 'error' + ]; + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @var string[] + */ + protected static $setters = [ + 'response_code' => 'setResponseCode', + 'error' => 'setError' + ]; + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @var string[] + */ + protected static $getters = [ + 'response_code' => 'getResponseCode', + 'error' => 'getError' + ]; + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @return array + */ + public static function attributeMap() + { + return self::$attributeMap; + } + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @return array + */ + public static function setters() + { + return self::$setters; + } + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @return array + */ + public static function getters() + { + return self::$getters; + } + + /** + * The original name of the model. + * + * @return string + */ + public function getModelName() + { + return self::$openAPIModelName; + } + + + /** + * Associative array for storing property values + * + * @var mixed[] + */ + protected $container = []; + + /** + * Constructor + * + * @param mixed[]|null $data Associated array of property values + * initializing the model + */ + public function __construct(?array $data = null) + { + $this->setIfExists('response_code', $data ?? [], null); + $this->setIfExists('error', $data ?? [], null); + } + + /** + * Sets $this->container[$variableName] to the given data or to the given default Value; if $variableName + * is nullable and its value is set to null in the $fields array, then mark it as "set to null" in the + * $this->openAPINullablesSetToNull array + * + * @param string $variableName + * @param array $fields + * @param mixed $defaultValue + */ + private function setIfExists(string $variableName, array $fields, $defaultValue): void + { + if (self::isNullable($variableName) && array_key_exists($variableName, $fields) && is_null($fields[$variableName])) { + $this->openAPINullablesSetToNull[] = $variableName; + } + + $this->container[$variableName] = $fields[$variableName] ?? $defaultValue; + } + + /** + * Show all the invalid properties with reasons. + * + * @return array invalid properties with reasons + */ + public function listInvalidProperties() + { + $invalidProperties = []; + + return $invalidProperties; + } + + /** + * Validate all the properties in the model + * return true if all passed + * + * @return bool True if all properties are valid + */ + public function valid() + { + return count($this->listInvalidProperties()) === 0; + } + + + /** + * Gets response_code + * + * @return int|null + */ + public function getResponseCode() + { + return $this->container['response_code']; + } + + /** + * Sets response_code + * + * @param int|null $response_code response_code + * + * @return self + */ + public function setResponseCode($response_code) + { + if (is_null($response_code)) { + throw new \InvalidArgumentException('non-nullable response_code cannot be null'); + } + $this->container['response_code'] = $response_code; + + return $this; + } + + /** + * Gets error + * + * @return string|null + */ + public function getError() + { + return $this->container['error']; + } + + /** + * Sets error + * + * @param string|null $error error + * + * @return self + */ + public function setError($error) + { + if (is_null($error)) { + throw new \InvalidArgumentException('non-nullable error cannot be null'); + } + $this->container['error'] = $error; + + return $this; + } + /** + * Returns true if offset exists. False otherwise. + * + * @param integer $offset Offset + * + * @return boolean + */ + public function offsetExists($offset): bool + { + return isset($this->container[$offset]); + } + + /** + * Gets offset. + * + * @param integer $offset Offset + * + * @return mixed|null + */ + #[\ReturnTypeWillChange] + public function offsetGet($offset) + { + return $this->container[$offset] ?? null; + } + + /** + * Sets value based on offset. + * + * @param int|null $offset Offset + * @param mixed $value Value to be set + * + * @return void + */ + public function offsetSet($offset, $value): void + { + if (is_null($offset)) { + $this->container[] = $value; + } else { + $this->container[$offset] = $value; + } + } + + /** + * Unsets offset. + * + * @param integer $offset Offset + * + * @return void + */ + public function offsetUnset($offset): void + { + unset($this->container[$offset]); + } + + /** + * Serializes the object to a value that can be serialized natively by json_encode(). + * @link https://www.php.net/manual/en/jsonserializable.jsonserialize.php + * + * @return mixed Returns data which can be serialized by json_encode(), which is a value + * of any type other than a resource. + */ + #[\ReturnTypeWillChange] + public function jsonSerialize() + { + return ObjectSerializer::sanitizeForSerialization($this); + } + + /** + * Gets the string presentation of the object + * + * @return string + */ + public function __toString() + { + return json_encode( + ObjectSerializer::sanitizeForSerialization($this), + JSON_PRETTY_PRINT + ); + } + + /** + * Gets a header-safe presentation of the object + * + * @return string + */ + public function toHeaderValue() + { + return json_encode(ObjectSerializer::sanitizeForSerialization($this)); + } +} + + diff --git a/samples/client/petstore/php/OpenAPIClient-php/lib/Model/ErrorResponse.php b/samples/client/petstore/php/OpenAPIClient-php/lib/Model/ErrorResponse.php new file mode 100644 index 000000000000..1e9c3940003f --- /dev/null +++ b/samples/client/petstore/php/OpenAPIClient-php/lib/Model/ErrorResponse.php @@ -0,0 +1,443 @@ + + */ +class ErrorResponse implements ModelInterface, ArrayAccess, \JsonSerializable +{ + public const DISCRIMINATOR = null; + + /** + * The original name of the model. + * + * @var string + */ + protected static $openAPIModelName = 'ErrorResponse'; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @var string[] + */ + protected static $openAPITypes = [ + 'response_code' => 'int', + 'error' => 'string' + ]; + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @var string[] + * @phpstan-var array + * @psalm-var array + */ + protected static $openAPIFormats = [ + 'response_code' => null, + 'error' => null + ]; + + /** + * Array of nullable properties. Used for (de)serialization + * + * @var boolean[] + */ + protected static array $openAPINullables = [ + 'response_code' => false, + 'error' => false + ]; + + /** + * If a nullable field gets set to null, insert it here + * + * @var boolean[] + */ + protected array $openAPINullablesSetToNull = []; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPITypes() + { + return self::$openAPITypes; + } + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPIFormats() + { + return self::$openAPIFormats; + } + + /** + * Array of nullable properties + * + * @return array + */ + protected static function openAPINullables(): array + { + return self::$openAPINullables; + } + + /** + * Array of nullable field names deliberately set to null + * + * @return boolean[] + */ + private function getOpenAPINullablesSetToNull(): array + { + return $this->openAPINullablesSetToNull; + } + + /** + * Setter - Array of nullable field names deliberately set to null + * + * @param boolean[] $openAPINullablesSetToNull + */ + private function setOpenAPINullablesSetToNull(array $openAPINullablesSetToNull): void + { + $this->openAPINullablesSetToNull = $openAPINullablesSetToNull; + } + + /** + * Checks if a property is nullable + * + * @param string $property + * @return bool + */ + public static function isNullable(string $property): bool + { + return self::openAPINullables()[$property] ?? false; + } + + /** + * Checks if a nullable property is set to null. + * + * @param string $property + * @return bool + */ + public function isNullableSetToNull(string $property): bool + { + return in_array($property, $this->getOpenAPINullablesSetToNull(), true); + } + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @var string[] + */ + protected static $attributeMap = [ + 'response_code' => 'response_code', + 'error' => 'error' + ]; + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @var string[] + */ + protected static $setters = [ + 'response_code' => 'setResponseCode', + 'error' => 'setError' + ]; + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @var string[] + */ + protected static $getters = [ + 'response_code' => 'getResponseCode', + 'error' => 'getError' + ]; + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @return array + */ + public static function attributeMap() + { + return self::$attributeMap; + } + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @return array + */ + public static function setters() + { + return self::$setters; + } + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @return array + */ + public static function getters() + { + return self::$getters; + } + + /** + * The original name of the model. + * + * @return string + */ + public function getModelName() + { + return self::$openAPIModelName; + } + + + /** + * Associative array for storing property values + * + * @var mixed[] + */ + protected $container = []; + + /** + * Constructor + * + * @param mixed[]|null $data Associated array of property values + * initializing the model + */ + public function __construct(?array $data = null) + { + $this->setIfExists('response_code', $data ?? [], null); + $this->setIfExists('error', $data ?? [], null); + } + + /** + * Sets $this->container[$variableName] to the given data or to the given default Value; if $variableName + * is nullable and its value is set to null in the $fields array, then mark it as "set to null" in the + * $this->openAPINullablesSetToNull array + * + * @param string $variableName + * @param array $fields + * @param mixed $defaultValue + */ + private function setIfExists(string $variableName, array $fields, $defaultValue): void + { + if (self::isNullable($variableName) && array_key_exists($variableName, $fields) && is_null($fields[$variableName])) { + $this->openAPINullablesSetToNull[] = $variableName; + } + + $this->container[$variableName] = $fields[$variableName] ?? $defaultValue; + } + + /** + * Show all the invalid properties with reasons. + * + * @return array invalid properties with reasons + */ + public function listInvalidProperties() + { + $invalidProperties = []; + + return $invalidProperties; + } + + /** + * Validate all the properties in the model + * return true if all passed + * + * @return bool True if all properties are valid + */ + public function valid() + { + return count($this->listInvalidProperties()) === 0; + } + + + /** + * Gets response_code + * + * @return int|null + */ + public function getResponseCode() + { + return $this->container['response_code']; + } + + /** + * Sets response_code + * + * @param int|null $response_code response_code + * + * @return self + */ + public function setResponseCode($response_code) + { + if (is_null($response_code)) { + throw new \InvalidArgumentException('non-nullable response_code cannot be null'); + } + $this->container['response_code'] = $response_code; + + return $this; + } + + /** + * Gets error + * + * @return string|null + */ + public function getError() + { + return $this->container['error']; + } + + /** + * Sets error + * + * @param string|null $error error + * + * @return self + */ + public function setError($error) + { + if (is_null($error)) { + throw new \InvalidArgumentException('non-nullable error cannot be null'); + } + $this->container['error'] = $error; + + return $this; + } + /** + * Returns true if offset exists. False otherwise. + * + * @param integer $offset Offset + * + * @return boolean + */ + public function offsetExists($offset): bool + { + return isset($this->container[$offset]); + } + + /** + * Gets offset. + * + * @param integer $offset Offset + * + * @return mixed|null + */ + #[\ReturnTypeWillChange] + public function offsetGet($offset) + { + return $this->container[$offset] ?? null; + } + + /** + * Sets value based on offset. + * + * @param int|null $offset Offset + * @param mixed $value Value to be set + * + * @return void + */ + public function offsetSet($offset, $value): void + { + if (is_null($offset)) { + $this->container[] = $value; + } else { + $this->container[$offset] = $value; + } + } + + /** + * Unsets offset. + * + * @param integer $offset Offset + * + * @return void + */ + public function offsetUnset($offset): void + { + unset($this->container[$offset]); + } + + /** + * Serializes the object to a value that can be serialized natively by json_encode(). + * @link https://www.php.net/manual/en/jsonserializable.jsonserialize.php + * + * @return mixed Returns data which can be serialized by json_encode(), which is a value + * of any type other than a resource. + */ + #[\ReturnTypeWillChange] + public function jsonSerialize() + { + return ObjectSerializer::sanitizeForSerialization($this); + } + + /** + * Gets the string presentation of the object + * + * @return string + */ + public function __toString() + { + return json_encode( + ObjectSerializer::sanitizeForSerialization($this), + JSON_PRETTY_PRINT + ); + } + + /** + * Gets a header-safe presentation of the object + * + * @return string + */ + public function toHeaderValue() + { + return json_encode(ObjectSerializer::sanitizeForSerialization($this)); + } +} + + diff --git a/samples/client/petstore/php/OpenAPIClient-php/test/Model/ErrorRangeResponseTest.php b/samples/client/petstore/php/OpenAPIClient-php/test/Model/ErrorRangeResponseTest.php new file mode 100644 index 000000000000..515ef826aad7 --- /dev/null +++ b/samples/client/petstore/php/OpenAPIClient-php/test/Model/ErrorRangeResponseTest.php @@ -0,0 +1,99 @@ +fakeWith400And4xxRangeResponseEndpoint($pet); +} catch (Exception $e) { + echo 'Exception when calling FakeApi->fakeWith400And4xxRangeResponseEndpoint: ', $e->getMessage(), PHP_EOL; +} +``` + +### Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **pet** | [**\OpenAPI\Client\Model\Pet**](../Model/Pet.md)| Pet object that needs to be added to the store | + +### Return type + +void (empty response body) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: `application/json`, `application/xml` +- **Accept**: `application/json` + +[[Back to top]](#) [[Back to API list]](../../README.md#endpoints) +[[Back to Model list]](../../README.md#models) +[[Back to README]](../../README.md) + +## `fakeWith400ResponseEndpoint()` + +```php +fakeWith400ResponseEndpoint($pet) +``` + +test endpoint with 400 response http code with dataType + +### Example + +```php +fakeWith400ResponseEndpoint($pet); +} catch (Exception $e) { + echo 'Exception when calling FakeApi->fakeWith400ResponseEndpoint: ', $e->getMessage(), PHP_EOL; +} +``` + +### Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **pet** | [**\OpenAPI\Client\Model\Pet**](../Model/Pet.md)| Pet object that needs to be added to the store | + +### Return type + +void (empty response body) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: `application/json`, `application/xml` +- **Accept**: `application/json` + +[[Back to top]](#) [[Back to API list]](../../README.md#endpoints) +[[Back to Model list]](../../README.md#models) +[[Back to README]](../../README.md) + +## `fakeWith4xxRangeResponseEndpoint()` + +```php +fakeWith4xxRangeResponseEndpoint($pet) +``` + +test endpoint with 400-499 range response http code with dataType + +### Example + +```php +fakeWith4xxRangeResponseEndpoint($pet); +} catch (Exception $e) { + echo 'Exception when calling FakeApi->fakeWith4xxRangeResponseEndpoint: ', $e->getMessage(), PHP_EOL; +} +``` + +### Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **pet** | [**\OpenAPI\Client\Model\Pet**](../Model/Pet.md)| Pet object that needs to be added to the store | + +### Return type + +void (empty response body) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: `application/json`, `application/xml` +- **Accept**: `application/json` + +[[Back to top]](#) [[Back to API list]](../../README.md#endpoints) +[[Back to Model list]](../../README.md#models) +[[Back to README]](../../README.md) + ## `getParameterNameMapping()` ```php diff --git a/samples/client/petstore/php/psr-18/docs/Model/ErrorRangeResponse.md b/samples/client/petstore/php/psr-18/docs/Model/ErrorRangeResponse.md new file mode 100644 index 000000000000..25a8fe846fba --- /dev/null +++ b/samples/client/petstore/php/psr-18/docs/Model/ErrorRangeResponse.md @@ -0,0 +1,10 @@ +# # ErrorRangeResponse + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**response_code** | **int** | | [optional] +**error** | **string** | | [optional] + +[[Back to Model list]](../../README.md#models) [[Back to API list]](../../README.md#endpoints) [[Back to README]](../../README.md) diff --git a/samples/client/petstore/php/psr-18/docs/Model/ErrorResponse.md b/samples/client/petstore/php/psr-18/docs/Model/ErrorResponse.md new file mode 100644 index 000000000000..a6db5fe293ef --- /dev/null +++ b/samples/client/petstore/php/psr-18/docs/Model/ErrorResponse.md @@ -0,0 +1,10 @@ +# # ErrorResponse + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**response_code** | **int** | | [optional] +**error** | **string** | | [optional] + +[[Back to Model list]](../../README.md#models) [[Back to API list]](../../README.md#endpoints) [[Back to README]](../../README.md) diff --git a/samples/client/petstore/php/psr-18/lib/Api/AnotherFakeApi.php b/samples/client/petstore/php/psr-18/lib/Api/AnotherFakeApi.php index 7e5e1afbfc2c..5c7c585e6291 100644 --- a/samples/client/petstore/php/psr-18/lib/Api/AnotherFakeApi.php +++ b/samples/client/petstore/php/psr-18/lib/Api/AnotherFakeApi.php @@ -48,6 +48,7 @@ use Psr\Http\Client\ClientInterface; use Psr\Http\Message\RequestFactoryInterface; use Psr\Http\Message\RequestInterface; +use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\StreamFactoryInterface; use Psr\Http\Message\UriFactoryInterface; use Psr\Http\Message\UriInterface; @@ -230,34 +231,34 @@ public function call123TestSpecialTagsWithHttpInfo($client) $statusCode = $response->getStatusCode(); + switch($statusCode) { case 200: - if ('\OpenAPI\Client\Model\Client' === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - } - - return [ - ObjectSerializer::deserialize($content, '\OpenAPI\Client\Model\Client', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Client', + $response, + ); } - $returnType = '\OpenAPI\Client\Model\Client'; - if ($returnType === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - } + - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Client', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -267,8 +268,10 @@ public function call123TestSpecialTagsWithHttpInfo($client) $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -489,4 +492,46 @@ private function createUri( return $uri; } + + private function handleResponseWithDataType( + string $dataType, + ResponseInterface $response + ): array { + if ($dataType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ($dataType !== 'string') { + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $response->getStatusCode(), + $response->getHeaders(), + $content + ); + } + } + } + + return [ + ObjectSerializer::deserialize($content, $dataType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + private function responseWithinRangeCode( + string $rangeCode, + int $statusCode + ): bool { + $left = (int) ($rangeCode[0].'00'); + $right = (int) ($rangeCode[0].'99'); + + return $statusCode >= $left && $statusCode <= $right; + } } diff --git a/samples/client/petstore/php/psr-18/lib/Api/DefaultApi.php b/samples/client/petstore/php/psr-18/lib/Api/DefaultApi.php index 005d6ffbafed..c441ff6fc025 100644 --- a/samples/client/petstore/php/psr-18/lib/Api/DefaultApi.php +++ b/samples/client/petstore/php/psr-18/lib/Api/DefaultApi.php @@ -48,6 +48,7 @@ use Psr\Http\Client\ClientInterface; use Psr\Http\Message\RequestFactoryInterface; use Psr\Http\Message\RequestInterface; +use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\StreamFactoryInterface; use Psr\Http\Message\UriFactoryInterface; use Psr\Http\Message\UriInterface; @@ -224,34 +225,34 @@ public function fooGetWithHttpInfo() $statusCode = $response->getStatusCode(); + switch($statusCode) { default: - if ('\OpenAPI\Client\Model\FooGetDefaultResponse' === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - } - - return [ - ObjectSerializer::deserialize($content, '\OpenAPI\Client\Model\FooGetDefaultResponse', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\FooGetDefaultResponse', + $response, + ); } - $returnType = '\OpenAPI\Client\Model\FooGetDefaultResponse'; - if ($returnType === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - } + - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\FooGetDefaultResponse', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { default: @@ -261,8 +262,10 @@ public function fooGetWithHttpInfo() $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -464,4 +467,46 @@ private function createUri( return $uri; } + + private function handleResponseWithDataType( + string $dataType, + ResponseInterface $response + ): array { + if ($dataType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ($dataType !== 'string') { + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $response->getStatusCode(), + $response->getHeaders(), + $content + ); + } + } + } + + return [ + ObjectSerializer::deserialize($content, $dataType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + private function responseWithinRangeCode( + string $rangeCode, + int $statusCode + ): bool { + $left = (int) ($rangeCode[0].'00'); + $right = (int) ($rangeCode[0].'99'); + + return $statusCode >= $left && $statusCode <= $right; + } } diff --git a/samples/client/petstore/php/psr-18/lib/Api/FakeApi.php b/samples/client/petstore/php/psr-18/lib/Api/FakeApi.php index 360a3b16f4c8..28c40f6b8d33 100644 --- a/samples/client/petstore/php/psr-18/lib/Api/FakeApi.php +++ b/samples/client/petstore/php/psr-18/lib/Api/FakeApi.php @@ -48,6 +48,7 @@ use Psr\Http\Client\ClientInterface; use Psr\Http\Message\RequestFactoryInterface; use Psr\Http\Message\RequestInterface; +use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\StreamFactoryInterface; use Psr\Http\Message\UriFactoryInterface; use Psr\Http\Message\UriInterface; @@ -224,34 +225,34 @@ public function fakeBigDecimalMapWithHttpInfo() $statusCode = $response->getStatusCode(); + switch($statusCode) { case 200: - if ('\OpenAPI\Client\Model\FakeBigDecimalMap200Response' === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - } - - return [ - ObjectSerializer::deserialize($content, '\OpenAPI\Client\Model\FakeBigDecimalMap200Response', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\FakeBigDecimalMap200Response', + $response, + ); } - $returnType = '\OpenAPI\Client\Model\FakeBigDecimalMap200Response'; - if ($returnType === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - } + - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\FakeBigDecimalMap200Response', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -261,8 +262,10 @@ public function fakeBigDecimalMapWithHttpInfo() $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -461,34 +464,34 @@ public function fakeEnumEndpointWithHttpInfo($enum_class, $enum_class_array, $en $statusCode = $response->getStatusCode(); + switch($statusCode) { case 200: - if ('\OpenAPI\Client\Model\EnumClass' === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - } - - return [ - ObjectSerializer::deserialize($content, '\OpenAPI\Client\Model\EnumClass', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\EnumClass', + $response, + ); } - $returnType = '\OpenAPI\Client\Model\EnumClass'; - if ($returnType === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - } + - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\EnumClass', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -498,8 +501,10 @@ public function fakeEnumEndpointWithHttpInfo($enum_class, $enum_class_array, $en $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -756,34 +761,34 @@ public function fakeHealthGetWithHttpInfo() $statusCode = $response->getStatusCode(); + switch($statusCode) { case 200: - if ('\OpenAPI\Client\Model\HealthCheckResult' === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - } - - return [ - ObjectSerializer::deserialize($content, '\OpenAPI\Client\Model\HealthCheckResult', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\HealthCheckResult', + $response, + ); } - $returnType = '\OpenAPI\Client\Model\HealthCheckResult'; - if ($returnType === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - } + - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\HealthCheckResult', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -793,8 +798,10 @@ public function fakeHealthGetWithHttpInfo() $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -996,11 +1003,13 @@ public function fakeHttpSignatureTestWithHttpInfo($pet, $query_1 = null, $header $statusCode = $response->getStatusCode(); - return [null, $statusCode, $response->getHeaders()]; + return [null, $statusCode, $response->getHeaders()]; } catch (ApiException $e) { switch ($e->getCode()) { } + + throw $e; } } @@ -1221,34 +1230,34 @@ public function fakeOuterBooleanSerializeWithHttpInfo($body = null) $statusCode = $response->getStatusCode(); + switch($statusCode) { case 200: - if ('bool' === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - } - - return [ - ObjectSerializer::deserialize($content, 'bool', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + 'bool', + $response, + ); } - $returnType = 'bool'; - if ($returnType === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - } + - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + return $this->handleResponseWithDataType( + 'bool', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -1258,8 +1267,10 @@ public function fakeOuterBooleanSerializeWithHttpInfo($body = null) $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -1459,34 +1470,34 @@ public function fakeOuterCompositeSerializeWithHttpInfo($outer_composite = null) $statusCode = $response->getStatusCode(); + switch($statusCode) { case 200: - if ('\OpenAPI\Client\Model\OuterComposite' === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - } - - return [ - ObjectSerializer::deserialize($content, '\OpenAPI\Client\Model\OuterComposite', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\OuterComposite', + $response, + ); } - $returnType = '\OpenAPI\Client\Model\OuterComposite'; - if ($returnType === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - } + - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\OuterComposite', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -1496,8 +1507,10 @@ public function fakeOuterCompositeSerializeWithHttpInfo($outer_composite = null) $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -1697,34 +1710,34 @@ public function fakeOuterNumberSerializeWithHttpInfo($body = null) $statusCode = $response->getStatusCode(); + switch($statusCode) { case 200: - if ('float' === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - } - - return [ - ObjectSerializer::deserialize($content, 'float', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + 'float', + $response, + ); } - $returnType = 'float'; - if ($returnType === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - } + - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + return $this->handleResponseWithDataType( + 'float', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -1734,8 +1747,10 @@ public function fakeOuterNumberSerializeWithHttpInfo($body = null) $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -1832,11 +1847,724 @@ public function fakeOuterNumberSerializeRequest($body = null) ); // for model (json/xml) - if (isset($body)) { + if (isset($body)) { + if ($this->headerSelector->isJsonMime($headers['Content-Type'])) { + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($body)); + } else { + $httpBody = $body; + } + } elseif (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; + foreach ($formParamValueItems as $formParamValueItem) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValueItem + ]; + } + } + // for HTTP post (form) + $httpBody = new MultipartStream($multipartContents); + + } elseif ($this->headerSelector->isJsonMime($headers['Content-Type'])) { + $httpBody = json_encode($formParams); + + } else { + // for HTTP post (form) + $httpBody = ObjectSerializer::buildQuery($formParams); + } + } + + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $operationHost = $this->config->getHost(); + + $uri = $this->createUri($operationHost, $resourcePath, $queryParams); + + return $this->createRequest('POST', $uri, $headers, $httpBody); + } + + /** + * Operation fakeOuterStringSerialize + * + * @param string $body Input string as post body (optional) + * + * @throws \OpenAPI\Client\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return string + */ + public function fakeOuterStringSerialize($body = null) + { + list($response) = $this->fakeOuterStringSerializeWithHttpInfo($body); + return $response; + } + + /** + * Operation fakeOuterStringSerializeWithHttpInfo + * + * @param string $body Input string as post body (optional) + * + * @throws \OpenAPI\Client\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of string, HTTP status code, HTTP response headers (array of strings) + */ + public function fakeOuterStringSerializeWithHttpInfo($body = null) + { + $request = $this->fakeOuterStringSerializeRequest($body); + + try { + try { + $response = $this->httpClient->sendRequest($request); + } catch (HttpException $e) { + $response = $e->getResponse(); + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $response->getStatusCode(), + (string) $request->getUri() + ), + $request, + $response, + $e + ); + } catch (ClientExceptionInterface $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $request, + null, + $e + ); + } + + $statusCode = $response->getStatusCode(); + + + switch($statusCode) { + case 200: + return $this->handleResponseWithDataType( + 'string', + $response, + ); + } + + + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + + return $this->handleResponseWithDataType( + 'string', + $response, + ); + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + 'string', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + throw $e; + } + + + throw $e; + } + } + + /** + * Operation fakeOuterStringSerializeAsync + * + * @param string $body Input string as post body (optional) + * + * @throws \InvalidArgumentException + * @return Promise + */ + public function fakeOuterStringSerializeAsync($body = null) + { + return $this->fakeOuterStringSerializeAsyncWithHttpInfo($body) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation fakeOuterStringSerializeAsyncWithHttpInfo + * + * @param string $body Input string as post body (optional) + * + * @throws \InvalidArgumentException + * @return Promise + */ + public function fakeOuterStringSerializeAsyncWithHttpInfo($body = null) + { + $returnType = 'string'; + $request = $this->fakeOuterStringSerializeRequest($body); + + return $this->httpAsyncClient->sendAsyncRequest($request) + ->then( + function ($response) use ($returnType) { + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, + function (HttpException $exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $exception->getRequest()->getUri() + ), + $exception->getRequest(), + $exception->getResponse(), + $exception + ); + } + ); + } + + /** + * Create request for operation 'fakeOuterStringSerialize' + * + * @param string $body Input string as post body (optional) + * + * @throws \InvalidArgumentException + * @return RequestInterface + */ + public function fakeOuterStringSerializeRequest($body = null) + { + + $resourcePath = '/fake/outer/string'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = null; + $multipart = false; + + + + + + $headers = $this->headerSelector->selectHeaders( + ['*/*'], + 'application/json', + $multipart + ); + + // for model (json/xml) + if (isset($body)) { + if ($this->headerSelector->isJsonMime($headers['Content-Type'])) { + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($body)); + } else { + $httpBody = $body; + } + } elseif (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; + foreach ($formParamValueItems as $formParamValueItem) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValueItem + ]; + } + } + // for HTTP post (form) + $httpBody = new MultipartStream($multipartContents); + + } elseif ($this->headerSelector->isJsonMime($headers['Content-Type'])) { + $httpBody = json_encode($formParams); + + } else { + // for HTTP post (form) + $httpBody = ObjectSerializer::buildQuery($formParams); + } + } + + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $operationHost = $this->config->getHost(); + + $uri = $this->createUri($operationHost, $resourcePath, $queryParams); + + return $this->createRequest('POST', $uri, $headers, $httpBody); + } + + /** + * Operation fakePropertyEnumIntegerSerialize + * + * @param \OpenAPI\Client\Model\OuterObjectWithEnumProperty $outer_object_with_enum_property Input enum (int) as post body (required) + * + * @throws \OpenAPI\Client\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return \OpenAPI\Client\Model\OuterObjectWithEnumProperty + */ + public function fakePropertyEnumIntegerSerialize($outer_object_with_enum_property) + { + list($response) = $this->fakePropertyEnumIntegerSerializeWithHttpInfo($outer_object_with_enum_property); + return $response; + } + + /** + * Operation fakePropertyEnumIntegerSerializeWithHttpInfo + * + * @param \OpenAPI\Client\Model\OuterObjectWithEnumProperty $outer_object_with_enum_property Input enum (int) as post body (required) + * + * @throws \OpenAPI\Client\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of \OpenAPI\Client\Model\OuterObjectWithEnumProperty, HTTP status code, HTTP response headers (array of strings) + */ + public function fakePropertyEnumIntegerSerializeWithHttpInfo($outer_object_with_enum_property) + { + $request = $this->fakePropertyEnumIntegerSerializeRequest($outer_object_with_enum_property); + + try { + try { + $response = $this->httpClient->sendRequest($request); + } catch (HttpException $e) { + $response = $e->getResponse(); + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $response->getStatusCode(), + (string) $request->getUri() + ), + $request, + $response, + $e + ); + } catch (ClientExceptionInterface $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $request, + null, + $e + ); + } + + $statusCode = $response->getStatusCode(); + + + switch($statusCode) { + case 200: + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\OuterObjectWithEnumProperty', + $response, + ); + } + + + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\OuterObjectWithEnumProperty', + $response, + ); + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\OpenAPI\Client\Model\OuterObjectWithEnumProperty', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + throw $e; + } + + + throw $e; + } + } + + /** + * Operation fakePropertyEnumIntegerSerializeAsync + * + * @param \OpenAPI\Client\Model\OuterObjectWithEnumProperty $outer_object_with_enum_property Input enum (int) as post body (required) + * + * @throws \InvalidArgumentException + * @return Promise + */ + public function fakePropertyEnumIntegerSerializeAsync($outer_object_with_enum_property) + { + return $this->fakePropertyEnumIntegerSerializeAsyncWithHttpInfo($outer_object_with_enum_property) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation fakePropertyEnumIntegerSerializeAsyncWithHttpInfo + * + * @param \OpenAPI\Client\Model\OuterObjectWithEnumProperty $outer_object_with_enum_property Input enum (int) as post body (required) + * + * @throws \InvalidArgumentException + * @return Promise + */ + public function fakePropertyEnumIntegerSerializeAsyncWithHttpInfo($outer_object_with_enum_property) + { + $returnType = '\OpenAPI\Client\Model\OuterObjectWithEnumProperty'; + $request = $this->fakePropertyEnumIntegerSerializeRequest($outer_object_with_enum_property); + + return $this->httpAsyncClient->sendAsyncRequest($request) + ->then( + function ($response) use ($returnType) { + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, + function (HttpException $exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $exception->getRequest()->getUri() + ), + $exception->getRequest(), + $exception->getResponse(), + $exception + ); + } + ); + } + + /** + * Create request for operation 'fakePropertyEnumIntegerSerialize' + * + * @param \OpenAPI\Client\Model\OuterObjectWithEnumProperty $outer_object_with_enum_property Input enum (int) as post body (required) + * + * @throws \InvalidArgumentException + * @return RequestInterface + */ + public function fakePropertyEnumIntegerSerializeRequest($outer_object_with_enum_property) + { + // verify the required parameter 'outer_object_with_enum_property' is set + if ($outer_object_with_enum_property === null || (is_array($outer_object_with_enum_property) && count($outer_object_with_enum_property) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $outer_object_with_enum_property when calling fakePropertyEnumIntegerSerialize' + ); + } + + $resourcePath = '/fake/property/enum-int'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = null; + $multipart = false; + + + + + + $headers = $this->headerSelector->selectHeaders( + ['*/*'], + 'application/json', + $multipart + ); + + // for model (json/xml) + if (isset($outer_object_with_enum_property)) { + if ($this->headerSelector->isJsonMime($headers['Content-Type'])) { + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($outer_object_with_enum_property)); + } else { + $httpBody = $outer_object_with_enum_property; + } + } elseif (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; + foreach ($formParamValueItems as $formParamValueItem) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValueItem + ]; + } + } + // for HTTP post (form) + $httpBody = new MultipartStream($multipartContents); + + } elseif ($this->headerSelector->isJsonMime($headers['Content-Type'])) { + $httpBody = json_encode($formParams); + + } else { + // for HTTP post (form) + $httpBody = ObjectSerializer::buildQuery($formParams); + } + } + + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $operationHost = $this->config->getHost(); + + $uri = $this->createUri($operationHost, $resourcePath, $queryParams); + + return $this->createRequest('POST', $uri, $headers, $httpBody); + } + + /** + * Operation fakeWith400And4xxRangeResponseEndpoint + * + * test endpoint with 400 and 400-499 range response http code with dataType + * + * @param \OpenAPI\Client\Model\Pet $pet Pet object that needs to be added to the store (required) + * + * @throws \OpenAPI\Client\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return void + */ + public function fakeWith400And4xxRangeResponseEndpoint($pet) + { + $this->fakeWith400And4xxRangeResponseEndpointWithHttpInfo($pet); + } + + /** + * Operation fakeWith400And4xxRangeResponseEndpointWithHttpInfo + * + * test endpoint with 400 and 400-499 range response http code with dataType + * + * @param \OpenAPI\Client\Model\Pet $pet Pet object that needs to be added to the store (required) + * + * @throws \OpenAPI\Client\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of null, HTTP status code, HTTP response headers (array of strings) + */ + public function fakeWith400And4xxRangeResponseEndpointWithHttpInfo($pet) + { + $request = $this->fakeWith400And4xxRangeResponseEndpointRequest($pet); + + try { + try { + $response = $this->httpClient->sendRequest($request); + } catch (HttpException $e) { + $response = $e->getResponse(); + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $response->getStatusCode(), + (string) $request->getUri() + ), + $request, + $response, + $e + ); + } catch (ClientExceptionInterface $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $request, + null, + $e + ); + } + + $statusCode = $response->getStatusCode(); + + + return [null, $statusCode, $response->getHeaders()]; + } catch (ApiException $e) { + switch ($e->getCode()) { + case 400: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\OpenAPI\Client\Model\ErrorResponse', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + throw $e; + + } + + if ($this->responseWithinRangeCode('4xx', $e->getCode())) { + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\OpenAPI\Client\Model\ErrorResponse', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + throw $e; + } + + throw $e; + } + } + + /** + * Operation fakeWith400And4xxRangeResponseEndpointAsync + * + * test endpoint with 400 and 400-499 range response http code with dataType + * + * @param \OpenAPI\Client\Model\Pet $pet Pet object that needs to be added to the store (required) + * + * @throws \InvalidArgumentException + * @return Promise + */ + public function fakeWith400And4xxRangeResponseEndpointAsync($pet) + { + return $this->fakeWith400And4xxRangeResponseEndpointAsyncWithHttpInfo($pet) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation fakeWith400And4xxRangeResponseEndpointAsyncWithHttpInfo + * + * test endpoint with 400 and 400-499 range response http code with dataType + * + * @param \OpenAPI\Client\Model\Pet $pet Pet object that needs to be added to the store (required) + * + * @throws \InvalidArgumentException + * @return Promise + */ + public function fakeWith400And4xxRangeResponseEndpointAsyncWithHttpInfo($pet) + { + $returnType = ''; + $request = $this->fakeWith400And4xxRangeResponseEndpointRequest($pet); + + return $this->httpAsyncClient->sendAsyncRequest($request) + ->then( + function ($response) use ($returnType) { + return [null, $response->getStatusCode(), $response->getHeaders()]; + }, + function (HttpException $exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $exception->getRequest()->getUri() + ), + $exception->getRequest(), + $exception->getResponse(), + $exception + ); + } + ); + } + + /** + * Create request for operation 'fakeWith400And4xxRangeResponseEndpoint' + * + * @param \OpenAPI\Client\Model\Pet $pet Pet object that needs to be added to the store (required) + * + * @throws \InvalidArgumentException + * @return RequestInterface + */ + public function fakeWith400And4xxRangeResponseEndpointRequest($pet) + { + // verify the required parameter 'pet' is set + if ($pet === null || (is_array($pet) && count($pet) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $pet when calling fakeWith400And4xxRangeResponseEndpoint' + ); + } + + $resourcePath = '/fake/with_400_and_4xx_range_response/endpoint'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = null; + $multipart = false; + + + + + + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + 'application/jsonapplication/xml', + $multipart + ); + + // for model (json/xml) + if (isset($pet)) { if ($this->headerSelector->isJsonMime($headers['Content-Type'])) { - $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($body)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($pet)); } else { - $httpBody = $body; + $httpBody = $pet; } } elseif (count($formParams) > 0) { if ($multipart) { @@ -1882,32 +2610,35 @@ public function fakeOuterNumberSerializeRequest($body = null) } /** - * Operation fakeOuterStringSerialize + * Operation fakeWith400ResponseEndpoint * - * @param string $body Input string as post body (optional) + * test endpoint with 400 response http code with dataType + * + * @param \OpenAPI\Client\Model\Pet $pet Pet object that needs to be added to the store (required) * * @throws \OpenAPI\Client\ApiException on non-2xx response * @throws \InvalidArgumentException - * @return string + * @return void */ - public function fakeOuterStringSerialize($body = null) + public function fakeWith400ResponseEndpoint($pet) { - list($response) = $this->fakeOuterStringSerializeWithHttpInfo($body); - return $response; + $this->fakeWith400ResponseEndpointWithHttpInfo($pet); } /** - * Operation fakeOuterStringSerializeWithHttpInfo + * Operation fakeWith400ResponseEndpointWithHttpInfo * - * @param string $body Input string as post body (optional) + * test endpoint with 400 response http code with dataType + * + * @param \OpenAPI\Client\Model\Pet $pet Pet object that needs to be added to the store (required) * * @throws \OpenAPI\Client\ApiException on non-2xx response * @throws \InvalidArgumentException - * @return array of string, HTTP status code, HTTP response headers (array of strings) + * @return array of null, HTTP status code, HTTP response headers (array of strings) */ - public function fakeOuterStringSerializeWithHttpInfo($body = null) + public function fakeWith400ResponseEndpointWithHttpInfo($pet) { - $request = $this->fakeOuterStringSerializeRequest($body); + $request = $this->fakeWith400ResponseEndpointRequest($pet); try { try { @@ -1935,60 +2666,38 @@ public function fakeOuterStringSerializeWithHttpInfo($body = null) $statusCode = $response->getStatusCode(); - switch($statusCode) { - case 200: - if ('string' === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - } - - return [ - ObjectSerializer::deserialize($content, 'string', []), - $response->getStatusCode(), - $response->getHeaders() - ]; - } - - $returnType = 'string'; - if ($returnType === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return [null, $statusCode, $response->getHeaders()]; } catch (ApiException $e) { switch ($e->getCode()) { - case 200: + case 400: $data = ObjectSerializer::deserialize( $e->getResponseBody(), - 'string', + '\OpenAPI\Client\Model\ErrorResponse', $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } /** - * Operation fakeOuterStringSerializeAsync + * Operation fakeWith400ResponseEndpointAsync * - * @param string $body Input string as post body (optional) + * test endpoint with 400 response http code with dataType + * + * @param \OpenAPI\Client\Model\Pet $pet Pet object that needs to be added to the store (required) * * @throws \InvalidArgumentException * @return Promise */ - public function fakeOuterStringSerializeAsync($body = null) + public function fakeWith400ResponseEndpointAsync($pet) { - return $this->fakeOuterStringSerializeAsyncWithHttpInfo($body) + return $this->fakeWith400ResponseEndpointAsyncWithHttpInfo($pet) ->then( function ($response) { return $response[0]; @@ -1997,32 +2706,24 @@ function ($response) { } /** - * Operation fakeOuterStringSerializeAsyncWithHttpInfo + * Operation fakeWith400ResponseEndpointAsyncWithHttpInfo * - * @param string $body Input string as post body (optional) + * test endpoint with 400 response http code with dataType + * + * @param \OpenAPI\Client\Model\Pet $pet Pet object that needs to be added to the store (required) * * @throws \InvalidArgumentException * @return Promise */ - public function fakeOuterStringSerializeAsyncWithHttpInfo($body = null) + public function fakeWith400ResponseEndpointAsyncWithHttpInfo($pet) { - $returnType = 'string'; - $request = $this->fakeOuterStringSerializeRequest($body); + $returnType = ''; + $request = $this->fakeWith400ResponseEndpointRequest($pet); return $this->httpAsyncClient->sendAsyncRequest($request) ->then( function ($response) use ($returnType) { - if ($returnType === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return [null, $response->getStatusCode(), $response->getHeaders()]; }, function (HttpException $exception) { $response = $exception->getResponse(); @@ -2042,17 +2743,23 @@ function (HttpException $exception) { } /** - * Create request for operation 'fakeOuterStringSerialize' + * Create request for operation 'fakeWith400ResponseEndpoint' * - * @param string $body Input string as post body (optional) + * @param \OpenAPI\Client\Model\Pet $pet Pet object that needs to be added to the store (required) * * @throws \InvalidArgumentException * @return RequestInterface */ - public function fakeOuterStringSerializeRequest($body = null) + public function fakeWith400ResponseEndpointRequest($pet) { + // verify the required parameter 'pet' is set + if ($pet === null || (is_array($pet) && count($pet) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $pet when calling fakeWith400ResponseEndpoint' + ); + } - $resourcePath = '/fake/outer/string'; + $resourcePath = '/fake/with_400_response/endpoint'; $formParams = []; $queryParams = []; $headerParams = []; @@ -2064,17 +2771,17 @@ public function fakeOuterStringSerializeRequest($body = null) $headers = $this->headerSelector->selectHeaders( - ['*/*'], - 'application/json', + ['application/json'], + 'application/jsonapplication/xml', $multipart ); // for model (json/xml) - if (isset($body)) { + if (isset($pet)) { if ($this->headerSelector->isJsonMime($headers['Content-Type'])) { - $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($body)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($pet)); } else { - $httpBody = $body; + $httpBody = $pet; } } elseif (count($formParams) > 0) { if ($multipart) { @@ -2120,32 +2827,35 @@ public function fakeOuterStringSerializeRequest($body = null) } /** - * Operation fakePropertyEnumIntegerSerialize + * Operation fakeWith4xxRangeResponseEndpoint * - * @param \OpenAPI\Client\Model\OuterObjectWithEnumProperty $outer_object_with_enum_property Input enum (int) as post body (required) + * test endpoint with 400-499 range response http code with dataType + * + * @param \OpenAPI\Client\Model\Pet $pet Pet object that needs to be added to the store (required) * * @throws \OpenAPI\Client\ApiException on non-2xx response * @throws \InvalidArgumentException - * @return \OpenAPI\Client\Model\OuterObjectWithEnumProperty + * @return void */ - public function fakePropertyEnumIntegerSerialize($outer_object_with_enum_property) + public function fakeWith4xxRangeResponseEndpoint($pet) { - list($response) = $this->fakePropertyEnumIntegerSerializeWithHttpInfo($outer_object_with_enum_property); - return $response; + $this->fakeWith4xxRangeResponseEndpointWithHttpInfo($pet); } /** - * Operation fakePropertyEnumIntegerSerializeWithHttpInfo + * Operation fakeWith4xxRangeResponseEndpointWithHttpInfo * - * @param \OpenAPI\Client\Model\OuterObjectWithEnumProperty $outer_object_with_enum_property Input enum (int) as post body (required) + * test endpoint with 400-499 range response http code with dataType + * + * @param \OpenAPI\Client\Model\Pet $pet Pet object that needs to be added to the store (required) * * @throws \OpenAPI\Client\ApiException on non-2xx response * @throws \InvalidArgumentException - * @return array of \OpenAPI\Client\Model\OuterObjectWithEnumProperty, HTTP status code, HTTP response headers (array of strings) + * @return array of null, HTTP status code, HTTP response headers (array of strings) */ - public function fakePropertyEnumIntegerSerializeWithHttpInfo($outer_object_with_enum_property) + public function fakeWith4xxRangeResponseEndpointWithHttpInfo($pet) { - $request = $this->fakePropertyEnumIntegerSerializeRequest($outer_object_with_enum_property); + $request = $this->fakeWith4xxRangeResponseEndpointRequest($pet); try { try { @@ -2173,60 +2883,40 @@ public function fakePropertyEnumIntegerSerializeWithHttpInfo($outer_object_with_ $statusCode = $response->getStatusCode(); - switch($statusCode) { - case 200: - if ('\OpenAPI\Client\Model\OuterObjectWithEnumProperty' === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - } - - return [ - ObjectSerializer::deserialize($content, '\OpenAPI\Client\Model\OuterObjectWithEnumProperty', []), - $response->getStatusCode(), - $response->getHeaders() - ]; - } - - $returnType = '\OpenAPI\Client\Model\OuterObjectWithEnumProperty'; - if ($returnType === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return [null, $statusCode, $response->getHeaders()]; } catch (ApiException $e) { switch ($e->getCode()) { - case 200: - $data = ObjectSerializer::deserialize( - $e->getResponseBody(), - '\OpenAPI\Client\Model\OuterObjectWithEnumProperty', - $e->getResponseHeaders() - ); - $e->setResponseObject($data); - break; + + } + + if ($this->responseWithinRangeCode('4xx', $e->getCode())) { + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\OpenAPI\Client\Model\ErrorResponse', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + throw $e; } + throw $e; } } /** - * Operation fakePropertyEnumIntegerSerializeAsync + * Operation fakeWith4xxRangeResponseEndpointAsync * - * @param \OpenAPI\Client\Model\OuterObjectWithEnumProperty $outer_object_with_enum_property Input enum (int) as post body (required) + * test endpoint with 400-499 range response http code with dataType + * + * @param \OpenAPI\Client\Model\Pet $pet Pet object that needs to be added to the store (required) * * @throws \InvalidArgumentException * @return Promise */ - public function fakePropertyEnumIntegerSerializeAsync($outer_object_with_enum_property) + public function fakeWith4xxRangeResponseEndpointAsync($pet) { - return $this->fakePropertyEnumIntegerSerializeAsyncWithHttpInfo($outer_object_with_enum_property) + return $this->fakeWith4xxRangeResponseEndpointAsyncWithHttpInfo($pet) ->then( function ($response) { return $response[0]; @@ -2235,32 +2925,24 @@ function ($response) { } /** - * Operation fakePropertyEnumIntegerSerializeAsyncWithHttpInfo + * Operation fakeWith4xxRangeResponseEndpointAsyncWithHttpInfo * - * @param \OpenAPI\Client\Model\OuterObjectWithEnumProperty $outer_object_with_enum_property Input enum (int) as post body (required) + * test endpoint with 400-499 range response http code with dataType + * + * @param \OpenAPI\Client\Model\Pet $pet Pet object that needs to be added to the store (required) * * @throws \InvalidArgumentException * @return Promise */ - public function fakePropertyEnumIntegerSerializeAsyncWithHttpInfo($outer_object_with_enum_property) + public function fakeWith4xxRangeResponseEndpointAsyncWithHttpInfo($pet) { - $returnType = '\OpenAPI\Client\Model\OuterObjectWithEnumProperty'; - $request = $this->fakePropertyEnumIntegerSerializeRequest($outer_object_with_enum_property); + $returnType = ''; + $request = $this->fakeWith4xxRangeResponseEndpointRequest($pet); return $this->httpAsyncClient->sendAsyncRequest($request) ->then( function ($response) use ($returnType) { - if ($returnType === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return [null, $response->getStatusCode(), $response->getHeaders()]; }, function (HttpException $exception) { $response = $exception->getResponse(); @@ -2280,23 +2962,23 @@ function (HttpException $exception) { } /** - * Create request for operation 'fakePropertyEnumIntegerSerialize' + * Create request for operation 'fakeWith4xxRangeResponseEndpoint' * - * @param \OpenAPI\Client\Model\OuterObjectWithEnumProperty $outer_object_with_enum_property Input enum (int) as post body (required) + * @param \OpenAPI\Client\Model\Pet $pet Pet object that needs to be added to the store (required) * * @throws \InvalidArgumentException * @return RequestInterface */ - public function fakePropertyEnumIntegerSerializeRequest($outer_object_with_enum_property) + public function fakeWith4xxRangeResponseEndpointRequest($pet) { - // verify the required parameter 'outer_object_with_enum_property' is set - if ($outer_object_with_enum_property === null || (is_array($outer_object_with_enum_property) && count($outer_object_with_enum_property) === 0)) { + // verify the required parameter 'pet' is set + if ($pet === null || (is_array($pet) && count($pet) === 0)) { throw new \InvalidArgumentException( - 'Missing the required parameter $outer_object_with_enum_property when calling fakePropertyEnumIntegerSerialize' + 'Missing the required parameter $pet when calling fakeWith4xxRangeResponseEndpoint' ); } - $resourcePath = '/fake/property/enum-int'; + $resourcePath = '/fake/with_4xx_range_response/endpoint'; $formParams = []; $queryParams = []; $headerParams = []; @@ -2308,17 +2990,17 @@ public function fakePropertyEnumIntegerSerializeRequest($outer_object_with_enum_ $headers = $this->headerSelector->selectHeaders( - ['*/*'], - 'application/json', + ['application/json'], + 'application/jsonapplication/xml', $multipart ); // for model (json/xml) - if (isset($outer_object_with_enum_property)) { + if (isset($pet)) { if ($this->headerSelector->isJsonMime($headers['Content-Type'])) { - $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($outer_object_with_enum_property)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($pet)); } else { - $httpBody = $outer_object_with_enum_property; + $httpBody = $pet; } } elseif (count($formParams) > 0) { if ($multipart) { @@ -2428,11 +3110,13 @@ public function getParameterNameMappingWithHttpInfo($underscore_type, $type, $ty $statusCode = $response->getStatusCode(); - return [null, $statusCode, $response->getHeaders()]; + return [null, $statusCode, $response->getHeaders()]; } catch (ApiException $e) { switch ($e->getCode()) { } + + throw $e; } } @@ -2699,11 +3383,13 @@ public function testAdditionalPropertiesReferenceWithHttpInfo($request_body) $statusCode = $response->getStatusCode(); - return [null, $statusCode, $response->getHeaders()]; + return [null, $statusCode, $response->getHeaders()]; } catch (ApiException $e) { switch ($e->getCode()) { } + + throw $e; } } @@ -2902,11 +3588,13 @@ public function testBodyWithBinaryWithHttpInfo($body) $statusCode = $response->getStatusCode(); - return [null, $statusCode, $response->getHeaders()]; + return [null, $statusCode, $response->getHeaders()]; } catch (ApiException $e) { switch ($e->getCode()) { } + + throw $e; } } @@ -3101,11 +3789,13 @@ public function testBodyWithFileSchemaWithHttpInfo($file_schema_test_class) $statusCode = $response->getStatusCode(); - return [null, $statusCode, $response->getHeaders()]; + return [null, $statusCode, $response->getHeaders()]; } catch (ApiException $e) { switch ($e->getCode()) { } + + throw $e; } } @@ -3302,11 +3992,13 @@ public function testBodyWithQueryParamsWithHttpInfo($query, $user) $statusCode = $response->getStatusCode(); - return [null, $statusCode, $response->getHeaders()]; + return [null, $statusCode, $response->getHeaders()]; } catch (ApiException $e) { switch ($e->getCode()) { } + + throw $e; } } @@ -3526,34 +4218,34 @@ public function testClientModelWithHttpInfo($client) $statusCode = $response->getStatusCode(); + switch($statusCode) { case 200: - if ('\OpenAPI\Client\Model\Client' === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - } - - return [ - ObjectSerializer::deserialize($content, '\OpenAPI\Client\Model\Client', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Client', + $response, + ); } - $returnType = '\OpenAPI\Client\Model\Client'; - if ($returnType === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - } + - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Client', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -3563,8 +4255,10 @@ public function testClientModelWithHttpInfo($client) $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -3803,11 +4497,13 @@ public function testEndpointParametersWithHttpInfo($number, $double, $pattern_wi $statusCode = $response->getStatusCode(); - return [null, $statusCode, $response->getHeaders()]; + return [null, $statusCode, $response->getHeaders()]; } catch (ApiException $e) { switch ($e->getCode()) { } + + throw $e; } } @@ -4192,11 +4888,13 @@ public function testEnumParametersWithHttpInfo($enum_header_string_array = null, $statusCode = $response->getStatusCode(); - return [null, $statusCode, $response->getHeaders()]; + return [null, $statusCode, $response->getHeaders()]; } catch (ApiException $e) { switch ($e->getCode()) { } + + throw $e; } } @@ -4499,11 +5197,13 @@ public function testGroupParametersWithHttpInfo($associative_array) $statusCode = $response->getStatusCode(); - return [null, $statusCode, $response->getHeaders()]; + return [null, $statusCode, $response->getHeaders()]; } catch (ApiException $e) { switch ($e->getCode()) { } + + throw $e; } } @@ -4797,11 +5497,13 @@ public function testInlineAdditionalPropertiesWithHttpInfo($request_body) $statusCode = $response->getStatusCode(); - return [null, $statusCode, $response->getHeaders()]; + return [null, $statusCode, $response->getHeaders()]; } catch (ApiException $e) { switch ($e->getCode()) { } + + throw $e; } } @@ -5004,11 +5706,13 @@ public function testInlineFreeformAdditionalPropertiesWithHttpInfo($test_inline_ $statusCode = $response->getStatusCode(); - return [null, $statusCode, $response->getHeaders()]; + return [null, $statusCode, $response->getHeaders()]; } catch (ApiException $e) { switch ($e->getCode()) { } + + throw $e; } } @@ -5213,11 +5917,13 @@ public function testJsonFormDataWithHttpInfo($param, $param2) $statusCode = $response->getStatusCode(); - return [null, $statusCode, $response->getHeaders()]; + return [null, $statusCode, $response->getHeaders()]; } catch (ApiException $e) { switch ($e->getCode()) { } + + throw $e; } } @@ -5439,11 +6145,13 @@ public function testQueryParameterCollectionFormatWithHttpInfo($pipe, $ioutil, $ $statusCode = $response->getStatusCode(); - return [null, $statusCode, $response->getHeaders()]; + return [null, $statusCode, $response->getHeaders()]; } catch (ApiException $e) { switch ($e->getCode()) { } + + throw $e; } } @@ -5745,11 +6453,13 @@ public function testStringMapReferenceWithHttpInfo($request_body) $statusCode = $response->getStatusCode(); - return [null, $statusCode, $response->getHeaders()]; + return [null, $statusCode, $response->getHeaders()]; } catch (ApiException $e) { switch ($e->getCode()) { } + + throw $e; } } @@ -5960,4 +6670,46 @@ private function createUri( return $uri; } + + private function handleResponseWithDataType( + string $dataType, + ResponseInterface $response + ): array { + if ($dataType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ($dataType !== 'string') { + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $response->getStatusCode(), + $response->getHeaders(), + $content + ); + } + } + } + + return [ + ObjectSerializer::deserialize($content, $dataType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + private function responseWithinRangeCode( + string $rangeCode, + int $statusCode + ): bool { + $left = (int) ($rangeCode[0].'00'); + $right = (int) ($rangeCode[0].'99'); + + return $statusCode >= $left && $statusCode <= $right; + } } diff --git a/samples/client/petstore/php/psr-18/lib/Api/FakeClassnameTags123Api.php b/samples/client/petstore/php/psr-18/lib/Api/FakeClassnameTags123Api.php index a0acbf6a5326..dd94589699cb 100644 --- a/samples/client/petstore/php/psr-18/lib/Api/FakeClassnameTags123Api.php +++ b/samples/client/petstore/php/psr-18/lib/Api/FakeClassnameTags123Api.php @@ -48,6 +48,7 @@ use Psr\Http\Client\ClientInterface; use Psr\Http\Message\RequestFactoryInterface; use Psr\Http\Message\RequestInterface; +use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\StreamFactoryInterface; use Psr\Http\Message\UriFactoryInterface; use Psr\Http\Message\UriInterface; @@ -230,34 +231,34 @@ public function testClassnameWithHttpInfo($client) $statusCode = $response->getStatusCode(); + switch($statusCode) { case 200: - if ('\OpenAPI\Client\Model\Client' === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - } - - return [ - ObjectSerializer::deserialize($content, '\OpenAPI\Client\Model\Client', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Client', + $response, + ); } - $returnType = '\OpenAPI\Client\Model\Client'; - if ($returnType === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - } + - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Client', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -267,8 +268,10 @@ public function testClassnameWithHttpInfo($client) $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -494,4 +497,46 @@ private function createUri( return $uri; } + + private function handleResponseWithDataType( + string $dataType, + ResponseInterface $response + ): array { + if ($dataType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ($dataType !== 'string') { + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $response->getStatusCode(), + $response->getHeaders(), + $content + ); + } + } + } + + return [ + ObjectSerializer::deserialize($content, $dataType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + private function responseWithinRangeCode( + string $rangeCode, + int $statusCode + ): bool { + $left = (int) ($rangeCode[0].'00'); + $right = (int) ($rangeCode[0].'99'); + + return $statusCode >= $left && $statusCode <= $right; + } } diff --git a/samples/client/petstore/php/psr-18/lib/Api/PetApi.php b/samples/client/petstore/php/psr-18/lib/Api/PetApi.php index 29b35822dba0..201e7a971c99 100644 --- a/samples/client/petstore/php/psr-18/lib/Api/PetApi.php +++ b/samples/client/petstore/php/psr-18/lib/Api/PetApi.php @@ -48,6 +48,7 @@ use Psr\Http\Client\ClientInterface; use Psr\Http\Message\RequestFactoryInterface; use Psr\Http\Message\RequestInterface; +use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\StreamFactoryInterface; use Psr\Http\Message\UriFactoryInterface; use Psr\Http\Message\UriInterface; @@ -239,11 +240,13 @@ public function addPetWithHttpInfo($pet) $statusCode = $response->getStatusCode(); - return [null, $statusCode, $response->getHeaders()]; + return [null, $statusCode, $response->getHeaders()]; } catch (ApiException $e) { switch ($e->getCode()) { } + + throw $e; } } @@ -471,11 +474,13 @@ public function deletePetWithHttpInfo($pet_id, $api_key = null) $statusCode = $response->getStatusCode(); - return [null, $statusCode, $response->getHeaders()]; + return [null, $statusCode, $response->getHeaders()]; } catch (ApiException $e) { switch ($e->getCode()) { } + + throw $e; } } @@ -692,34 +697,34 @@ public function findPetsByStatusWithHttpInfo($status) $statusCode = $response->getStatusCode(); + switch($statusCode) { case 200: - if ('\OpenAPI\Client\Model\Pet[]' === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - } - - return [ - ObjectSerializer::deserialize($content, '\OpenAPI\Client\Model\Pet[]', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Pet[]', + $response, + ); } - $returnType = '\OpenAPI\Client\Model\Pet[]'; - if ($returnType === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - } + - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Pet[]', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -729,8 +734,10 @@ public function findPetsByStatusWithHttpInfo($status) $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -949,34 +956,34 @@ public function findPetsByTagsWithHttpInfo($tags) $statusCode = $response->getStatusCode(); + switch($statusCode) { case 200: - if ('\OpenAPI\Client\Model\Pet[]' === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - } - - return [ - ObjectSerializer::deserialize($content, '\OpenAPI\Client\Model\Pet[]', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Pet[]', + $response, + ); } - $returnType = '\OpenAPI\Client\Model\Pet[]'; - if ($returnType === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - } + - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Pet[]', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -986,8 +993,10 @@ public function findPetsByTagsWithHttpInfo($tags) $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -1207,34 +1216,34 @@ public function getPetByIdWithHttpInfo($pet_id) $statusCode = $response->getStatusCode(); + switch($statusCode) { case 200: - if ('\OpenAPI\Client\Model\Pet' === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - } - - return [ - ObjectSerializer::deserialize($content, '\OpenAPI\Client\Model\Pet', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Pet', + $response, + ); } - $returnType = '\OpenAPI\Client\Model\Pet'; - if ($returnType === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - } + - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Pet', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -1244,8 +1253,10 @@ public function getPetByIdWithHttpInfo($pet_id) $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -1475,11 +1486,13 @@ public function updatePetWithHttpInfo($pet) $statusCode = $response->getStatusCode(); - return [null, $statusCode, $response->getHeaders()]; + return [null, $statusCode, $response->getHeaders()]; } catch (ApiException $e) { switch ($e->getCode()) { } + + throw $e; } } @@ -1709,11 +1722,13 @@ public function updatePetWithFormWithHttpInfo($pet_id, $name = null, $status = n $statusCode = $response->getStatusCode(); - return [null, $statusCode, $response->getHeaders()]; + return [null, $statusCode, $response->getHeaders()]; } catch (ApiException $e) { switch ($e->getCode()) { } + + throw $e; } } @@ -1941,34 +1956,34 @@ public function uploadFileWithHttpInfo($pet_id, $additional_metadata = null, $fi $statusCode = $response->getStatusCode(); + switch($statusCode) { case 200: - if ('\OpenAPI\Client\Model\ApiResponse' === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - } - - return [ - ObjectSerializer::deserialize($content, '\OpenAPI\Client\Model\ApiResponse', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\ApiResponse', + $response, + ); } - $returnType = '\OpenAPI\Client\Model\ApiResponse'; - if ($returnType === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - } + - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\ApiResponse', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -1978,8 +1993,10 @@ public function uploadFileWithHttpInfo($pet_id, $additional_metadata = null, $fi $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -2225,34 +2242,34 @@ public function uploadFileWithRequiredFileWithHttpInfo($pet_id, $required_file, $statusCode = $response->getStatusCode(); + switch($statusCode) { case 200: - if ('\OpenAPI\Client\Model\ApiResponse' === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - } - - return [ - ObjectSerializer::deserialize($content, '\OpenAPI\Client\Model\ApiResponse', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\ApiResponse', + $response, + ); } - $returnType = '\OpenAPI\Client\Model\ApiResponse'; - if ($returnType === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - } + - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\ApiResponse', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -2262,8 +2279,10 @@ public function uploadFileWithRequiredFileWithHttpInfo($pet_id, $required_file, $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -2527,34 +2546,34 @@ public function uploadImageFullFormDataWithHttpInfo($pet_id, $name, $photo_urls, $statusCode = $response->getStatusCode(); + switch($statusCode) { case 200: - if ('\OpenAPI\Client\Model\ApiResponse' === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - } - - return [ - ObjectSerializer::deserialize($content, '\OpenAPI\Client\Model\ApiResponse', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\ApiResponse', + $response, + ); } - $returnType = '\OpenAPI\Client\Model\ApiResponse'; - if ($returnType === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - } + - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\ApiResponse', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -2564,8 +2583,10 @@ public function uploadImageFullFormDataWithHttpInfo($pet_id, $name, $photo_urls, $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -2877,4 +2898,46 @@ private function createUri( return $uri; } + + private function handleResponseWithDataType( + string $dataType, + ResponseInterface $response + ): array { + if ($dataType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ($dataType !== 'string') { + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $response->getStatusCode(), + $response->getHeaders(), + $content + ); + } + } + } + + return [ + ObjectSerializer::deserialize($content, $dataType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + private function responseWithinRangeCode( + string $rangeCode, + int $statusCode + ): bool { + $left = (int) ($rangeCode[0].'00'); + $right = (int) ($rangeCode[0].'99'); + + return $statusCode >= $left && $statusCode <= $right; + } } diff --git a/samples/client/petstore/php/psr-18/lib/Api/StoreApi.php b/samples/client/petstore/php/psr-18/lib/Api/StoreApi.php index 9f41d0568f2d..5ef769dbdd1f 100644 --- a/samples/client/petstore/php/psr-18/lib/Api/StoreApi.php +++ b/samples/client/petstore/php/psr-18/lib/Api/StoreApi.php @@ -48,6 +48,7 @@ use Psr\Http\Client\ClientInterface; use Psr\Http\Message\RequestFactoryInterface; use Psr\Http\Message\RequestInterface; +use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\StreamFactoryInterface; use Psr\Http\Message\UriFactoryInterface; use Psr\Http\Message\UriInterface; @@ -229,11 +230,13 @@ public function deleteOrderWithHttpInfo($order_id) $statusCode = $response->getStatusCode(); - return [null, $statusCode, $response->getHeaders()]; + return [null, $statusCode, $response->getHeaders()]; } catch (ApiException $e) { switch ($e->getCode()) { } + + throw $e; } } @@ -437,34 +440,34 @@ public function getInventoryWithHttpInfo() $statusCode = $response->getStatusCode(); + switch($statusCode) { case 200: - if ('array' === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - } - - return [ - ObjectSerializer::deserialize($content, 'array', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + 'array', + $response, + ); } - $returnType = 'array'; - if ($returnType === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - } + - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + return $this->handleResponseWithDataType( + 'array', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -474,8 +477,10 @@ public function getInventoryWithHttpInfo() $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -679,34 +684,34 @@ public function getOrderByIdWithHttpInfo($order_id) $statusCode = $response->getStatusCode(); + switch($statusCode) { case 200: - if ('\OpenAPI\Client\Model\Order' === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - } - - return [ - ObjectSerializer::deserialize($content, '\OpenAPI\Client\Model\Order', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Order', + $response, + ); } - $returnType = '\OpenAPI\Client\Model\Order'; - if ($returnType === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - } + - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Order', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -716,8 +721,10 @@ public function getOrderByIdWithHttpInfo($order_id) $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -940,34 +947,34 @@ public function placeOrderWithHttpInfo($order) $statusCode = $response->getStatusCode(); + switch($statusCode) { case 200: - if ('\OpenAPI\Client\Model\Order' === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - } - - return [ - ObjectSerializer::deserialize($content, '\OpenAPI\Client\Model\Order', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Order', + $response, + ); } - $returnType = '\OpenAPI\Client\Model\Order'; - if ($returnType === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - } + - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Order', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -977,8 +984,10 @@ public function placeOrderWithHttpInfo($order) $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -1199,4 +1208,46 @@ private function createUri( return $uri; } + + private function handleResponseWithDataType( + string $dataType, + ResponseInterface $response + ): array { + if ($dataType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ($dataType !== 'string') { + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $response->getStatusCode(), + $response->getHeaders(), + $content + ); + } + } + } + + return [ + ObjectSerializer::deserialize($content, $dataType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + private function responseWithinRangeCode( + string $rangeCode, + int $statusCode + ): bool { + $left = (int) ($rangeCode[0].'00'); + $right = (int) ($rangeCode[0].'99'); + + return $statusCode >= $left && $statusCode <= $right; + } } diff --git a/samples/client/petstore/php/psr-18/lib/Api/UserApi.php b/samples/client/petstore/php/psr-18/lib/Api/UserApi.php index 7e001b952306..02b267cadc49 100644 --- a/samples/client/petstore/php/psr-18/lib/Api/UserApi.php +++ b/samples/client/petstore/php/psr-18/lib/Api/UserApi.php @@ -48,6 +48,7 @@ use Psr\Http\Client\ClientInterface; use Psr\Http\Message\RequestFactoryInterface; use Psr\Http\Message\RequestInterface; +use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\StreamFactoryInterface; use Psr\Http\Message\UriFactoryInterface; use Psr\Http\Message\UriInterface; @@ -229,11 +230,13 @@ public function createUserWithHttpInfo($user) $statusCode = $response->getStatusCode(); - return [null, $statusCode, $response->getHeaders()]; + return [null, $statusCode, $response->getHeaders()]; } catch (ApiException $e) { switch ($e->getCode()) { } + + throw $e; } } @@ -436,11 +439,13 @@ public function createUsersWithArrayInputWithHttpInfo($user) $statusCode = $response->getStatusCode(); - return [null, $statusCode, $response->getHeaders()]; + return [null, $statusCode, $response->getHeaders()]; } catch (ApiException $e) { switch ($e->getCode()) { } + + throw $e; } } @@ -643,11 +648,13 @@ public function createUsersWithListInputWithHttpInfo($user) $statusCode = $response->getStatusCode(); - return [null, $statusCode, $response->getHeaders()]; + return [null, $statusCode, $response->getHeaders()]; } catch (ApiException $e) { switch ($e->getCode()) { } + + throw $e; } } @@ -850,11 +857,13 @@ public function deleteUserWithHttpInfo($username) $statusCode = $response->getStatusCode(); - return [null, $statusCode, $response->getHeaders()]; + return [null, $statusCode, $response->getHeaders()]; } catch (ApiException $e) { switch ($e->getCode()) { } + + throw $e; } } @@ -1060,34 +1069,34 @@ public function getUserByNameWithHttpInfo($username) $statusCode = $response->getStatusCode(); + switch($statusCode) { case 200: - if ('\OpenAPI\Client\Model\User' === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - } - - return [ - ObjectSerializer::deserialize($content, '\OpenAPI\Client\Model\User', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\User', + $response, + ); } - $returnType = '\OpenAPI\Client\Model\User'; - if ($returnType === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - } + - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\User', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -1097,8 +1106,10 @@ public function getUserByNameWithHttpInfo($username) $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -1316,34 +1327,34 @@ public function loginUserWithHttpInfo($username, $password) $statusCode = $response->getStatusCode(); + switch($statusCode) { case 200: - if ('string' === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - } - - return [ - ObjectSerializer::deserialize($content, 'string', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + return $this->handleResponseWithDataType( + 'string', + $response, + ); } - $returnType = 'string'; - if ($returnType === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - } + - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + return $this->handleResponseWithDataType( + 'string', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -1353,8 +1364,10 @@ public function loginUserWithHttpInfo($username, $password) $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -1590,11 +1603,13 @@ public function logoutUserWithHttpInfo() $statusCode = $response->getStatusCode(); - return [null, $statusCode, $response->getHeaders()]; + return [null, $statusCode, $response->getHeaders()]; } catch (ApiException $e) { switch ($e->getCode()) { } + + throw $e; } } @@ -1784,11 +1799,13 @@ public function updateUserWithHttpInfo($username, $user) $statusCode = $response->getStatusCode(); - return [null, $statusCode, $response->getHeaders()]; + return [null, $statusCode, $response->getHeaders()]; } catch (ApiException $e) { switch ($e->getCode()) { } + + throw $e; } } @@ -2016,4 +2033,46 @@ private function createUri( return $uri; } + + private function handleResponseWithDataType( + string $dataType, + ResponseInterface $response + ): array { + if ($dataType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ($dataType !== 'string') { + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $response->getStatusCode(), + $response->getHeaders(), + $content + ); + } + } + } + + return [ + ObjectSerializer::deserialize($content, $dataType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + private function responseWithinRangeCode( + string $rangeCode, + int $statusCode + ): bool { + $left = (int) ($rangeCode[0].'00'); + $right = (int) ($rangeCode[0].'99'); + + return $statusCode >= $left && $statusCode <= $right; + } } diff --git a/samples/client/petstore/php/psr-18/lib/Model/ErrorRangeResponse.php b/samples/client/petstore/php/psr-18/lib/Model/ErrorRangeResponse.php new file mode 100644 index 000000000000..8fef20574d1a --- /dev/null +++ b/samples/client/petstore/php/psr-18/lib/Model/ErrorRangeResponse.php @@ -0,0 +1,443 @@ + + */ +class ErrorRangeResponse implements ModelInterface, ArrayAccess, \JsonSerializable +{ + public const DISCRIMINATOR = null; + + /** + * The original name of the model. + * + * @var string + */ + protected static $openAPIModelName = 'ErrorRangeResponse'; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @var string[] + */ + protected static $openAPITypes = [ + 'response_code' => 'int', + 'error' => 'string' + ]; + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @var string[] + * @phpstan-var array + * @psalm-var array + */ + protected static $openAPIFormats = [ + 'response_code' => null, + 'error' => null + ]; + + /** + * Array of nullable properties. Used for (de)serialization + * + * @var boolean[] + */ + protected static array $openAPINullables = [ + 'response_code' => false, + 'error' => false + ]; + + /** + * If a nullable field gets set to null, insert it here + * + * @var boolean[] + */ + protected array $openAPINullablesSetToNull = []; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPITypes() + { + return self::$openAPITypes; + } + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPIFormats() + { + return self::$openAPIFormats; + } + + /** + * Array of nullable properties + * + * @return array + */ + protected static function openAPINullables(): array + { + return self::$openAPINullables; + } + + /** + * Array of nullable field names deliberately set to null + * + * @return boolean[] + */ + private function getOpenAPINullablesSetToNull(): array + { + return $this->openAPINullablesSetToNull; + } + + /** + * Setter - Array of nullable field names deliberately set to null + * + * @param boolean[] $openAPINullablesSetToNull + */ + private function setOpenAPINullablesSetToNull(array $openAPINullablesSetToNull): void + { + $this->openAPINullablesSetToNull = $openAPINullablesSetToNull; + } + + /** + * Checks if a property is nullable + * + * @param string $property + * @return bool + */ + public static function isNullable(string $property): bool + { + return self::openAPINullables()[$property] ?? false; + } + + /** + * Checks if a nullable property is set to null. + * + * @param string $property + * @return bool + */ + public function isNullableSetToNull(string $property): bool + { + return in_array($property, $this->getOpenAPINullablesSetToNull(), true); + } + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @var string[] + */ + protected static $attributeMap = [ + 'response_code' => 'response_code', + 'error' => 'error' + ]; + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @var string[] + */ + protected static $setters = [ + 'response_code' => 'setResponseCode', + 'error' => 'setError' + ]; + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @var string[] + */ + protected static $getters = [ + 'response_code' => 'getResponseCode', + 'error' => 'getError' + ]; + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @return array + */ + public static function attributeMap() + { + return self::$attributeMap; + } + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @return array + */ + public static function setters() + { + return self::$setters; + } + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @return array + */ + public static function getters() + { + return self::$getters; + } + + /** + * The original name of the model. + * + * @return string + */ + public function getModelName() + { + return self::$openAPIModelName; + } + + + /** + * Associative array for storing property values + * + * @var mixed[] + */ + protected $container = []; + + /** + * Constructor + * + * @param mixed[]|null $data Associated array of property values + * initializing the model + */ + public function __construct(?array $data = null) + { + $this->setIfExists('response_code', $data ?? [], null); + $this->setIfExists('error', $data ?? [], null); + } + + /** + * Sets $this->container[$variableName] to the given data or to the given default Value; if $variableName + * is nullable and its value is set to null in the $fields array, then mark it as "set to null" in the + * $this->openAPINullablesSetToNull array + * + * @param string $variableName + * @param array $fields + * @param mixed $defaultValue + */ + private function setIfExists(string $variableName, array $fields, $defaultValue): void + { + if (self::isNullable($variableName) && array_key_exists($variableName, $fields) && is_null($fields[$variableName])) { + $this->openAPINullablesSetToNull[] = $variableName; + } + + $this->container[$variableName] = $fields[$variableName] ?? $defaultValue; + } + + /** + * Show all the invalid properties with reasons. + * + * @return array invalid properties with reasons + */ + public function listInvalidProperties() + { + $invalidProperties = []; + + return $invalidProperties; + } + + /** + * Validate all the properties in the model + * return true if all passed + * + * @return bool True if all properties are valid + */ + public function valid() + { + return count($this->listInvalidProperties()) === 0; + } + + + /** + * Gets response_code + * + * @return int|null + */ + public function getResponseCode() + { + return $this->container['response_code']; + } + + /** + * Sets response_code + * + * @param int|null $response_code response_code + * + * @return self + */ + public function setResponseCode($response_code) + { + if (is_null($response_code)) { + throw new \InvalidArgumentException('non-nullable response_code cannot be null'); + } + $this->container['response_code'] = $response_code; + + return $this; + } + + /** + * Gets error + * + * @return string|null + */ + public function getError() + { + return $this->container['error']; + } + + /** + * Sets error + * + * @param string|null $error error + * + * @return self + */ + public function setError($error) + { + if (is_null($error)) { + throw new \InvalidArgumentException('non-nullable error cannot be null'); + } + $this->container['error'] = $error; + + return $this; + } + /** + * Returns true if offset exists. False otherwise. + * + * @param integer $offset Offset + * + * @return boolean + */ + public function offsetExists($offset): bool + { + return isset($this->container[$offset]); + } + + /** + * Gets offset. + * + * @param integer $offset Offset + * + * @return mixed|null + */ + #[\ReturnTypeWillChange] + public function offsetGet($offset) + { + return $this->container[$offset] ?? null; + } + + /** + * Sets value based on offset. + * + * @param int|null $offset Offset + * @param mixed $value Value to be set + * + * @return void + */ + public function offsetSet($offset, $value): void + { + if (is_null($offset)) { + $this->container[] = $value; + } else { + $this->container[$offset] = $value; + } + } + + /** + * Unsets offset. + * + * @param integer $offset Offset + * + * @return void + */ + public function offsetUnset($offset): void + { + unset($this->container[$offset]); + } + + /** + * Serializes the object to a value that can be serialized natively by json_encode(). + * @link https://www.php.net/manual/en/jsonserializable.jsonserialize.php + * + * @return mixed Returns data which can be serialized by json_encode(), which is a value + * of any type other than a resource. + */ + #[\ReturnTypeWillChange] + public function jsonSerialize() + { + return ObjectSerializer::sanitizeForSerialization($this); + } + + /** + * Gets the string presentation of the object + * + * @return string + */ + public function __toString() + { + return json_encode( + ObjectSerializer::sanitizeForSerialization($this), + JSON_PRETTY_PRINT + ); + } + + /** + * Gets a header-safe presentation of the object + * + * @return string + */ + public function toHeaderValue() + { + return json_encode(ObjectSerializer::sanitizeForSerialization($this)); + } +} + + diff --git a/samples/client/petstore/php/psr-18/lib/Model/ErrorResponse.php b/samples/client/petstore/php/psr-18/lib/Model/ErrorResponse.php new file mode 100644 index 000000000000..1e9c3940003f --- /dev/null +++ b/samples/client/petstore/php/psr-18/lib/Model/ErrorResponse.php @@ -0,0 +1,443 @@ + + */ +class ErrorResponse implements ModelInterface, ArrayAccess, \JsonSerializable +{ + public const DISCRIMINATOR = null; + + /** + * The original name of the model. + * + * @var string + */ + protected static $openAPIModelName = 'ErrorResponse'; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @var string[] + */ + protected static $openAPITypes = [ + 'response_code' => 'int', + 'error' => 'string' + ]; + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @var string[] + * @phpstan-var array + * @psalm-var array + */ + protected static $openAPIFormats = [ + 'response_code' => null, + 'error' => null + ]; + + /** + * Array of nullable properties. Used for (de)serialization + * + * @var boolean[] + */ + protected static array $openAPINullables = [ + 'response_code' => false, + 'error' => false + ]; + + /** + * If a nullable field gets set to null, insert it here + * + * @var boolean[] + */ + protected array $openAPINullablesSetToNull = []; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPITypes() + { + return self::$openAPITypes; + } + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPIFormats() + { + return self::$openAPIFormats; + } + + /** + * Array of nullable properties + * + * @return array + */ + protected static function openAPINullables(): array + { + return self::$openAPINullables; + } + + /** + * Array of nullable field names deliberately set to null + * + * @return boolean[] + */ + private function getOpenAPINullablesSetToNull(): array + { + return $this->openAPINullablesSetToNull; + } + + /** + * Setter - Array of nullable field names deliberately set to null + * + * @param boolean[] $openAPINullablesSetToNull + */ + private function setOpenAPINullablesSetToNull(array $openAPINullablesSetToNull): void + { + $this->openAPINullablesSetToNull = $openAPINullablesSetToNull; + } + + /** + * Checks if a property is nullable + * + * @param string $property + * @return bool + */ + public static function isNullable(string $property): bool + { + return self::openAPINullables()[$property] ?? false; + } + + /** + * Checks if a nullable property is set to null. + * + * @param string $property + * @return bool + */ + public function isNullableSetToNull(string $property): bool + { + return in_array($property, $this->getOpenAPINullablesSetToNull(), true); + } + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @var string[] + */ + protected static $attributeMap = [ + 'response_code' => 'response_code', + 'error' => 'error' + ]; + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @var string[] + */ + protected static $setters = [ + 'response_code' => 'setResponseCode', + 'error' => 'setError' + ]; + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @var string[] + */ + protected static $getters = [ + 'response_code' => 'getResponseCode', + 'error' => 'getError' + ]; + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @return array + */ + public static function attributeMap() + { + return self::$attributeMap; + } + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @return array + */ + public static function setters() + { + return self::$setters; + } + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @return array + */ + public static function getters() + { + return self::$getters; + } + + /** + * The original name of the model. + * + * @return string + */ + public function getModelName() + { + return self::$openAPIModelName; + } + + + /** + * Associative array for storing property values + * + * @var mixed[] + */ + protected $container = []; + + /** + * Constructor + * + * @param mixed[]|null $data Associated array of property values + * initializing the model + */ + public function __construct(?array $data = null) + { + $this->setIfExists('response_code', $data ?? [], null); + $this->setIfExists('error', $data ?? [], null); + } + + /** + * Sets $this->container[$variableName] to the given data or to the given default Value; if $variableName + * is nullable and its value is set to null in the $fields array, then mark it as "set to null" in the + * $this->openAPINullablesSetToNull array + * + * @param string $variableName + * @param array $fields + * @param mixed $defaultValue + */ + private function setIfExists(string $variableName, array $fields, $defaultValue): void + { + if (self::isNullable($variableName) && array_key_exists($variableName, $fields) && is_null($fields[$variableName])) { + $this->openAPINullablesSetToNull[] = $variableName; + } + + $this->container[$variableName] = $fields[$variableName] ?? $defaultValue; + } + + /** + * Show all the invalid properties with reasons. + * + * @return array invalid properties with reasons + */ + public function listInvalidProperties() + { + $invalidProperties = []; + + return $invalidProperties; + } + + /** + * Validate all the properties in the model + * return true if all passed + * + * @return bool True if all properties are valid + */ + public function valid() + { + return count($this->listInvalidProperties()) === 0; + } + + + /** + * Gets response_code + * + * @return int|null + */ + public function getResponseCode() + { + return $this->container['response_code']; + } + + /** + * Sets response_code + * + * @param int|null $response_code response_code + * + * @return self + */ + public function setResponseCode($response_code) + { + if (is_null($response_code)) { + throw new \InvalidArgumentException('non-nullable response_code cannot be null'); + } + $this->container['response_code'] = $response_code; + + return $this; + } + + /** + * Gets error + * + * @return string|null + */ + public function getError() + { + return $this->container['error']; + } + + /** + * Sets error + * + * @param string|null $error error + * + * @return self + */ + public function setError($error) + { + if (is_null($error)) { + throw new \InvalidArgumentException('non-nullable error cannot be null'); + } + $this->container['error'] = $error; + + return $this; + } + /** + * Returns true if offset exists. False otherwise. + * + * @param integer $offset Offset + * + * @return boolean + */ + public function offsetExists($offset): bool + { + return isset($this->container[$offset]); + } + + /** + * Gets offset. + * + * @param integer $offset Offset + * + * @return mixed|null + */ + #[\ReturnTypeWillChange] + public function offsetGet($offset) + { + return $this->container[$offset] ?? null; + } + + /** + * Sets value based on offset. + * + * @param int|null $offset Offset + * @param mixed $value Value to be set + * + * @return void + */ + public function offsetSet($offset, $value): void + { + if (is_null($offset)) { + $this->container[] = $value; + } else { + $this->container[$offset] = $value; + } + } + + /** + * Unsets offset. + * + * @param integer $offset Offset + * + * @return void + */ + public function offsetUnset($offset): void + { + unset($this->container[$offset]); + } + + /** + * Serializes the object to a value that can be serialized natively by json_encode(). + * @link https://www.php.net/manual/en/jsonserializable.jsonserialize.php + * + * @return mixed Returns data which can be serialized by json_encode(), which is a value + * of any type other than a resource. + */ + #[\ReturnTypeWillChange] + public function jsonSerialize() + { + return ObjectSerializer::sanitizeForSerialization($this); + } + + /** + * Gets the string presentation of the object + * + * @return string + */ + public function __toString() + { + return json_encode( + ObjectSerializer::sanitizeForSerialization($this), + JSON_PRETTY_PRINT + ); + } + + /** + * Gets a header-safe presentation of the object + * + * @return string + */ + public function toHeaderValue() + { + return json_encode(ObjectSerializer::sanitizeForSerialization($this)); + } +} + + diff --git a/samples/client/petstore/php/psr-18/test/Model/ErrorRangeResponseTest.php b/samples/client/petstore/php/psr-18/test/Model/ErrorRangeResponseTest.php new file mode 100644 index 000000000000..515ef826aad7 --- /dev/null +++ b/samples/client/petstore/php/psr-18/test/Model/ErrorRangeResponseTest.php @@ -0,0 +1,99 @@ + Date: Sat, 29 Mar 2025 12:59:10 -0500 Subject: [PATCH 2/8] Adding response body to 200 --- ...ith-fake-endpoints-models-for-testing.yaml | 12 + .../.openapi-generator/FILES | 1 + .../src/FormDataProcessor.php | 237 +++++++++++++++++ .../php-nextgen/.openapi-generator/FILES | 1 + .../php-nextgen/src/FormDataProcessor.php | 237 +++++++++++++++++ .../.openapi-generator/FILES | 1 + .../src/FormDataProcessor.php | 236 +++++++++++++++++ .../.openapi-generator/FILES | 2 +- .../php/OpenAPIClient-php/docs/Api/FakeApi.md | 21 +- .../php/OpenAPIClient-php/lib/Api/FakeApi.php | 202 +++++++++++++-- .../lib/FormDataProcessor.php | 242 ++++++++++++++++++ .../lib/Model/ErrorResponse.php | 2 +- .../php/psr-18/.openapi-generator/FILES | 2 +- .../petstore/php/psr-18/docs/Api/FakeApi.md | 21 +- .../petstore/php/psr-18/lib/Api/FakeApi.php | 193 ++++++++++++-- .../php/psr-18/lib/FormDataProcessor.php | 242 ++++++++++++++++++ .../php/psr-18/lib/Model/ErrorResponse.php | 2 +- 17 files changed, 1596 insertions(+), 58 deletions(-) create mode 100644 samples/client/echo_api/php-nextgen-streaming/src/FormDataProcessor.php create mode 100644 samples/client/echo_api/php-nextgen/src/FormDataProcessor.php create mode 100644 samples/client/petstore/php-nextgen/OpenAPIClient-php/src/FormDataProcessor.php create mode 100644 samples/client/petstore/php/OpenAPIClient-php/lib/FormDataProcessor.php create mode 100644 samples/client/petstore/php/psr-18/lib/FormDataProcessor.php diff --git a/modules/openapi-generator/src/test/resources/3_0/php/petstore-with-fake-endpoints-models-for-testing.yaml b/modules/openapi-generator/src/test/resources/3_0/php/petstore-with-fake-endpoints-models-for-testing.yaml index c716c5b6fadb..8cea116dd8e2 100644 --- a/modules/openapi-generator/src/test/resources/3_0/php/petstore-with-fake-endpoints-models-for-testing.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/php/petstore-with-fake-endpoints-models-for-testing.yaml @@ -1403,6 +1403,10 @@ paths: responses: 200: description: Valid status value + content: + application/json: + schema: + $ref: '#/components/schemas/Pet' '400': description: Invalid status value content: @@ -1420,6 +1424,10 @@ paths: responses: 200: description: Valid status value + content: + application/json: + schema: + $ref: '#/components/schemas/Pet' '4xx': description: Range of HTTP code 400-499 content: @@ -1437,6 +1445,10 @@ paths: responses: 200: description: Valid status value + content: + application/json: + schema: + $ref: '#/components/schemas/Pet' '400': description: Invalid status value content: diff --git a/samples/client/echo_api/php-nextgen-streaming/.openapi-generator/FILES b/samples/client/echo_api/php-nextgen-streaming/.openapi-generator/FILES index c51141c743e7..d849d4cffa36 100644 --- a/samples/client/echo_api/php-nextgen-streaming/.openapi-generator/FILES +++ b/samples/client/echo_api/php-nextgen-streaming/.openapi-generator/FILES @@ -32,6 +32,7 @@ src/Api/PathApi.php src/Api/QueryApi.php src/ApiException.php src/Configuration.php +src/FormDataProcessor.php src/HeaderSelector.php src/Model/Bird.php src/Model/Category.php diff --git a/samples/client/echo_api/php-nextgen-streaming/src/FormDataProcessor.php b/samples/client/echo_api/php-nextgen-streaming/src/FormDataProcessor.php new file mode 100644 index 000000000000..b7a31b3f2a01 --- /dev/null +++ b/samples/client/echo_api/php-nextgen-streaming/src/FormDataProcessor.php @@ -0,0 +1,237 @@ + $values the value of the form parameter + * + * @return array [key => value] of formdata + */ + public function prepare(array $values): array + { + $this->has_file = false; + $result = []; + + foreach ($values as $k => $v) { + if ($v === null) { + continue; + } + + $result[$k] = $this->makeFormSafe($v); + } + + return $result; + } + + /** + * Flattens a multi-level array of data and generates a single-level array + * compatible with formdata - a single-level array where the keys use bracket + * notation to signify nested data. + * + * credit: https://github.com/FranBar1966/FlatPHP + */ + public static function flatten(array $source, string $start = ''): array + { + $opt = [ + 'prefix' => '[', + 'suffix' => ']', + 'suffix-end' => true, + 'prefix-list' => '[', + 'suffix-list' => ']', + 'suffix-list-end' => true, + ]; + + if ($start === '') { + $currentPrefix = ''; + $currentSuffix = ''; + $currentSuffixEnd = false; + } elseif (array_is_list($source)) { + $currentPrefix = $opt['prefix-list']; + $currentSuffix = $opt['suffix-list']; + $currentSuffixEnd = $opt['suffix-list-end']; + } else { + $currentPrefix = $opt['prefix']; + $currentSuffix = $opt['suffix']; + $currentSuffixEnd = $opt['suffix-end']; + } + + $currentName = $start; + $result = []; + + foreach ($source as $key => $val) { + $currentName .= $currentPrefix . $key; + + if (is_array($val) && !empty($val)) { + $currentName .= $currentSuffix; + $result += self::flatten($val, $currentName); + } else { + if ($currentSuffixEnd) { + $currentName .= $currentSuffix; + } + + $result[$currentName] = ObjectSerializer::toString($val); + } + + $currentName = $start; + } + + return $result; + } + + /** + * formdata must be limited to scalars or arrays of scalar values, + * or a resource for a file upload. Here we iterate through all available + * data and identify how to handle each scenario + * + * @param string|bool|array|DateTime|ArrayAccess|SplFileObject $value + */ + protected function makeFormSafe(mixed $value) + { + if ($value instanceof SplFileObject) { + return $this->processFiles([$value])[0]; + } + + if (is_resource($value)) { + $this->has_file = true; + + return $value; + } + + if ($value instanceof ModelInterface) { + return $this->processModel($value); + } + + if (is_array($value) || is_object($value)) { + $data = []; + + foreach ($value as $k => $v) { + $data[$k] = $this->makeFormSafe($v); + } + + return $data; + } + + return ObjectSerializer::toString($value); + } + + /** + * We are able to handle nested ModelInterface. We do not simply call + * json_decode(json_encode()) because any given model may have binary data + * or other data that cannot be serialized to a JSON string + */ + protected function processModel(ModelInterface $model): array + { + $result = []; + + foreach ($model::openAPITypes() as $name => $type) { + $value = $model->offsetGet($name); + + if ($value === null) { + continue; + } + + if (str_contains($type, '\SplFileObject')) { + $file = is_array($value) ? $value : [$value]; + $result[$name] = $this->processFiles($file); + + continue; + } + + if ($value instanceof ModelInterface) { + $result[$name] = $this->processModel($value); + + continue; + } + + if (is_array($value) || is_object($value)) { + $result[$name] = $this->makeFormSafe($value); + + continue; + } + + $result[$name] = ObjectSerializer::toString($value); + } + + return $result; + } + + /** + * Handle file data + */ + protected function processFiles(array $files): array + { + $this->has_file = true; + + $result = []; + + foreach ($files as $i => $file) { + if (is_array($file)) { + $result[$i] = $this->processFiles($file); + + continue; + } + + if ($file instanceof StreamInterface) { + $result[$i] = $file; + + continue; + } + + if ($file instanceof SplFileObject) { + $result[$i] = $this->tryFopen($file); + } + } + + return $result; + } + + private function tryFopen(SplFileObject $file) + { + return Utils::tryFopen($file->getRealPath(), 'rb'); + } +} diff --git a/samples/client/echo_api/php-nextgen/.openapi-generator/FILES b/samples/client/echo_api/php-nextgen/.openapi-generator/FILES index c51141c743e7..d849d4cffa36 100644 --- a/samples/client/echo_api/php-nextgen/.openapi-generator/FILES +++ b/samples/client/echo_api/php-nextgen/.openapi-generator/FILES @@ -32,6 +32,7 @@ src/Api/PathApi.php src/Api/QueryApi.php src/ApiException.php src/Configuration.php +src/FormDataProcessor.php src/HeaderSelector.php src/Model/Bird.php src/Model/Category.php diff --git a/samples/client/echo_api/php-nextgen/src/FormDataProcessor.php b/samples/client/echo_api/php-nextgen/src/FormDataProcessor.php new file mode 100644 index 000000000000..b7a31b3f2a01 --- /dev/null +++ b/samples/client/echo_api/php-nextgen/src/FormDataProcessor.php @@ -0,0 +1,237 @@ + $values the value of the form parameter + * + * @return array [key => value] of formdata + */ + public function prepare(array $values): array + { + $this->has_file = false; + $result = []; + + foreach ($values as $k => $v) { + if ($v === null) { + continue; + } + + $result[$k] = $this->makeFormSafe($v); + } + + return $result; + } + + /** + * Flattens a multi-level array of data and generates a single-level array + * compatible with formdata - a single-level array where the keys use bracket + * notation to signify nested data. + * + * credit: https://github.com/FranBar1966/FlatPHP + */ + public static function flatten(array $source, string $start = ''): array + { + $opt = [ + 'prefix' => '[', + 'suffix' => ']', + 'suffix-end' => true, + 'prefix-list' => '[', + 'suffix-list' => ']', + 'suffix-list-end' => true, + ]; + + if ($start === '') { + $currentPrefix = ''; + $currentSuffix = ''; + $currentSuffixEnd = false; + } elseif (array_is_list($source)) { + $currentPrefix = $opt['prefix-list']; + $currentSuffix = $opt['suffix-list']; + $currentSuffixEnd = $opt['suffix-list-end']; + } else { + $currentPrefix = $opt['prefix']; + $currentSuffix = $opt['suffix']; + $currentSuffixEnd = $opt['suffix-end']; + } + + $currentName = $start; + $result = []; + + foreach ($source as $key => $val) { + $currentName .= $currentPrefix . $key; + + if (is_array($val) && !empty($val)) { + $currentName .= $currentSuffix; + $result += self::flatten($val, $currentName); + } else { + if ($currentSuffixEnd) { + $currentName .= $currentSuffix; + } + + $result[$currentName] = ObjectSerializer::toString($val); + } + + $currentName = $start; + } + + return $result; + } + + /** + * formdata must be limited to scalars or arrays of scalar values, + * or a resource for a file upload. Here we iterate through all available + * data and identify how to handle each scenario + * + * @param string|bool|array|DateTime|ArrayAccess|SplFileObject $value + */ + protected function makeFormSafe(mixed $value) + { + if ($value instanceof SplFileObject) { + return $this->processFiles([$value])[0]; + } + + if (is_resource($value)) { + $this->has_file = true; + + return $value; + } + + if ($value instanceof ModelInterface) { + return $this->processModel($value); + } + + if (is_array($value) || is_object($value)) { + $data = []; + + foreach ($value as $k => $v) { + $data[$k] = $this->makeFormSafe($v); + } + + return $data; + } + + return ObjectSerializer::toString($value); + } + + /** + * We are able to handle nested ModelInterface. We do not simply call + * json_decode(json_encode()) because any given model may have binary data + * or other data that cannot be serialized to a JSON string + */ + protected function processModel(ModelInterface $model): array + { + $result = []; + + foreach ($model::openAPITypes() as $name => $type) { + $value = $model->offsetGet($name); + + if ($value === null) { + continue; + } + + if (str_contains($type, '\SplFileObject')) { + $file = is_array($value) ? $value : [$value]; + $result[$name] = $this->processFiles($file); + + continue; + } + + if ($value instanceof ModelInterface) { + $result[$name] = $this->processModel($value); + + continue; + } + + if (is_array($value) || is_object($value)) { + $result[$name] = $this->makeFormSafe($value); + + continue; + } + + $result[$name] = ObjectSerializer::toString($value); + } + + return $result; + } + + /** + * Handle file data + */ + protected function processFiles(array $files): array + { + $this->has_file = true; + + $result = []; + + foreach ($files as $i => $file) { + if (is_array($file)) { + $result[$i] = $this->processFiles($file); + + continue; + } + + if ($file instanceof StreamInterface) { + $result[$i] = $file; + + continue; + } + + if ($file instanceof SplFileObject) { + $result[$i] = $this->tryFopen($file); + } + } + + return $result; + } + + private function tryFopen(SplFileObject $file) + { + return Utils::tryFopen($file->getRealPath(), 'rb'); + } +} diff --git a/samples/client/petstore/php-nextgen/OpenAPIClient-php/.openapi-generator/FILES b/samples/client/petstore/php-nextgen/OpenAPIClient-php/.openapi-generator/FILES index ebd39c9d9de9..2f93e8839383 100644 --- a/samples/client/petstore/php-nextgen/OpenAPIClient-php/.openapi-generator/FILES +++ b/samples/client/petstore/php-nextgen/OpenAPIClient-php/.openapi-generator/FILES @@ -73,6 +73,7 @@ src/Api/StoreApi.php src/Api/UserApi.php src/ApiException.php src/Configuration.php +src/FormDataProcessor.php src/HeaderSelector.php src/Model/AdditionalPropertiesClass.php src/Model/AllOfWithSingleRef.php diff --git a/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/FormDataProcessor.php b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/FormDataProcessor.php new file mode 100644 index 000000000000..f044f1c6dbc7 --- /dev/null +++ b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/FormDataProcessor.php @@ -0,0 +1,236 @@ + $values the value of the form parameter + * + * @return array [key => value] of formdata + */ + public function prepare(array $values): array + { + $this->has_file = false; + $result = []; + + foreach ($values as $k => $v) { + if ($v === null) { + continue; + } + + $result[$k] = $this->makeFormSafe($v); + } + + return $result; + } + + /** + * Flattens a multi-level array of data and generates a single-level array + * compatible with formdata - a single-level array where the keys use bracket + * notation to signify nested data. + * + * credit: https://github.com/FranBar1966/FlatPHP + */ + public static function flatten(array $source, string $start = ''): array + { + $opt = [ + 'prefix' => '[', + 'suffix' => ']', + 'suffix-end' => true, + 'prefix-list' => '[', + 'suffix-list' => ']', + 'suffix-list-end' => true, + ]; + + if ($start === '') { + $currentPrefix = ''; + $currentSuffix = ''; + $currentSuffixEnd = false; + } elseif (array_is_list($source)) { + $currentPrefix = $opt['prefix-list']; + $currentSuffix = $opt['suffix-list']; + $currentSuffixEnd = $opt['suffix-list-end']; + } else { + $currentPrefix = $opt['prefix']; + $currentSuffix = $opt['suffix']; + $currentSuffixEnd = $opt['suffix-end']; + } + + $currentName = $start; + $result = []; + + foreach ($source as $key => $val) { + $currentName .= $currentPrefix . $key; + + if (is_array($val) && !empty($val)) { + $currentName .= $currentSuffix; + $result += self::flatten($val, $currentName); + } else { + if ($currentSuffixEnd) { + $currentName .= $currentSuffix; + } + + $result[$currentName] = ObjectSerializer::toString($val); + } + + $currentName = $start; + } + + return $result; + } + + /** + * formdata must be limited to scalars or arrays of scalar values, + * or a resource for a file upload. Here we iterate through all available + * data and identify how to handle each scenario + * + * @param string|bool|array|DateTime|ArrayAccess|SplFileObject $value + */ + protected function makeFormSafe(mixed $value) + { + if ($value instanceof SplFileObject) { + return $this->processFiles([$value])[0]; + } + + if (is_resource($value)) { + $this->has_file = true; + + return $value; + } + + if ($value instanceof ModelInterface) { + return $this->processModel($value); + } + + if (is_array($value) || is_object($value)) { + $data = []; + + foreach ($value as $k => $v) { + $data[$k] = $this->makeFormSafe($v); + } + + return $data; + } + + return ObjectSerializer::toString($value); + } + + /** + * We are able to handle nested ModelInterface. We do not simply call + * json_decode(json_encode()) because any given model may have binary data + * or other data that cannot be serialized to a JSON string + */ + protected function processModel(ModelInterface $model): array + { + $result = []; + + foreach ($model::openAPITypes() as $name => $type) { + $value = $model->offsetGet($name); + + if ($value === null) { + continue; + } + + if (str_contains($type, '\SplFileObject')) { + $file = is_array($value) ? $value : [$value]; + $result[$name] = $this->processFiles($file); + + continue; + } + + if ($value instanceof ModelInterface) { + $result[$name] = $this->processModel($value); + + continue; + } + + if (is_array($value) || is_object($value)) { + $result[$name] = $this->makeFormSafe($value); + + continue; + } + + $result[$name] = ObjectSerializer::toString($value); + } + + return $result; + } + + /** + * Handle file data + */ + protected function processFiles(array $files): array + { + $this->has_file = true; + + $result = []; + + foreach ($files as $i => $file) { + if (is_array($file)) { + $result[$i] = $this->processFiles($file); + + continue; + } + + if ($file instanceof StreamInterface) { + $result[$i] = $file; + + continue; + } + + if ($file instanceof SplFileObject) { + $result[$i] = $this->tryFopen($file); + } + } + + return $result; + } + + private function tryFopen(SplFileObject $file) + { + return Utils::tryFopen($file->getRealPath(), 'rb'); + } +} diff --git a/samples/client/petstore/php/OpenAPIClient-php/.openapi-generator/FILES b/samples/client/petstore/php/OpenAPIClient-php/.openapi-generator/FILES index fa5b51302970..e4f07975e540 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/.openapi-generator/FILES +++ b/samples/client/petstore/php/OpenAPIClient-php/.openapi-generator/FILES @@ -71,6 +71,7 @@ lib/Api/StoreApi.php lib/Api/UserApi.php lib/ApiException.php lib/Configuration.php +lib/FormDataProcessor.php lib/HeaderSelector.php lib/Model/AdditionalPropertiesClass.php lib/Model/AllOfWithSingleRef.php @@ -126,4 +127,3 @@ lib/Model/TestInlineFreeformAdditionalPropertiesRequest.php lib/Model/User.php lib/ObjectSerializer.php phpunit.xml.dist -test/Model/ErrorResponseTest.php diff --git a/samples/client/petstore/php/OpenAPIClient-php/docs/Api/FakeApi.md b/samples/client/petstore/php/OpenAPIClient-php/docs/Api/FakeApi.md index c7f1fa71c1d2..8e89001178a1 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/docs/Api/FakeApi.md +++ b/samples/client/petstore/php/OpenAPIClient-php/docs/Api/FakeApi.md @@ -536,7 +536,7 @@ No authorization required ## `fakeWith400And4xxRangeResponseEndpoint()` ```php -fakeWith400And4xxRangeResponseEndpoint($pet) +fakeWith400And4xxRangeResponseEndpoint($pet): \OpenAPI\Client\Model\Pet ``` test endpoint with 400 and 400-499 range response http code with dataType @@ -557,7 +557,8 @@ $apiInstance = new OpenAPI\Client\Api\FakeApi( $pet = new \OpenAPI\Client\Model\Pet(); // \OpenAPI\Client\Model\Pet | Pet object that needs to be added to the store try { - $apiInstance->fakeWith400And4xxRangeResponseEndpoint($pet); + $result = $apiInstance->fakeWith400And4xxRangeResponseEndpoint($pet); + print_r($result); } catch (Exception $e) { echo 'Exception when calling FakeApi->fakeWith400And4xxRangeResponseEndpoint: ', $e->getMessage(), PHP_EOL; } @@ -571,7 +572,7 @@ try { ### Return type -void (empty response body) +[**\OpenAPI\Client\Model\Pet**](../Model/Pet.md) ### Authorization @@ -589,7 +590,7 @@ No authorization required ## `fakeWith400ResponseEndpoint()` ```php -fakeWith400ResponseEndpoint($pet) +fakeWith400ResponseEndpoint($pet): \OpenAPI\Client\Model\Pet ``` test endpoint with 400 response http code with dataType @@ -610,7 +611,8 @@ $apiInstance = new OpenAPI\Client\Api\FakeApi( $pet = new \OpenAPI\Client\Model\Pet(); // \OpenAPI\Client\Model\Pet | Pet object that needs to be added to the store try { - $apiInstance->fakeWith400ResponseEndpoint($pet); + $result = $apiInstance->fakeWith400ResponseEndpoint($pet); + print_r($result); } catch (Exception $e) { echo 'Exception when calling FakeApi->fakeWith400ResponseEndpoint: ', $e->getMessage(), PHP_EOL; } @@ -624,7 +626,7 @@ try { ### Return type -void (empty response body) +[**\OpenAPI\Client\Model\Pet**](../Model/Pet.md) ### Authorization @@ -642,7 +644,7 @@ No authorization required ## `fakeWith4xxRangeResponseEndpoint()` ```php -fakeWith4xxRangeResponseEndpoint($pet) +fakeWith4xxRangeResponseEndpoint($pet): \OpenAPI\Client\Model\Pet ``` test endpoint with 400-499 range response http code with dataType @@ -663,7 +665,8 @@ $apiInstance = new OpenAPI\Client\Api\FakeApi( $pet = new \OpenAPI\Client\Model\Pet(); // \OpenAPI\Client\Model\Pet | Pet object that needs to be added to the store try { - $apiInstance->fakeWith4xxRangeResponseEndpoint($pet); + $result = $apiInstance->fakeWith4xxRangeResponseEndpoint($pet); + print_r($result); } catch (Exception $e) { echo 'Exception when calling FakeApi->fakeWith4xxRangeResponseEndpoint: ', $e->getMessage(), PHP_EOL; } @@ -677,7 +680,7 @@ try { ### Return type -void (empty response body) +[**\OpenAPI\Client\Model\Pet**](../Model/Pet.md) ### Authorization diff --git a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/FakeApi.php b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/FakeApi.php index bd829d3699d7..80055fa07753 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/FakeApi.php +++ b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/FakeApi.php @@ -2508,11 +2508,12 @@ public function fakePropertyEnumIntegerSerializeRequest($outer_object_with_enum_ * * @throws \OpenAPI\Client\ApiException on non-2xx response or if the response body is not in the expected format * @throws \InvalidArgumentException - * @return void + * @return \OpenAPI\Client\Model\Pet|\OpenAPI\Client\Model\ErrorResponse|\OpenAPI\Client\Model\ErrorResponse */ public function fakeWith400And4xxRangeResponseEndpoint($pet, string $contentType = self::contentTypes['fakeWith400And4xxRangeResponseEndpoint'][0]) { - $this->fakeWith400And4xxRangeResponseEndpointWithHttpInfo($pet, $contentType); + list($response) = $this->fakeWith400And4xxRangeResponseEndpointWithHttpInfo($pet, $contentType); + return $response; } /** @@ -2525,7 +2526,7 @@ public function fakeWith400And4xxRangeResponseEndpoint($pet, string $contentType * * @throws \OpenAPI\Client\ApiException on non-2xx response or if the response body is not in the expected format * @throws \InvalidArgumentException - * @return array of null, HTTP status code, HTTP response headers (array of strings) + * @return array of \OpenAPI\Client\Model\Pet|\OpenAPI\Client\Model\ErrorResponse|\OpenAPI\Client\Model\ErrorResponse, HTTP status code, HTTP response headers (array of strings) */ public function fakeWith400And4xxRangeResponseEndpointWithHttpInfo($pet, string $contentType = self::contentTypes['fakeWith400And4xxRangeResponseEndpoint'][0]) { @@ -2554,9 +2555,54 @@ public function fakeWith400And4xxRangeResponseEndpointWithHttpInfo($pet, string $statusCode = $response->getStatusCode(); - return [null, $statusCode, $response->getHeaders()]; + switch($statusCode) { + case 200: + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Pet', + $response, + ); + case 400: + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\ErrorResponse', + $response, + ); + + } + + if ($this->responseWithinRangeCode('4xx', $statusCode)) { + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\ErrorResponse', + $response, + ); + } + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Pet', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\OpenAPI\Client\Model\Pet', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + throw $e; case 400: $data = ObjectSerializer::deserialize( $e->getResponseBody(), @@ -2616,14 +2662,27 @@ function ($response) { */ public function fakeWith400And4xxRangeResponseEndpointAsyncWithHttpInfo($pet, string $contentType = self::contentTypes['fakeWith400And4xxRangeResponseEndpoint'][0]) { - $returnType = ''; + $returnType = '\OpenAPI\Client\Model\Pet'; $request = $this->fakeWith400And4xxRangeResponseEndpointRequest($pet, $contentType); return $this->client ->sendAsync($request, $this->createHttpClientOption()) ->then( function ($response) use ($returnType) { - return [null, $response->getStatusCode(), $response->getHeaders()]; + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; }, function ($exception) { $response = $exception->getResponse(); @@ -2743,11 +2802,12 @@ public function fakeWith400And4xxRangeResponseEndpointRequest($pet, string $cont * * @throws \OpenAPI\Client\ApiException on non-2xx response or if the response body is not in the expected format * @throws \InvalidArgumentException - * @return void + * @return \OpenAPI\Client\Model\Pet|\OpenAPI\Client\Model\ErrorResponse */ public function fakeWith400ResponseEndpoint($pet, string $contentType = self::contentTypes['fakeWith400ResponseEndpoint'][0]) { - $this->fakeWith400ResponseEndpointWithHttpInfo($pet, $contentType); + list($response) = $this->fakeWith400ResponseEndpointWithHttpInfo($pet, $contentType); + return $response; } /** @@ -2760,7 +2820,7 @@ public function fakeWith400ResponseEndpoint($pet, string $contentType = self::co * * @throws \OpenAPI\Client\ApiException on non-2xx response or if the response body is not in the expected format * @throws \InvalidArgumentException - * @return array of null, HTTP status code, HTTP response headers (array of strings) + * @return array of \OpenAPI\Client\Model\Pet|\OpenAPI\Client\Model\ErrorResponse, HTTP status code, HTTP response headers (array of strings) */ public function fakeWith400ResponseEndpointWithHttpInfo($pet, string $contentType = self::contentTypes['fakeWith400ResponseEndpoint'][0]) { @@ -2789,9 +2849,48 @@ public function fakeWith400ResponseEndpointWithHttpInfo($pet, string $contentTyp $statusCode = $response->getStatusCode(); - return [null, $statusCode, $response->getHeaders()]; + switch($statusCode) { + case 200: + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Pet', + $response, + ); + case 400: + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\ErrorResponse', + $response, + ); + } + + + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Pet', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\OpenAPI\Client\Model\Pet', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + throw $e; case 400: $data = ObjectSerializer::deserialize( $e->getResponseBody(), @@ -2841,14 +2940,27 @@ function ($response) { */ public function fakeWith400ResponseEndpointAsyncWithHttpInfo($pet, string $contentType = self::contentTypes['fakeWith400ResponseEndpoint'][0]) { - $returnType = ''; + $returnType = '\OpenAPI\Client\Model\Pet'; $request = $this->fakeWith400ResponseEndpointRequest($pet, $contentType); return $this->client ->sendAsync($request, $this->createHttpClientOption()) ->then( function ($response) use ($returnType) { - return [null, $response->getStatusCode(), $response->getHeaders()]; + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; }, function ($exception) { $response = $exception->getResponse(); @@ -2968,11 +3080,12 @@ public function fakeWith400ResponseEndpointRequest($pet, string $contentType = s * * @throws \OpenAPI\Client\ApiException on non-2xx response or if the response body is not in the expected format * @throws \InvalidArgumentException - * @return void + * @return \OpenAPI\Client\Model\Pet|\OpenAPI\Client\Model\ErrorResponse */ public function fakeWith4xxRangeResponseEndpoint($pet, string $contentType = self::contentTypes['fakeWith4xxRangeResponseEndpoint'][0]) { - $this->fakeWith4xxRangeResponseEndpointWithHttpInfo($pet, $contentType); + list($response) = $this->fakeWith4xxRangeResponseEndpointWithHttpInfo($pet, $contentType); + return $response; } /** @@ -2985,7 +3098,7 @@ public function fakeWith4xxRangeResponseEndpoint($pet, string $contentType = sel * * @throws \OpenAPI\Client\ApiException on non-2xx response or if the response body is not in the expected format * @throws \InvalidArgumentException - * @return array of null, HTTP status code, HTTP response headers (array of strings) + * @return array of \OpenAPI\Client\Model\Pet|\OpenAPI\Client\Model\ErrorResponse, HTTP status code, HTTP response headers (array of strings) */ public function fakeWith4xxRangeResponseEndpointWithHttpInfo($pet, string $contentType = self::contentTypes['fakeWith4xxRangeResponseEndpoint'][0]) { @@ -3014,9 +3127,49 @@ public function fakeWith4xxRangeResponseEndpointWithHttpInfo($pet, string $conte $statusCode = $response->getStatusCode(); - return [null, $statusCode, $response->getHeaders()]; + switch($statusCode) { + case 200: + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Pet', + $response, + ); + + } + + if ($this->responseWithinRangeCode('4xx', $statusCode)) { + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\ErrorResponse', + $response, + ); + } + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Pet', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\OpenAPI\Client\Model\Pet', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + throw $e; } @@ -3068,14 +3221,27 @@ function ($response) { */ public function fakeWith4xxRangeResponseEndpointAsyncWithHttpInfo($pet, string $contentType = self::contentTypes['fakeWith4xxRangeResponseEndpoint'][0]) { - $returnType = ''; + $returnType = '\OpenAPI\Client\Model\Pet'; $request = $this->fakeWith4xxRangeResponseEndpointRequest($pet, $contentType); return $this->client ->sendAsync($request, $this->createHttpClientOption()) ->then( function ($response) use ($returnType) { - return [null, $response->getStatusCode(), $response->getHeaders()]; + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; }, function ($exception) { $response = $exception->getResponse(); diff --git a/samples/client/petstore/php/OpenAPIClient-php/lib/FormDataProcessor.php b/samples/client/petstore/php/OpenAPIClient-php/lib/FormDataProcessor.php new file mode 100644 index 000000000000..c416f584e6aa --- /dev/null +++ b/samples/client/petstore/php/OpenAPIClient-php/lib/FormDataProcessor.php @@ -0,0 +1,242 @@ + $values the value of the form parameter + * + * @return array [key => value] of formdata + */ + public function prepare(array $values): array + { + $this->has_file = false; + $result = []; + + foreach ($values as $k => $v) { + if ($v === null) { + continue; + } + + $result[$k] = $this->makeFormSafe($v); + } + + return $result; + } + + /** + * Flattens a multi-level array of data and generates a single-level array + * compatible with formdata - a single-level array where the keys use bracket + * notation to signify nested data. + * + * credit: https://github.com/FranBar1966/FlatPHP + */ + public static function flatten(array $source, string $start = ''): array + { + $opt = [ + 'prefix' => '[', + 'suffix' => ']', + 'suffix-end' => true, + 'prefix-list' => '[', + 'suffix-list' => ']', + 'suffix-list-end' => true, + ]; + + if ($start === '') { + $currentPrefix = ''; + $currentSuffix = ''; + $currentSuffixEnd = false; + } elseif (array_is_list($source)) { + $currentPrefix = $opt['prefix-list']; + $currentSuffix = $opt['suffix-list']; + $currentSuffixEnd = $opt['suffix-list-end']; + } else { + $currentPrefix = $opt['prefix']; + $currentSuffix = $opt['suffix']; + $currentSuffixEnd = $opt['suffix-end']; + } + + $currentName = $start; + $result = []; + + foreach ($source as $key => $val) { + $currentName .= $currentPrefix.$key; + + if (is_array($val) && !empty($val)) { + $currentName .= $currentSuffix; + $result += self::flatten($val, $currentName); + } else { + if ($currentSuffixEnd) { + $currentName .= $currentSuffix; + } + + $result[$currentName] = ObjectSerializer::toString($val); + } + + $currentName = $start; + } + + return $result; + } + + /** + * formdata must be limited to scalars or arrays of scalar values, + * or a resource for a file upload. Here we iterate through all available + * data and identify how to handle each scenario + */ + protected function makeFormSafe($value) + { + if ($value instanceof SplFileObject) { + return $this->processFiles([$value])[0]; + } + + if (is_resource($value)) { + $this->has_file = true; + + return $value; + } + + if ($value instanceof ModelInterface) { + return $this->processModel($value); + } + + if (is_array($value) || (is_object($value) && !$value instanceof \DateTimeInterface)) { + $data = []; + + foreach ($value as $k => $v) { + $data[$k] = $this->makeFormSafe($v); + } + + return $data; + } + + return ObjectSerializer::toString($value); + } + + /** + * We are able to handle nested ModelInterface. We do not simply call + * json_decode(json_encode()) because any given model may have binary data + * or other data that cannot be serialized to a JSON string + */ + protected function processModel(ModelInterface $model): array + { + $result = []; + + foreach ($model::openAPITypes() as $name => $type) { + $value = $model->offsetGet($name); + + if ($value === null) { + continue; + } + + if (strpos($type, '\SplFileObject') !== false) { + $file = is_array($value) ? $value : [$value]; + $result[$name] = $this->processFiles($file); + + continue; + } + + if ($value instanceof ModelInterface) { + $result[$name] = $this->processModel($value); + + continue; + } + + if (is_array($value) || is_object($value)) { + $result[$name] = $this->makeFormSafe($value); + + continue; + } + + $result[$name] = ObjectSerializer::toString($value); + } + + return $result; + } + + /** + * Handle file data + */ + protected function processFiles(array $files): array + { + $this->has_file = true; + + $result = []; + + foreach ($files as $i => $file) { + if (is_array($file)) { + $result[$i] = $this->processFiles($file); + + continue; + } + + if ($file instanceof StreamInterface) { + $result[$i] = $file; + + continue; + } + + if ($file instanceof SplFileObject) { + $result[$i] = $this->tryFopen($file); + } + } + + return $result; + } + + private function tryFopen(SplFileObject $file) + { + return Utils::tryFopen($file->getRealPath(), 'rb'); + } +} diff --git a/samples/client/petstore/php/OpenAPIClient-php/lib/Model/ErrorResponse.php b/samples/client/petstore/php/OpenAPIClient-php/lib/Model/ErrorResponse.php index 1e9c3940003f..458660568ffd 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/lib/Model/ErrorResponse.php +++ b/samples/client/petstore/php/OpenAPIClient-php/lib/Model/ErrorResponse.php @@ -2,7 +2,7 @@ /** * ErrorResponse * - * PHP version 7.4 + * PHP version 8.1 * * @category Class * @package OpenAPI\Client diff --git a/samples/client/petstore/php/psr-18/.openapi-generator/FILES b/samples/client/petstore/php/psr-18/.openapi-generator/FILES index 7234f6746545..41b774cef923 100644 --- a/samples/client/petstore/php/psr-18/.openapi-generator/FILES +++ b/samples/client/petstore/php/psr-18/.openapi-generator/FILES @@ -72,6 +72,7 @@ lib/Api/UserApi.php lib/ApiException.php lib/Configuration.php lib/DebugPlugin.php +lib/FormDataProcessor.php lib/HeaderSelector.php lib/Model/AdditionalPropertiesClass.php lib/Model/AllOfWithSingleRef.php @@ -127,4 +128,3 @@ lib/Model/TestInlineFreeformAdditionalPropertiesRequest.php lib/Model/User.php lib/ObjectSerializer.php phpunit.xml.dist -test/Model/ErrorResponseTest.php diff --git a/samples/client/petstore/php/psr-18/docs/Api/FakeApi.md b/samples/client/petstore/php/psr-18/docs/Api/FakeApi.md index c4a2981c0c5a..326b784cd2f3 100644 --- a/samples/client/petstore/php/psr-18/docs/Api/FakeApi.md +++ b/samples/client/petstore/php/psr-18/docs/Api/FakeApi.md @@ -536,7 +536,7 @@ No authorization required ## `fakeWith400And4xxRangeResponseEndpoint()` ```php -fakeWith400And4xxRangeResponseEndpoint($pet) +fakeWith400And4xxRangeResponseEndpoint($pet): \OpenAPI\Client\Model\Pet ``` test endpoint with 400 and 400-499 range response http code with dataType @@ -557,7 +557,8 @@ $apiInstance = new OpenAPI\Client\Api\FakeApi( $pet = new \OpenAPI\Client\Model\Pet(); // \OpenAPI\Client\Model\Pet | Pet object that needs to be added to the store try { - $apiInstance->fakeWith400And4xxRangeResponseEndpoint($pet); + $result = $apiInstance->fakeWith400And4xxRangeResponseEndpoint($pet); + print_r($result); } catch (Exception $e) { echo 'Exception when calling FakeApi->fakeWith400And4xxRangeResponseEndpoint: ', $e->getMessage(), PHP_EOL; } @@ -571,7 +572,7 @@ Name | Type | Description | Notes ### Return type -void (empty response body) +[**\OpenAPI\Client\Model\Pet**](../Model/Pet.md) ### Authorization @@ -589,7 +590,7 @@ No authorization required ## `fakeWith400ResponseEndpoint()` ```php -fakeWith400ResponseEndpoint($pet) +fakeWith400ResponseEndpoint($pet): \OpenAPI\Client\Model\Pet ``` test endpoint with 400 response http code with dataType @@ -610,7 +611,8 @@ $apiInstance = new OpenAPI\Client\Api\FakeApi( $pet = new \OpenAPI\Client\Model\Pet(); // \OpenAPI\Client\Model\Pet | Pet object that needs to be added to the store try { - $apiInstance->fakeWith400ResponseEndpoint($pet); + $result = $apiInstance->fakeWith400ResponseEndpoint($pet); + print_r($result); } catch (Exception $e) { echo 'Exception when calling FakeApi->fakeWith400ResponseEndpoint: ', $e->getMessage(), PHP_EOL; } @@ -624,7 +626,7 @@ Name | Type | Description | Notes ### Return type -void (empty response body) +[**\OpenAPI\Client\Model\Pet**](../Model/Pet.md) ### Authorization @@ -642,7 +644,7 @@ No authorization required ## `fakeWith4xxRangeResponseEndpoint()` ```php -fakeWith4xxRangeResponseEndpoint($pet) +fakeWith4xxRangeResponseEndpoint($pet): \OpenAPI\Client\Model\Pet ``` test endpoint with 400-499 range response http code with dataType @@ -663,7 +665,8 @@ $apiInstance = new OpenAPI\Client\Api\FakeApi( $pet = new \OpenAPI\Client\Model\Pet(); // \OpenAPI\Client\Model\Pet | Pet object that needs to be added to the store try { - $apiInstance->fakeWith4xxRangeResponseEndpoint($pet); + $result = $apiInstance->fakeWith4xxRangeResponseEndpoint($pet); + print_r($result); } catch (Exception $e) { echo 'Exception when calling FakeApi->fakeWith4xxRangeResponseEndpoint: ', $e->getMessage(), PHP_EOL; } @@ -677,7 +680,7 @@ Name | Type | Description | Notes ### Return type -void (empty response body) +[**\OpenAPI\Client\Model\Pet**](../Model/Pet.md) ### Authorization diff --git a/samples/client/petstore/php/psr-18/lib/Api/FakeApi.php b/samples/client/petstore/php/psr-18/lib/Api/FakeApi.php index 28c40f6b8d33..d6f5dfcd5fd4 100644 --- a/samples/client/petstore/php/psr-18/lib/Api/FakeApi.php +++ b/samples/client/petstore/php/psr-18/lib/Api/FakeApi.php @@ -2391,11 +2391,12 @@ public function fakePropertyEnumIntegerSerializeRequest($outer_object_with_enum_ * * @throws \OpenAPI\Client\ApiException on non-2xx response * @throws \InvalidArgumentException - * @return void + * @return \OpenAPI\Client\Model\Pet|\OpenAPI\Client\Model\ErrorResponse|\OpenAPI\Client\Model\ErrorResponse */ public function fakeWith400And4xxRangeResponseEndpoint($pet) { - $this->fakeWith400And4xxRangeResponseEndpointWithHttpInfo($pet); + list($response) = $this->fakeWith400And4xxRangeResponseEndpointWithHttpInfo($pet); + return $response; } /** @@ -2407,7 +2408,7 @@ public function fakeWith400And4xxRangeResponseEndpoint($pet) * * @throws \OpenAPI\Client\ApiException on non-2xx response * @throws \InvalidArgumentException - * @return array of null, HTTP status code, HTTP response headers (array of strings) + * @return array of \OpenAPI\Client\Model\Pet|\OpenAPI\Client\Model\ErrorResponse|\OpenAPI\Client\Model\ErrorResponse, HTTP status code, HTTP response headers (array of strings) */ public function fakeWith400And4xxRangeResponseEndpointWithHttpInfo($pet) { @@ -2440,9 +2441,54 @@ public function fakeWith400And4xxRangeResponseEndpointWithHttpInfo($pet) $statusCode = $response->getStatusCode(); - return [null, $statusCode, $response->getHeaders()]; + switch($statusCode) { + case 200: + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Pet', + $response, + ); + case 400: + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\ErrorResponse', + $response, + ); + + } + + if ($this->responseWithinRangeCode('4xx', $statusCode)) { + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\ErrorResponse', + $response, + ); + } + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Pet', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\OpenAPI\Client\Model\Pet', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + throw $e; case 400: $data = ObjectSerializer::deserialize( $e->getResponseBody(), @@ -2500,13 +2546,23 @@ function ($response) { */ public function fakeWith400And4xxRangeResponseEndpointAsyncWithHttpInfo($pet) { - $returnType = ''; + $returnType = '\OpenAPI\Client\Model\Pet'; $request = $this->fakeWith400And4xxRangeResponseEndpointRequest($pet); return $this->httpAsyncClient->sendAsyncRequest($request) ->then( function ($response) use ($returnType) { - return [null, $response->getStatusCode(), $response->getHeaders()]; + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; }, function (HttpException $exception) { $response = $exception->getResponse(); @@ -2618,11 +2674,12 @@ public function fakeWith400And4xxRangeResponseEndpointRequest($pet) * * @throws \OpenAPI\Client\ApiException on non-2xx response * @throws \InvalidArgumentException - * @return void + * @return \OpenAPI\Client\Model\Pet|\OpenAPI\Client\Model\ErrorResponse */ public function fakeWith400ResponseEndpoint($pet) { - $this->fakeWith400ResponseEndpointWithHttpInfo($pet); + list($response) = $this->fakeWith400ResponseEndpointWithHttpInfo($pet); + return $response; } /** @@ -2634,7 +2691,7 @@ public function fakeWith400ResponseEndpoint($pet) * * @throws \OpenAPI\Client\ApiException on non-2xx response * @throws \InvalidArgumentException - * @return array of null, HTTP status code, HTTP response headers (array of strings) + * @return array of \OpenAPI\Client\Model\Pet|\OpenAPI\Client\Model\ErrorResponse, HTTP status code, HTTP response headers (array of strings) */ public function fakeWith400ResponseEndpointWithHttpInfo($pet) { @@ -2667,9 +2724,48 @@ public function fakeWith400ResponseEndpointWithHttpInfo($pet) $statusCode = $response->getStatusCode(); - return [null, $statusCode, $response->getHeaders()]; + switch($statusCode) { + case 200: + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Pet', + $response, + ); + case 400: + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\ErrorResponse', + $response, + ); + } + + + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Pet', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\OpenAPI\Client\Model\Pet', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + throw $e; case 400: $data = ObjectSerializer::deserialize( $e->getResponseBody(), @@ -2717,13 +2813,23 @@ function ($response) { */ public function fakeWith400ResponseEndpointAsyncWithHttpInfo($pet) { - $returnType = ''; + $returnType = '\OpenAPI\Client\Model\Pet'; $request = $this->fakeWith400ResponseEndpointRequest($pet); return $this->httpAsyncClient->sendAsyncRequest($request) ->then( function ($response) use ($returnType) { - return [null, $response->getStatusCode(), $response->getHeaders()]; + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; }, function (HttpException $exception) { $response = $exception->getResponse(); @@ -2835,11 +2941,12 @@ public function fakeWith400ResponseEndpointRequest($pet) * * @throws \OpenAPI\Client\ApiException on non-2xx response * @throws \InvalidArgumentException - * @return void + * @return \OpenAPI\Client\Model\Pet|\OpenAPI\Client\Model\ErrorResponse */ public function fakeWith4xxRangeResponseEndpoint($pet) { - $this->fakeWith4xxRangeResponseEndpointWithHttpInfo($pet); + list($response) = $this->fakeWith4xxRangeResponseEndpointWithHttpInfo($pet); + return $response; } /** @@ -2851,7 +2958,7 @@ public function fakeWith4xxRangeResponseEndpoint($pet) * * @throws \OpenAPI\Client\ApiException on non-2xx response * @throws \InvalidArgumentException - * @return array of null, HTTP status code, HTTP response headers (array of strings) + * @return array of \OpenAPI\Client\Model\Pet|\OpenAPI\Client\Model\ErrorResponse, HTTP status code, HTTP response headers (array of strings) */ public function fakeWith4xxRangeResponseEndpointWithHttpInfo($pet) { @@ -2884,9 +2991,49 @@ public function fakeWith4xxRangeResponseEndpointWithHttpInfo($pet) $statusCode = $response->getStatusCode(); - return [null, $statusCode, $response->getHeaders()]; + switch($statusCode) { + case 200: + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Pet', + $response, + ); + + } + + if ($this->responseWithinRangeCode('4xx', $statusCode)) { + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\ErrorResponse', + $response, + ); + } + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Pet', + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\OpenAPI\Client\Model\Pet', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + throw $e; } @@ -2936,13 +3083,23 @@ function ($response) { */ public function fakeWith4xxRangeResponseEndpointAsyncWithHttpInfo($pet) { - $returnType = ''; + $returnType = '\OpenAPI\Client\Model\Pet'; $request = $this->fakeWith4xxRangeResponseEndpointRequest($pet); return $this->httpAsyncClient->sendAsyncRequest($request) ->then( function ($response) use ($returnType) { - return [null, $response->getStatusCode(), $response->getHeaders()]; + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; }, function (HttpException $exception) { $response = $exception->getResponse(); diff --git a/samples/client/petstore/php/psr-18/lib/FormDataProcessor.php b/samples/client/petstore/php/psr-18/lib/FormDataProcessor.php new file mode 100644 index 000000000000..c416f584e6aa --- /dev/null +++ b/samples/client/petstore/php/psr-18/lib/FormDataProcessor.php @@ -0,0 +1,242 @@ + $values the value of the form parameter + * + * @return array [key => value] of formdata + */ + public function prepare(array $values): array + { + $this->has_file = false; + $result = []; + + foreach ($values as $k => $v) { + if ($v === null) { + continue; + } + + $result[$k] = $this->makeFormSafe($v); + } + + return $result; + } + + /** + * Flattens a multi-level array of data and generates a single-level array + * compatible with formdata - a single-level array where the keys use bracket + * notation to signify nested data. + * + * credit: https://github.com/FranBar1966/FlatPHP + */ + public static function flatten(array $source, string $start = ''): array + { + $opt = [ + 'prefix' => '[', + 'suffix' => ']', + 'suffix-end' => true, + 'prefix-list' => '[', + 'suffix-list' => ']', + 'suffix-list-end' => true, + ]; + + if ($start === '') { + $currentPrefix = ''; + $currentSuffix = ''; + $currentSuffixEnd = false; + } elseif (array_is_list($source)) { + $currentPrefix = $opt['prefix-list']; + $currentSuffix = $opt['suffix-list']; + $currentSuffixEnd = $opt['suffix-list-end']; + } else { + $currentPrefix = $opt['prefix']; + $currentSuffix = $opt['suffix']; + $currentSuffixEnd = $opt['suffix-end']; + } + + $currentName = $start; + $result = []; + + foreach ($source as $key => $val) { + $currentName .= $currentPrefix.$key; + + if (is_array($val) && !empty($val)) { + $currentName .= $currentSuffix; + $result += self::flatten($val, $currentName); + } else { + if ($currentSuffixEnd) { + $currentName .= $currentSuffix; + } + + $result[$currentName] = ObjectSerializer::toString($val); + } + + $currentName = $start; + } + + return $result; + } + + /** + * formdata must be limited to scalars or arrays of scalar values, + * or a resource for a file upload. Here we iterate through all available + * data and identify how to handle each scenario + */ + protected function makeFormSafe($value) + { + if ($value instanceof SplFileObject) { + return $this->processFiles([$value])[0]; + } + + if (is_resource($value)) { + $this->has_file = true; + + return $value; + } + + if ($value instanceof ModelInterface) { + return $this->processModel($value); + } + + if (is_array($value) || (is_object($value) && !$value instanceof \DateTimeInterface)) { + $data = []; + + foreach ($value as $k => $v) { + $data[$k] = $this->makeFormSafe($v); + } + + return $data; + } + + return ObjectSerializer::toString($value); + } + + /** + * We are able to handle nested ModelInterface. We do not simply call + * json_decode(json_encode()) because any given model may have binary data + * or other data that cannot be serialized to a JSON string + */ + protected function processModel(ModelInterface $model): array + { + $result = []; + + foreach ($model::openAPITypes() as $name => $type) { + $value = $model->offsetGet($name); + + if ($value === null) { + continue; + } + + if (strpos($type, '\SplFileObject') !== false) { + $file = is_array($value) ? $value : [$value]; + $result[$name] = $this->processFiles($file); + + continue; + } + + if ($value instanceof ModelInterface) { + $result[$name] = $this->processModel($value); + + continue; + } + + if (is_array($value) || is_object($value)) { + $result[$name] = $this->makeFormSafe($value); + + continue; + } + + $result[$name] = ObjectSerializer::toString($value); + } + + return $result; + } + + /** + * Handle file data + */ + protected function processFiles(array $files): array + { + $this->has_file = true; + + $result = []; + + foreach ($files as $i => $file) { + if (is_array($file)) { + $result[$i] = $this->processFiles($file); + + continue; + } + + if ($file instanceof StreamInterface) { + $result[$i] = $file; + + continue; + } + + if ($file instanceof SplFileObject) { + $result[$i] = $this->tryFopen($file); + } + } + + return $result; + } + + private function tryFopen(SplFileObject $file) + { + return Utils::tryFopen($file->getRealPath(), 'rb'); + } +} diff --git a/samples/client/petstore/php/psr-18/lib/Model/ErrorResponse.php b/samples/client/petstore/php/psr-18/lib/Model/ErrorResponse.php index 1e9c3940003f..458660568ffd 100644 --- a/samples/client/petstore/php/psr-18/lib/Model/ErrorResponse.php +++ b/samples/client/petstore/php/psr-18/lib/Model/ErrorResponse.php @@ -2,7 +2,7 @@ /** * ErrorResponse * - * PHP version 7.4 + * PHP version 8.1 * * @category Class * @package OpenAPI\Client From b1623f790ebd9cd11d4d90abe9bc8a46aba0a6e8 Mon Sep 17 00:00:00 2001 From: Juan Treminio Date: Sat, 29 Mar 2025 13:05:57 -0500 Subject: [PATCH 3/8] Fix diff; update php-nextgen sample --- ...ith-fake-endpoints-models-for-testing.yaml | 76 ++ .../.openapi-generator/FILES | 3 + .../php-nextgen/OpenAPIClient-php/README.md | 4 + .../OpenAPIClient-php/docs/Api/FakeApi.md | 165 ++++ .../docs/Model/ErrorResponse.md | 10 + .../OpenAPIClient-php/src/Api/FakeApi.php | 903 ++++++++++++++++++ .../src/Model/ErrorResponse.php} | 126 ++- .../tests/Model/ErrorResponseTest.php | 97 ++ .../lib/Model/ErrorResponse.php | 2 +- .../psr-18/lib/Model/ErrorRangeResponse.php | 443 --------- .../php/psr-18/lib/Model/ErrorResponse.php | 2 +- 11 files changed, 1322 insertions(+), 509 deletions(-) create mode 100644 samples/client/petstore/php-nextgen/OpenAPIClient-php/docs/Model/ErrorResponse.md rename samples/client/petstore/{php/OpenAPIClient-php/lib/Model/ErrorRangeResponse.php => php-nextgen/OpenAPIClient-php/src/Model/ErrorResponse.php} (75%) create mode 100644 samples/client/petstore/php-nextgen/OpenAPIClient-php/tests/Model/ErrorResponseTest.php delete mode 100644 samples/client/petstore/php/psr-18/lib/Model/ErrorRangeResponse.php diff --git a/modules/openapi-generator/src/test/resources/3_0/php-nextgen/petstore-with-fake-endpoints-models-for-testing.yaml b/modules/openapi-generator/src/test/resources/3_0/php-nextgen/petstore-with-fake-endpoints-models-for-testing.yaml index 81e7a7ca407d..c662c097e3a5 100644 --- a/modules/openapi-generator/src/test/resources/3_0/php-nextgen/petstore-with-fake-endpoints-models-for-testing.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/php-nextgen/petstore-with-fake-endpoints-models-for-testing.yaml @@ -1339,6 +1339,75 @@ paths: application/json: schema: $ref: '#/components/schemas/EnumClass' + /fake/with_400_response/endpoint: + post: + tags: + - fake + summary: test endpoint with 400 response http code with dataType + operationId: fake-with_400_response-endpoint + responses: + 200: + description: Valid status value + content: + application/json: + schema: + $ref: '#/components/schemas/Pet' + '400': + description: Invalid status value + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorResponse' + requestBody: + $ref: '#/components/requestBodies/Pet' + /fake/with_4xx_range_response/endpoint: + post: + tags: + - fake + summary: test endpoint with 400-499 range response http code with dataType + operationId: fake-with_4xx_range_response-endpoint + responses: + 200: + description: Valid status value + content: + application/json: + schema: + $ref: '#/components/schemas/Pet' + '4xx': + description: Range of HTTP code 400-499 + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorResponse' + requestBody: + $ref: '#/components/requestBodies/Pet' + /fake/with_400_and_4xx_range_response/endpoint: + post: + tags: + - fake + summary: test endpoint with 400 and 400-499 range response http code with dataType + operationId: fake-with_400_and_4xx_range_response-endpoint + responses: + 200: + description: Valid status value + content: + application/json: + schema: + $ref: '#/components/schemas/Pet' + '400': + description: Invalid status value + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorResponse' + '4xx': + description: Range of HTTP code 400-499 + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorResponse' + requestBody: + $ref: '#/components/requestBodies/Pet' servers: - url: 'http://{server}.swagger.io:{port}/v2' description: petstore server @@ -2118,3 +2187,10 @@ components: - The word one - The digit two - The digit three prefixed by a space + ErrorResponse: + type: object + properties: + response_code: + type: integer + error: + type: string diff --git a/samples/client/petstore/php-nextgen/OpenAPIClient-php/.openapi-generator/FILES b/samples/client/petstore/php-nextgen/OpenAPIClient-php/.openapi-generator/FILES index 2f93e8839383..3dbde1d34a3b 100644 --- a/samples/client/petstore/php-nextgen/OpenAPIClient-php/.openapi-generator/FILES +++ b/samples/client/petstore/php-nextgen/OpenAPIClient-php/.openapi-generator/FILES @@ -30,6 +30,7 @@ docs/Model/EnumArrays.md docs/Model/EnumClass.md docs/Model/EnumTest.md docs/Model/EnumWithNameAndDescription.md +docs/Model/ErrorResponse.md docs/Model/FakeBigDecimalMap200Response.md docs/Model/File.md docs/Model/FileSchemaTestClass.md @@ -94,6 +95,7 @@ src/Model/EnumArrays.php src/Model/EnumClass.php src/Model/EnumTest.php src/Model/EnumWithNameAndDescription.php +src/Model/ErrorResponse.php src/Model/FakeBigDecimalMap200Response.php src/Model/File.php src/Model/FileSchemaTestClass.php @@ -128,3 +130,4 @@ src/Model/Tag.php src/Model/TestInlineFreeformAdditionalPropertiesRequest.php src/Model/User.php src/ObjectSerializer.php +tests/Model/ErrorResponseTest.php diff --git a/samples/client/petstore/php-nextgen/OpenAPIClient-php/README.md b/samples/client/petstore/php-nextgen/OpenAPIClient-php/README.md index a58f453c3355..caaaf3cdc901 100644 --- a/samples/client/petstore/php-nextgen/OpenAPIClient-php/README.md +++ b/samples/client/petstore/php-nextgen/OpenAPIClient-php/README.md @@ -82,6 +82,9 @@ Class | Method | HTTP request | Description *FakeApi* | [**fakeOuterNumberSerialize**](docs/Api/FakeApi.md#fakeouternumberserialize) | **POST** /fake/outer/number | *FakeApi* | [**fakeOuterStringSerialize**](docs/Api/FakeApi.md#fakeouterstringserialize) | **POST** /fake/outer/string | *FakeApi* | [**fakePropertyEnumIntegerSerialize**](docs/Api/FakeApi.md#fakepropertyenumintegerserialize) | **POST** /fake/property/enum-int | +*FakeApi* | [**fakeWith400And4xxRangeResponseEndpoint**](docs/Api/FakeApi.md#fakewith400and4xxrangeresponseendpoint) | **POST** /fake/with_400_and_4xx_range_response/endpoint | test endpoint with 400 and 400-499 range response http code with dataType +*FakeApi* | [**fakeWith400ResponseEndpoint**](docs/Api/FakeApi.md#fakewith400responseendpoint) | **POST** /fake/with_400_response/endpoint | test endpoint with 400 response http code with dataType +*FakeApi* | [**fakeWith4xxRangeResponseEndpoint**](docs/Api/FakeApi.md#fakewith4xxrangeresponseendpoint) | **POST** /fake/with_4xx_range_response/endpoint | test endpoint with 400-499 range response http code with dataType *FakeApi* | [**testAdditionalPropertiesReference**](docs/Api/FakeApi.md#testadditionalpropertiesreference) | **POST** /fake/additionalProperties-reference | test referenced additionalProperties *FakeApi* | [**testBodyWithBinary**](docs/Api/FakeApi.md#testbodywithbinary) | **PUT** /fake/body-with-binary | *FakeApi* | [**testBodyWithFileSchema**](docs/Api/FakeApi.md#testbodywithfileschema) | **PUT** /fake/body-with-file-schema | @@ -140,6 +143,7 @@ Class | Method | HTTP request | Description - [EnumClass](docs/Model/EnumClass.md) - [EnumTest](docs/Model/EnumTest.md) - [EnumWithNameAndDescription](docs/Model/EnumWithNameAndDescription.md) +- [ErrorResponse](docs/Model/ErrorResponse.md) - [FakeBigDecimalMap200Response](docs/Model/FakeBigDecimalMap200Response.md) - [File](docs/Model/File.md) - [FileSchemaTestClass](docs/Model/FileSchemaTestClass.md) diff --git a/samples/client/petstore/php-nextgen/OpenAPIClient-php/docs/Api/FakeApi.md b/samples/client/petstore/php-nextgen/OpenAPIClient-php/docs/Api/FakeApi.md index f9994a6971d8..23e7e2bb8dcb 100644 --- a/samples/client/petstore/php-nextgen/OpenAPIClient-php/docs/Api/FakeApi.md +++ b/samples/client/petstore/php-nextgen/OpenAPIClient-php/docs/Api/FakeApi.md @@ -13,6 +13,9 @@ All URIs are relative to http://petstore.swagger.io:80/v2, except if the operati | [**fakeOuterNumberSerialize()**](FakeApi.md#fakeOuterNumberSerialize) | **POST** /fake/outer/number | | | [**fakeOuterStringSerialize()**](FakeApi.md#fakeOuterStringSerialize) | **POST** /fake/outer/string | | | [**fakePropertyEnumIntegerSerialize()**](FakeApi.md#fakePropertyEnumIntegerSerialize) | **POST** /fake/property/enum-int | | +| [**fakeWith400And4xxRangeResponseEndpoint()**](FakeApi.md#fakeWith400And4xxRangeResponseEndpoint) | **POST** /fake/with_400_and_4xx_range_response/endpoint | test endpoint with 400 and 400-499 range response http code with dataType | +| [**fakeWith400ResponseEndpoint()**](FakeApi.md#fakeWith400ResponseEndpoint) | **POST** /fake/with_400_response/endpoint | test endpoint with 400 response http code with dataType | +| [**fakeWith4xxRangeResponseEndpoint()**](FakeApi.md#fakeWith4xxRangeResponseEndpoint) | **POST** /fake/with_4xx_range_response/endpoint | test endpoint with 400-499 range response http code with dataType | | [**testAdditionalPropertiesReference()**](FakeApi.md#testAdditionalPropertiesReference) | **POST** /fake/additionalProperties-reference | test referenced additionalProperties | | [**testBodyWithBinary()**](FakeApi.md#testBodyWithBinary) | **PUT** /fake/body-with-binary | | | [**testBodyWithFileSchema()**](FakeApi.md#testBodyWithFileSchema) | **PUT** /fake/body-with-file-schema | | @@ -530,6 +533,168 @@ No authorization required [[Back to Model list]](../../README.md#models) [[Back to README]](../../README.md) +## `fakeWith400And4xxRangeResponseEndpoint()` + +```php +fakeWith400And4xxRangeResponseEndpoint($pet): \OpenAPI\Client\Model\Pet +``` + +test endpoint with 400 and 400-499 range response http code with dataType + +### Example + +```php +fakeWith400And4xxRangeResponseEndpoint($pet); + print_r($result); +} catch (Exception $e) { + echo 'Exception when calling FakeApi->fakeWith400And4xxRangeResponseEndpoint: ', $e->getMessage(), PHP_EOL; +} +``` + +### Parameters + +| Name | Type | Description | Notes | +| ------------- | ------------- | ------------- | ------------- | +| **pet** | [**\OpenAPI\Client\Model\Pet**](../Model/Pet.md)| Pet object that needs to be added to the store | | + +### Return type + +[**\OpenAPI\Client\Model\Pet**](../Model/Pet.md) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: `application/json`, `application/xml` +- **Accept**: `application/json` + +[[Back to top]](#) [[Back to API list]](../../README.md#endpoints) +[[Back to Model list]](../../README.md#models) +[[Back to README]](../../README.md) + +## `fakeWith400ResponseEndpoint()` + +```php +fakeWith400ResponseEndpoint($pet): \OpenAPI\Client\Model\Pet +``` + +test endpoint with 400 response http code with dataType + +### Example + +```php +fakeWith400ResponseEndpoint($pet); + print_r($result); +} catch (Exception $e) { + echo 'Exception when calling FakeApi->fakeWith400ResponseEndpoint: ', $e->getMessage(), PHP_EOL; +} +``` + +### Parameters + +| Name | Type | Description | Notes | +| ------------- | ------------- | ------------- | ------------- | +| **pet** | [**\OpenAPI\Client\Model\Pet**](../Model/Pet.md)| Pet object that needs to be added to the store | | + +### Return type + +[**\OpenAPI\Client\Model\Pet**](../Model/Pet.md) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: `application/json`, `application/xml` +- **Accept**: `application/json` + +[[Back to top]](#) [[Back to API list]](../../README.md#endpoints) +[[Back to Model list]](../../README.md#models) +[[Back to README]](../../README.md) + +## `fakeWith4xxRangeResponseEndpoint()` + +```php +fakeWith4xxRangeResponseEndpoint($pet): \OpenAPI\Client\Model\Pet +``` + +test endpoint with 400-499 range response http code with dataType + +### Example + +```php +fakeWith4xxRangeResponseEndpoint($pet); + print_r($result); +} catch (Exception $e) { + echo 'Exception when calling FakeApi->fakeWith4xxRangeResponseEndpoint: ', $e->getMessage(), PHP_EOL; +} +``` + +### Parameters + +| Name | Type | Description | Notes | +| ------------- | ------------- | ------------- | ------------- | +| **pet** | [**\OpenAPI\Client\Model\Pet**](../Model/Pet.md)| Pet object that needs to be added to the store | | + +### Return type + +[**\OpenAPI\Client\Model\Pet**](../Model/Pet.md) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: `application/json`, `application/xml` +- **Accept**: `application/json` + +[[Back to top]](#) [[Back to API list]](../../README.md#endpoints) +[[Back to Model list]](../../README.md#models) +[[Back to README]](../../README.md) + ## `testAdditionalPropertiesReference()` ```php diff --git a/samples/client/petstore/php-nextgen/OpenAPIClient-php/docs/Model/ErrorResponse.md b/samples/client/petstore/php-nextgen/OpenAPIClient-php/docs/Model/ErrorResponse.md new file mode 100644 index 000000000000..a6db5fe293ef --- /dev/null +++ b/samples/client/petstore/php-nextgen/OpenAPIClient-php/docs/Model/ErrorResponse.md @@ -0,0 +1,10 @@ +# # ErrorResponse + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**response_code** | **int** | | [optional] +**error** | **string** | | [optional] + +[[Back to Model list]](../../README.md#models) [[Back to API list]](../../README.md#endpoints) [[Back to README]](../../README.md) diff --git a/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/FakeApi.php b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/FakeApi.php index 3d64c0790964..65824deacb5a 100644 --- a/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/FakeApi.php +++ b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/FakeApi.php @@ -100,6 +100,18 @@ class FakeApi 'fakePropertyEnumIntegerSerialize' => [ 'application/json', ], + 'fakeWith400And4xxRangeResponseEndpoint' => [ + 'application/json', + 'application/xml', + ], + 'fakeWith400ResponseEndpoint' => [ + 'application/json', + 'application/xml', + ], + 'fakeWith4xxRangeResponseEndpoint' => [ + 'application/json', + 'application/xml', + ], 'testAdditionalPropertiesReference' => [ 'application/json', ], @@ -2606,6 +2618,897 @@ public function fakePropertyEnumIntegerSerializeRequest( ); } + /** + * Operation fakeWith400And4xxRangeResponseEndpoint + * + * test endpoint with 400 and 400-499 range response http code with dataType + * + * @param \OpenAPI\Client\Model\Pet $pet Pet object that needs to be added to the store (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeWith400And4xxRangeResponseEndpoint'] to see the possible values for this operation + * + * @throws ApiException on non-2xx response or if the response body is not in the expected format + * @throws InvalidArgumentException + * @return \OpenAPI\Client\Model\Pet|\OpenAPI\Client\Model\ErrorResponse + */ + public function fakeWith400And4xxRangeResponseEndpoint( + \OpenAPI\Client\Model\Pet $pet, + string $contentType = self::contentTypes['fakeWith400And4xxRangeResponseEndpoint'][0] + ): \OpenAPI\Client\Model\Pet|\OpenAPI\Client\Model\ErrorResponse + { + list($response) = $this->fakeWith400And4xxRangeResponseEndpointWithHttpInfo($pet, $contentType); + return $response; + } + + /** + * Operation fakeWith400And4xxRangeResponseEndpointWithHttpInfo + * + * test endpoint with 400 and 400-499 range response http code with dataType + * + * @param \OpenAPI\Client\Model\Pet $pet Pet object that needs to be added to the store (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeWith400And4xxRangeResponseEndpoint'] to see the possible values for this operation + * + * @throws ApiException on non-2xx response or if the response body is not in the expected format + * @throws InvalidArgumentException + * @return array of \OpenAPI\Client\Model\Pet|\OpenAPI\Client\Model\ErrorResponse|\OpenAPI\Client\Model\ErrorResponse, HTTP status code, HTTP response headers (array of strings) + */ + public function fakeWith400And4xxRangeResponseEndpointWithHttpInfo( + \OpenAPI\Client\Model\Pet $pet, + string $contentType = self::contentTypes['fakeWith400And4xxRangeResponseEndpoint'][0] + ): array + { + $request = $this->fakeWith400And4xxRangeResponseEndpointRequest($pet, $contentType); + + try { + $options = $this->createHttpClientOption(); + try { + $response = $this->client->send($request, $options); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null, + $e->getResponse() ? (string) $e->getResponse()->getBody() : null + ); + } catch (ConnectException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + null, + null + ); + } + + $statusCode = $response->getStatusCode(); + + switch($statusCode) { + case 200: + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Pet', + $response, + ); + case 400: + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\ErrorResponse', + $response, + ); + + } + + if ($this->responseWithinRangeCode('4xx', $statusCode)) { + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\ErrorResponse', + $response, + ); + } + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Pet', + $response, + ); + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\OpenAPI\Client\Model\Pet', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + throw $e; + case 400: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\OpenAPI\Client\Model\ErrorResponse', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + throw $e; + + } + + if ($this->responseWithinRangeCode('4xx', $e->getCode())) { + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\OpenAPI\Client\Model\ErrorResponse', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + throw $e; + } + throw $e; + } + } + + /** + * Operation fakeWith400And4xxRangeResponseEndpointAsync + * + * test endpoint with 400 and 400-499 range response http code with dataType + * + * @param \OpenAPI\Client\Model\Pet $pet Pet object that needs to be added to the store (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeWith400And4xxRangeResponseEndpoint'] to see the possible values for this operation + * + * @throws InvalidArgumentException + * @return PromiseInterface + */ + public function fakeWith400And4xxRangeResponseEndpointAsync( + \OpenAPI\Client\Model\Pet $pet, + string $contentType = self::contentTypes['fakeWith400And4xxRangeResponseEndpoint'][0] + ): PromiseInterface + { + return $this->fakeWith400And4xxRangeResponseEndpointAsyncWithHttpInfo($pet, $contentType) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation fakeWith400And4xxRangeResponseEndpointAsyncWithHttpInfo + * + * test endpoint with 400 and 400-499 range response http code with dataType + * + * @param \OpenAPI\Client\Model\Pet $pet Pet object that needs to be added to the store (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeWith400And4xxRangeResponseEndpoint'] to see the possible values for this operation + * + * @throws InvalidArgumentException + * @return PromiseInterface + */ + public function fakeWith400And4xxRangeResponseEndpointAsyncWithHttpInfo( + \OpenAPI\Client\Model\Pet $pet, + string $contentType = self::contentTypes['fakeWith400And4xxRangeResponseEndpoint'][0] + ): PromiseInterface + { + $returnType = '\OpenAPI\Client\Model\Pet'; + $request = $this->fakeWith400And4xxRangeResponseEndpointRequest($pet, $contentType); + + return $this->client + ->sendAsync($request, $this->createHttpClientOption()) + ->then( + function ($response) use ($returnType) { + if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + 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( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $exception->getRequest()->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + ); + } + + /** + * Create request for operation 'fakeWith400And4xxRangeResponseEndpoint' + * + * @param \OpenAPI\Client\Model\Pet $pet Pet object that needs to be added to the store (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeWith400And4xxRangeResponseEndpoint'] to see the possible values for this operation + * + * @throws InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + public function fakeWith400And4xxRangeResponseEndpointRequest( + \OpenAPI\Client\Model\Pet $pet, + string $contentType = self::contentTypes['fakeWith400And4xxRangeResponseEndpoint'][0] + ): Request + { + + // verify the required parameter 'pet' is set + if ($pet === null || (is_array($pet) && count($pet) === 0)) { + throw new InvalidArgumentException( + 'Missing the required parameter $pet when calling fakeWith400And4xxRangeResponseEndpoint' + ); + } + + + $resourcePath = '/fake/with_400_and_4xx_range_response/endpoint'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + + + + + $headers = $this->headerSelector->selectHeaders( + ['application/json', ], + $contentType, + $multipart + ); + + // for model (json/xml) + if (isset($pet)) { + if (stripos($headers['Content-Type'], 'application/json') !== false) { + # if Content-Type contains "application/json", json_encode the body + $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($pet)); + } else { + $httpBody = $pet; + } + } elseif (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; + foreach ($formParamValueItems as $formParamValueItem) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValueItem + ]; + } + } + // for HTTP post (form) + $httpBody = new MultipartStream($multipartContents); + + } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { + # if Content-Type contains "application/json", json_encode the form parameters + $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + } else { + // for HTTP post (form) + $httpBody = ObjectSerializer::buildQuery($formParams); + } + } + + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $operationHost = $this->config->getHost(); + $query = ObjectSerializer::buildQuery($queryParams); + return new Request( + 'POST', + $operationHost . $resourcePath . ($query ? "?{$query}" : ''), + $headers, + $httpBody + ); + } + + /** + * Operation fakeWith400ResponseEndpoint + * + * test endpoint with 400 response http code with dataType + * + * @param \OpenAPI\Client\Model\Pet $pet Pet object that needs to be added to the store (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeWith400ResponseEndpoint'] to see the possible values for this operation + * + * @throws ApiException on non-2xx response or if the response body is not in the expected format + * @throws InvalidArgumentException + * @return \OpenAPI\Client\Model\Pet|\OpenAPI\Client\Model\ErrorResponse + */ + public function fakeWith400ResponseEndpoint( + \OpenAPI\Client\Model\Pet $pet, + string $contentType = self::contentTypes['fakeWith400ResponseEndpoint'][0] + ): \OpenAPI\Client\Model\Pet|\OpenAPI\Client\Model\ErrorResponse + { + list($response) = $this->fakeWith400ResponseEndpointWithHttpInfo($pet, $contentType); + return $response; + } + + /** + * Operation fakeWith400ResponseEndpointWithHttpInfo + * + * test endpoint with 400 response http code with dataType + * + * @param \OpenAPI\Client\Model\Pet $pet Pet object that needs to be added to the store (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeWith400ResponseEndpoint'] to see the possible values for this operation + * + * @throws ApiException on non-2xx response or if the response body is not in the expected format + * @throws InvalidArgumentException + * @return array of \OpenAPI\Client\Model\Pet|\OpenAPI\Client\Model\ErrorResponse, HTTP status code, HTTP response headers (array of strings) + */ + public function fakeWith400ResponseEndpointWithHttpInfo( + \OpenAPI\Client\Model\Pet $pet, + string $contentType = self::contentTypes['fakeWith400ResponseEndpoint'][0] + ): array + { + $request = $this->fakeWith400ResponseEndpointRequest($pet, $contentType); + + try { + $options = $this->createHttpClientOption(); + try { + $response = $this->client->send($request, $options); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null, + $e->getResponse() ? (string) $e->getResponse()->getBody() : null + ); + } catch (ConnectException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + null, + null + ); + } + + $statusCode = $response->getStatusCode(); + + switch($statusCode) { + case 200: + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Pet', + $response, + ); + case 400: + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\ErrorResponse', + $response, + ); + } + + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Pet', + $response, + ); + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\OpenAPI\Client\Model\Pet', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + throw $e; + case 400: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\OpenAPI\Client\Model\ErrorResponse', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + throw $e; + } + + throw $e; + } + } + + /** + * Operation fakeWith400ResponseEndpointAsync + * + * test endpoint with 400 response http code with dataType + * + * @param \OpenAPI\Client\Model\Pet $pet Pet object that needs to be added to the store (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeWith400ResponseEndpoint'] to see the possible values for this operation + * + * @throws InvalidArgumentException + * @return PromiseInterface + */ + public function fakeWith400ResponseEndpointAsync( + \OpenAPI\Client\Model\Pet $pet, + string $contentType = self::contentTypes['fakeWith400ResponseEndpoint'][0] + ): PromiseInterface + { + return $this->fakeWith400ResponseEndpointAsyncWithHttpInfo($pet, $contentType) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation fakeWith400ResponseEndpointAsyncWithHttpInfo + * + * test endpoint with 400 response http code with dataType + * + * @param \OpenAPI\Client\Model\Pet $pet Pet object that needs to be added to the store (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeWith400ResponseEndpoint'] to see the possible values for this operation + * + * @throws InvalidArgumentException + * @return PromiseInterface + */ + public function fakeWith400ResponseEndpointAsyncWithHttpInfo( + \OpenAPI\Client\Model\Pet $pet, + string $contentType = self::contentTypes['fakeWith400ResponseEndpoint'][0] + ): PromiseInterface + { + $returnType = '\OpenAPI\Client\Model\Pet'; + $request = $this->fakeWith400ResponseEndpointRequest($pet, $contentType); + + return $this->client + ->sendAsync($request, $this->createHttpClientOption()) + ->then( + function ($response) use ($returnType) { + if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + 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( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $exception->getRequest()->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + ); + } + + /** + * Create request for operation 'fakeWith400ResponseEndpoint' + * + * @param \OpenAPI\Client\Model\Pet $pet Pet object that needs to be added to the store (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeWith400ResponseEndpoint'] to see the possible values for this operation + * + * @throws InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + public function fakeWith400ResponseEndpointRequest( + \OpenAPI\Client\Model\Pet $pet, + string $contentType = self::contentTypes['fakeWith400ResponseEndpoint'][0] + ): Request + { + + // verify the required parameter 'pet' is set + if ($pet === null || (is_array($pet) && count($pet) === 0)) { + throw new InvalidArgumentException( + 'Missing the required parameter $pet when calling fakeWith400ResponseEndpoint' + ); + } + + + $resourcePath = '/fake/with_400_response/endpoint'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + + + + + $headers = $this->headerSelector->selectHeaders( + ['application/json', ], + $contentType, + $multipart + ); + + // for model (json/xml) + if (isset($pet)) { + if (stripos($headers['Content-Type'], 'application/json') !== false) { + # if Content-Type contains "application/json", json_encode the body + $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($pet)); + } else { + $httpBody = $pet; + } + } elseif (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; + foreach ($formParamValueItems as $formParamValueItem) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValueItem + ]; + } + } + // for HTTP post (form) + $httpBody = new MultipartStream($multipartContents); + + } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { + # if Content-Type contains "application/json", json_encode the form parameters + $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + } else { + // for HTTP post (form) + $httpBody = ObjectSerializer::buildQuery($formParams); + } + } + + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $operationHost = $this->config->getHost(); + $query = ObjectSerializer::buildQuery($queryParams); + return new Request( + 'POST', + $operationHost . $resourcePath . ($query ? "?{$query}" : ''), + $headers, + $httpBody + ); + } + + /** + * Operation fakeWith4xxRangeResponseEndpoint + * + * test endpoint with 400-499 range response http code with dataType + * + * @param \OpenAPI\Client\Model\Pet $pet Pet object that needs to be added to the store (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeWith4xxRangeResponseEndpoint'] to see the possible values for this operation + * + * @throws ApiException on non-2xx response or if the response body is not in the expected format + * @throws InvalidArgumentException + * @return \OpenAPI\Client\Model\Pet|\OpenAPI\Client\Model\ErrorResponse + */ + public function fakeWith4xxRangeResponseEndpoint( + \OpenAPI\Client\Model\Pet $pet, + string $contentType = self::contentTypes['fakeWith4xxRangeResponseEndpoint'][0] + ): \OpenAPI\Client\Model\Pet|\OpenAPI\Client\Model\ErrorResponse + { + list($response) = $this->fakeWith4xxRangeResponseEndpointWithHttpInfo($pet, $contentType); + return $response; + } + + /** + * Operation fakeWith4xxRangeResponseEndpointWithHttpInfo + * + * test endpoint with 400-499 range response http code with dataType + * + * @param \OpenAPI\Client\Model\Pet $pet Pet object that needs to be added to the store (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeWith4xxRangeResponseEndpoint'] to see the possible values for this operation + * + * @throws ApiException on non-2xx response or if the response body is not in the expected format + * @throws InvalidArgumentException + * @return array of \OpenAPI\Client\Model\Pet|\OpenAPI\Client\Model\ErrorResponse, HTTP status code, HTTP response headers (array of strings) + */ + public function fakeWith4xxRangeResponseEndpointWithHttpInfo( + \OpenAPI\Client\Model\Pet $pet, + string $contentType = self::contentTypes['fakeWith4xxRangeResponseEndpoint'][0] + ): array + { + $request = $this->fakeWith4xxRangeResponseEndpointRequest($pet, $contentType); + + try { + $options = $this->createHttpClientOption(); + try { + $response = $this->client->send($request, $options); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null, + $e->getResponse() ? (string) $e->getResponse()->getBody() : null + ); + } catch (ConnectException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + null, + null + ); + } + + $statusCode = $response->getStatusCode(); + + switch($statusCode) { + case 200: + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Pet', + $response, + ); + + } + + if ($this->responseWithinRangeCode('4xx', $statusCode)) { + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\ErrorResponse', + $response, + ); + } + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Pet', + $response, + ); + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\OpenAPI\Client\Model\Pet', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + throw $e; + + } + + if ($this->responseWithinRangeCode('4xx', $e->getCode())) { + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\OpenAPI\Client\Model\ErrorResponse', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + throw $e; + } + throw $e; + } + } + + /** + * Operation fakeWith4xxRangeResponseEndpointAsync + * + * test endpoint with 400-499 range response http code with dataType + * + * @param \OpenAPI\Client\Model\Pet $pet Pet object that needs to be added to the store (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeWith4xxRangeResponseEndpoint'] to see the possible values for this operation + * + * @throws InvalidArgumentException + * @return PromiseInterface + */ + public function fakeWith4xxRangeResponseEndpointAsync( + \OpenAPI\Client\Model\Pet $pet, + string $contentType = self::contentTypes['fakeWith4xxRangeResponseEndpoint'][0] + ): PromiseInterface + { + return $this->fakeWith4xxRangeResponseEndpointAsyncWithHttpInfo($pet, $contentType) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation fakeWith4xxRangeResponseEndpointAsyncWithHttpInfo + * + * test endpoint with 400-499 range response http code with dataType + * + * @param \OpenAPI\Client\Model\Pet $pet Pet object that needs to be added to the store (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeWith4xxRangeResponseEndpoint'] to see the possible values for this operation + * + * @throws InvalidArgumentException + * @return PromiseInterface + */ + public function fakeWith4xxRangeResponseEndpointAsyncWithHttpInfo( + \OpenAPI\Client\Model\Pet $pet, + string $contentType = self::contentTypes['fakeWith4xxRangeResponseEndpoint'][0] + ): PromiseInterface + { + $returnType = '\OpenAPI\Client\Model\Pet'; + $request = $this->fakeWith4xxRangeResponseEndpointRequest($pet, $contentType); + + return $this->client + ->sendAsync($request, $this->createHttpClientOption()) + ->then( + function ($response) use ($returnType) { + if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + 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( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $exception->getRequest()->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + ); + } + + /** + * Create request for operation 'fakeWith4xxRangeResponseEndpoint' + * + * @param \OpenAPI\Client\Model\Pet $pet Pet object that needs to be added to the store (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeWith4xxRangeResponseEndpoint'] to see the possible values for this operation + * + * @throws InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + public function fakeWith4xxRangeResponseEndpointRequest( + \OpenAPI\Client\Model\Pet $pet, + string $contentType = self::contentTypes['fakeWith4xxRangeResponseEndpoint'][0] + ): Request + { + + // verify the required parameter 'pet' is set + if ($pet === null || (is_array($pet) && count($pet) === 0)) { + throw new InvalidArgumentException( + 'Missing the required parameter $pet when calling fakeWith4xxRangeResponseEndpoint' + ); + } + + + $resourcePath = '/fake/with_4xx_range_response/endpoint'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + + + + + $headers = $this->headerSelector->selectHeaders( + ['application/json', ], + $contentType, + $multipart + ); + + // for model (json/xml) + if (isset($pet)) { + if (stripos($headers['Content-Type'], 'application/json') !== false) { + # if Content-Type contains "application/json", json_encode the body + $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($pet)); + } else { + $httpBody = $pet; + } + } elseif (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; + foreach ($formParamValueItems as $formParamValueItem) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValueItem + ]; + } + } + // for HTTP post (form) + $httpBody = new MultipartStream($multipartContents); + + } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { + # if Content-Type contains "application/json", json_encode the form parameters + $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + } else { + // for HTTP post (form) + $httpBody = ObjectSerializer::buildQuery($formParams); + } + } + + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $operationHost = $this->config->getHost(); + $query = ObjectSerializer::buildQuery($queryParams); + return new Request( + 'POST', + $operationHost . $resourcePath . ($query ? "?{$query}" : ''), + $headers, + $httpBody + ); + } + /** * Operation testAdditionalPropertiesReference * diff --git a/samples/client/petstore/php/OpenAPIClient-php/lib/Model/ErrorRangeResponse.php b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Model/ErrorResponse.php similarity index 75% rename from samples/client/petstore/php/OpenAPIClient-php/lib/Model/ErrorRangeResponse.php rename to samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Model/ErrorResponse.php index 8fef20574d1a..45fc8ad004d8 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/lib/Model/ErrorRangeResponse.php +++ b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Model/ErrorResponse.php @@ -1,10 +1,9 @@ + * @implements ArrayAccess */ -class ErrorRangeResponse implements ModelInterface, ArrayAccess, \JsonSerializable +class ErrorResponse implements ModelInterface, ArrayAccess, JsonSerializable { public const DISCRIMINATOR = null; @@ -49,14 +50,14 @@ class ErrorRangeResponse implements ModelInterface, ArrayAccess, \JsonSerializab * * @var string */ - protected static $openAPIModelName = 'ErrorRangeResponse'; + protected static string $openAPIModelName = 'ErrorResponse'; /** * Array of property to type mappings. Used for (de)serialization * - * @var string[] + * @var array */ - protected static $openAPITypes = [ + protected static array $openAPITypes = [ 'response_code' => 'int', 'error' => 'string' ]; @@ -64,11 +65,9 @@ class ErrorRangeResponse implements ModelInterface, ArrayAccess, \JsonSerializab /** * Array of property to format mappings. Used for (de)serialization * - * @var string[] - * @phpstan-var array - * @psalm-var array + * @var array */ - protected static $openAPIFormats = [ + protected static array $openAPIFormats = [ 'response_code' => null, 'error' => null ]; @@ -76,7 +75,7 @@ class ErrorRangeResponse implements ModelInterface, ArrayAccess, \JsonSerializab /** * Array of nullable properties. Used for (de)serialization * - * @var boolean[] + * @var array */ protected static array $openAPINullables = [ 'response_code' => false, @@ -86,16 +85,16 @@ class ErrorRangeResponse implements ModelInterface, ArrayAccess, \JsonSerializab /** * If a nullable field gets set to null, insert it here * - * @var boolean[] + * @var array */ protected array $openAPINullablesSetToNull = []; /** * Array of property to type mappings. Used for (de)serialization * - * @return array + * @return array */ - public static function openAPITypes() + public static function openAPITypes(): array { return self::$openAPITypes; } @@ -103,9 +102,9 @@ public static function openAPITypes() /** * Array of property to format mappings. Used for (de)serialization * - * @return array + * @return array */ - public static function openAPIFormats() + public static function openAPIFormats(): array { return self::$openAPIFormats; } @@ -113,7 +112,7 @@ public static function openAPIFormats() /** * Array of nullable properties * - * @return array + * @return array */ protected static function openAPINullables(): array { @@ -123,7 +122,7 @@ protected static function openAPINullables(): array /** * Array of nullable field names deliberately set to null * - * @return boolean[] + * @return array */ private function getOpenAPINullablesSetToNull(): array { @@ -133,7 +132,7 @@ private function getOpenAPINullablesSetToNull(): array /** * Setter - Array of nullable field names deliberately set to null * - * @param boolean[] $openAPINullablesSetToNull + * @param array $openAPINullablesSetToNull */ private function setOpenAPINullablesSetToNull(array $openAPINullablesSetToNull): void { @@ -166,9 +165,9 @@ public function isNullableSetToNull(string $property): bool * Array of attributes where the key is the local name, * and the value is the original name * - * @var string[] + * @var array */ - protected static $attributeMap = [ + protected static array $attributeMap = [ 'response_code' => 'response_code', 'error' => 'error' ]; @@ -176,9 +175,9 @@ public function isNullableSetToNull(string $property): bool /** * Array of attributes to setter functions (for deserialization of responses) * - * @var string[] + * @var array */ - protected static $setters = [ + protected static array $setters = [ 'response_code' => 'setResponseCode', 'error' => 'setError' ]; @@ -186,9 +185,9 @@ public function isNullableSetToNull(string $property): bool /** * Array of attributes to getter functions (for serialization of requests) * - * @var string[] + * @var array */ - protected static $getters = [ + protected static array $getters = [ 'response_code' => 'getResponseCode', 'error' => 'getError' ]; @@ -197,9 +196,9 @@ public function isNullableSetToNull(string $property): bool * Array of attributes where the key is the local name, * and the value is the original name * - * @return array + * @return array */ - public static function attributeMap() + public static function attributeMap(): array { return self::$attributeMap; } @@ -207,9 +206,9 @@ public static function attributeMap() /** * Array of attributes to setter functions (for deserialization of responses) * - * @return array + * @return array */ - public static function setters() + public static function setters(): array { return self::$setters; } @@ -217,9 +216,9 @@ public static function setters() /** * Array of attributes to getter functions (for serialization of requests) * - * @return array + * @return array */ - public static function getters() + public static function getters(): array { return self::$getters; } @@ -229,7 +228,7 @@ public static function getters() * * @return string */ - public function getModelName() + public function getModelName(): string { return self::$openAPIModelName; } @@ -238,15 +237,14 @@ public function getModelName() /** * Associative array for storing property values * - * @var mixed[] + * @var array */ - protected $container = []; + protected array $container = []; /** * Constructor * - * @param mixed[]|null $data Associated array of property values - * initializing the model + * @param array $data Associated array of property values initializing the model */ public function __construct(?array $data = null) { @@ -263,7 +261,7 @@ public function __construct(?array $data = null) * @param array $fields * @param mixed $defaultValue */ - private function setIfExists(string $variableName, array $fields, $defaultValue): void + private function setIfExists(string $variableName, array $fields, mixed $defaultValue): void { if (self::isNullable($variableName) && array_key_exists($variableName, $fields) && is_null($fields[$variableName])) { $this->openAPINullablesSetToNull[] = $variableName; @@ -275,9 +273,9 @@ private function setIfExists(string $variableName, array $fields, $defaultValue) /** * Show all the invalid properties with reasons. * - * @return array invalid properties with reasons + * @return string[] invalid properties with reasons */ - public function listInvalidProperties() + public function listInvalidProperties(): array { $invalidProperties = []; @@ -290,7 +288,7 @@ public function listInvalidProperties() * * @return bool True if all properties are valid */ - public function valid() + public function valid(): bool { return count($this->listInvalidProperties()) === 0; } @@ -301,7 +299,7 @@ public function valid() * * @return int|null */ - public function getResponseCode() + public function getResponseCode(): ?int { return $this->container['response_code']; } @@ -311,12 +309,12 @@ public function getResponseCode() * * @param int|null $response_code response_code * - * @return self + * @return $this */ - public function setResponseCode($response_code) + public function setResponseCode(?int $response_code): static { if (is_null($response_code)) { - throw new \InvalidArgumentException('non-nullable response_code cannot be null'); + throw new InvalidArgumentException('non-nullable response_code cannot be null'); } $this->container['response_code'] = $response_code; @@ -328,7 +326,7 @@ public function setResponseCode($response_code) * * @return string|null */ - public function getError() + public function getError(): ?string { return $this->container['error']; } @@ -338,12 +336,12 @@ public function getError() * * @param string|null $error error * - * @return self + * @return $this */ - public function setError($error) + public function setError(?string $error): static { if (is_null($error)) { - throw new \InvalidArgumentException('non-nullable error cannot be null'); + throw new InvalidArgumentException('non-nullable error cannot be null'); } $this->container['error'] = $error; @@ -356,7 +354,7 @@ public function setError($error) * * @return boolean */ - public function offsetExists($offset): bool + public function offsetExists(mixed $offset): bool { return isset($this->container[$offset]); } @@ -368,8 +366,8 @@ public function offsetExists($offset): bool * * @return mixed|null */ - #[\ReturnTypeWillChange] - public function offsetGet($offset) + #[ReturnTypeWillChange] + public function offsetGet(mixed $offset): mixed { return $this->container[$offset] ?? null; } @@ -382,7 +380,7 @@ public function offsetGet($offset) * * @return void */ - public function offsetSet($offset, $value): void + public function offsetSet(mixed $offset, mixed $value): void { if (is_null($offset)) { $this->container[] = $value; @@ -398,7 +396,7 @@ public function offsetSet($offset, $value): void * * @return void */ - public function offsetUnset($offset): void + public function offsetUnset(mixed $offset): void { unset($this->container[$offset]); } @@ -410,8 +408,8 @@ public function offsetUnset($offset): void * @return mixed Returns data which can be serialized by json_encode(), which is a value * of any type other than a resource. */ - #[\ReturnTypeWillChange] - public function jsonSerialize() + #[ReturnTypeWillChange] + public function jsonSerialize(): mixed { return ObjectSerializer::sanitizeForSerialization($this); } @@ -421,7 +419,7 @@ public function jsonSerialize() * * @return string */ - public function __toString() + public function __toString(): string { return json_encode( ObjectSerializer::sanitizeForSerialization($this), @@ -434,7 +432,7 @@ public function __toString() * * @return string */ - public function toHeaderValue() + public function toHeaderValue(): string { return json_encode(ObjectSerializer::sanitizeForSerialization($this)); } diff --git a/samples/client/petstore/php-nextgen/OpenAPIClient-php/tests/Model/ErrorResponseTest.php b/samples/client/petstore/php-nextgen/OpenAPIClient-php/tests/Model/ErrorResponseTest.php new file mode 100644 index 000000000000..8d74ef38d898 --- /dev/null +++ b/samples/client/petstore/php-nextgen/OpenAPIClient-php/tests/Model/ErrorResponseTest.php @@ -0,0 +1,97 @@ + - */ -class ErrorRangeResponse implements ModelInterface, ArrayAccess, \JsonSerializable -{ - public const DISCRIMINATOR = null; - - /** - * The original name of the model. - * - * @var string - */ - protected static $openAPIModelName = 'ErrorRangeResponse'; - - /** - * Array of property to type mappings. Used for (de)serialization - * - * @var string[] - */ - protected static $openAPITypes = [ - 'response_code' => 'int', - 'error' => 'string' - ]; - - /** - * Array of property to format mappings. Used for (de)serialization - * - * @var string[] - * @phpstan-var array - * @psalm-var array - */ - protected static $openAPIFormats = [ - 'response_code' => null, - 'error' => null - ]; - - /** - * Array of nullable properties. Used for (de)serialization - * - * @var boolean[] - */ - protected static array $openAPINullables = [ - 'response_code' => false, - 'error' => false - ]; - - /** - * If a nullable field gets set to null, insert it here - * - * @var boolean[] - */ - protected array $openAPINullablesSetToNull = []; - - /** - * Array of property to type mappings. Used for (de)serialization - * - * @return array - */ - public static function openAPITypes() - { - return self::$openAPITypes; - } - - /** - * Array of property to format mappings. Used for (de)serialization - * - * @return array - */ - public static function openAPIFormats() - { - return self::$openAPIFormats; - } - - /** - * Array of nullable properties - * - * @return array - */ - protected static function openAPINullables(): array - { - return self::$openAPINullables; - } - - /** - * Array of nullable field names deliberately set to null - * - * @return boolean[] - */ - private function getOpenAPINullablesSetToNull(): array - { - return $this->openAPINullablesSetToNull; - } - - /** - * Setter - Array of nullable field names deliberately set to null - * - * @param boolean[] $openAPINullablesSetToNull - */ - private function setOpenAPINullablesSetToNull(array $openAPINullablesSetToNull): void - { - $this->openAPINullablesSetToNull = $openAPINullablesSetToNull; - } - - /** - * Checks if a property is nullable - * - * @param string $property - * @return bool - */ - public static function isNullable(string $property): bool - { - return self::openAPINullables()[$property] ?? false; - } - - /** - * Checks if a nullable property is set to null. - * - * @param string $property - * @return bool - */ - public function isNullableSetToNull(string $property): bool - { - return in_array($property, $this->getOpenAPINullablesSetToNull(), true); - } - - /** - * Array of attributes where the key is the local name, - * and the value is the original name - * - * @var string[] - */ - protected static $attributeMap = [ - 'response_code' => 'response_code', - 'error' => 'error' - ]; - - /** - * Array of attributes to setter functions (for deserialization of responses) - * - * @var string[] - */ - protected static $setters = [ - 'response_code' => 'setResponseCode', - 'error' => 'setError' - ]; - - /** - * Array of attributes to getter functions (for serialization of requests) - * - * @var string[] - */ - protected static $getters = [ - 'response_code' => 'getResponseCode', - 'error' => 'getError' - ]; - - /** - * Array of attributes where the key is the local name, - * and the value is the original name - * - * @return array - */ - public static function attributeMap() - { - return self::$attributeMap; - } - - /** - * Array of attributes to setter functions (for deserialization of responses) - * - * @return array - */ - public static function setters() - { - return self::$setters; - } - - /** - * Array of attributes to getter functions (for serialization of requests) - * - * @return array - */ - public static function getters() - { - return self::$getters; - } - - /** - * The original name of the model. - * - * @return string - */ - public function getModelName() - { - return self::$openAPIModelName; - } - - - /** - * Associative array for storing property values - * - * @var mixed[] - */ - protected $container = []; - - /** - * Constructor - * - * @param mixed[]|null $data Associated array of property values - * initializing the model - */ - public function __construct(?array $data = null) - { - $this->setIfExists('response_code', $data ?? [], null); - $this->setIfExists('error', $data ?? [], null); - } - - /** - * Sets $this->container[$variableName] to the given data or to the given default Value; if $variableName - * is nullable and its value is set to null in the $fields array, then mark it as "set to null" in the - * $this->openAPINullablesSetToNull array - * - * @param string $variableName - * @param array $fields - * @param mixed $defaultValue - */ - private function setIfExists(string $variableName, array $fields, $defaultValue): void - { - if (self::isNullable($variableName) && array_key_exists($variableName, $fields) && is_null($fields[$variableName])) { - $this->openAPINullablesSetToNull[] = $variableName; - } - - $this->container[$variableName] = $fields[$variableName] ?? $defaultValue; - } - - /** - * Show all the invalid properties with reasons. - * - * @return array invalid properties with reasons - */ - public function listInvalidProperties() - { - $invalidProperties = []; - - return $invalidProperties; - } - - /** - * Validate all the properties in the model - * return true if all passed - * - * @return bool True if all properties are valid - */ - public function valid() - { - return count($this->listInvalidProperties()) === 0; - } - - - /** - * Gets response_code - * - * @return int|null - */ - public function getResponseCode() - { - return $this->container['response_code']; - } - - /** - * Sets response_code - * - * @param int|null $response_code response_code - * - * @return self - */ - public function setResponseCode($response_code) - { - if (is_null($response_code)) { - throw new \InvalidArgumentException('non-nullable response_code cannot be null'); - } - $this->container['response_code'] = $response_code; - - return $this; - } - - /** - * Gets error - * - * @return string|null - */ - public function getError() - { - return $this->container['error']; - } - - /** - * Sets error - * - * @param string|null $error error - * - * @return self - */ - public function setError($error) - { - if (is_null($error)) { - throw new \InvalidArgumentException('non-nullable error cannot be null'); - } - $this->container['error'] = $error; - - return $this; - } - /** - * Returns true if offset exists. False otherwise. - * - * @param integer $offset Offset - * - * @return boolean - */ - public function offsetExists($offset): bool - { - return isset($this->container[$offset]); - } - - /** - * Gets offset. - * - * @param integer $offset Offset - * - * @return mixed|null - */ - #[\ReturnTypeWillChange] - public function offsetGet($offset) - { - return $this->container[$offset] ?? null; - } - - /** - * Sets value based on offset. - * - * @param int|null $offset Offset - * @param mixed $value Value to be set - * - * @return void - */ - public function offsetSet($offset, $value): void - { - if (is_null($offset)) { - $this->container[] = $value; - } else { - $this->container[$offset] = $value; - } - } - - /** - * Unsets offset. - * - * @param integer $offset Offset - * - * @return void - */ - public function offsetUnset($offset): void - { - unset($this->container[$offset]); - } - - /** - * Serializes the object to a value that can be serialized natively by json_encode(). - * @link https://www.php.net/manual/en/jsonserializable.jsonserialize.php - * - * @return mixed Returns data which can be serialized by json_encode(), which is a value - * of any type other than a resource. - */ - #[\ReturnTypeWillChange] - public function jsonSerialize() - { - return ObjectSerializer::sanitizeForSerialization($this); - } - - /** - * Gets the string presentation of the object - * - * @return string - */ - public function __toString() - { - return json_encode( - ObjectSerializer::sanitizeForSerialization($this), - JSON_PRETTY_PRINT - ); - } - - /** - * Gets a header-safe presentation of the object - * - * @return string - */ - public function toHeaderValue() - { - return json_encode(ObjectSerializer::sanitizeForSerialization($this)); - } -} - - diff --git a/samples/client/petstore/php/psr-18/lib/Model/ErrorResponse.php b/samples/client/petstore/php/psr-18/lib/Model/ErrorResponse.php index 458660568ffd..1e9c3940003f 100644 --- a/samples/client/petstore/php/psr-18/lib/Model/ErrorResponse.php +++ b/samples/client/petstore/php/psr-18/lib/Model/ErrorResponse.php @@ -2,7 +2,7 @@ /** * ErrorResponse * - * PHP version 8.1 + * PHP version 7.4 * * @category Class * @package OpenAPI\Client From 23bd142a7a15de852b931997a6df8264d5aff82c Mon Sep 17 00:00:00 2001 From: Juan Treminio Date: Sat, 29 Mar 2025 13:15:26 -0500 Subject: [PATCH 4/8] Working on unit tests --- .../tests/ResponseTypesTest.php | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/samples/client/petstore/php/OpenAPIClient-php/tests/ResponseTypesTest.php b/samples/client/petstore/php/OpenAPIClient-php/tests/ResponseTypesTest.php index 1dd5a618b597..6ebccec1a405 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/tests/ResponseTypesTest.php +++ b/samples/client/petstore/php/OpenAPIClient-php/tests/ResponseTypesTest.php @@ -4,6 +4,8 @@ use GuzzleHttp\Psr7\Response; use OpenAPI\Client\Api\PetApi; +use OpenAPI\Client\Api\FakeApi; +use OpenAPI\Client\Model\ErrorResponse; use OpenAPI\Client\Model\Pet; use PHPUnit\Framework\TestCase; @@ -114,4 +116,26 @@ public function testNotJSONResponse($statusCode, $responseBody) $this->fakeHttpClient->setResponse(new Response($statusCode, [], $responseBody)); $this->api->getPetById(123); } + + public function testRangeResponse() + { + $responseCode = mt_rand(400, 499); + $this->fakeHttpClient->setResponse(new Response($responseCode, [], json_encode([]))); + $api = new FakeApi($this->fakeHttpClient); + + $pet = new Model\Pet([]); + $pet->setId(1234); + + $result = $api->fakeWith4xxRangeResponseEndpoint($pet); + + $this->assertInstanceOf(Pet::class, $result); + + + $this->expectExceptionCode(404); + $this->expectException(\OpenAPI\Client\ApiException::class); + $statusCode = 404; + + $this->fakeHttpClient->setResponse(new Response($statusCode, [], '{}')); + $this->api->getPetById(123); + } } From 79cc0afccab6655aaca85c0bba30a54609b6c8a1 Mon Sep 17 00:00:00 2001 From: Juan Treminio Date: Sat, 29 Mar 2025 13:24:21 -0500 Subject: [PATCH 5/8] Removes dangling files --- .../.openapi-generator/FILES | 1 - .../src/FormDataProcessor.php | 237 ----------------- .../php-nextgen/.openapi-generator/FILES | 1 - .../php-nextgen/src/FormDataProcessor.php | 237 ----------------- .../.openapi-generator/FILES | 1 - .../src/FormDataProcessor.php | 236 ----------------- .../.openapi-generator/FILES | 1 - .../lib/FormDataProcessor.php | 242 ------------------ .../php/psr-18/.openapi-generator/FILES | 1 - .../php/psr-18/lib/FormDataProcessor.php | 242 ------------------ 10 files changed, 1199 deletions(-) delete mode 100644 samples/client/echo_api/php-nextgen-streaming/src/FormDataProcessor.php delete mode 100644 samples/client/echo_api/php-nextgen/src/FormDataProcessor.php delete mode 100644 samples/client/petstore/php-nextgen/OpenAPIClient-php/src/FormDataProcessor.php delete mode 100644 samples/client/petstore/php/OpenAPIClient-php/lib/FormDataProcessor.php delete mode 100644 samples/client/petstore/php/psr-18/lib/FormDataProcessor.php diff --git a/samples/client/echo_api/php-nextgen-streaming/.openapi-generator/FILES b/samples/client/echo_api/php-nextgen-streaming/.openapi-generator/FILES index d849d4cffa36..c51141c743e7 100644 --- a/samples/client/echo_api/php-nextgen-streaming/.openapi-generator/FILES +++ b/samples/client/echo_api/php-nextgen-streaming/.openapi-generator/FILES @@ -32,7 +32,6 @@ src/Api/PathApi.php src/Api/QueryApi.php src/ApiException.php src/Configuration.php -src/FormDataProcessor.php src/HeaderSelector.php src/Model/Bird.php src/Model/Category.php diff --git a/samples/client/echo_api/php-nextgen-streaming/src/FormDataProcessor.php b/samples/client/echo_api/php-nextgen-streaming/src/FormDataProcessor.php deleted file mode 100644 index b7a31b3f2a01..000000000000 --- a/samples/client/echo_api/php-nextgen-streaming/src/FormDataProcessor.php +++ /dev/null @@ -1,237 +0,0 @@ - $values the value of the form parameter - * - * @return array [key => value] of formdata - */ - public function prepare(array $values): array - { - $this->has_file = false; - $result = []; - - foreach ($values as $k => $v) { - if ($v === null) { - continue; - } - - $result[$k] = $this->makeFormSafe($v); - } - - return $result; - } - - /** - * Flattens a multi-level array of data and generates a single-level array - * compatible with formdata - a single-level array where the keys use bracket - * notation to signify nested data. - * - * credit: https://github.com/FranBar1966/FlatPHP - */ - public static function flatten(array $source, string $start = ''): array - { - $opt = [ - 'prefix' => '[', - 'suffix' => ']', - 'suffix-end' => true, - 'prefix-list' => '[', - 'suffix-list' => ']', - 'suffix-list-end' => true, - ]; - - if ($start === '') { - $currentPrefix = ''; - $currentSuffix = ''; - $currentSuffixEnd = false; - } elseif (array_is_list($source)) { - $currentPrefix = $opt['prefix-list']; - $currentSuffix = $opt['suffix-list']; - $currentSuffixEnd = $opt['suffix-list-end']; - } else { - $currentPrefix = $opt['prefix']; - $currentSuffix = $opt['suffix']; - $currentSuffixEnd = $opt['suffix-end']; - } - - $currentName = $start; - $result = []; - - foreach ($source as $key => $val) { - $currentName .= $currentPrefix . $key; - - if (is_array($val) && !empty($val)) { - $currentName .= $currentSuffix; - $result += self::flatten($val, $currentName); - } else { - if ($currentSuffixEnd) { - $currentName .= $currentSuffix; - } - - $result[$currentName] = ObjectSerializer::toString($val); - } - - $currentName = $start; - } - - return $result; - } - - /** - * formdata must be limited to scalars or arrays of scalar values, - * or a resource for a file upload. Here we iterate through all available - * data and identify how to handle each scenario - * - * @param string|bool|array|DateTime|ArrayAccess|SplFileObject $value - */ - protected function makeFormSafe(mixed $value) - { - if ($value instanceof SplFileObject) { - return $this->processFiles([$value])[0]; - } - - if (is_resource($value)) { - $this->has_file = true; - - return $value; - } - - if ($value instanceof ModelInterface) { - return $this->processModel($value); - } - - if (is_array($value) || is_object($value)) { - $data = []; - - foreach ($value as $k => $v) { - $data[$k] = $this->makeFormSafe($v); - } - - return $data; - } - - return ObjectSerializer::toString($value); - } - - /** - * We are able to handle nested ModelInterface. We do not simply call - * json_decode(json_encode()) because any given model may have binary data - * or other data that cannot be serialized to a JSON string - */ - protected function processModel(ModelInterface $model): array - { - $result = []; - - foreach ($model::openAPITypes() as $name => $type) { - $value = $model->offsetGet($name); - - if ($value === null) { - continue; - } - - if (str_contains($type, '\SplFileObject')) { - $file = is_array($value) ? $value : [$value]; - $result[$name] = $this->processFiles($file); - - continue; - } - - if ($value instanceof ModelInterface) { - $result[$name] = $this->processModel($value); - - continue; - } - - if (is_array($value) || is_object($value)) { - $result[$name] = $this->makeFormSafe($value); - - continue; - } - - $result[$name] = ObjectSerializer::toString($value); - } - - return $result; - } - - /** - * Handle file data - */ - protected function processFiles(array $files): array - { - $this->has_file = true; - - $result = []; - - foreach ($files as $i => $file) { - if (is_array($file)) { - $result[$i] = $this->processFiles($file); - - continue; - } - - if ($file instanceof StreamInterface) { - $result[$i] = $file; - - continue; - } - - if ($file instanceof SplFileObject) { - $result[$i] = $this->tryFopen($file); - } - } - - return $result; - } - - private function tryFopen(SplFileObject $file) - { - return Utils::tryFopen($file->getRealPath(), 'rb'); - } -} diff --git a/samples/client/echo_api/php-nextgen/.openapi-generator/FILES b/samples/client/echo_api/php-nextgen/.openapi-generator/FILES index d849d4cffa36..c51141c743e7 100644 --- a/samples/client/echo_api/php-nextgen/.openapi-generator/FILES +++ b/samples/client/echo_api/php-nextgen/.openapi-generator/FILES @@ -32,7 +32,6 @@ src/Api/PathApi.php src/Api/QueryApi.php src/ApiException.php src/Configuration.php -src/FormDataProcessor.php src/HeaderSelector.php src/Model/Bird.php src/Model/Category.php diff --git a/samples/client/echo_api/php-nextgen/src/FormDataProcessor.php b/samples/client/echo_api/php-nextgen/src/FormDataProcessor.php deleted file mode 100644 index b7a31b3f2a01..000000000000 --- a/samples/client/echo_api/php-nextgen/src/FormDataProcessor.php +++ /dev/null @@ -1,237 +0,0 @@ - $values the value of the form parameter - * - * @return array [key => value] of formdata - */ - public function prepare(array $values): array - { - $this->has_file = false; - $result = []; - - foreach ($values as $k => $v) { - if ($v === null) { - continue; - } - - $result[$k] = $this->makeFormSafe($v); - } - - return $result; - } - - /** - * Flattens a multi-level array of data and generates a single-level array - * compatible with formdata - a single-level array where the keys use bracket - * notation to signify nested data. - * - * credit: https://github.com/FranBar1966/FlatPHP - */ - public static function flatten(array $source, string $start = ''): array - { - $opt = [ - 'prefix' => '[', - 'suffix' => ']', - 'suffix-end' => true, - 'prefix-list' => '[', - 'suffix-list' => ']', - 'suffix-list-end' => true, - ]; - - if ($start === '') { - $currentPrefix = ''; - $currentSuffix = ''; - $currentSuffixEnd = false; - } elseif (array_is_list($source)) { - $currentPrefix = $opt['prefix-list']; - $currentSuffix = $opt['suffix-list']; - $currentSuffixEnd = $opt['suffix-list-end']; - } else { - $currentPrefix = $opt['prefix']; - $currentSuffix = $opt['suffix']; - $currentSuffixEnd = $opt['suffix-end']; - } - - $currentName = $start; - $result = []; - - foreach ($source as $key => $val) { - $currentName .= $currentPrefix . $key; - - if (is_array($val) && !empty($val)) { - $currentName .= $currentSuffix; - $result += self::flatten($val, $currentName); - } else { - if ($currentSuffixEnd) { - $currentName .= $currentSuffix; - } - - $result[$currentName] = ObjectSerializer::toString($val); - } - - $currentName = $start; - } - - return $result; - } - - /** - * formdata must be limited to scalars or arrays of scalar values, - * or a resource for a file upload. Here we iterate through all available - * data and identify how to handle each scenario - * - * @param string|bool|array|DateTime|ArrayAccess|SplFileObject $value - */ - protected function makeFormSafe(mixed $value) - { - if ($value instanceof SplFileObject) { - return $this->processFiles([$value])[0]; - } - - if (is_resource($value)) { - $this->has_file = true; - - return $value; - } - - if ($value instanceof ModelInterface) { - return $this->processModel($value); - } - - if (is_array($value) || is_object($value)) { - $data = []; - - foreach ($value as $k => $v) { - $data[$k] = $this->makeFormSafe($v); - } - - return $data; - } - - return ObjectSerializer::toString($value); - } - - /** - * We are able to handle nested ModelInterface. We do not simply call - * json_decode(json_encode()) because any given model may have binary data - * or other data that cannot be serialized to a JSON string - */ - protected function processModel(ModelInterface $model): array - { - $result = []; - - foreach ($model::openAPITypes() as $name => $type) { - $value = $model->offsetGet($name); - - if ($value === null) { - continue; - } - - if (str_contains($type, '\SplFileObject')) { - $file = is_array($value) ? $value : [$value]; - $result[$name] = $this->processFiles($file); - - continue; - } - - if ($value instanceof ModelInterface) { - $result[$name] = $this->processModel($value); - - continue; - } - - if (is_array($value) || is_object($value)) { - $result[$name] = $this->makeFormSafe($value); - - continue; - } - - $result[$name] = ObjectSerializer::toString($value); - } - - return $result; - } - - /** - * Handle file data - */ - protected function processFiles(array $files): array - { - $this->has_file = true; - - $result = []; - - foreach ($files as $i => $file) { - if (is_array($file)) { - $result[$i] = $this->processFiles($file); - - continue; - } - - if ($file instanceof StreamInterface) { - $result[$i] = $file; - - continue; - } - - if ($file instanceof SplFileObject) { - $result[$i] = $this->tryFopen($file); - } - } - - return $result; - } - - private function tryFopen(SplFileObject $file) - { - return Utils::tryFopen($file->getRealPath(), 'rb'); - } -} diff --git a/samples/client/petstore/php-nextgen/OpenAPIClient-php/.openapi-generator/FILES b/samples/client/petstore/php-nextgen/OpenAPIClient-php/.openapi-generator/FILES index 3dbde1d34a3b..a7e753bda7df 100644 --- a/samples/client/petstore/php-nextgen/OpenAPIClient-php/.openapi-generator/FILES +++ b/samples/client/petstore/php-nextgen/OpenAPIClient-php/.openapi-generator/FILES @@ -74,7 +74,6 @@ src/Api/StoreApi.php src/Api/UserApi.php src/ApiException.php src/Configuration.php -src/FormDataProcessor.php src/HeaderSelector.php src/Model/AdditionalPropertiesClass.php src/Model/AllOfWithSingleRef.php diff --git a/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/FormDataProcessor.php b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/FormDataProcessor.php deleted file mode 100644 index f044f1c6dbc7..000000000000 --- a/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/FormDataProcessor.php +++ /dev/null @@ -1,236 +0,0 @@ - $values the value of the form parameter - * - * @return array [key => value] of formdata - */ - public function prepare(array $values): array - { - $this->has_file = false; - $result = []; - - foreach ($values as $k => $v) { - if ($v === null) { - continue; - } - - $result[$k] = $this->makeFormSafe($v); - } - - return $result; - } - - /** - * Flattens a multi-level array of data and generates a single-level array - * compatible with formdata - a single-level array where the keys use bracket - * notation to signify nested data. - * - * credit: https://github.com/FranBar1966/FlatPHP - */ - public static function flatten(array $source, string $start = ''): array - { - $opt = [ - 'prefix' => '[', - 'suffix' => ']', - 'suffix-end' => true, - 'prefix-list' => '[', - 'suffix-list' => ']', - 'suffix-list-end' => true, - ]; - - if ($start === '') { - $currentPrefix = ''; - $currentSuffix = ''; - $currentSuffixEnd = false; - } elseif (array_is_list($source)) { - $currentPrefix = $opt['prefix-list']; - $currentSuffix = $opt['suffix-list']; - $currentSuffixEnd = $opt['suffix-list-end']; - } else { - $currentPrefix = $opt['prefix']; - $currentSuffix = $opt['suffix']; - $currentSuffixEnd = $opt['suffix-end']; - } - - $currentName = $start; - $result = []; - - foreach ($source as $key => $val) { - $currentName .= $currentPrefix . $key; - - if (is_array($val) && !empty($val)) { - $currentName .= $currentSuffix; - $result += self::flatten($val, $currentName); - } else { - if ($currentSuffixEnd) { - $currentName .= $currentSuffix; - } - - $result[$currentName] = ObjectSerializer::toString($val); - } - - $currentName = $start; - } - - return $result; - } - - /** - * formdata must be limited to scalars or arrays of scalar values, - * or a resource for a file upload. Here we iterate through all available - * data and identify how to handle each scenario - * - * @param string|bool|array|DateTime|ArrayAccess|SplFileObject $value - */ - protected function makeFormSafe(mixed $value) - { - if ($value instanceof SplFileObject) { - return $this->processFiles([$value])[0]; - } - - if (is_resource($value)) { - $this->has_file = true; - - return $value; - } - - if ($value instanceof ModelInterface) { - return $this->processModel($value); - } - - if (is_array($value) || is_object($value)) { - $data = []; - - foreach ($value as $k => $v) { - $data[$k] = $this->makeFormSafe($v); - } - - return $data; - } - - return ObjectSerializer::toString($value); - } - - /** - * We are able to handle nested ModelInterface. We do not simply call - * json_decode(json_encode()) because any given model may have binary data - * or other data that cannot be serialized to a JSON string - */ - protected function processModel(ModelInterface $model): array - { - $result = []; - - foreach ($model::openAPITypes() as $name => $type) { - $value = $model->offsetGet($name); - - if ($value === null) { - continue; - } - - if (str_contains($type, '\SplFileObject')) { - $file = is_array($value) ? $value : [$value]; - $result[$name] = $this->processFiles($file); - - continue; - } - - if ($value instanceof ModelInterface) { - $result[$name] = $this->processModel($value); - - continue; - } - - if (is_array($value) || is_object($value)) { - $result[$name] = $this->makeFormSafe($value); - - continue; - } - - $result[$name] = ObjectSerializer::toString($value); - } - - return $result; - } - - /** - * Handle file data - */ - protected function processFiles(array $files): array - { - $this->has_file = true; - - $result = []; - - foreach ($files as $i => $file) { - if (is_array($file)) { - $result[$i] = $this->processFiles($file); - - continue; - } - - if ($file instanceof StreamInterface) { - $result[$i] = $file; - - continue; - } - - if ($file instanceof SplFileObject) { - $result[$i] = $this->tryFopen($file); - } - } - - return $result; - } - - private function tryFopen(SplFileObject $file) - { - return Utils::tryFopen($file->getRealPath(), 'rb'); - } -} diff --git a/samples/client/petstore/php/OpenAPIClient-php/.openapi-generator/FILES b/samples/client/petstore/php/OpenAPIClient-php/.openapi-generator/FILES index e4f07975e540..9b385cc2b953 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/.openapi-generator/FILES +++ b/samples/client/petstore/php/OpenAPIClient-php/.openapi-generator/FILES @@ -71,7 +71,6 @@ lib/Api/StoreApi.php lib/Api/UserApi.php lib/ApiException.php lib/Configuration.php -lib/FormDataProcessor.php lib/HeaderSelector.php lib/Model/AdditionalPropertiesClass.php lib/Model/AllOfWithSingleRef.php diff --git a/samples/client/petstore/php/OpenAPIClient-php/lib/FormDataProcessor.php b/samples/client/petstore/php/OpenAPIClient-php/lib/FormDataProcessor.php deleted file mode 100644 index c416f584e6aa..000000000000 --- a/samples/client/petstore/php/OpenAPIClient-php/lib/FormDataProcessor.php +++ /dev/null @@ -1,242 +0,0 @@ - $values the value of the form parameter - * - * @return array [key => value] of formdata - */ - public function prepare(array $values): array - { - $this->has_file = false; - $result = []; - - foreach ($values as $k => $v) { - if ($v === null) { - continue; - } - - $result[$k] = $this->makeFormSafe($v); - } - - return $result; - } - - /** - * Flattens a multi-level array of data and generates a single-level array - * compatible with formdata - a single-level array where the keys use bracket - * notation to signify nested data. - * - * credit: https://github.com/FranBar1966/FlatPHP - */ - public static function flatten(array $source, string $start = ''): array - { - $opt = [ - 'prefix' => '[', - 'suffix' => ']', - 'suffix-end' => true, - 'prefix-list' => '[', - 'suffix-list' => ']', - 'suffix-list-end' => true, - ]; - - if ($start === '') { - $currentPrefix = ''; - $currentSuffix = ''; - $currentSuffixEnd = false; - } elseif (array_is_list($source)) { - $currentPrefix = $opt['prefix-list']; - $currentSuffix = $opt['suffix-list']; - $currentSuffixEnd = $opt['suffix-list-end']; - } else { - $currentPrefix = $opt['prefix']; - $currentSuffix = $opt['suffix']; - $currentSuffixEnd = $opt['suffix-end']; - } - - $currentName = $start; - $result = []; - - foreach ($source as $key => $val) { - $currentName .= $currentPrefix.$key; - - if (is_array($val) && !empty($val)) { - $currentName .= $currentSuffix; - $result += self::flatten($val, $currentName); - } else { - if ($currentSuffixEnd) { - $currentName .= $currentSuffix; - } - - $result[$currentName] = ObjectSerializer::toString($val); - } - - $currentName = $start; - } - - return $result; - } - - /** - * formdata must be limited to scalars or arrays of scalar values, - * or a resource for a file upload. Here we iterate through all available - * data and identify how to handle each scenario - */ - protected function makeFormSafe($value) - { - if ($value instanceof SplFileObject) { - return $this->processFiles([$value])[0]; - } - - if (is_resource($value)) { - $this->has_file = true; - - return $value; - } - - if ($value instanceof ModelInterface) { - return $this->processModel($value); - } - - if (is_array($value) || (is_object($value) && !$value instanceof \DateTimeInterface)) { - $data = []; - - foreach ($value as $k => $v) { - $data[$k] = $this->makeFormSafe($v); - } - - return $data; - } - - return ObjectSerializer::toString($value); - } - - /** - * We are able to handle nested ModelInterface. We do not simply call - * json_decode(json_encode()) because any given model may have binary data - * or other data that cannot be serialized to a JSON string - */ - protected function processModel(ModelInterface $model): array - { - $result = []; - - foreach ($model::openAPITypes() as $name => $type) { - $value = $model->offsetGet($name); - - if ($value === null) { - continue; - } - - if (strpos($type, '\SplFileObject') !== false) { - $file = is_array($value) ? $value : [$value]; - $result[$name] = $this->processFiles($file); - - continue; - } - - if ($value instanceof ModelInterface) { - $result[$name] = $this->processModel($value); - - continue; - } - - if (is_array($value) || is_object($value)) { - $result[$name] = $this->makeFormSafe($value); - - continue; - } - - $result[$name] = ObjectSerializer::toString($value); - } - - return $result; - } - - /** - * Handle file data - */ - protected function processFiles(array $files): array - { - $this->has_file = true; - - $result = []; - - foreach ($files as $i => $file) { - if (is_array($file)) { - $result[$i] = $this->processFiles($file); - - continue; - } - - if ($file instanceof StreamInterface) { - $result[$i] = $file; - - continue; - } - - if ($file instanceof SplFileObject) { - $result[$i] = $this->tryFopen($file); - } - } - - return $result; - } - - private function tryFopen(SplFileObject $file) - { - return Utils::tryFopen($file->getRealPath(), 'rb'); - } -} diff --git a/samples/client/petstore/php/psr-18/.openapi-generator/FILES b/samples/client/petstore/php/psr-18/.openapi-generator/FILES index 41b774cef923..37dca3df0af8 100644 --- a/samples/client/petstore/php/psr-18/.openapi-generator/FILES +++ b/samples/client/petstore/php/psr-18/.openapi-generator/FILES @@ -72,7 +72,6 @@ lib/Api/UserApi.php lib/ApiException.php lib/Configuration.php lib/DebugPlugin.php -lib/FormDataProcessor.php lib/HeaderSelector.php lib/Model/AdditionalPropertiesClass.php lib/Model/AllOfWithSingleRef.php diff --git a/samples/client/petstore/php/psr-18/lib/FormDataProcessor.php b/samples/client/petstore/php/psr-18/lib/FormDataProcessor.php deleted file mode 100644 index c416f584e6aa..000000000000 --- a/samples/client/petstore/php/psr-18/lib/FormDataProcessor.php +++ /dev/null @@ -1,242 +0,0 @@ - $values the value of the form parameter - * - * @return array [key => value] of formdata - */ - public function prepare(array $values): array - { - $this->has_file = false; - $result = []; - - foreach ($values as $k => $v) { - if ($v === null) { - continue; - } - - $result[$k] = $this->makeFormSafe($v); - } - - return $result; - } - - /** - * Flattens a multi-level array of data and generates a single-level array - * compatible with formdata - a single-level array where the keys use bracket - * notation to signify nested data. - * - * credit: https://github.com/FranBar1966/FlatPHP - */ - public static function flatten(array $source, string $start = ''): array - { - $opt = [ - 'prefix' => '[', - 'suffix' => ']', - 'suffix-end' => true, - 'prefix-list' => '[', - 'suffix-list' => ']', - 'suffix-list-end' => true, - ]; - - if ($start === '') { - $currentPrefix = ''; - $currentSuffix = ''; - $currentSuffixEnd = false; - } elseif (array_is_list($source)) { - $currentPrefix = $opt['prefix-list']; - $currentSuffix = $opt['suffix-list']; - $currentSuffixEnd = $opt['suffix-list-end']; - } else { - $currentPrefix = $opt['prefix']; - $currentSuffix = $opt['suffix']; - $currentSuffixEnd = $opt['suffix-end']; - } - - $currentName = $start; - $result = []; - - foreach ($source as $key => $val) { - $currentName .= $currentPrefix.$key; - - if (is_array($val) && !empty($val)) { - $currentName .= $currentSuffix; - $result += self::flatten($val, $currentName); - } else { - if ($currentSuffixEnd) { - $currentName .= $currentSuffix; - } - - $result[$currentName] = ObjectSerializer::toString($val); - } - - $currentName = $start; - } - - return $result; - } - - /** - * formdata must be limited to scalars or arrays of scalar values, - * or a resource for a file upload. Here we iterate through all available - * data and identify how to handle each scenario - */ - protected function makeFormSafe($value) - { - if ($value instanceof SplFileObject) { - return $this->processFiles([$value])[0]; - } - - if (is_resource($value)) { - $this->has_file = true; - - return $value; - } - - if ($value instanceof ModelInterface) { - return $this->processModel($value); - } - - if (is_array($value) || (is_object($value) && !$value instanceof \DateTimeInterface)) { - $data = []; - - foreach ($value as $k => $v) { - $data[$k] = $this->makeFormSafe($v); - } - - return $data; - } - - return ObjectSerializer::toString($value); - } - - /** - * We are able to handle nested ModelInterface. We do not simply call - * json_decode(json_encode()) because any given model may have binary data - * or other data that cannot be serialized to a JSON string - */ - protected function processModel(ModelInterface $model): array - { - $result = []; - - foreach ($model::openAPITypes() as $name => $type) { - $value = $model->offsetGet($name); - - if ($value === null) { - continue; - } - - if (strpos($type, '\SplFileObject') !== false) { - $file = is_array($value) ? $value : [$value]; - $result[$name] = $this->processFiles($file); - - continue; - } - - if ($value instanceof ModelInterface) { - $result[$name] = $this->processModel($value); - - continue; - } - - if (is_array($value) || is_object($value)) { - $result[$name] = $this->makeFormSafe($value); - - continue; - } - - $result[$name] = ObjectSerializer::toString($value); - } - - return $result; - } - - /** - * Handle file data - */ - protected function processFiles(array $files): array - { - $this->has_file = true; - - $result = []; - - foreach ($files as $i => $file) { - if (is_array($file)) { - $result[$i] = $this->processFiles($file); - - continue; - } - - if ($file instanceof StreamInterface) { - $result[$i] = $file; - - continue; - } - - if ($file instanceof SplFileObject) { - $result[$i] = $this->tryFopen($file); - } - } - - return $result; - } - - private function tryFopen(SplFileObject $file) - { - return Utils::tryFopen($file->getRealPath(), 'rb'); - } -} From e5b451d80f8be6461e4a881f5b3c87d9516cbaf7 Mon Sep 17 00:00:00 2001 From: Juan Treminio Date: Sat, 29 Mar 2025 13:39:50 -0500 Subject: [PATCH 6/8] Finalize tests --- .../main/resources/php-nextgen/api.mustache | 5 ++ .../src/main/resources/php/api.mustache | 5 ++ .../php/libraries/psr-18/api.mustache | 4 ++ .../php-nextgen-streaming/src/Api/AuthApi.php | 6 +++ .../php-nextgen-streaming/src/Api/BodyApi.php | 22 ++++++++ .../php-nextgen-streaming/src/Api/FormApi.php | 8 +++ .../src/Api/HeaderApi.php | 4 ++ .../php-nextgen-streaming/src/Api/PathApi.php | 4 ++ .../src/Api/QueryApi.php | 22 ++++++++ .../echo_api/php-nextgen/src/Api/AuthApi.php | 6 +++ .../echo_api/php-nextgen/src/Api/BodyApi.php | 22 ++++++++ .../echo_api/php-nextgen/src/Api/FormApi.php | 8 +++ .../php-nextgen/src/Api/HeaderApi.php | 4 ++ .../echo_api/php-nextgen/src/Api/PathApi.php | 4 ++ .../echo_api/php-nextgen/src/Api/QueryApi.php | 22 ++++++++ .../.openapi-generator/FILES | 1 - .../src/Api/AnotherFakeApi.php | 4 ++ .../OpenAPIClient-php/src/Api/DefaultApi.php | 4 ++ .../OpenAPIClient-php/src/Api/FakeApi.php | 30 +++++++++++ .../src/Api/FakeClassnameTags123Api.php | 4 ++ .../OpenAPIClient-php/src/Api/PetApi.php | 12 +++++ .../OpenAPIClient-php/src/Api/StoreApi.php | 8 +++ .../OpenAPIClient-php/src/Api/UserApi.php | 6 +++ .../lib/Api/AnotherFakeApi.php | 4 ++ .../OpenAPIClient-php/lib/Api/DefaultApi.php | 4 ++ .../php/OpenAPIClient-php/lib/Api/FakeApi.php | 30 +++++++++++ .../lib/Api/FakeClassnameTags123Api.php | 4 ++ .../php/OpenAPIClient-php/lib/Api/PetApi.php | 14 +++++ .../OpenAPIClient-php/lib/Api/StoreApi.php | 8 +++ .../php/OpenAPIClient-php/lib/Api/UserApi.php | 6 +++ .../lib/Model/ErrorResponse.php | 2 +- .../tests/ResponseTypesTest.php | 51 ++++++++++++++++--- .../php/psr-18/lib/Api/AnotherFakeApi.php | 3 ++ .../php/psr-18/lib/Api/DefaultApi.php | 3 ++ .../petstore/php/psr-18/lib/Api/FakeApi.php | 29 +++++++++++ .../lib/Api/FakeClassnameTags123Api.php | 3 ++ .../petstore/php/psr-18/lib/Api/PetApi.php | 13 +++++ .../petstore/php/psr-18/lib/Api/StoreApi.php | 7 +++ .../petstore/php/psr-18/lib/Api/UserApi.php | 5 ++ .../php/psr-18/lib/Model/ErrorResponse.php | 2 +- 40 files changed, 392 insertions(+), 11 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/php-nextgen/api.mustache b/modules/openapi-generator/src/main/resources/php-nextgen/api.mustache index 99e6ed4d250d..dcf2019d0bfd 100644 --- a/modules/openapi-generator/src/main/resources/php-nextgen/api.mustache +++ b/modules/openapi-generator/src/main/resources/php-nextgen/api.mustache @@ -26,6 +26,7 @@ use GuzzleHttp\Psr7\MultipartStream; use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; use GuzzleHttp\Promise\PromiseInterface; +use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use {{invokerPackage}}\ApiException; use {{invokerPackage}}\Configuration; @@ -296,6 +297,7 @@ use {{invokerPackage}}\ObjectSerializer; {{^isRange}}{{^isWildcard}}case {{code}}:{{/isWildcard}}{{#isWildcard}}default:{{/isWildcard}} return $this->handleResponseWithDataType( '{{{dataType}}}', + $request, $response, );{{/isRange}} {{/dataType}} @@ -307,6 +309,7 @@ use {{invokerPackage}}\ObjectSerializer; if ($this->responseWithinRangeCode('{{code}}', $statusCode)) { return $this->handleResponseWithDataType( '{{{dataType}}}', + $request, $response, ); }{{/isWildcard}}{{/isRange}}{{/dataType}}{{/responses}} @@ -326,6 +329,7 @@ use {{invokerPackage}}\ObjectSerializer; return $this->handleResponseWithDataType( '{{{returnType}}}', + $request, $response, ); {{/returnType}} @@ -912,6 +916,7 @@ use {{invokerPackage}}\ObjectSerializer; private function handleResponseWithDataType( string $dataType, + RequestInterface $request, ResponseInterface $response, ): array { if (in_array($dataType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { diff --git a/modules/openapi-generator/src/main/resources/php/api.mustache b/modules/openapi-generator/src/main/resources/php/api.mustache index da502f43680a..5e014c011e4e 100644 --- a/modules/openapi-generator/src/main/resources/php/api.mustache +++ b/modules/openapi-generator/src/main/resources/php/api.mustache @@ -25,6 +25,7 @@ use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Psr7\MultipartStream; use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; +use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use {{invokerPackage}}\ApiException; use {{invokerPackage}}\Configuration; @@ -265,6 +266,7 @@ use {{invokerPackage}}\ObjectSerializer; {{^isRange}}{{^isWildcard}}case {{code}}:{{/isWildcard}}{{#isWildcard}}default:{{/isWildcard}} return $this->handleResponseWithDataType( '{{{dataType}}}', + $request, $response, );{{/isRange}} {{/dataType}} @@ -276,6 +278,7 @@ use {{invokerPackage}}\ObjectSerializer; {{#responses}}{{#dataType}}{{#isRange}}{{^isWildcard}}if ($this->responseWithinRangeCode('{{code}}', $statusCode)) { return $this->handleResponseWithDataType( '{{{dataType}}}', + $request, $response, ); }{{/isWildcard}}{{/isRange}}{{/dataType}}{{/responses}} @@ -295,6 +298,7 @@ use {{invokerPackage}}\ObjectSerializer; return $this->handleResponseWithDataType( '{{{returnType}}}', + $request, $response, ); {{/returnType}} @@ -835,6 +839,7 @@ use {{invokerPackage}}\ObjectSerializer; private function handleResponseWithDataType( string $dataType, + RequestInterface $request, ResponseInterface $response ): array { if ($dataType === '\SplFileObject') { diff --git a/modules/openapi-generator/src/main/resources/php/libraries/psr-18/api.mustache b/modules/openapi-generator/src/main/resources/php/libraries/psr-18/api.mustache index 14ec231659d7..7cbb99a58f0f 100644 --- a/modules/openapi-generator/src/main/resources/php/libraries/psr-18/api.mustache +++ b/modules/openapi-generator/src/main/resources/php/libraries/psr-18/api.mustache @@ -275,6 +275,7 @@ use function sprintf; {{^isRange}}{{^isWildcard}}case {{code}}:{{/isWildcard}}{{#isWildcard}}default:{{/isWildcard}} return $this->handleResponseWithDataType( '{{{dataType}}}', + $request, $response, );{{/isRange}} {{/dataType}} @@ -286,6 +287,7 @@ use function sprintf; {{#responses}}{{#dataType}}{{#isRange}}{{^isWildcard}}if ($this->responseWithinRangeCode('{{code}}', $statusCode)) { return $this->handleResponseWithDataType( '{{{dataType}}}', + $request, $response, ); }{{/isWildcard}}{{/isRange}}{{/dataType}}{{/responses}} @@ -305,6 +307,7 @@ use function sprintf; return $this->handleResponseWithDataType( '{{{returnType}}}', + $request, $response, ); {{/returnType}} @@ -789,6 +792,7 @@ use function sprintf; private function handleResponseWithDataType( string $dataType, + RequestInterface $request, ResponseInterface $response ): array { if ($dataType === '\SplFileObject') { diff --git a/samples/client/echo_api/php-nextgen-streaming/src/Api/AuthApi.php b/samples/client/echo_api/php-nextgen-streaming/src/Api/AuthApi.php index 740aeab82ba8..eac402dd75dd 100644 --- a/samples/client/echo_api/php-nextgen-streaming/src/Api/AuthApi.php +++ b/samples/client/echo_api/php-nextgen-streaming/src/Api/AuthApi.php @@ -36,6 +36,7 @@ use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; use GuzzleHttp\Promise\PromiseInterface; +use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use OpenAPI\Client\ApiException; use OpenAPI\Client\Configuration; @@ -189,6 +190,7 @@ public function testAuthHttpBasicWithHttpInfo( case 200: return $this->handleResponseWithDataType( 'string', + $request, $response, ); } @@ -209,6 +211,7 @@ public function testAuthHttpBasicWithHttpInfo( return $this->handleResponseWithDataType( 'string', + $request, $response, ); } catch (ApiException $e) { @@ -446,6 +449,7 @@ public function testAuthHttpBearerWithHttpInfo( case 200: return $this->handleResponseWithDataType( 'string', + $request, $response, ); } @@ -466,6 +470,7 @@ public function testAuthHttpBearerWithHttpInfo( return $this->handleResponseWithDataType( 'string', + $request, $response, ); } catch (ApiException $e) { @@ -662,6 +667,7 @@ protected function createHttpClientOption(): array private function handleResponseWithDataType( string $dataType, + RequestInterface $request, ResponseInterface $response, ): array { if (in_array($dataType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { diff --git a/samples/client/echo_api/php-nextgen-streaming/src/Api/BodyApi.php b/samples/client/echo_api/php-nextgen-streaming/src/Api/BodyApi.php index d55ea687ea37..bdf56a65bb26 100644 --- a/samples/client/echo_api/php-nextgen-streaming/src/Api/BodyApi.php +++ b/samples/client/echo_api/php-nextgen-streaming/src/Api/BodyApi.php @@ -36,6 +36,7 @@ use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; use GuzzleHttp\Promise\PromiseInterface; +use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use OpenAPI\Client\ApiException; use OpenAPI\Client\Configuration; @@ -213,6 +214,7 @@ public function testBinaryGifWithHttpInfo( case 200: return $this->handleResponseWithDataType( '\Psr\Http\Message\StreamInterface', + $request, $response, ); } @@ -233,6 +235,7 @@ public function testBinaryGifWithHttpInfo( return $this->handleResponseWithDataType( '\Psr\Http\Message\StreamInterface', + $request, $response, ); } catch (ApiException $e) { @@ -470,6 +473,7 @@ public function testBodyApplicationOctetstreamBinaryWithHttpInfo( case 200: return $this->handleResponseWithDataType( 'string', + $request, $response, ); } @@ -490,6 +494,7 @@ public function testBodyApplicationOctetstreamBinaryWithHttpInfo( return $this->handleResponseWithDataType( 'string', + $request, $response, ); } catch (ApiException $e) { @@ -741,6 +746,7 @@ public function testBodyMultipartFormdataArrayOfBinaryWithHttpInfo( case 200: return $this->handleResponseWithDataType( 'string', + $request, $response, ); } @@ -761,6 +767,7 @@ public function testBodyMultipartFormdataArrayOfBinaryWithHttpInfo( return $this->handleResponseWithDataType( 'string', + $request, $response, ); } catch (ApiException $e) { @@ -1025,6 +1032,7 @@ public function testBodyMultipartFormdataSingleBinaryWithHttpInfo( case 200: return $this->handleResponseWithDataType( 'string', + $request, $response, ); } @@ -1045,6 +1053,7 @@ public function testBodyMultipartFormdataSingleBinaryWithHttpInfo( return $this->handleResponseWithDataType( 'string', + $request, $response, ); } catch (ApiException $e) { @@ -1303,6 +1312,7 @@ public function testEchoBodyAllOfPetWithHttpInfo( case 200: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\Pet', + $request, $response, ); } @@ -1323,6 +1333,7 @@ public function testEchoBodyAllOfPetWithHttpInfo( return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\Pet', + $request, $response, ); } catch (ApiException $e) { @@ -1574,6 +1585,7 @@ public function testEchoBodyFreeFormObjectResponseStringWithHttpInfo( case 200: return $this->handleResponseWithDataType( 'string', + $request, $response, ); } @@ -1594,6 +1606,7 @@ public function testEchoBodyFreeFormObjectResponseStringWithHttpInfo( return $this->handleResponseWithDataType( 'string', + $request, $response, ); } catch (ApiException $e) { @@ -1845,6 +1858,7 @@ public function testEchoBodyPetWithHttpInfo( case 200: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\Pet', + $request, $response, ); } @@ -1865,6 +1879,7 @@ public function testEchoBodyPetWithHttpInfo( return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\Pet', + $request, $response, ); } catch (ApiException $e) { @@ -2116,6 +2131,7 @@ public function testEchoBodyPetResponseStringWithHttpInfo( case 200: return $this->handleResponseWithDataType( 'string', + $request, $response, ); } @@ -2136,6 +2152,7 @@ public function testEchoBodyPetResponseStringWithHttpInfo( return $this->handleResponseWithDataType( 'string', + $request, $response, ); } catch (ApiException $e) { @@ -2387,6 +2404,7 @@ public function testEchoBodyStringEnumWithHttpInfo( case 200: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\StringEnumRef', + $request, $response, ); } @@ -2407,6 +2425,7 @@ public function testEchoBodyStringEnumWithHttpInfo( return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\StringEnumRef', + $request, $response, ); } catch (ApiException $e) { @@ -2658,6 +2677,7 @@ public function testEchoBodyTagResponseStringWithHttpInfo( case 200: return $this->handleResponseWithDataType( 'string', + $request, $response, ); } @@ -2678,6 +2698,7 @@ public function testEchoBodyTagResponseStringWithHttpInfo( return $this->handleResponseWithDataType( 'string', + $request, $response, ); } catch (ApiException $e) { @@ -2884,6 +2905,7 @@ protected function createHttpClientOption(): array private function handleResponseWithDataType( string $dataType, + RequestInterface $request, ResponseInterface $response, ): array { if (in_array($dataType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { diff --git a/samples/client/echo_api/php-nextgen-streaming/src/Api/FormApi.php b/samples/client/echo_api/php-nextgen-streaming/src/Api/FormApi.php index 1b1bb8aecaa2..23be7e56f066 100644 --- a/samples/client/echo_api/php-nextgen-streaming/src/Api/FormApi.php +++ b/samples/client/echo_api/php-nextgen-streaming/src/Api/FormApi.php @@ -36,6 +36,7 @@ use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; use GuzzleHttp\Promise\PromiseInterface; +use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use OpenAPI\Client\ApiException; use OpenAPI\Client\Configuration; @@ -204,6 +205,7 @@ public function testFormIntegerBooleanStringWithHttpInfo( case 200: return $this->handleResponseWithDataType( 'string', + $request, $response, ); } @@ -224,6 +226,7 @@ public function testFormIntegerBooleanStringWithHttpInfo( return $this->handleResponseWithDataType( 'string', + $request, $response, ); } catch (ApiException $e) { @@ -494,6 +497,7 @@ public function testFormObjectMultipartWithHttpInfo( case 200: return $this->handleResponseWithDataType( 'string', + $request, $response, ); } @@ -514,6 +518,7 @@ public function testFormObjectMultipartWithHttpInfo( return $this->handleResponseWithDataType( 'string', + $request, $response, ); } catch (ApiException $e) { @@ -788,6 +793,7 @@ public function testFormOneofWithHttpInfo( case 200: return $this->handleResponseWithDataType( 'string', + $request, $response, ); } @@ -808,6 +814,7 @@ public function testFormOneofWithHttpInfo( return $this->handleResponseWithDataType( 'string', + $request, $response, ); } catch (ApiException $e) { @@ -1066,6 +1073,7 @@ protected function createHttpClientOption(): array private function handleResponseWithDataType( string $dataType, + RequestInterface $request, ResponseInterface $response, ): array { if (in_array($dataType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { diff --git a/samples/client/echo_api/php-nextgen-streaming/src/Api/HeaderApi.php b/samples/client/echo_api/php-nextgen-streaming/src/Api/HeaderApi.php index 3d18038f17eb..7590397a6d90 100644 --- a/samples/client/echo_api/php-nextgen-streaming/src/Api/HeaderApi.php +++ b/samples/client/echo_api/php-nextgen-streaming/src/Api/HeaderApi.php @@ -36,6 +36,7 @@ use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; use GuzzleHttp\Promise\PromiseInterface; +use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use OpenAPI\Client\ApiException; use OpenAPI\Client\Configuration; @@ -206,6 +207,7 @@ public function testHeaderIntegerBooleanStringEnumsWithHttpInfo( case 200: return $this->handleResponseWithDataType( 'string', + $request, $response, ); } @@ -226,6 +228,7 @@ public function testHeaderIntegerBooleanStringEnumsWithHttpInfo( return $this->handleResponseWithDataType( 'string', + $request, $response, ); } catch (ApiException $e) { @@ -473,6 +476,7 @@ protected function createHttpClientOption(): array private function handleResponseWithDataType( string $dataType, + RequestInterface $request, ResponseInterface $response, ): array { if (in_array($dataType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { diff --git a/samples/client/echo_api/php-nextgen-streaming/src/Api/PathApi.php b/samples/client/echo_api/php-nextgen-streaming/src/Api/PathApi.php index 0842612e45a9..d40c949e05e3 100644 --- a/samples/client/echo_api/php-nextgen-streaming/src/Api/PathApi.php +++ b/samples/client/echo_api/php-nextgen-streaming/src/Api/PathApi.php @@ -36,6 +36,7 @@ use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; use GuzzleHttp\Promise\PromiseInterface; +use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use OpenAPI\Client\ApiException; use OpenAPI\Client\Configuration; @@ -202,6 +203,7 @@ public function testsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathE case 200: return $this->handleResponseWithDataType( 'string', + $request, $response, ); } @@ -222,6 +224,7 @@ public function testsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathE return $this->handleResponseWithDataType( 'string', + $request, $response, ); } catch (ApiException $e) { @@ -498,6 +501,7 @@ protected function createHttpClientOption(): array private function handleResponseWithDataType( string $dataType, + RequestInterface $request, ResponseInterface $response, ): array { if (in_array($dataType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { diff --git a/samples/client/echo_api/php-nextgen-streaming/src/Api/QueryApi.php b/samples/client/echo_api/php-nextgen-streaming/src/Api/QueryApi.php index cd1a249558a9..34b6a4d324c8 100644 --- a/samples/client/echo_api/php-nextgen-streaming/src/Api/QueryApi.php +++ b/samples/client/echo_api/php-nextgen-streaming/src/Api/QueryApi.php @@ -36,6 +36,7 @@ use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; use GuzzleHttp\Promise\PromiseInterface; +use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use OpenAPI\Client\ApiException; use OpenAPI\Client\Configuration; @@ -221,6 +222,7 @@ public function testEnumRefStringWithHttpInfo( case 200: return $this->handleResponseWithDataType( 'string', + $request, $response, ); } @@ -241,6 +243,7 @@ public function testEnumRefStringWithHttpInfo( return $this->handleResponseWithDataType( 'string', + $request, $response, ); } catch (ApiException $e) { @@ -518,6 +521,7 @@ public function testQueryDatetimeDateStringWithHttpInfo( case 200: return $this->handleResponseWithDataType( 'string', + $request, $response, ); } @@ -538,6 +542,7 @@ public function testQueryDatetimeDateStringWithHttpInfo( return $this->handleResponseWithDataType( 'string', + $request, $response, ); } catch (ApiException $e) { @@ -831,6 +836,7 @@ public function testQueryIntegerBooleanStringWithHttpInfo( case 200: return $this->handleResponseWithDataType( 'string', + $request, $response, ); } @@ -851,6 +857,7 @@ public function testQueryIntegerBooleanStringWithHttpInfo( return $this->handleResponseWithDataType( 'string', + $request, $response, ); } catch (ApiException $e) { @@ -1136,6 +1143,7 @@ public function testQueryStyleDeepObjectExplodeTrueObjectWithHttpInfo( case 200: return $this->handleResponseWithDataType( 'string', + $request, $response, ); } @@ -1156,6 +1164,7 @@ public function testQueryStyleDeepObjectExplodeTrueObjectWithHttpInfo( return $this->handleResponseWithDataType( 'string', + $request, $response, ); } catch (ApiException $e) { @@ -1409,6 +1418,7 @@ public function testQueryStyleDeepObjectExplodeTrueObjectAllOfWithHttpInfo( case 200: return $this->handleResponseWithDataType( 'string', + $request, $response, ); } @@ -1429,6 +1439,7 @@ public function testQueryStyleDeepObjectExplodeTrueObjectAllOfWithHttpInfo( return $this->handleResponseWithDataType( 'string', + $request, $response, ); } catch (ApiException $e) { @@ -1682,6 +1693,7 @@ public function testQueryStyleFormExplodeFalseArrayIntegerWithHttpInfo( case 200: return $this->handleResponseWithDataType( 'string', + $request, $response, ); } @@ -1702,6 +1714,7 @@ public function testQueryStyleFormExplodeFalseArrayIntegerWithHttpInfo( return $this->handleResponseWithDataType( 'string', + $request, $response, ); } catch (ApiException $e) { @@ -1955,6 +1968,7 @@ public function testQueryStyleFormExplodeFalseArrayStringWithHttpInfo( case 200: return $this->handleResponseWithDataType( 'string', + $request, $response, ); } @@ -1975,6 +1989,7 @@ public function testQueryStyleFormExplodeFalseArrayStringWithHttpInfo( return $this->handleResponseWithDataType( 'string', + $request, $response, ); } catch (ApiException $e) { @@ -2228,6 +2243,7 @@ public function testQueryStyleFormExplodeTrueArrayStringWithHttpInfo( case 200: return $this->handleResponseWithDataType( 'string', + $request, $response, ); } @@ -2248,6 +2264,7 @@ public function testQueryStyleFormExplodeTrueArrayStringWithHttpInfo( return $this->handleResponseWithDataType( 'string', + $request, $response, ); } catch (ApiException $e) { @@ -2501,6 +2518,7 @@ public function testQueryStyleFormExplodeTrueObjectWithHttpInfo( case 200: return $this->handleResponseWithDataType( 'string', + $request, $response, ); } @@ -2521,6 +2539,7 @@ public function testQueryStyleFormExplodeTrueObjectWithHttpInfo( return $this->handleResponseWithDataType( 'string', + $request, $response, ); } catch (ApiException $e) { @@ -2774,6 +2793,7 @@ public function testQueryStyleFormExplodeTrueObjectAllOfWithHttpInfo( case 200: return $this->handleResponseWithDataType( 'string', + $request, $response, ); } @@ -2794,6 +2814,7 @@ public function testQueryStyleFormExplodeTrueObjectAllOfWithHttpInfo( return $this->handleResponseWithDataType( 'string', + $request, $response, ); } catch (ApiException $e) { @@ -3002,6 +3023,7 @@ protected function createHttpClientOption(): array private function handleResponseWithDataType( string $dataType, + RequestInterface $request, ResponseInterface $response, ): array { if (in_array($dataType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { diff --git a/samples/client/echo_api/php-nextgen/src/Api/AuthApi.php b/samples/client/echo_api/php-nextgen/src/Api/AuthApi.php index 740aeab82ba8..eac402dd75dd 100644 --- a/samples/client/echo_api/php-nextgen/src/Api/AuthApi.php +++ b/samples/client/echo_api/php-nextgen/src/Api/AuthApi.php @@ -36,6 +36,7 @@ use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; use GuzzleHttp\Promise\PromiseInterface; +use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use OpenAPI\Client\ApiException; use OpenAPI\Client\Configuration; @@ -189,6 +190,7 @@ public function testAuthHttpBasicWithHttpInfo( case 200: return $this->handleResponseWithDataType( 'string', + $request, $response, ); } @@ -209,6 +211,7 @@ public function testAuthHttpBasicWithHttpInfo( return $this->handleResponseWithDataType( 'string', + $request, $response, ); } catch (ApiException $e) { @@ -446,6 +449,7 @@ public function testAuthHttpBearerWithHttpInfo( case 200: return $this->handleResponseWithDataType( 'string', + $request, $response, ); } @@ -466,6 +470,7 @@ public function testAuthHttpBearerWithHttpInfo( return $this->handleResponseWithDataType( 'string', + $request, $response, ); } catch (ApiException $e) { @@ -662,6 +667,7 @@ protected function createHttpClientOption(): array private function handleResponseWithDataType( string $dataType, + RequestInterface $request, ResponseInterface $response, ): array { if (in_array($dataType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { diff --git a/samples/client/echo_api/php-nextgen/src/Api/BodyApi.php b/samples/client/echo_api/php-nextgen/src/Api/BodyApi.php index be8394f36b5f..3d63c8a2d4b7 100644 --- a/samples/client/echo_api/php-nextgen/src/Api/BodyApi.php +++ b/samples/client/echo_api/php-nextgen/src/Api/BodyApi.php @@ -36,6 +36,7 @@ use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; use GuzzleHttp\Promise\PromiseInterface; +use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use OpenAPI\Client\ApiException; use OpenAPI\Client\Configuration; @@ -213,6 +214,7 @@ public function testBinaryGifWithHttpInfo( case 200: return $this->handleResponseWithDataType( '\SplFileObject', + $request, $response, ); } @@ -233,6 +235,7 @@ public function testBinaryGifWithHttpInfo( return $this->handleResponseWithDataType( '\SplFileObject', + $request, $response, ); } catch (ApiException $e) { @@ -470,6 +473,7 @@ public function testBodyApplicationOctetstreamBinaryWithHttpInfo( case 200: return $this->handleResponseWithDataType( 'string', + $request, $response, ); } @@ -490,6 +494,7 @@ public function testBodyApplicationOctetstreamBinaryWithHttpInfo( return $this->handleResponseWithDataType( 'string', + $request, $response, ); } catch (ApiException $e) { @@ -741,6 +746,7 @@ public function testBodyMultipartFormdataArrayOfBinaryWithHttpInfo( case 200: return $this->handleResponseWithDataType( 'string', + $request, $response, ); } @@ -761,6 +767,7 @@ public function testBodyMultipartFormdataArrayOfBinaryWithHttpInfo( return $this->handleResponseWithDataType( 'string', + $request, $response, ); } catch (ApiException $e) { @@ -1025,6 +1032,7 @@ public function testBodyMultipartFormdataSingleBinaryWithHttpInfo( case 200: return $this->handleResponseWithDataType( 'string', + $request, $response, ); } @@ -1045,6 +1053,7 @@ public function testBodyMultipartFormdataSingleBinaryWithHttpInfo( return $this->handleResponseWithDataType( 'string', + $request, $response, ); } catch (ApiException $e) { @@ -1303,6 +1312,7 @@ public function testEchoBodyAllOfPetWithHttpInfo( case 200: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\Pet', + $request, $response, ); } @@ -1323,6 +1333,7 @@ public function testEchoBodyAllOfPetWithHttpInfo( return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\Pet', + $request, $response, ); } catch (ApiException $e) { @@ -1574,6 +1585,7 @@ public function testEchoBodyFreeFormObjectResponseStringWithHttpInfo( case 200: return $this->handleResponseWithDataType( 'string', + $request, $response, ); } @@ -1594,6 +1606,7 @@ public function testEchoBodyFreeFormObjectResponseStringWithHttpInfo( return $this->handleResponseWithDataType( 'string', + $request, $response, ); } catch (ApiException $e) { @@ -1845,6 +1858,7 @@ public function testEchoBodyPetWithHttpInfo( case 200: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\Pet', + $request, $response, ); } @@ -1865,6 +1879,7 @@ public function testEchoBodyPetWithHttpInfo( return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\Pet', + $request, $response, ); } catch (ApiException $e) { @@ -2116,6 +2131,7 @@ public function testEchoBodyPetResponseStringWithHttpInfo( case 200: return $this->handleResponseWithDataType( 'string', + $request, $response, ); } @@ -2136,6 +2152,7 @@ public function testEchoBodyPetResponseStringWithHttpInfo( return $this->handleResponseWithDataType( 'string', + $request, $response, ); } catch (ApiException $e) { @@ -2387,6 +2404,7 @@ public function testEchoBodyStringEnumWithHttpInfo( case 200: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\StringEnumRef', + $request, $response, ); } @@ -2407,6 +2425,7 @@ public function testEchoBodyStringEnumWithHttpInfo( return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\StringEnumRef', + $request, $response, ); } catch (ApiException $e) { @@ -2658,6 +2677,7 @@ public function testEchoBodyTagResponseStringWithHttpInfo( case 200: return $this->handleResponseWithDataType( 'string', + $request, $response, ); } @@ -2678,6 +2698,7 @@ public function testEchoBodyTagResponseStringWithHttpInfo( return $this->handleResponseWithDataType( 'string', + $request, $response, ); } catch (ApiException $e) { @@ -2884,6 +2905,7 @@ protected function createHttpClientOption(): array private function handleResponseWithDataType( string $dataType, + RequestInterface $request, ResponseInterface $response, ): array { if (in_array($dataType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { diff --git a/samples/client/echo_api/php-nextgen/src/Api/FormApi.php b/samples/client/echo_api/php-nextgen/src/Api/FormApi.php index 1b1bb8aecaa2..23be7e56f066 100644 --- a/samples/client/echo_api/php-nextgen/src/Api/FormApi.php +++ b/samples/client/echo_api/php-nextgen/src/Api/FormApi.php @@ -36,6 +36,7 @@ use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; use GuzzleHttp\Promise\PromiseInterface; +use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use OpenAPI\Client\ApiException; use OpenAPI\Client\Configuration; @@ -204,6 +205,7 @@ public function testFormIntegerBooleanStringWithHttpInfo( case 200: return $this->handleResponseWithDataType( 'string', + $request, $response, ); } @@ -224,6 +226,7 @@ public function testFormIntegerBooleanStringWithHttpInfo( return $this->handleResponseWithDataType( 'string', + $request, $response, ); } catch (ApiException $e) { @@ -494,6 +497,7 @@ public function testFormObjectMultipartWithHttpInfo( case 200: return $this->handleResponseWithDataType( 'string', + $request, $response, ); } @@ -514,6 +518,7 @@ public function testFormObjectMultipartWithHttpInfo( return $this->handleResponseWithDataType( 'string', + $request, $response, ); } catch (ApiException $e) { @@ -788,6 +793,7 @@ public function testFormOneofWithHttpInfo( case 200: return $this->handleResponseWithDataType( 'string', + $request, $response, ); } @@ -808,6 +814,7 @@ public function testFormOneofWithHttpInfo( return $this->handleResponseWithDataType( 'string', + $request, $response, ); } catch (ApiException $e) { @@ -1066,6 +1073,7 @@ protected function createHttpClientOption(): array private function handleResponseWithDataType( string $dataType, + RequestInterface $request, ResponseInterface $response, ): array { if (in_array($dataType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { diff --git a/samples/client/echo_api/php-nextgen/src/Api/HeaderApi.php b/samples/client/echo_api/php-nextgen/src/Api/HeaderApi.php index 3d18038f17eb..7590397a6d90 100644 --- a/samples/client/echo_api/php-nextgen/src/Api/HeaderApi.php +++ b/samples/client/echo_api/php-nextgen/src/Api/HeaderApi.php @@ -36,6 +36,7 @@ use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; use GuzzleHttp\Promise\PromiseInterface; +use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use OpenAPI\Client\ApiException; use OpenAPI\Client\Configuration; @@ -206,6 +207,7 @@ public function testHeaderIntegerBooleanStringEnumsWithHttpInfo( case 200: return $this->handleResponseWithDataType( 'string', + $request, $response, ); } @@ -226,6 +228,7 @@ public function testHeaderIntegerBooleanStringEnumsWithHttpInfo( return $this->handleResponseWithDataType( 'string', + $request, $response, ); } catch (ApiException $e) { @@ -473,6 +476,7 @@ protected function createHttpClientOption(): array private function handleResponseWithDataType( string $dataType, + RequestInterface $request, ResponseInterface $response, ): array { if (in_array($dataType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { diff --git a/samples/client/echo_api/php-nextgen/src/Api/PathApi.php b/samples/client/echo_api/php-nextgen/src/Api/PathApi.php index 0842612e45a9..d40c949e05e3 100644 --- a/samples/client/echo_api/php-nextgen/src/Api/PathApi.php +++ b/samples/client/echo_api/php-nextgen/src/Api/PathApi.php @@ -36,6 +36,7 @@ use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; use GuzzleHttp\Promise\PromiseInterface; +use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use OpenAPI\Client\ApiException; use OpenAPI\Client\Configuration; @@ -202,6 +203,7 @@ public function testsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathE case 200: return $this->handleResponseWithDataType( 'string', + $request, $response, ); } @@ -222,6 +224,7 @@ public function testsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathE return $this->handleResponseWithDataType( 'string', + $request, $response, ); } catch (ApiException $e) { @@ -498,6 +501,7 @@ protected function createHttpClientOption(): array private function handleResponseWithDataType( string $dataType, + RequestInterface $request, ResponseInterface $response, ): array { if (in_array($dataType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { diff --git a/samples/client/echo_api/php-nextgen/src/Api/QueryApi.php b/samples/client/echo_api/php-nextgen/src/Api/QueryApi.php index cd1a249558a9..34b6a4d324c8 100644 --- a/samples/client/echo_api/php-nextgen/src/Api/QueryApi.php +++ b/samples/client/echo_api/php-nextgen/src/Api/QueryApi.php @@ -36,6 +36,7 @@ use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; use GuzzleHttp\Promise\PromiseInterface; +use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use OpenAPI\Client\ApiException; use OpenAPI\Client\Configuration; @@ -221,6 +222,7 @@ public function testEnumRefStringWithHttpInfo( case 200: return $this->handleResponseWithDataType( 'string', + $request, $response, ); } @@ -241,6 +243,7 @@ public function testEnumRefStringWithHttpInfo( return $this->handleResponseWithDataType( 'string', + $request, $response, ); } catch (ApiException $e) { @@ -518,6 +521,7 @@ public function testQueryDatetimeDateStringWithHttpInfo( case 200: return $this->handleResponseWithDataType( 'string', + $request, $response, ); } @@ -538,6 +542,7 @@ public function testQueryDatetimeDateStringWithHttpInfo( return $this->handleResponseWithDataType( 'string', + $request, $response, ); } catch (ApiException $e) { @@ -831,6 +836,7 @@ public function testQueryIntegerBooleanStringWithHttpInfo( case 200: return $this->handleResponseWithDataType( 'string', + $request, $response, ); } @@ -851,6 +857,7 @@ public function testQueryIntegerBooleanStringWithHttpInfo( return $this->handleResponseWithDataType( 'string', + $request, $response, ); } catch (ApiException $e) { @@ -1136,6 +1143,7 @@ public function testQueryStyleDeepObjectExplodeTrueObjectWithHttpInfo( case 200: return $this->handleResponseWithDataType( 'string', + $request, $response, ); } @@ -1156,6 +1164,7 @@ public function testQueryStyleDeepObjectExplodeTrueObjectWithHttpInfo( return $this->handleResponseWithDataType( 'string', + $request, $response, ); } catch (ApiException $e) { @@ -1409,6 +1418,7 @@ public function testQueryStyleDeepObjectExplodeTrueObjectAllOfWithHttpInfo( case 200: return $this->handleResponseWithDataType( 'string', + $request, $response, ); } @@ -1429,6 +1439,7 @@ public function testQueryStyleDeepObjectExplodeTrueObjectAllOfWithHttpInfo( return $this->handleResponseWithDataType( 'string', + $request, $response, ); } catch (ApiException $e) { @@ -1682,6 +1693,7 @@ public function testQueryStyleFormExplodeFalseArrayIntegerWithHttpInfo( case 200: return $this->handleResponseWithDataType( 'string', + $request, $response, ); } @@ -1702,6 +1714,7 @@ public function testQueryStyleFormExplodeFalseArrayIntegerWithHttpInfo( return $this->handleResponseWithDataType( 'string', + $request, $response, ); } catch (ApiException $e) { @@ -1955,6 +1968,7 @@ public function testQueryStyleFormExplodeFalseArrayStringWithHttpInfo( case 200: return $this->handleResponseWithDataType( 'string', + $request, $response, ); } @@ -1975,6 +1989,7 @@ public function testQueryStyleFormExplodeFalseArrayStringWithHttpInfo( return $this->handleResponseWithDataType( 'string', + $request, $response, ); } catch (ApiException $e) { @@ -2228,6 +2243,7 @@ public function testQueryStyleFormExplodeTrueArrayStringWithHttpInfo( case 200: return $this->handleResponseWithDataType( 'string', + $request, $response, ); } @@ -2248,6 +2264,7 @@ public function testQueryStyleFormExplodeTrueArrayStringWithHttpInfo( return $this->handleResponseWithDataType( 'string', + $request, $response, ); } catch (ApiException $e) { @@ -2501,6 +2518,7 @@ public function testQueryStyleFormExplodeTrueObjectWithHttpInfo( case 200: return $this->handleResponseWithDataType( 'string', + $request, $response, ); } @@ -2521,6 +2539,7 @@ public function testQueryStyleFormExplodeTrueObjectWithHttpInfo( return $this->handleResponseWithDataType( 'string', + $request, $response, ); } catch (ApiException $e) { @@ -2774,6 +2793,7 @@ public function testQueryStyleFormExplodeTrueObjectAllOfWithHttpInfo( case 200: return $this->handleResponseWithDataType( 'string', + $request, $response, ); } @@ -2794,6 +2814,7 @@ public function testQueryStyleFormExplodeTrueObjectAllOfWithHttpInfo( return $this->handleResponseWithDataType( 'string', + $request, $response, ); } catch (ApiException $e) { @@ -3002,6 +3023,7 @@ protected function createHttpClientOption(): array private function handleResponseWithDataType( string $dataType, + RequestInterface $request, ResponseInterface $response, ): array { if (in_array($dataType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { diff --git a/samples/client/petstore/php-nextgen/OpenAPIClient-php/.openapi-generator/FILES b/samples/client/petstore/php-nextgen/OpenAPIClient-php/.openapi-generator/FILES index a7e753bda7df..15feb03a699f 100644 --- a/samples/client/petstore/php-nextgen/OpenAPIClient-php/.openapi-generator/FILES +++ b/samples/client/petstore/php-nextgen/OpenAPIClient-php/.openapi-generator/FILES @@ -129,4 +129,3 @@ src/Model/Tag.php src/Model/TestInlineFreeformAdditionalPropertiesRequest.php src/Model/User.php src/ObjectSerializer.php -tests/Model/ErrorResponseTest.php diff --git a/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/AnotherFakeApi.php b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/AnotherFakeApi.php index 811f1aaf63c8..9927734e053a 100644 --- a/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/AnotherFakeApi.php +++ b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/AnotherFakeApi.php @@ -35,6 +35,7 @@ use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; use GuzzleHttp\Promise\PromiseInterface; +use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use OpenAPI\Client\ApiException; use OpenAPI\Client\Configuration; @@ -189,6 +190,7 @@ public function call123TestSpecialTagsWithHttpInfo( case 200: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\Client', + $request, $response, ); } @@ -209,6 +211,7 @@ public function call123TestSpecialTagsWithHttpInfo( return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\Client', + $request, $response, ); } catch (ApiException $e) { @@ -421,6 +424,7 @@ protected function createHttpClientOption(): array private function handleResponseWithDataType( string $dataType, + RequestInterface $request, ResponseInterface $response, ): array { if (in_array($dataType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { diff --git a/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/DefaultApi.php b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/DefaultApi.php index 435f979780e6..bdc2f7af0c14 100644 --- a/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/DefaultApi.php +++ b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/DefaultApi.php @@ -35,6 +35,7 @@ use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; use GuzzleHttp\Promise\PromiseInterface; +use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use OpenAPI\Client\ApiException; use OpenAPI\Client\Configuration; @@ -181,6 +182,7 @@ public function fooGetWithHttpInfo( default: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\FooGetDefaultResponse', + $request, $response, ); } @@ -201,6 +203,7 @@ public function fooGetWithHttpInfo( return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\FooGetDefaultResponse', + $request, $response, ); } catch (ApiException $e) { @@ -389,6 +392,7 @@ protected function createHttpClientOption(): array private function handleResponseWithDataType( string $dataType, + RequestInterface $request, ResponseInterface $response, ): array { if (in_array($dataType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { diff --git a/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/FakeApi.php b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/FakeApi.php index 65824deacb5a..20570f12e579 100644 --- a/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/FakeApi.php +++ b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/FakeApi.php @@ -35,6 +35,7 @@ use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; use GuzzleHttp\Promise\PromiseInterface; +use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use OpenAPI\Client\ApiException; use OpenAPI\Client\Configuration; @@ -260,6 +261,7 @@ public function fakeBigDecimalMapWithHttpInfo( case 200: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\FakeBigDecimalMap200Response', + $request, $response, ); } @@ -280,6 +282,7 @@ public function fakeBigDecimalMapWithHttpInfo( return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\FakeBigDecimalMap200Response', + $request, $response, ); } catch (ApiException $e) { @@ -521,6 +524,7 @@ public function fakeEnumEndpointWithHttpInfo( case 200: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\EnumClass', + $request, $response, ); } @@ -541,6 +545,7 @@ public function fakeEnumEndpointWithHttpInfo( return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\EnumClass', + $request, $response, ); } catch (ApiException $e) { @@ -840,6 +845,7 @@ public function fakeHealthGetWithHttpInfo( case 200: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\HealthCheckResult', + $request, $response, ); } @@ -860,6 +866,7 @@ public function fakeHealthGetWithHttpInfo( return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\HealthCheckResult', + $request, $response, ); } catch (ApiException $e) { @@ -1359,6 +1366,7 @@ public function fakeOuterBooleanSerializeWithHttpInfo( case 200: return $this->handleResponseWithDataType( 'bool', + $request, $response, ); } @@ -1379,6 +1387,7 @@ public function fakeOuterBooleanSerializeWithHttpInfo( return $this->handleResponseWithDataType( 'bool', + $request, $response, ); } catch (ApiException $e) { @@ -1622,6 +1631,7 @@ public function fakeOuterCompositeSerializeWithHttpInfo( case 200: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\OuterComposite', + $request, $response, ); } @@ -1642,6 +1652,7 @@ public function fakeOuterCompositeSerializeWithHttpInfo( return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\OuterComposite', + $request, $response, ); } catch (ApiException $e) { @@ -1885,6 +1896,7 @@ public function fakeOuterNumberSerializeWithHttpInfo( case 200: return $this->handleResponseWithDataType( 'float', + $request, $response, ); } @@ -1905,6 +1917,7 @@ public function fakeOuterNumberSerializeWithHttpInfo( return $this->handleResponseWithDataType( 'float', + $request, $response, ); } catch (ApiException $e) { @@ -2148,6 +2161,7 @@ public function fakeOuterStringSerializeWithHttpInfo( case 200: return $this->handleResponseWithDataType( 'string', + $request, $response, ); } @@ -2168,6 +2182,7 @@ public function fakeOuterStringSerializeWithHttpInfo( return $this->handleResponseWithDataType( 'string', + $request, $response, ); } catch (ApiException $e) { @@ -2411,6 +2426,7 @@ public function fakePropertyEnumIntegerSerializeWithHttpInfo( case 200: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\OuterObjectWithEnumProperty', + $request, $response, ); } @@ -2431,6 +2447,7 @@ public function fakePropertyEnumIntegerSerializeWithHttpInfo( return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\OuterObjectWithEnumProperty', + $request, $response, ); } catch (ApiException $e) { @@ -2684,11 +2701,13 @@ public function fakeWith400And4xxRangeResponseEndpointWithHttpInfo( case 200: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\Pet', + $request, $response, ); case 400: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\ErrorResponse', + $request, $response, ); @@ -2697,6 +2716,7 @@ public function fakeWith400And4xxRangeResponseEndpointWithHttpInfo( if ($this->responseWithinRangeCode('4xx', $statusCode)) { return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\ErrorResponse', + $request, $response, ); } @@ -2716,6 +2736,7 @@ public function fakeWith400And4xxRangeResponseEndpointWithHttpInfo( return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\Pet', + $request, $response, ); } catch (ApiException $e) { @@ -2991,11 +3012,13 @@ public function fakeWith400ResponseEndpointWithHttpInfo( case 200: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\Pet', + $request, $response, ); case 400: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\ErrorResponse', + $request, $response, ); } @@ -3016,6 +3039,7 @@ public function fakeWith400ResponseEndpointWithHttpInfo( return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\Pet', + $request, $response, ); } catch (ApiException $e) { @@ -3281,6 +3305,7 @@ public function fakeWith4xxRangeResponseEndpointWithHttpInfo( case 200: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\Pet', + $request, $response, ); @@ -3289,6 +3314,7 @@ public function fakeWith4xxRangeResponseEndpointWithHttpInfo( if ($this->responseWithinRangeCode('4xx', $statusCode)) { return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\ErrorResponse', + $request, $response, ); } @@ -3308,6 +3334,7 @@ public function fakeWith4xxRangeResponseEndpointWithHttpInfo( return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\Pet', + $request, $response, ); } catch (ApiException $e) { @@ -4501,6 +4528,7 @@ public function testClientModelWithHttpInfo( case 200: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\Client', + $request, $response, ); } @@ -4521,6 +4549,7 @@ public function testClientModelWithHttpInfo( return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\Client', + $request, $response, ); } catch (ApiException $e) { @@ -7472,6 +7501,7 @@ protected function createHttpClientOption(): array private function handleResponseWithDataType( string $dataType, + RequestInterface $request, ResponseInterface $response, ): array { if (in_array($dataType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { diff --git a/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/FakeClassnameTags123Api.php b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/FakeClassnameTags123Api.php index c9b4667ecb3a..30635a2fe9ee 100644 --- a/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/FakeClassnameTags123Api.php +++ b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/FakeClassnameTags123Api.php @@ -35,6 +35,7 @@ use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; use GuzzleHttp\Promise\PromiseInterface; +use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use OpenAPI\Client\ApiException; use OpenAPI\Client\Configuration; @@ -189,6 +190,7 @@ public function testClassnameWithHttpInfo( case 200: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\Client', + $request, $response, ); } @@ -209,6 +211,7 @@ public function testClassnameWithHttpInfo( return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\Client', + $request, $response, ); } catch (ApiException $e) { @@ -426,6 +429,7 @@ protected function createHttpClientOption(): array private function handleResponseWithDataType( string $dataType, + RequestInterface $request, ResponseInterface $response, ): array { if (in_array($dataType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { diff --git a/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/PetApi.php b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/PetApi.php index 00de4eba4a38..702bc9e51cc6 100644 --- a/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/PetApi.php +++ b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/PetApi.php @@ -35,6 +35,7 @@ use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; use GuzzleHttp\Promise\PromiseInterface; +use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use OpenAPI\Client\ApiException; use OpenAPI\Client\Configuration; @@ -853,6 +854,7 @@ public function findPetsByStatusWithHttpInfo( case 200: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\Pet[]', + $request, $response, ); } @@ -873,6 +875,7 @@ public function findPetsByStatusWithHttpInfo( return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\Pet[]', + $request, $response, ); } catch (ApiException $e) { @@ -1138,6 +1141,7 @@ public function findPetsByTagsWithHttpInfo( case 200: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\Pet[]', + $request, $response, ); } @@ -1158,6 +1162,7 @@ public function findPetsByTagsWithHttpInfo( return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\Pet[]', + $request, $response, ); } catch (ApiException $e) { @@ -1424,6 +1429,7 @@ public function getPetByIdWithHttpInfo( case 200: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\Pet', + $request, $response, ); } @@ -1444,6 +1450,7 @@ public function getPetByIdWithHttpInfo( return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\Pet', + $request, $response, ); } catch (ApiException $e) { @@ -2368,6 +2375,7 @@ public function uploadFileWithHttpInfo( case 200: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\ApiResponse', + $request, $response, ); } @@ -2388,6 +2396,7 @@ public function uploadFileWithHttpInfo( return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\ApiResponse', + $request, $response, ); } catch (ApiException $e) { @@ -2690,6 +2699,7 @@ public function uploadFileWithRequiredFileWithHttpInfo( case 200: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\ApiResponse', + $request, $response, ); } @@ -2710,6 +2720,7 @@ public function uploadFileWithRequiredFileWithHttpInfo( return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\ApiResponse', + $request, $response, ); } catch (ApiException $e) { @@ -2965,6 +2976,7 @@ protected function createHttpClientOption(): array private function handleResponseWithDataType( string $dataType, + RequestInterface $request, ResponseInterface $response, ): array { if (in_array($dataType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { diff --git a/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/StoreApi.php b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/StoreApi.php index 81a3e408f22e..d815e6651c47 100644 --- a/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/StoreApi.php +++ b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/StoreApi.php @@ -35,6 +35,7 @@ use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; use GuzzleHttp\Promise\PromiseInterface; +use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use OpenAPI\Client\ApiException; use OpenAPI\Client\Configuration; @@ -426,6 +427,7 @@ public function getInventoryWithHttpInfo( case 200: return $this->handleResponseWithDataType( 'array', + $request, $response, ); } @@ -446,6 +448,7 @@ public function getInventoryWithHttpInfo( return $this->handleResponseWithDataType( 'array', + $request, $response, ); } catch (ApiException $e) { @@ -688,6 +691,7 @@ public function getOrderByIdWithHttpInfo( case 200: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\Order', + $request, $response, ); } @@ -708,6 +712,7 @@ public function getOrderByIdWithHttpInfo( return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\Order', + $request, $response, ); } catch (ApiException $e) { @@ -972,6 +977,7 @@ public function placeOrderWithHttpInfo( case 200: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\Order', + $request, $response, ); } @@ -992,6 +998,7 @@ public function placeOrderWithHttpInfo( return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\Order', + $request, $response, ); } catch (ApiException $e) { @@ -1204,6 +1211,7 @@ protected function createHttpClientOption(): array private function handleResponseWithDataType( string $dataType, + RequestInterface $request, ResponseInterface $response, ): array { if (in_array($dataType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { diff --git a/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/UserApi.php b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/UserApi.php index 85f2087f21d2..880491926710 100644 --- a/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/UserApi.php +++ b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/UserApi.php @@ -35,6 +35,7 @@ use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; use GuzzleHttp\Promise\PromiseInterface; +use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use OpenAPI\Client\ApiException; use OpenAPI\Client\Configuration; @@ -1135,6 +1136,7 @@ public function getUserByNameWithHttpInfo( case 200: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\User', + $request, $response, ); } @@ -1155,6 +1157,7 @@ public function getUserByNameWithHttpInfo( return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\User', + $request, $response, ); } catch (ApiException $e) { @@ -1417,6 +1420,7 @@ public function loginUserWithHttpInfo( case 200: return $this->handleResponseWithDataType( 'string', + $request, $response, ); } @@ -1437,6 +1441,7 @@ public function loginUserWithHttpInfo( return $this->handleResponseWithDataType( 'string', + $request, $response, ); } catch (ApiException $e) { @@ -2136,6 +2141,7 @@ protected function createHttpClientOption(): array private function handleResponseWithDataType( string $dataType, + RequestInterface $request, ResponseInterface $response, ): array { if (in_array($dataType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { diff --git a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/AnotherFakeApi.php b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/AnotherFakeApi.php index 9af2ab03bef1..34f82fd71744 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/AnotherFakeApi.php +++ b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/AnotherFakeApi.php @@ -34,6 +34,7 @@ use GuzzleHttp\Psr7\MultipartStream; use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; +use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use OpenAPI\Client\ApiException; use OpenAPI\Client\Configuration; @@ -184,6 +185,7 @@ public function call123TestSpecialTagsWithHttpInfo($client, string $contentType case 200: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\Client', + $request, $response, ); } @@ -205,6 +207,7 @@ public function call123TestSpecialTagsWithHttpInfo($client, string $contentType return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\Client', + $request, $response, ); } catch (ApiException $e) { @@ -409,6 +412,7 @@ protected function createHttpClientOption() private function handleResponseWithDataType( string $dataType, + RequestInterface $request, ResponseInterface $response ): array { if ($dataType === '\SplFileObject') { diff --git a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/DefaultApi.php b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/DefaultApi.php index 3c17b07a4bc4..00ff8ae25454 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/DefaultApi.php +++ b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/DefaultApi.php @@ -34,6 +34,7 @@ use GuzzleHttp\Psr7\MultipartStream; use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; +use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use OpenAPI\Client\ApiException; use OpenAPI\Client\Configuration; @@ -178,6 +179,7 @@ public function fooGetWithHttpInfo(string $contentType = self::contentTypes['foo default: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\FooGetDefaultResponse', + $request, $response, ); } @@ -199,6 +201,7 @@ public function fooGetWithHttpInfo(string $contentType = self::contentTypes['foo return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\FooGetDefaultResponse', + $request, $response, ); } catch (ApiException $e) { @@ -382,6 +385,7 @@ protected function createHttpClientOption() private function handleResponseWithDataType( string $dataType, + RequestInterface $request, ResponseInterface $response ): array { if ($dataType === '\SplFileObject') { diff --git a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/FakeApi.php b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/FakeApi.php index 80055fa07753..c70b1d893dd2 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/FakeApi.php +++ b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/FakeApi.php @@ -34,6 +34,7 @@ use GuzzleHttp\Psr7\MultipartStream; use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; +use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use OpenAPI\Client\ApiException; use OpenAPI\Client\Configuration; @@ -257,6 +258,7 @@ public function fakeBigDecimalMapWithHttpInfo(string $contentType = self::conten case 200: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\FakeBigDecimalMap200Response', + $request, $response, ); } @@ -278,6 +280,7 @@ public function fakeBigDecimalMapWithHttpInfo(string $contentType = self::conten return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\FakeBigDecimalMap200Response', + $request, $response, ); } catch (ApiException $e) { @@ -505,6 +508,7 @@ public function fakeEnumEndpointWithHttpInfo($enum_class, $enum_class_array, $en case 200: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\EnumClass', + $request, $response, ); } @@ -526,6 +530,7 @@ public function fakeEnumEndpointWithHttpInfo($enum_class, $enum_class_array, $en return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\EnumClass', + $request, $response, ); } catch (ApiException $e) { @@ -808,6 +813,7 @@ public function fakeHealthGetWithHttpInfo(string $contentType = self::contentTyp case 200: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\HealthCheckResult', + $request, $response, ); } @@ -829,6 +835,7 @@ public function fakeHealthGetWithHttpInfo(string $contentType = self::contentTyp return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\HealthCheckResult', + $request, $response, ); } catch (ApiException $e) { @@ -1294,6 +1301,7 @@ public function fakeOuterBooleanSerializeWithHttpInfo($body = null, string $cont case 200: return $this->handleResponseWithDataType( 'bool', + $request, $response, ); } @@ -1315,6 +1323,7 @@ public function fakeOuterBooleanSerializeWithHttpInfo($body = null, string $cont return $this->handleResponseWithDataType( 'bool', + $request, $response, ); } catch (ApiException $e) { @@ -1545,6 +1554,7 @@ public function fakeOuterCompositeSerializeWithHttpInfo($outer_composite = null, case 200: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\OuterComposite', + $request, $response, ); } @@ -1566,6 +1576,7 @@ public function fakeOuterCompositeSerializeWithHttpInfo($outer_composite = null, return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\OuterComposite', + $request, $response, ); } catch (ApiException $e) { @@ -1796,6 +1807,7 @@ public function fakeOuterNumberSerializeWithHttpInfo($body = null, string $conte case 200: return $this->handleResponseWithDataType( 'float', + $request, $response, ); } @@ -1817,6 +1829,7 @@ public function fakeOuterNumberSerializeWithHttpInfo($body = null, string $conte return $this->handleResponseWithDataType( 'float', + $request, $response, ); } catch (ApiException $e) { @@ -2047,6 +2060,7 @@ public function fakeOuterStringSerializeWithHttpInfo($body = null, string $conte case 200: return $this->handleResponseWithDataType( 'string', + $request, $response, ); } @@ -2068,6 +2082,7 @@ public function fakeOuterStringSerializeWithHttpInfo($body = null, string $conte return $this->handleResponseWithDataType( 'string', + $request, $response, ); } catch (ApiException $e) { @@ -2298,6 +2313,7 @@ public function fakePropertyEnumIntegerSerializeWithHttpInfo($outer_object_with_ case 200: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\OuterObjectWithEnumProperty', + $request, $response, ); } @@ -2319,6 +2335,7 @@ public function fakePropertyEnumIntegerSerializeWithHttpInfo($outer_object_with_ return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\OuterObjectWithEnumProperty', + $request, $response, ); } catch (ApiException $e) { @@ -2559,11 +2576,13 @@ public function fakeWith400And4xxRangeResponseEndpointWithHttpInfo($pet, string case 200: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\Pet', + $request, $response, ); case 400: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\ErrorResponse', + $request, $response, ); @@ -2572,6 +2591,7 @@ public function fakeWith400And4xxRangeResponseEndpointWithHttpInfo($pet, string if ($this->responseWithinRangeCode('4xx', $statusCode)) { return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\ErrorResponse', + $request, $response, ); } @@ -2591,6 +2611,7 @@ public function fakeWith400And4xxRangeResponseEndpointWithHttpInfo($pet, string return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\Pet', + $request, $response, ); } catch (ApiException $e) { @@ -2853,11 +2874,13 @@ public function fakeWith400ResponseEndpointWithHttpInfo($pet, string $contentTyp case 200: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\Pet', + $request, $response, ); case 400: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\ErrorResponse', + $request, $response, ); } @@ -2879,6 +2902,7 @@ public function fakeWith400ResponseEndpointWithHttpInfo($pet, string $contentTyp return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\Pet', + $request, $response, ); } catch (ApiException $e) { @@ -3131,6 +3155,7 @@ public function fakeWith4xxRangeResponseEndpointWithHttpInfo($pet, string $conte case 200: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\Pet', + $request, $response, ); @@ -3139,6 +3164,7 @@ public function fakeWith4xxRangeResponseEndpointWithHttpInfo($pet, string $conte if ($this->responseWithinRangeCode('4xx', $statusCode)) { return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\ErrorResponse', + $request, $response, ); } @@ -3158,6 +3184,7 @@ public function fakeWith4xxRangeResponseEndpointWithHttpInfo($pet, string $conte return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\Pet', + $request, $response, ); } catch (ApiException $e) { @@ -4565,6 +4592,7 @@ public function testClientModelWithHttpInfo($client, string $contentType = self: case 200: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\Client', + $request, $response, ); } @@ -4586,6 +4614,7 @@ public function testClientModelWithHttpInfo($client, string $contentType = self: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\Client', + $request, $response, ); } catch (ApiException $e) { @@ -7049,6 +7078,7 @@ protected function createHttpClientOption() private function handleResponseWithDataType( string $dataType, + RequestInterface $request, ResponseInterface $response ): array { if ($dataType === '\SplFileObject') { diff --git a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/FakeClassnameTags123Api.php b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/FakeClassnameTags123Api.php index 4f60c0adbc34..3508d16ea37f 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/FakeClassnameTags123Api.php +++ b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/FakeClassnameTags123Api.php @@ -34,6 +34,7 @@ use GuzzleHttp\Psr7\MultipartStream; use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; +use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use OpenAPI\Client\ApiException; use OpenAPI\Client\Configuration; @@ -184,6 +185,7 @@ public function testClassnameWithHttpInfo($client, string $contentType = self::c case 200: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\Client', + $request, $response, ); } @@ -205,6 +207,7 @@ public function testClassnameWithHttpInfo($client, string $contentType = self::c return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\Client', + $request, $response, ); } catch (ApiException $e) { @@ -414,6 +417,7 @@ protected function createHttpClientOption() private function handleResponseWithDataType( string $dataType, + RequestInterface $request, ResponseInterface $response ): array { if ($dataType === '\SplFileObject') { diff --git a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/PetApi.php b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/PetApi.php index 2695796312f9..48b57f7f140d 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/PetApi.php +++ b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/PetApi.php @@ -34,6 +34,7 @@ use GuzzleHttp\Psr7\MultipartStream; use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; +use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use OpenAPI\Client\ApiException; use OpenAPI\Client\Configuration; @@ -808,6 +809,7 @@ public function findPetsByStatusWithHttpInfo($status, string $contentType = self case 200: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\Pet[]', + $request, $response, ); } @@ -829,6 +831,7 @@ public function findPetsByStatusWithHttpInfo($status, string $contentType = self return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\Pet[]', + $request, $response, ); } catch (ApiException $e) { @@ -1081,6 +1084,7 @@ public function findPetsByTagsWithHttpInfo($tags, string $contentType = self::co case 200: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\Pet[]', + $request, $response, ); } @@ -1102,6 +1106,7 @@ public function findPetsByTagsWithHttpInfo($tags, string $contentType = self::co return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\Pet[]', + $request, $response, ); } catch (ApiException $e) { @@ -1355,6 +1360,7 @@ public function getPetByIdWithHttpInfo($pet_id, string $contentType = self::cont case 200: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\Pet', + $request, $response, ); } @@ -1376,6 +1382,7 @@ public function getPetByIdWithHttpInfo($pet_id, string $contentType = self::cont return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\Pet', + $request, $response, ); } catch (ApiException $e) { @@ -2235,6 +2242,7 @@ public function uploadFileWithHttpInfo($pet_id, $additional_metadata = null, $fi case 200: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\ApiResponse', + $request, $response, ); } @@ -2256,6 +2264,7 @@ public function uploadFileWithHttpInfo($pet_id, $additional_metadata = null, $fi return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\ApiResponse', + $request, $response, ); } catch (ApiException $e) { @@ -2534,6 +2543,7 @@ public function uploadFileWithRequiredFileWithHttpInfo($pet_id, $required_file, case 200: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\ApiResponse', + $request, $response, ); } @@ -2555,6 +2565,7 @@ public function uploadFileWithRequiredFileWithHttpInfo($pet_id, $required_file, return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\ApiResponse', + $request, $response, ); } catch (ApiException $e) { @@ -2851,6 +2862,7 @@ public function uploadImageFullFormDataWithHttpInfo($pet_id, $name, $photo_urls, case 200: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\ApiResponse', + $request, $response, ); } @@ -2872,6 +2884,7 @@ public function uploadImageFullFormDataWithHttpInfo($pet_id, $name, $photo_urls, return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\ApiResponse', + $request, $response, ); } catch (ApiException $e) { @@ -3174,6 +3187,7 @@ protected function createHttpClientOption() private function handleResponseWithDataType( string $dataType, + RequestInterface $request, ResponseInterface $response ): array { if ($dataType === '\SplFileObject') { diff --git a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/StoreApi.php b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/StoreApi.php index cfa1cfd5443e..bfbcfcd2e119 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/StoreApi.php +++ b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/StoreApi.php @@ -34,6 +34,7 @@ use GuzzleHttp\Psr7\MultipartStream; use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; +use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use OpenAPI\Client\ApiException; use OpenAPI\Client\Configuration; @@ -409,6 +410,7 @@ public function getInventoryWithHttpInfo(string $contentType = self::contentType case 200: return $this->handleResponseWithDataType( 'array', + $request, $response, ); } @@ -430,6 +432,7 @@ public function getInventoryWithHttpInfo(string $contentType = self::contentType return $this->handleResponseWithDataType( 'array', + $request, $response, ); } catch (ApiException $e) { @@ -662,6 +665,7 @@ public function getOrderByIdWithHttpInfo($order_id, string $contentType = self:: case 200: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\Order', + $request, $response, ); } @@ -683,6 +687,7 @@ public function getOrderByIdWithHttpInfo($order_id, string $contentType = self:: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\Order', + $request, $response, ); } catch (ApiException $e) { @@ -934,6 +939,7 @@ public function placeOrderWithHttpInfo($order, string $contentType = self::conte case 200: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\Order', + $request, $response, ); } @@ -955,6 +961,7 @@ public function placeOrderWithHttpInfo($order, string $contentType = self::conte return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\Order', + $request, $response, ); } catch (ApiException $e) { @@ -1159,6 +1166,7 @@ protected function createHttpClientOption() private function handleResponseWithDataType( string $dataType, + RequestInterface $request, ResponseInterface $response ): array { if ($dataType === '\SplFileObject') { diff --git a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/UserApi.php b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/UserApi.php index f8d871661371..2fd2e9423493 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/UserApi.php +++ b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/UserApi.php @@ -34,6 +34,7 @@ use GuzzleHttp\Psr7\MultipartStream; use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; +use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use OpenAPI\Client\ApiException; use OpenAPI\Client\Configuration; @@ -1074,6 +1075,7 @@ public function getUserByNameWithHttpInfo($username, string $contentType = self: case 200: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\User', + $request, $response, ); } @@ -1095,6 +1097,7 @@ public function getUserByNameWithHttpInfo($username, string $contentType = self: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\User', + $request, $response, ); } catch (ApiException $e) { @@ -1342,6 +1345,7 @@ public function loginUserWithHttpInfo($username, $password, string $contentType case 200: return $this->handleResponseWithDataType( 'string', + $request, $response, ); } @@ -1363,6 +1367,7 @@ public function loginUserWithHttpInfo($username, $password, string $contentType return $this->handleResponseWithDataType( 'string', + $request, $response, ); } catch (ApiException $e) { @@ -2023,6 +2028,7 @@ protected function createHttpClientOption() private function handleResponseWithDataType( string $dataType, + RequestInterface $request, ResponseInterface $response ): array { if ($dataType === '\SplFileObject') { diff --git a/samples/client/petstore/php/OpenAPIClient-php/lib/Model/ErrorResponse.php b/samples/client/petstore/php/OpenAPIClient-php/lib/Model/ErrorResponse.php index 1e9c3940003f..458660568ffd 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/lib/Model/ErrorResponse.php +++ b/samples/client/petstore/php/OpenAPIClient-php/lib/Model/ErrorResponse.php @@ -2,7 +2,7 @@ /** * ErrorResponse * - * PHP version 7.4 + * PHP version 8.1 * * @category Class * @package OpenAPI\Client diff --git a/samples/client/petstore/php/OpenAPIClient-php/tests/ResponseTypesTest.php b/samples/client/petstore/php/OpenAPIClient-php/tests/ResponseTypesTest.php index 6ebccec1a405..392330b88637 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/tests/ResponseTypesTest.php +++ b/samples/client/petstore/php/OpenAPIClient-php/tests/ResponseTypesTest.php @@ -117,10 +117,14 @@ public function testNotJSONResponse($statusCode, $responseBody) $this->api->getPetById(123); } - public function testRangeResponse() + public function testErrorRangeResponseWithDataType() { $responseCode = mt_rand(400, 499); - $this->fakeHttpClient->setResponse(new Response($responseCode, [], json_encode([]))); + $responseContent = [ + 'response_code' => $responseCode, + 'error' => 'Some random error', + ]; + $this->fakeHttpClient->setResponse(new Response($responseCode, [], json_encode($responseContent))); $api = new FakeApi($this->fakeHttpClient); $pet = new Model\Pet([]); @@ -128,14 +132,45 @@ public function testRangeResponse() $result = $api->fakeWith4xxRangeResponseEndpoint($pet); - $this->assertInstanceOf(Pet::class, $result); + $this->assertInstanceOf(Model\ErrorResponse::class, $result); + $this->assertEquals($responseContent['response_code'], $result->getResponseCode()); + } + public function testError400ResponseWithDataType() + { + $responseCode = 400; + $responseContent = [ + 'response_code' => $responseCode, + 'error' => 'Some random error', + ]; + $this->fakeHttpClient->setResponse(new Response($responseCode, [], json_encode($responseContent))); + $api = new FakeApi($this->fakeHttpClient); - $this->expectExceptionCode(404); - $this->expectException(\OpenAPI\Client\ApiException::class); - $statusCode = 404; + $pet = new Model\Pet([]); + $pet->setId(1234); - $this->fakeHttpClient->setResponse(new Response($statusCode, [], '{}')); - $this->api->getPetById(123); + $result = $api->fakeWith400ResponseEndpoint($pet); + + $this->assertInstanceOf(Model\ErrorResponse::class, $result); + $this->assertEquals($responseContent['response_code'], $result->getResponseCode()); + } + + public function testErrorRangeAnd400ResponseWithDataType() + { + $responseCode = mt_rand(400, 499); + $responseContent = [ + 'response_code' => $responseCode, + 'error' => 'Some random error', + ]; + $this->fakeHttpClient->setResponse(new Response($responseCode, [], json_encode($responseContent))); + $api = new FakeApi($this->fakeHttpClient); + + $pet = new Model\Pet([]); + $pet->setId(1234); + + $result = $api->fakeWith400And4xxRangeResponseEndpoint($pet); + + $this->assertInstanceOf(Model\ErrorResponse::class, $result); + $this->assertEquals($responseContent['response_code'], $result->getResponseCode()); } } diff --git a/samples/client/petstore/php/psr-18/lib/Api/AnotherFakeApi.php b/samples/client/petstore/php/psr-18/lib/Api/AnotherFakeApi.php index 5c7c585e6291..62a8fceab5f1 100644 --- a/samples/client/petstore/php/psr-18/lib/Api/AnotherFakeApi.php +++ b/samples/client/petstore/php/psr-18/lib/Api/AnotherFakeApi.php @@ -236,6 +236,7 @@ public function call123TestSpecialTagsWithHttpInfo($client) case 200: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\Client', + $request, $response, ); } @@ -257,6 +258,7 @@ public function call123TestSpecialTagsWithHttpInfo($client) return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\Client', + $request, $response, ); } catch (ApiException $e) { @@ -495,6 +497,7 @@ private function createUri( private function handleResponseWithDataType( string $dataType, + RequestInterface $request, ResponseInterface $response ): array { if ($dataType === '\SplFileObject') { diff --git a/samples/client/petstore/php/psr-18/lib/Api/DefaultApi.php b/samples/client/petstore/php/psr-18/lib/Api/DefaultApi.php index c441ff6fc025..888725830578 100644 --- a/samples/client/petstore/php/psr-18/lib/Api/DefaultApi.php +++ b/samples/client/petstore/php/psr-18/lib/Api/DefaultApi.php @@ -230,6 +230,7 @@ public function fooGetWithHttpInfo() default: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\FooGetDefaultResponse', + $request, $response, ); } @@ -251,6 +252,7 @@ public function fooGetWithHttpInfo() return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\FooGetDefaultResponse', + $request, $response, ); } catch (ApiException $e) { @@ -470,6 +472,7 @@ private function createUri( private function handleResponseWithDataType( string $dataType, + RequestInterface $request, ResponseInterface $response ): array { if ($dataType === '\SplFileObject') { diff --git a/samples/client/petstore/php/psr-18/lib/Api/FakeApi.php b/samples/client/petstore/php/psr-18/lib/Api/FakeApi.php index d6f5dfcd5fd4..181c8eb9fc0a 100644 --- a/samples/client/petstore/php/psr-18/lib/Api/FakeApi.php +++ b/samples/client/petstore/php/psr-18/lib/Api/FakeApi.php @@ -230,6 +230,7 @@ public function fakeBigDecimalMapWithHttpInfo() case 200: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\FakeBigDecimalMap200Response', + $request, $response, ); } @@ -251,6 +252,7 @@ public function fakeBigDecimalMapWithHttpInfo() return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\FakeBigDecimalMap200Response', + $request, $response, ); } catch (ApiException $e) { @@ -469,6 +471,7 @@ public function fakeEnumEndpointWithHttpInfo($enum_class, $enum_class_array, $en case 200: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\EnumClass', + $request, $response, ); } @@ -490,6 +493,7 @@ public function fakeEnumEndpointWithHttpInfo($enum_class, $enum_class_array, $en return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\EnumClass', + $request, $response, ); } catch (ApiException $e) { @@ -766,6 +770,7 @@ public function fakeHealthGetWithHttpInfo() case 200: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\HealthCheckResult', + $request, $response, ); } @@ -787,6 +792,7 @@ public function fakeHealthGetWithHttpInfo() return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\HealthCheckResult', + $request, $response, ); } catch (ApiException $e) { @@ -1235,6 +1241,7 @@ public function fakeOuterBooleanSerializeWithHttpInfo($body = null) case 200: return $this->handleResponseWithDataType( 'bool', + $request, $response, ); } @@ -1256,6 +1263,7 @@ public function fakeOuterBooleanSerializeWithHttpInfo($body = null) return $this->handleResponseWithDataType( 'bool', + $request, $response, ); } catch (ApiException $e) { @@ -1475,6 +1483,7 @@ public function fakeOuterCompositeSerializeWithHttpInfo($outer_composite = null) case 200: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\OuterComposite', + $request, $response, ); } @@ -1496,6 +1505,7 @@ public function fakeOuterCompositeSerializeWithHttpInfo($outer_composite = null) return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\OuterComposite', + $request, $response, ); } catch (ApiException $e) { @@ -1715,6 +1725,7 @@ public function fakeOuterNumberSerializeWithHttpInfo($body = null) case 200: return $this->handleResponseWithDataType( 'float', + $request, $response, ); } @@ -1736,6 +1747,7 @@ public function fakeOuterNumberSerializeWithHttpInfo($body = null) return $this->handleResponseWithDataType( 'float', + $request, $response, ); } catch (ApiException $e) { @@ -1955,6 +1967,7 @@ public function fakeOuterStringSerializeWithHttpInfo($body = null) case 200: return $this->handleResponseWithDataType( 'string', + $request, $response, ); } @@ -1976,6 +1989,7 @@ public function fakeOuterStringSerializeWithHttpInfo($body = null) return $this->handleResponseWithDataType( 'string', + $request, $response, ); } catch (ApiException $e) { @@ -2195,6 +2209,7 @@ public function fakePropertyEnumIntegerSerializeWithHttpInfo($outer_object_with_ case 200: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\OuterObjectWithEnumProperty', + $request, $response, ); } @@ -2216,6 +2231,7 @@ public function fakePropertyEnumIntegerSerializeWithHttpInfo($outer_object_with_ return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\OuterObjectWithEnumProperty', + $request, $response, ); } catch (ApiException $e) { @@ -2445,11 +2461,13 @@ public function fakeWith400And4xxRangeResponseEndpointWithHttpInfo($pet) case 200: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\Pet', + $request, $response, ); case 400: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\ErrorResponse', + $request, $response, ); @@ -2458,6 +2476,7 @@ public function fakeWith400And4xxRangeResponseEndpointWithHttpInfo($pet) if ($this->responseWithinRangeCode('4xx', $statusCode)) { return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\ErrorResponse', + $request, $response, ); } @@ -2477,6 +2496,7 @@ public function fakeWith400And4xxRangeResponseEndpointWithHttpInfo($pet) return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\Pet', + $request, $response, ); } catch (ApiException $e) { @@ -2728,11 +2748,13 @@ public function fakeWith400ResponseEndpointWithHttpInfo($pet) case 200: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\Pet', + $request, $response, ); case 400: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\ErrorResponse', + $request, $response, ); } @@ -2754,6 +2776,7 @@ public function fakeWith400ResponseEndpointWithHttpInfo($pet) return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\Pet', + $request, $response, ); } catch (ApiException $e) { @@ -2995,6 +3018,7 @@ public function fakeWith4xxRangeResponseEndpointWithHttpInfo($pet) case 200: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\Pet', + $request, $response, ); @@ -3003,6 +3027,7 @@ public function fakeWith4xxRangeResponseEndpointWithHttpInfo($pet) if ($this->responseWithinRangeCode('4xx', $statusCode)) { return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\ErrorResponse', + $request, $response, ); } @@ -3022,6 +3047,7 @@ public function fakeWith4xxRangeResponseEndpointWithHttpInfo($pet) return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\Pet', + $request, $response, ); } catch (ApiException $e) { @@ -4380,6 +4406,7 @@ public function testClientModelWithHttpInfo($client) case 200: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\Client', + $request, $response, ); } @@ -4401,6 +4428,7 @@ public function testClientModelWithHttpInfo($client) return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\Client', + $request, $response, ); } catch (ApiException $e) { @@ -6830,6 +6858,7 @@ private function createUri( private function handleResponseWithDataType( string $dataType, + RequestInterface $request, ResponseInterface $response ): array { if ($dataType === '\SplFileObject') { diff --git a/samples/client/petstore/php/psr-18/lib/Api/FakeClassnameTags123Api.php b/samples/client/petstore/php/psr-18/lib/Api/FakeClassnameTags123Api.php index dd94589699cb..100429551e05 100644 --- a/samples/client/petstore/php/psr-18/lib/Api/FakeClassnameTags123Api.php +++ b/samples/client/petstore/php/psr-18/lib/Api/FakeClassnameTags123Api.php @@ -236,6 +236,7 @@ public function testClassnameWithHttpInfo($client) case 200: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\Client', + $request, $response, ); } @@ -257,6 +258,7 @@ public function testClassnameWithHttpInfo($client) return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\Client', + $request, $response, ); } catch (ApiException $e) { @@ -500,6 +502,7 @@ private function createUri( private function handleResponseWithDataType( string $dataType, + RequestInterface $request, ResponseInterface $response ): array { if ($dataType === '\SplFileObject') { diff --git a/samples/client/petstore/php/psr-18/lib/Api/PetApi.php b/samples/client/petstore/php/psr-18/lib/Api/PetApi.php index 201e7a971c99..62abe18f2bd1 100644 --- a/samples/client/petstore/php/psr-18/lib/Api/PetApi.php +++ b/samples/client/petstore/php/psr-18/lib/Api/PetApi.php @@ -702,6 +702,7 @@ public function findPetsByStatusWithHttpInfo($status) case 200: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\Pet[]', + $request, $response, ); } @@ -723,6 +724,7 @@ public function findPetsByStatusWithHttpInfo($status) return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\Pet[]', + $request, $response, ); } catch (ApiException $e) { @@ -961,6 +963,7 @@ public function findPetsByTagsWithHttpInfo($tags) case 200: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\Pet[]', + $request, $response, ); } @@ -982,6 +985,7 @@ public function findPetsByTagsWithHttpInfo($tags) return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\Pet[]', + $request, $response, ); } catch (ApiException $e) { @@ -1221,6 +1225,7 @@ public function getPetByIdWithHttpInfo($pet_id) case 200: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\Pet', + $request, $response, ); } @@ -1242,6 +1247,7 @@ public function getPetByIdWithHttpInfo($pet_id) return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\Pet', + $request, $response, ); } catch (ApiException $e) { @@ -1961,6 +1967,7 @@ public function uploadFileWithHttpInfo($pet_id, $additional_metadata = null, $fi case 200: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\ApiResponse', + $request, $response, ); } @@ -1982,6 +1989,7 @@ public function uploadFileWithHttpInfo($pet_id, $additional_metadata = null, $fi return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\ApiResponse', + $request, $response, ); } catch (ApiException $e) { @@ -2247,6 +2255,7 @@ public function uploadFileWithRequiredFileWithHttpInfo($pet_id, $required_file, case 200: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\ApiResponse', + $request, $response, ); } @@ -2268,6 +2277,7 @@ public function uploadFileWithRequiredFileWithHttpInfo($pet_id, $required_file, return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\ApiResponse', + $request, $response, ); } catch (ApiException $e) { @@ -2551,6 +2561,7 @@ public function uploadImageFullFormDataWithHttpInfo($pet_id, $name, $photo_urls, case 200: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\ApiResponse', + $request, $response, ); } @@ -2572,6 +2583,7 @@ public function uploadImageFullFormDataWithHttpInfo($pet_id, $name, $photo_urls, return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\ApiResponse', + $request, $response, ); } catch (ApiException $e) { @@ -2901,6 +2913,7 @@ private function createUri( private function handleResponseWithDataType( string $dataType, + RequestInterface $request, ResponseInterface $response ): array { if ($dataType === '\SplFileObject') { diff --git a/samples/client/petstore/php/psr-18/lib/Api/StoreApi.php b/samples/client/petstore/php/psr-18/lib/Api/StoreApi.php index 5ef769dbdd1f..387bd9864a30 100644 --- a/samples/client/petstore/php/psr-18/lib/Api/StoreApi.php +++ b/samples/client/petstore/php/psr-18/lib/Api/StoreApi.php @@ -445,6 +445,7 @@ public function getInventoryWithHttpInfo() case 200: return $this->handleResponseWithDataType( 'array', + $request, $response, ); } @@ -466,6 +467,7 @@ public function getInventoryWithHttpInfo() return $this->handleResponseWithDataType( 'array', + $request, $response, ); } catch (ApiException $e) { @@ -689,6 +691,7 @@ public function getOrderByIdWithHttpInfo($order_id) case 200: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\Order', + $request, $response, ); } @@ -710,6 +713,7 @@ public function getOrderByIdWithHttpInfo($order_id) return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\Order', + $request, $response, ); } catch (ApiException $e) { @@ -952,6 +956,7 @@ public function placeOrderWithHttpInfo($order) case 200: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\Order', + $request, $response, ); } @@ -973,6 +978,7 @@ public function placeOrderWithHttpInfo($order) return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\Order', + $request, $response, ); } catch (ApiException $e) { @@ -1211,6 +1217,7 @@ private function createUri( private function handleResponseWithDataType( string $dataType, + RequestInterface $request, ResponseInterface $response ): array { if ($dataType === '\SplFileObject') { diff --git a/samples/client/petstore/php/psr-18/lib/Api/UserApi.php b/samples/client/petstore/php/psr-18/lib/Api/UserApi.php index 02b267cadc49..e0c744726ed9 100644 --- a/samples/client/petstore/php/psr-18/lib/Api/UserApi.php +++ b/samples/client/petstore/php/psr-18/lib/Api/UserApi.php @@ -1074,6 +1074,7 @@ public function getUserByNameWithHttpInfo($username) case 200: return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\User', + $request, $response, ); } @@ -1095,6 +1096,7 @@ public function getUserByNameWithHttpInfo($username) return $this->handleResponseWithDataType( '\OpenAPI\Client\Model\User', + $request, $response, ); } catch (ApiException $e) { @@ -1332,6 +1334,7 @@ public function loginUserWithHttpInfo($username, $password) case 200: return $this->handleResponseWithDataType( 'string', + $request, $response, ); } @@ -1353,6 +1356,7 @@ public function loginUserWithHttpInfo($username, $password) return $this->handleResponseWithDataType( 'string', + $request, $response, ); } catch (ApiException $e) { @@ -2036,6 +2040,7 @@ private function createUri( private function handleResponseWithDataType( string $dataType, + RequestInterface $request, ResponseInterface $response ): array { if ($dataType === '\SplFileObject') { diff --git a/samples/client/petstore/php/psr-18/lib/Model/ErrorResponse.php b/samples/client/petstore/php/psr-18/lib/Model/ErrorResponse.php index 1e9c3940003f..458660568ffd 100644 --- a/samples/client/petstore/php/psr-18/lib/Model/ErrorResponse.php +++ b/samples/client/petstore/php/psr-18/lib/Model/ErrorResponse.php @@ -2,7 +2,7 @@ /** * ErrorResponse * - * PHP version 7.4 + * PHP version 8.1 * * @category Class * @package OpenAPI\Client From 313dbb88509a37f12feaaee692f4023043eadc97 Mon Sep 17 00:00:00 2001 From: Juan Treminio Date: Sat, 29 Mar 2025 13:41:52 -0500 Subject: [PATCH 7/8] Remove dangling files --- .../docs/Model/ErrorRangeResponse.md | 10 -- .../test/Model/ErrorRangeResponseTest.php | 99 ------------------- .../psr-18/docs/Model/ErrorRangeResponse.md | 10 -- .../test/Model/ErrorRangeResponseTest.php | 99 ------------------- 4 files changed, 218 deletions(-) delete mode 100644 samples/client/petstore/php/OpenAPIClient-php/docs/Model/ErrorRangeResponse.md delete mode 100644 samples/client/petstore/php/OpenAPIClient-php/test/Model/ErrorRangeResponseTest.php delete mode 100644 samples/client/petstore/php/psr-18/docs/Model/ErrorRangeResponse.md delete mode 100644 samples/client/petstore/php/psr-18/test/Model/ErrorRangeResponseTest.php diff --git a/samples/client/petstore/php/OpenAPIClient-php/docs/Model/ErrorRangeResponse.md b/samples/client/petstore/php/OpenAPIClient-php/docs/Model/ErrorRangeResponse.md deleted file mode 100644 index 25a8fe846fba..000000000000 --- a/samples/client/petstore/php/OpenAPIClient-php/docs/Model/ErrorRangeResponse.md +++ /dev/null @@ -1,10 +0,0 @@ -# # ErrorRangeResponse - -## Properties - -Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- -**response_code** | **int** | | [optional] -**error** | **string** | | [optional] - -[[Back to Model list]](../../README.md#models) [[Back to API list]](../../README.md#endpoints) [[Back to README]](../../README.md) diff --git a/samples/client/petstore/php/OpenAPIClient-php/test/Model/ErrorRangeResponseTest.php b/samples/client/petstore/php/OpenAPIClient-php/test/Model/ErrorRangeResponseTest.php deleted file mode 100644 index 515ef826aad7..000000000000 --- a/samples/client/petstore/php/OpenAPIClient-php/test/Model/ErrorRangeResponseTest.php +++ /dev/null @@ -1,99 +0,0 @@ - Date: Sat, 29 Mar 2025 13:54:17 -0500 Subject: [PATCH 8/8] Add tests for no response body exception --- ...ith-fake-endpoints-models-for-testing.yaml | 36 ++ ...ith-fake-endpoints-models-for-testing.yaml | 36 ++ .../php-nextgen/OpenAPIClient-php/README.md | 2 + .../OpenAPIClient-php/docs/Api/FakeApi.md | 110 ++++ .../OpenAPIClient-php/src/Api/FakeApi.php | 566 ++++++++++++++++++ .../petstore/php/OpenAPIClient-php/README.md | 2 + .../php/OpenAPIClient-php/docs/Api/FakeApi.md | 110 ++++ .../php/OpenAPIClient-php/lib/Api/FakeApi.php | 542 +++++++++++++++++ .../tests/ResponseTypesTest.php | 32 + samples/client/petstore/php/psr-18/README.md | 2 + .../petstore/php/psr-18/docs/Api/FakeApi.md | 110 ++++ .../petstore/php/psr-18/lib/Api/FakeApi.php | 512 ++++++++++++++++ 12 files changed, 2060 insertions(+) diff --git a/modules/openapi-generator/src/test/resources/3_0/php-nextgen/petstore-with-fake-endpoints-models-for-testing.yaml b/modules/openapi-generator/src/test/resources/3_0/php-nextgen/petstore-with-fake-endpoints-models-for-testing.yaml index c662c097e3a5..0b74a7aa046e 100644 --- a/modules/openapi-generator/src/test/resources/3_0/php-nextgen/petstore-with-fake-endpoints-models-for-testing.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/php-nextgen/petstore-with-fake-endpoints-models-for-testing.yaml @@ -1381,6 +1381,23 @@ paths: $ref: '#/components/schemas/ErrorResponse' requestBody: $ref: '#/components/requestBodies/Pet' + /fake/with_4xx_range_response_no_4xx_datatype/endpoint: + post: + tags: + - fake + summary: test endpoint with 400-499 range response http code without dataType + operationId: fake-with_4xx_range_response_no_4xx_datatype-endpoint + responses: + 200: + description: Valid status value + content: + application/json: + schema: + $ref: '#/components/schemas/Pet' + '4xx': + description: Range of HTTP code 400-499 + requestBody: + $ref: '#/components/requestBodies/Pet' /fake/with_400_and_4xx_range_response/endpoint: post: tags: @@ -1408,6 +1425,25 @@ paths: $ref: '#/components/schemas/ErrorResponse' requestBody: $ref: '#/components/requestBodies/Pet' + /fake/with_400_and_4xx_range_response_no_4xx_datatype/endpoint: + post: + tags: + - fake + summary: test endpoint with 400 and 400-499 range response http code without dataType + operationId: fake-with_400_and_4xx_range_response_no_4xx_datatype-endpoint + responses: + 200: + description: Valid status value + content: + application/json: + schema: + $ref: '#/components/schemas/Pet' + '400': + description: Invalid status value + '4xx': + description: Range of HTTP code 400-499 + requestBody: + $ref: '#/components/requestBodies/Pet' servers: - url: 'http://{server}.swagger.io:{port}/v2' description: petstore server diff --git a/modules/openapi-generator/src/test/resources/3_0/php/petstore-with-fake-endpoints-models-for-testing.yaml b/modules/openapi-generator/src/test/resources/3_0/php/petstore-with-fake-endpoints-models-for-testing.yaml index 8cea116dd8e2..18161aec8bed 100644 --- a/modules/openapi-generator/src/test/resources/3_0/php/petstore-with-fake-endpoints-models-for-testing.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/php/petstore-with-fake-endpoints-models-for-testing.yaml @@ -1436,6 +1436,23 @@ paths: $ref: '#/components/schemas/ErrorResponse' requestBody: $ref: '#/components/requestBodies/Pet' + /fake/with_4xx_range_response_no_4xx_datatype/endpoint: + post: + tags: + - fake + summary: test endpoint with 400-499 range response http code without dataType + operationId: fake-with_4xx_range_response_no_4xx_datatype-endpoint + responses: + 200: + description: Valid status value + content: + application/json: + schema: + $ref: '#/components/schemas/Pet' + '4xx': + description: Range of HTTP code 400-499 + requestBody: + $ref: '#/components/requestBodies/Pet' /fake/with_400_and_4xx_range_response/endpoint: post: tags: @@ -1463,6 +1480,25 @@ paths: $ref: '#/components/schemas/ErrorResponse' requestBody: $ref: '#/components/requestBodies/Pet' + /fake/with_400_and_4xx_range_response_no_4xx_datatype/endpoint: + post: + tags: + - fake + summary: test endpoint with 400 and 400-499 range response http code without dataType + operationId: fake-with_400_and_4xx_range_response_no_4xx_datatype-endpoint + responses: + 200: + description: Valid status value + content: + application/json: + schema: + $ref: '#/components/schemas/Pet' + '400': + description: Invalid status value + '4xx': + description: Range of HTTP code 400-499 + requestBody: + $ref: '#/components/requestBodies/Pet' servers: - url: 'http://{server}.swagger.io:{port}/v2' description: petstore server diff --git a/samples/client/petstore/php-nextgen/OpenAPIClient-php/README.md b/samples/client/petstore/php-nextgen/OpenAPIClient-php/README.md index caaaf3cdc901..103d2a59c10d 100644 --- a/samples/client/petstore/php-nextgen/OpenAPIClient-php/README.md +++ b/samples/client/petstore/php-nextgen/OpenAPIClient-php/README.md @@ -83,8 +83,10 @@ Class | Method | HTTP request | Description *FakeApi* | [**fakeOuterStringSerialize**](docs/Api/FakeApi.md#fakeouterstringserialize) | **POST** /fake/outer/string | *FakeApi* | [**fakePropertyEnumIntegerSerialize**](docs/Api/FakeApi.md#fakepropertyenumintegerserialize) | **POST** /fake/property/enum-int | *FakeApi* | [**fakeWith400And4xxRangeResponseEndpoint**](docs/Api/FakeApi.md#fakewith400and4xxrangeresponseendpoint) | **POST** /fake/with_400_and_4xx_range_response/endpoint | test endpoint with 400 and 400-499 range response http code with dataType +*FakeApi* | [**fakeWith400And4xxRangeResponseNo4xxDatatypeEndpoint**](docs/Api/FakeApi.md#fakewith400and4xxrangeresponseno4xxdatatypeendpoint) | **POST** /fake/with_400_and_4xx_range_response_no_4xx_datatype/endpoint | test endpoint with 400 and 400-499 range response http code without dataType *FakeApi* | [**fakeWith400ResponseEndpoint**](docs/Api/FakeApi.md#fakewith400responseendpoint) | **POST** /fake/with_400_response/endpoint | test endpoint with 400 response http code with dataType *FakeApi* | [**fakeWith4xxRangeResponseEndpoint**](docs/Api/FakeApi.md#fakewith4xxrangeresponseendpoint) | **POST** /fake/with_4xx_range_response/endpoint | test endpoint with 400-499 range response http code with dataType +*FakeApi* | [**fakeWith4xxRangeResponseNo4xxDatatypeEndpoint**](docs/Api/FakeApi.md#fakewith4xxrangeresponseno4xxdatatypeendpoint) | **POST** /fake/with_4xx_range_response_no_4xx_datatype/endpoint | test endpoint with 400-499 range response http code without dataType *FakeApi* | [**testAdditionalPropertiesReference**](docs/Api/FakeApi.md#testadditionalpropertiesreference) | **POST** /fake/additionalProperties-reference | test referenced additionalProperties *FakeApi* | [**testBodyWithBinary**](docs/Api/FakeApi.md#testbodywithbinary) | **PUT** /fake/body-with-binary | *FakeApi* | [**testBodyWithFileSchema**](docs/Api/FakeApi.md#testbodywithfileschema) | **PUT** /fake/body-with-file-schema | diff --git a/samples/client/petstore/php-nextgen/OpenAPIClient-php/docs/Api/FakeApi.md b/samples/client/petstore/php-nextgen/OpenAPIClient-php/docs/Api/FakeApi.md index 23e7e2bb8dcb..74de3fcede10 100644 --- a/samples/client/petstore/php-nextgen/OpenAPIClient-php/docs/Api/FakeApi.md +++ b/samples/client/petstore/php-nextgen/OpenAPIClient-php/docs/Api/FakeApi.md @@ -14,8 +14,10 @@ All URIs are relative to http://petstore.swagger.io:80/v2, except if the operati | [**fakeOuterStringSerialize()**](FakeApi.md#fakeOuterStringSerialize) | **POST** /fake/outer/string | | | [**fakePropertyEnumIntegerSerialize()**](FakeApi.md#fakePropertyEnumIntegerSerialize) | **POST** /fake/property/enum-int | | | [**fakeWith400And4xxRangeResponseEndpoint()**](FakeApi.md#fakeWith400And4xxRangeResponseEndpoint) | **POST** /fake/with_400_and_4xx_range_response/endpoint | test endpoint with 400 and 400-499 range response http code with dataType | +| [**fakeWith400And4xxRangeResponseNo4xxDatatypeEndpoint()**](FakeApi.md#fakeWith400And4xxRangeResponseNo4xxDatatypeEndpoint) | **POST** /fake/with_400_and_4xx_range_response_no_4xx_datatype/endpoint | test endpoint with 400 and 400-499 range response http code without dataType | | [**fakeWith400ResponseEndpoint()**](FakeApi.md#fakeWith400ResponseEndpoint) | **POST** /fake/with_400_response/endpoint | test endpoint with 400 response http code with dataType | | [**fakeWith4xxRangeResponseEndpoint()**](FakeApi.md#fakeWith4xxRangeResponseEndpoint) | **POST** /fake/with_4xx_range_response/endpoint | test endpoint with 400-499 range response http code with dataType | +| [**fakeWith4xxRangeResponseNo4xxDatatypeEndpoint()**](FakeApi.md#fakeWith4xxRangeResponseNo4xxDatatypeEndpoint) | **POST** /fake/with_4xx_range_response_no_4xx_datatype/endpoint | test endpoint with 400-499 range response http code without dataType | | [**testAdditionalPropertiesReference()**](FakeApi.md#testAdditionalPropertiesReference) | **POST** /fake/additionalProperties-reference | test referenced additionalProperties | | [**testBodyWithBinary()**](FakeApi.md#testBodyWithBinary) | **PUT** /fake/body-with-binary | | | [**testBodyWithFileSchema()**](FakeApi.md#testBodyWithFileSchema) | **PUT** /fake/body-with-file-schema | | @@ -587,6 +589,60 @@ No authorization required [[Back to Model list]](../../README.md#models) [[Back to README]](../../README.md) +## `fakeWith400And4xxRangeResponseNo4xxDatatypeEndpoint()` + +```php +fakeWith400And4xxRangeResponseNo4xxDatatypeEndpoint($pet): \OpenAPI\Client\Model\Pet +``` + +test endpoint with 400 and 400-499 range response http code without dataType + +### Example + +```php +fakeWith400And4xxRangeResponseNo4xxDatatypeEndpoint($pet); + print_r($result); +} catch (Exception $e) { + echo 'Exception when calling FakeApi->fakeWith400And4xxRangeResponseNo4xxDatatypeEndpoint: ', $e->getMessage(), PHP_EOL; +} +``` + +### Parameters + +| Name | Type | Description | Notes | +| ------------- | ------------- | ------------- | ------------- | +| **pet** | [**\OpenAPI\Client\Model\Pet**](../Model/Pet.md)| Pet object that needs to be added to the store | | + +### Return type + +[**\OpenAPI\Client\Model\Pet**](../Model/Pet.md) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: `application/json`, `application/xml` +- **Accept**: `application/json` + +[[Back to top]](#) [[Back to API list]](../../README.md#endpoints) +[[Back to Model list]](../../README.md#models) +[[Back to README]](../../README.md) + ## `fakeWith400ResponseEndpoint()` ```php @@ -695,6 +751,60 @@ No authorization required [[Back to Model list]](../../README.md#models) [[Back to README]](../../README.md) +## `fakeWith4xxRangeResponseNo4xxDatatypeEndpoint()` + +```php +fakeWith4xxRangeResponseNo4xxDatatypeEndpoint($pet): \OpenAPI\Client\Model\Pet +``` + +test endpoint with 400-499 range response http code without dataType + +### Example + +```php +fakeWith4xxRangeResponseNo4xxDatatypeEndpoint($pet); + print_r($result); +} catch (Exception $e) { + echo 'Exception when calling FakeApi->fakeWith4xxRangeResponseNo4xxDatatypeEndpoint: ', $e->getMessage(), PHP_EOL; +} +``` + +### Parameters + +| Name | Type | Description | Notes | +| ------------- | ------------- | ------------- | ------------- | +| **pet** | [**\OpenAPI\Client\Model\Pet**](../Model/Pet.md)| Pet object that needs to be added to the store | | + +### Return type + +[**\OpenAPI\Client\Model\Pet**](../Model/Pet.md) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: `application/json`, `application/xml` +- **Accept**: `application/json` + +[[Back to top]](#) [[Back to API list]](../../README.md#endpoints) +[[Back to Model list]](../../README.md#models) +[[Back to README]](../../README.md) + ## `testAdditionalPropertiesReference()` ```php diff --git a/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/FakeApi.php b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/FakeApi.php index 20570f12e579..88940c8bc124 100644 --- a/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/FakeApi.php +++ b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/FakeApi.php @@ -105,6 +105,10 @@ class FakeApi 'application/json', 'application/xml', ], + 'fakeWith400And4xxRangeResponseNo4xxDatatypeEndpoint' => [ + 'application/json', + 'application/xml', + ], 'fakeWith400ResponseEndpoint' => [ 'application/json', 'application/xml', @@ -113,6 +117,10 @@ class FakeApi 'application/json', 'application/xml', ], + 'fakeWith4xxRangeResponseNo4xxDatatypeEndpoint' => [ + 'application/json', + 'application/xml', + ], 'testAdditionalPropertiesReference' => [ 'application/json', ], @@ -2886,6 +2894,285 @@ public function fakeWith400And4xxRangeResponseEndpointRequest( + $headers = $this->headerSelector->selectHeaders( + ['application/json', ], + $contentType, + $multipart + ); + + // for model (json/xml) + if (isset($pet)) { + if (stripos($headers['Content-Type'], 'application/json') !== false) { + # if Content-Type contains "application/json", json_encode the body + $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($pet)); + } else { + $httpBody = $pet; + } + } elseif (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; + foreach ($formParamValueItems as $formParamValueItem) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValueItem + ]; + } + } + // for HTTP post (form) + $httpBody = new MultipartStream($multipartContents); + + } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { + # if Content-Type contains "application/json", json_encode the form parameters + $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + } else { + // for HTTP post (form) + $httpBody = ObjectSerializer::buildQuery($formParams); + } + } + + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $operationHost = $this->config->getHost(); + $query = ObjectSerializer::buildQuery($queryParams); + return new Request( + 'POST', + $operationHost . $resourcePath . ($query ? "?{$query}" : ''), + $headers, + $httpBody + ); + } + + /** + * Operation fakeWith400And4xxRangeResponseNo4xxDatatypeEndpoint + * + * test endpoint with 400 and 400-499 range response http code without dataType + * + * @param \OpenAPI\Client\Model\Pet $pet Pet object that needs to be added to the store (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeWith400And4xxRangeResponseNo4xxDatatypeEndpoint'] to see the possible values for this operation + * + * @throws ApiException on non-2xx response or if the response body is not in the expected format + * @throws InvalidArgumentException + * @return \OpenAPI\Client\Model\Pet + */ + public function fakeWith400And4xxRangeResponseNo4xxDatatypeEndpoint( + \OpenAPI\Client\Model\Pet $pet, + string $contentType = self::contentTypes['fakeWith400And4xxRangeResponseNo4xxDatatypeEndpoint'][0] + ): \OpenAPI\Client\Model\Pet + { + list($response) = $this->fakeWith400And4xxRangeResponseNo4xxDatatypeEndpointWithHttpInfo($pet, $contentType); + return $response; + } + + /** + * Operation fakeWith400And4xxRangeResponseNo4xxDatatypeEndpointWithHttpInfo + * + * test endpoint with 400 and 400-499 range response http code without dataType + * + * @param \OpenAPI\Client\Model\Pet $pet Pet object that needs to be added to the store (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeWith400And4xxRangeResponseNo4xxDatatypeEndpoint'] to see the possible values for this operation + * + * @throws ApiException on non-2xx response or if the response body is not in the expected format + * @throws InvalidArgumentException + * @return array of \OpenAPI\Client\Model\Pet, HTTP status code, HTTP response headers (array of strings) + */ + public function fakeWith400And4xxRangeResponseNo4xxDatatypeEndpointWithHttpInfo( + \OpenAPI\Client\Model\Pet $pet, + string $contentType = self::contentTypes['fakeWith400And4xxRangeResponseNo4xxDatatypeEndpoint'][0] + ): array + { + $request = $this->fakeWith400And4xxRangeResponseNo4xxDatatypeEndpointRequest($pet, $contentType); + + try { + $options = $this->createHttpClientOption(); + try { + $response = $this->client->send($request, $options); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null, + $e->getResponse() ? (string) $e->getResponse()->getBody() : null + ); + } catch (ConnectException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + null, + null + ); + } + + $statusCode = $response->getStatusCode(); + + switch($statusCode) { + case 200: + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Pet', + $request, + $response, + ); + } + + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Pet', + $request, + $response, + ); + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\OpenAPI\Client\Model\Pet', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + throw $e; + } + + throw $e; + } + } + + /** + * Operation fakeWith400And4xxRangeResponseNo4xxDatatypeEndpointAsync + * + * test endpoint with 400 and 400-499 range response http code without dataType + * + * @param \OpenAPI\Client\Model\Pet $pet Pet object that needs to be added to the store (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeWith400And4xxRangeResponseNo4xxDatatypeEndpoint'] to see the possible values for this operation + * + * @throws InvalidArgumentException + * @return PromiseInterface + */ + public function fakeWith400And4xxRangeResponseNo4xxDatatypeEndpointAsync( + \OpenAPI\Client\Model\Pet $pet, + string $contentType = self::contentTypes['fakeWith400And4xxRangeResponseNo4xxDatatypeEndpoint'][0] + ): PromiseInterface + { + return $this->fakeWith400And4xxRangeResponseNo4xxDatatypeEndpointAsyncWithHttpInfo($pet, $contentType) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation fakeWith400And4xxRangeResponseNo4xxDatatypeEndpointAsyncWithHttpInfo + * + * test endpoint with 400 and 400-499 range response http code without dataType + * + * @param \OpenAPI\Client\Model\Pet $pet Pet object that needs to be added to the store (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeWith400And4xxRangeResponseNo4xxDatatypeEndpoint'] to see the possible values for this operation + * + * @throws InvalidArgumentException + * @return PromiseInterface + */ + public function fakeWith400And4xxRangeResponseNo4xxDatatypeEndpointAsyncWithHttpInfo( + \OpenAPI\Client\Model\Pet $pet, + string $contentType = self::contentTypes['fakeWith400And4xxRangeResponseNo4xxDatatypeEndpoint'][0] + ): PromiseInterface + { + $returnType = '\OpenAPI\Client\Model\Pet'; + $request = $this->fakeWith400And4xxRangeResponseNo4xxDatatypeEndpointRequest($pet, $contentType); + + return $this->client + ->sendAsync($request, $this->createHttpClientOption()) + ->then( + function ($response) use ($returnType) { + if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + 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( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $exception->getRequest()->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + ); + } + + /** + * Create request for operation 'fakeWith400And4xxRangeResponseNo4xxDatatypeEndpoint' + * + * @param \OpenAPI\Client\Model\Pet $pet Pet object that needs to be added to the store (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeWith400And4xxRangeResponseNo4xxDatatypeEndpoint'] to see the possible values for this operation + * + * @throws InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + public function fakeWith400And4xxRangeResponseNo4xxDatatypeEndpointRequest( + \OpenAPI\Client\Model\Pet $pet, + string $contentType = self::contentTypes['fakeWith400And4xxRangeResponseNo4xxDatatypeEndpoint'][0] + ): Request + { + + // verify the required parameter 'pet' is set + if ($pet === null || (is_array($pet) && count($pet) === 0)) { + throw new InvalidArgumentException( + 'Missing the required parameter $pet when calling fakeWith400And4xxRangeResponseNo4xxDatatypeEndpoint' + ); + } + + + $resourcePath = '/fake/with_400_and_4xx_range_response_no_4xx_datatype/endpoint'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + + + + $headers = $this->headerSelector->selectHeaders( ['application/json', ], $contentType, @@ -3476,6 +3763,285 @@ public function fakeWith4xxRangeResponseEndpointRequest( + $headers = $this->headerSelector->selectHeaders( + ['application/json', ], + $contentType, + $multipart + ); + + // for model (json/xml) + if (isset($pet)) { + if (stripos($headers['Content-Type'], 'application/json') !== false) { + # if Content-Type contains "application/json", json_encode the body + $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($pet)); + } else { + $httpBody = $pet; + } + } elseif (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; + foreach ($formParamValueItems as $formParamValueItem) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValueItem + ]; + } + } + // for HTTP post (form) + $httpBody = new MultipartStream($multipartContents); + + } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { + # if Content-Type contains "application/json", json_encode the form parameters + $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + } else { + // for HTTP post (form) + $httpBody = ObjectSerializer::buildQuery($formParams); + } + } + + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $operationHost = $this->config->getHost(); + $query = ObjectSerializer::buildQuery($queryParams); + return new Request( + 'POST', + $operationHost . $resourcePath . ($query ? "?{$query}" : ''), + $headers, + $httpBody + ); + } + + /** + * Operation fakeWith4xxRangeResponseNo4xxDatatypeEndpoint + * + * test endpoint with 400-499 range response http code without dataType + * + * @param \OpenAPI\Client\Model\Pet $pet Pet object that needs to be added to the store (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeWith4xxRangeResponseNo4xxDatatypeEndpoint'] to see the possible values for this operation + * + * @throws ApiException on non-2xx response or if the response body is not in the expected format + * @throws InvalidArgumentException + * @return \OpenAPI\Client\Model\Pet + */ + public function fakeWith4xxRangeResponseNo4xxDatatypeEndpoint( + \OpenAPI\Client\Model\Pet $pet, + string $contentType = self::contentTypes['fakeWith4xxRangeResponseNo4xxDatatypeEndpoint'][0] + ): \OpenAPI\Client\Model\Pet + { + list($response) = $this->fakeWith4xxRangeResponseNo4xxDatatypeEndpointWithHttpInfo($pet, $contentType); + return $response; + } + + /** + * Operation fakeWith4xxRangeResponseNo4xxDatatypeEndpointWithHttpInfo + * + * test endpoint with 400-499 range response http code without dataType + * + * @param \OpenAPI\Client\Model\Pet $pet Pet object that needs to be added to the store (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeWith4xxRangeResponseNo4xxDatatypeEndpoint'] to see the possible values for this operation + * + * @throws ApiException on non-2xx response or if the response body is not in the expected format + * @throws InvalidArgumentException + * @return array of \OpenAPI\Client\Model\Pet, HTTP status code, HTTP response headers (array of strings) + */ + public function fakeWith4xxRangeResponseNo4xxDatatypeEndpointWithHttpInfo( + \OpenAPI\Client\Model\Pet $pet, + string $contentType = self::contentTypes['fakeWith4xxRangeResponseNo4xxDatatypeEndpoint'][0] + ): array + { + $request = $this->fakeWith4xxRangeResponseNo4xxDatatypeEndpointRequest($pet, $contentType); + + try { + $options = $this->createHttpClientOption(); + try { + $response = $this->client->send($request, $options); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null, + $e->getResponse() ? (string) $e->getResponse()->getBody() : null + ); + } catch (ConnectException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + null, + null + ); + } + + $statusCode = $response->getStatusCode(); + + switch($statusCode) { + case 200: + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Pet', + $request, + $response, + ); + } + + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Pet', + $request, + $response, + ); + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\OpenAPI\Client\Model\Pet', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + throw $e; + } + + throw $e; + } + } + + /** + * Operation fakeWith4xxRangeResponseNo4xxDatatypeEndpointAsync + * + * test endpoint with 400-499 range response http code without dataType + * + * @param \OpenAPI\Client\Model\Pet $pet Pet object that needs to be added to the store (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeWith4xxRangeResponseNo4xxDatatypeEndpoint'] to see the possible values for this operation + * + * @throws InvalidArgumentException + * @return PromiseInterface + */ + public function fakeWith4xxRangeResponseNo4xxDatatypeEndpointAsync( + \OpenAPI\Client\Model\Pet $pet, + string $contentType = self::contentTypes['fakeWith4xxRangeResponseNo4xxDatatypeEndpoint'][0] + ): PromiseInterface + { + return $this->fakeWith4xxRangeResponseNo4xxDatatypeEndpointAsyncWithHttpInfo($pet, $contentType) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation fakeWith4xxRangeResponseNo4xxDatatypeEndpointAsyncWithHttpInfo + * + * test endpoint with 400-499 range response http code without dataType + * + * @param \OpenAPI\Client\Model\Pet $pet Pet object that needs to be added to the store (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeWith4xxRangeResponseNo4xxDatatypeEndpoint'] to see the possible values for this operation + * + * @throws InvalidArgumentException + * @return PromiseInterface + */ + public function fakeWith4xxRangeResponseNo4xxDatatypeEndpointAsyncWithHttpInfo( + \OpenAPI\Client\Model\Pet $pet, + string $contentType = self::contentTypes['fakeWith4xxRangeResponseNo4xxDatatypeEndpoint'][0] + ): PromiseInterface + { + $returnType = '\OpenAPI\Client\Model\Pet'; + $request = $this->fakeWith4xxRangeResponseNo4xxDatatypeEndpointRequest($pet, $contentType); + + return $this->client + ->sendAsync($request, $this->createHttpClientOption()) + ->then( + function ($response) use ($returnType) { + if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + 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( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $exception->getRequest()->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + ); + } + + /** + * Create request for operation 'fakeWith4xxRangeResponseNo4xxDatatypeEndpoint' + * + * @param \OpenAPI\Client\Model\Pet $pet Pet object that needs to be added to the store (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeWith4xxRangeResponseNo4xxDatatypeEndpoint'] to see the possible values for this operation + * + * @throws InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + public function fakeWith4xxRangeResponseNo4xxDatatypeEndpointRequest( + \OpenAPI\Client\Model\Pet $pet, + string $contentType = self::contentTypes['fakeWith4xxRangeResponseNo4xxDatatypeEndpoint'][0] + ): Request + { + + // verify the required parameter 'pet' is set + if ($pet === null || (is_array($pet) && count($pet) === 0)) { + throw new InvalidArgumentException( + 'Missing the required parameter $pet when calling fakeWith4xxRangeResponseNo4xxDatatypeEndpoint' + ); + } + + + $resourcePath = '/fake/with_4xx_range_response_no_4xx_datatype/endpoint'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + + + + $headers = $this->headerSelector->selectHeaders( ['application/json', ], $contentType, diff --git a/samples/client/petstore/php/OpenAPIClient-php/README.md b/samples/client/petstore/php/OpenAPIClient-php/README.md index f23a92463d7c..90688e77c356 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/README.md +++ b/samples/client/petstore/php/OpenAPIClient-php/README.md @@ -83,8 +83,10 @@ Class | Method | HTTP request | Description *FakeApi* | [**fakeOuterStringSerialize**](docs/Api/FakeApi.md#fakeouterstringserialize) | **POST** /fake/outer/string | *FakeApi* | [**fakePropertyEnumIntegerSerialize**](docs/Api/FakeApi.md#fakepropertyenumintegerserialize) | **POST** /fake/property/enum-int | *FakeApi* | [**fakeWith400And4xxRangeResponseEndpoint**](docs/Api/FakeApi.md#fakewith400and4xxrangeresponseendpoint) | **POST** /fake/with_400_and_4xx_range_response/endpoint | test endpoint with 400 and 400-499 range response http code with dataType +*FakeApi* | [**fakeWith400And4xxRangeResponseNo4xxDatatypeEndpoint**](docs/Api/FakeApi.md#fakewith400and4xxrangeresponseno4xxdatatypeendpoint) | **POST** /fake/with_400_and_4xx_range_response_no_4xx_datatype/endpoint | test endpoint with 400 and 400-499 range response http code without dataType *FakeApi* | [**fakeWith400ResponseEndpoint**](docs/Api/FakeApi.md#fakewith400responseendpoint) | **POST** /fake/with_400_response/endpoint | test endpoint with 400 response http code with dataType *FakeApi* | [**fakeWith4xxRangeResponseEndpoint**](docs/Api/FakeApi.md#fakewith4xxrangeresponseendpoint) | **POST** /fake/with_4xx_range_response/endpoint | test endpoint with 400-499 range response http code with dataType +*FakeApi* | [**fakeWith4xxRangeResponseNo4xxDatatypeEndpoint**](docs/Api/FakeApi.md#fakewith4xxrangeresponseno4xxdatatypeendpoint) | **POST** /fake/with_4xx_range_response_no_4xx_datatype/endpoint | test endpoint with 400-499 range response http code without dataType *FakeApi* | [**getParameterNameMapping**](docs/Api/FakeApi.md#getparameternamemapping) | **GET** /fake/parameter-name-mapping | parameter name mapping test *FakeApi* | [**testAdditionalPropertiesReference**](docs/Api/FakeApi.md#testadditionalpropertiesreference) | **POST** /fake/additionalProperties-reference | test referenced additionalProperties *FakeApi* | [**testBodyWithBinary**](docs/Api/FakeApi.md#testbodywithbinary) | **PUT** /fake/body-with-binary | diff --git a/samples/client/petstore/php/OpenAPIClient-php/docs/Api/FakeApi.md b/samples/client/petstore/php/OpenAPIClient-php/docs/Api/FakeApi.md index 8e89001178a1..a232f3069fb8 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/docs/Api/FakeApi.md +++ b/samples/client/petstore/php/OpenAPIClient-php/docs/Api/FakeApi.md @@ -14,8 +14,10 @@ All URIs are relative to http://petstore.swagger.io:80/v2, except if the operati | [**fakeOuterStringSerialize()**](FakeApi.md#fakeOuterStringSerialize) | **POST** /fake/outer/string | | | [**fakePropertyEnumIntegerSerialize()**](FakeApi.md#fakePropertyEnumIntegerSerialize) | **POST** /fake/property/enum-int | | | [**fakeWith400And4xxRangeResponseEndpoint()**](FakeApi.md#fakeWith400And4xxRangeResponseEndpoint) | **POST** /fake/with_400_and_4xx_range_response/endpoint | test endpoint with 400 and 400-499 range response http code with dataType | +| [**fakeWith400And4xxRangeResponseNo4xxDatatypeEndpoint()**](FakeApi.md#fakeWith400And4xxRangeResponseNo4xxDatatypeEndpoint) | **POST** /fake/with_400_and_4xx_range_response_no_4xx_datatype/endpoint | test endpoint with 400 and 400-499 range response http code without dataType | | [**fakeWith400ResponseEndpoint()**](FakeApi.md#fakeWith400ResponseEndpoint) | **POST** /fake/with_400_response/endpoint | test endpoint with 400 response http code with dataType | | [**fakeWith4xxRangeResponseEndpoint()**](FakeApi.md#fakeWith4xxRangeResponseEndpoint) | **POST** /fake/with_4xx_range_response/endpoint | test endpoint with 400-499 range response http code with dataType | +| [**fakeWith4xxRangeResponseNo4xxDatatypeEndpoint()**](FakeApi.md#fakeWith4xxRangeResponseNo4xxDatatypeEndpoint) | **POST** /fake/with_4xx_range_response_no_4xx_datatype/endpoint | test endpoint with 400-499 range response http code without dataType | | [**getParameterNameMapping()**](FakeApi.md#getParameterNameMapping) | **GET** /fake/parameter-name-mapping | parameter name mapping test | | [**testAdditionalPropertiesReference()**](FakeApi.md#testAdditionalPropertiesReference) | **POST** /fake/additionalProperties-reference | test referenced additionalProperties | | [**testBodyWithBinary()**](FakeApi.md#testBodyWithBinary) | **PUT** /fake/body-with-binary | | @@ -587,6 +589,60 @@ No authorization required [[Back to Model list]](../../README.md#models) [[Back to README]](../../README.md) +## `fakeWith400And4xxRangeResponseNo4xxDatatypeEndpoint()` + +```php +fakeWith400And4xxRangeResponseNo4xxDatatypeEndpoint($pet): \OpenAPI\Client\Model\Pet +``` + +test endpoint with 400 and 400-499 range response http code without dataType + +### Example + +```php +fakeWith400And4xxRangeResponseNo4xxDatatypeEndpoint($pet); + print_r($result); +} catch (Exception $e) { + echo 'Exception when calling FakeApi->fakeWith400And4xxRangeResponseNo4xxDatatypeEndpoint: ', $e->getMessage(), PHP_EOL; +} +``` + +### Parameters + +| Name | Type | Description | Notes | +| ------------- | ------------- | ------------- | ------------- | +| **pet** | [**\OpenAPI\Client\Model\Pet**](../Model/Pet.md)| Pet object that needs to be added to the store | | + +### Return type + +[**\OpenAPI\Client\Model\Pet**](../Model/Pet.md) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: `application/json`, `application/xml` +- **Accept**: `application/json` + +[[Back to top]](#) [[Back to API list]](../../README.md#endpoints) +[[Back to Model list]](../../README.md#models) +[[Back to README]](../../README.md) + ## `fakeWith400ResponseEndpoint()` ```php @@ -695,6 +751,60 @@ No authorization required [[Back to Model list]](../../README.md#models) [[Back to README]](../../README.md) +## `fakeWith4xxRangeResponseNo4xxDatatypeEndpoint()` + +```php +fakeWith4xxRangeResponseNo4xxDatatypeEndpoint($pet): \OpenAPI\Client\Model\Pet +``` + +test endpoint with 400-499 range response http code without dataType + +### Example + +```php +fakeWith4xxRangeResponseNo4xxDatatypeEndpoint($pet); + print_r($result); +} catch (Exception $e) { + echo 'Exception when calling FakeApi->fakeWith4xxRangeResponseNo4xxDatatypeEndpoint: ', $e->getMessage(), PHP_EOL; +} +``` + +### Parameters + +| Name | Type | Description | Notes | +| ------------- | ------------- | ------------- | ------------- | +| **pet** | [**\OpenAPI\Client\Model\Pet**](../Model/Pet.md)| Pet object that needs to be added to the store | | + +### Return type + +[**\OpenAPI\Client\Model\Pet**](../Model/Pet.md) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: `application/json`, `application/xml` +- **Accept**: `application/json` + +[[Back to top]](#) [[Back to API list]](../../README.md#endpoints) +[[Back to Model list]](../../README.md#models) +[[Back to README]](../../README.md) + ## `getParameterNameMapping()` ```php diff --git a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/FakeApi.php b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/FakeApi.php index c70b1d893dd2..762e9d7a1849 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/FakeApi.php +++ b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/FakeApi.php @@ -105,6 +105,10 @@ class FakeApi 'application/json', 'application/xml', ], + 'fakeWith400And4xxRangeResponseNo4xxDatatypeEndpoint' => [ + 'application/json', + 'application/xml', + ], 'fakeWith400ResponseEndpoint' => [ 'application/json', 'application/xml', @@ -113,6 +117,10 @@ class FakeApi 'application/json', 'application/xml', ], + 'fakeWith4xxRangeResponseNo4xxDatatypeEndpoint' => [ + 'application/json', + 'application/xml', + ], 'getParameterNameMapping' => [ 'application/json', ], @@ -2753,6 +2761,273 @@ public function fakeWith400And4xxRangeResponseEndpointRequest($pet, string $cont + $headers = $this->headerSelector->selectHeaders( + ['application/json', ], + $contentType, + $multipart + ); + + // for model (json/xml) + if (isset($pet)) { + if (stripos($headers['Content-Type'], 'application/json') !== false) { + # if Content-Type contains "application/json", json_encode the body + $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($pet)); + } else { + $httpBody = $pet; + } + } elseif (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; + foreach ($formParamValueItems as $formParamValueItem) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValueItem + ]; + } + } + // for HTTP post (form) + $httpBody = new MultipartStream($multipartContents); + + } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { + # if Content-Type contains "application/json", json_encode the form parameters + $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + } else { + // for HTTP post (form) + $httpBody = ObjectSerializer::buildQuery($formParams); + } + } + + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $operationHost = $this->config->getHost(); + $query = ObjectSerializer::buildQuery($queryParams); + return new Request( + 'POST', + $operationHost . $resourcePath . ($query ? "?{$query}" : ''), + $headers, + $httpBody + ); + } + + /** + * Operation fakeWith400And4xxRangeResponseNo4xxDatatypeEndpoint + * + * test endpoint with 400 and 400-499 range response http code without dataType + * + * @param \OpenAPI\Client\Model\Pet $pet Pet object that needs to be added to the store (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeWith400And4xxRangeResponseNo4xxDatatypeEndpoint'] to see the possible values for this operation + * + * @throws \OpenAPI\Client\ApiException on non-2xx response or if the response body is not in the expected format + * @throws \InvalidArgumentException + * @return \OpenAPI\Client\Model\Pet + */ + public function fakeWith400And4xxRangeResponseNo4xxDatatypeEndpoint($pet, string $contentType = self::contentTypes['fakeWith400And4xxRangeResponseNo4xxDatatypeEndpoint'][0]) + { + list($response) = $this->fakeWith400And4xxRangeResponseNo4xxDatatypeEndpointWithHttpInfo($pet, $contentType); + return $response; + } + + /** + * Operation fakeWith400And4xxRangeResponseNo4xxDatatypeEndpointWithHttpInfo + * + * test endpoint with 400 and 400-499 range response http code without dataType + * + * @param \OpenAPI\Client\Model\Pet $pet Pet object that needs to be added to the store (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeWith400And4xxRangeResponseNo4xxDatatypeEndpoint'] to see the possible values for this operation + * + * @throws \OpenAPI\Client\ApiException on non-2xx response or if the response body is not in the expected format + * @throws \InvalidArgumentException + * @return array of \OpenAPI\Client\Model\Pet, HTTP status code, HTTP response headers (array of strings) + */ + public function fakeWith400And4xxRangeResponseNo4xxDatatypeEndpointWithHttpInfo($pet, string $contentType = self::contentTypes['fakeWith400And4xxRangeResponseNo4xxDatatypeEndpoint'][0]) + { + $request = $this->fakeWith400And4xxRangeResponseNo4xxDatatypeEndpointRequest($pet, $contentType); + + try { + $options = $this->createHttpClientOption(); + try { + $response = $this->client->send($request, $options); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null, + $e->getResponse() ? (string) $e->getResponse()->getBody() : null + ); + } catch (ConnectException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + null, + null + ); + } + + $statusCode = $response->getStatusCode(); + + + switch($statusCode) { + case 200: + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Pet', + $request, + $response, + ); + } + + + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Pet', + $request, + $response, + ); + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\OpenAPI\Client\Model\Pet', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + throw $e; + } + + + throw $e; + } + } + + /** + * Operation fakeWith400And4xxRangeResponseNo4xxDatatypeEndpointAsync + * + * test endpoint with 400 and 400-499 range response http code without dataType + * + * @param \OpenAPI\Client\Model\Pet $pet Pet object that needs to be added to the store (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeWith400And4xxRangeResponseNo4xxDatatypeEndpoint'] to see the possible values for this operation + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function fakeWith400And4xxRangeResponseNo4xxDatatypeEndpointAsync($pet, string $contentType = self::contentTypes['fakeWith400And4xxRangeResponseNo4xxDatatypeEndpoint'][0]) + { + return $this->fakeWith400And4xxRangeResponseNo4xxDatatypeEndpointAsyncWithHttpInfo($pet, $contentType) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation fakeWith400And4xxRangeResponseNo4xxDatatypeEndpointAsyncWithHttpInfo + * + * test endpoint with 400 and 400-499 range response http code without dataType + * + * @param \OpenAPI\Client\Model\Pet $pet Pet object that needs to be added to the store (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeWith400And4xxRangeResponseNo4xxDatatypeEndpoint'] to see the possible values for this operation + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function fakeWith400And4xxRangeResponseNo4xxDatatypeEndpointAsyncWithHttpInfo($pet, string $contentType = self::contentTypes['fakeWith400And4xxRangeResponseNo4xxDatatypeEndpoint'][0]) + { + $returnType = '\OpenAPI\Client\Model\Pet'; + $request = $this->fakeWith400And4xxRangeResponseNo4xxDatatypeEndpointRequest($pet, $contentType); + + return $this->client + ->sendAsync($request, $this->createHttpClientOption()) + ->then( + function ($response) use ($returnType) { + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + 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( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $exception->getRequest()->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + ); + } + + /** + * Create request for operation 'fakeWith400And4xxRangeResponseNo4xxDatatypeEndpoint' + * + * @param \OpenAPI\Client\Model\Pet $pet Pet object that needs to be added to the store (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeWith400And4xxRangeResponseNo4xxDatatypeEndpoint'] to see the possible values for this operation + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + public function fakeWith400And4xxRangeResponseNo4xxDatatypeEndpointRequest($pet, string $contentType = self::contentTypes['fakeWith400And4xxRangeResponseNo4xxDatatypeEndpoint'][0]) + { + + // verify the required parameter 'pet' is set + if ($pet === null || (is_array($pet) && count($pet) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $pet when calling fakeWith400And4xxRangeResponseNo4xxDatatypeEndpoint' + ); + } + + + $resourcePath = '/fake/with_400_and_4xx_range_response_no_4xx_datatype/endpoint'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + + + + $headers = $this->headerSelector->selectHeaders( ['application/json', ], $contentType, @@ -3318,6 +3593,273 @@ public function fakeWith4xxRangeResponseEndpointRequest($pet, string $contentTyp + $headers = $this->headerSelector->selectHeaders( + ['application/json', ], + $contentType, + $multipart + ); + + // for model (json/xml) + if (isset($pet)) { + if (stripos($headers['Content-Type'], 'application/json') !== false) { + # if Content-Type contains "application/json", json_encode the body + $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($pet)); + } else { + $httpBody = $pet; + } + } elseif (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; + foreach ($formParamValueItems as $formParamValueItem) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValueItem + ]; + } + } + // for HTTP post (form) + $httpBody = new MultipartStream($multipartContents); + + } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { + # if Content-Type contains "application/json", json_encode the form parameters + $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + } else { + // for HTTP post (form) + $httpBody = ObjectSerializer::buildQuery($formParams); + } + } + + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $operationHost = $this->config->getHost(); + $query = ObjectSerializer::buildQuery($queryParams); + return new Request( + 'POST', + $operationHost . $resourcePath . ($query ? "?{$query}" : ''), + $headers, + $httpBody + ); + } + + /** + * Operation fakeWith4xxRangeResponseNo4xxDatatypeEndpoint + * + * test endpoint with 400-499 range response http code without dataType + * + * @param \OpenAPI\Client\Model\Pet $pet Pet object that needs to be added to the store (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeWith4xxRangeResponseNo4xxDatatypeEndpoint'] to see the possible values for this operation + * + * @throws \OpenAPI\Client\ApiException on non-2xx response or if the response body is not in the expected format + * @throws \InvalidArgumentException + * @return \OpenAPI\Client\Model\Pet + */ + public function fakeWith4xxRangeResponseNo4xxDatatypeEndpoint($pet, string $contentType = self::contentTypes['fakeWith4xxRangeResponseNo4xxDatatypeEndpoint'][0]) + { + list($response) = $this->fakeWith4xxRangeResponseNo4xxDatatypeEndpointWithHttpInfo($pet, $contentType); + return $response; + } + + /** + * Operation fakeWith4xxRangeResponseNo4xxDatatypeEndpointWithHttpInfo + * + * test endpoint with 400-499 range response http code without dataType + * + * @param \OpenAPI\Client\Model\Pet $pet Pet object that needs to be added to the store (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeWith4xxRangeResponseNo4xxDatatypeEndpoint'] to see the possible values for this operation + * + * @throws \OpenAPI\Client\ApiException on non-2xx response or if the response body is not in the expected format + * @throws \InvalidArgumentException + * @return array of \OpenAPI\Client\Model\Pet, HTTP status code, HTTP response headers (array of strings) + */ + public function fakeWith4xxRangeResponseNo4xxDatatypeEndpointWithHttpInfo($pet, string $contentType = self::contentTypes['fakeWith4xxRangeResponseNo4xxDatatypeEndpoint'][0]) + { + $request = $this->fakeWith4xxRangeResponseNo4xxDatatypeEndpointRequest($pet, $contentType); + + try { + $options = $this->createHttpClientOption(); + try { + $response = $this->client->send($request, $options); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null, + $e->getResponse() ? (string) $e->getResponse()->getBody() : null + ); + } catch (ConnectException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + null, + null + ); + } + + $statusCode = $response->getStatusCode(); + + + switch($statusCode) { + case 200: + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Pet', + $request, + $response, + ); + } + + + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Pet', + $request, + $response, + ); + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\OpenAPI\Client\Model\Pet', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + throw $e; + } + + + throw $e; + } + } + + /** + * Operation fakeWith4xxRangeResponseNo4xxDatatypeEndpointAsync + * + * test endpoint with 400-499 range response http code without dataType + * + * @param \OpenAPI\Client\Model\Pet $pet Pet object that needs to be added to the store (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeWith4xxRangeResponseNo4xxDatatypeEndpoint'] to see the possible values for this operation + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function fakeWith4xxRangeResponseNo4xxDatatypeEndpointAsync($pet, string $contentType = self::contentTypes['fakeWith4xxRangeResponseNo4xxDatatypeEndpoint'][0]) + { + return $this->fakeWith4xxRangeResponseNo4xxDatatypeEndpointAsyncWithHttpInfo($pet, $contentType) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation fakeWith4xxRangeResponseNo4xxDatatypeEndpointAsyncWithHttpInfo + * + * test endpoint with 400-499 range response http code without dataType + * + * @param \OpenAPI\Client\Model\Pet $pet Pet object that needs to be added to the store (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeWith4xxRangeResponseNo4xxDatatypeEndpoint'] to see the possible values for this operation + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function fakeWith4xxRangeResponseNo4xxDatatypeEndpointAsyncWithHttpInfo($pet, string $contentType = self::contentTypes['fakeWith4xxRangeResponseNo4xxDatatypeEndpoint'][0]) + { + $returnType = '\OpenAPI\Client\Model\Pet'; + $request = $this->fakeWith4xxRangeResponseNo4xxDatatypeEndpointRequest($pet, $contentType); + + return $this->client + ->sendAsync($request, $this->createHttpClientOption()) + ->then( + function ($response) use ($returnType) { + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + 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( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $exception->getRequest()->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + ); + } + + /** + * Create request for operation 'fakeWith4xxRangeResponseNo4xxDatatypeEndpoint' + * + * @param \OpenAPI\Client\Model\Pet $pet Pet object that needs to be added to the store (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeWith4xxRangeResponseNo4xxDatatypeEndpoint'] to see the possible values for this operation + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + public function fakeWith4xxRangeResponseNo4xxDatatypeEndpointRequest($pet, string $contentType = self::contentTypes['fakeWith4xxRangeResponseNo4xxDatatypeEndpoint'][0]) + { + + // verify the required parameter 'pet' is set + if ($pet === null || (is_array($pet) && count($pet) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $pet when calling fakeWith4xxRangeResponseNo4xxDatatypeEndpoint' + ); + } + + + $resourcePath = '/fake/with_4xx_range_response_no_4xx_datatype/endpoint'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + + + + $headers = $this->headerSelector->selectHeaders( ['application/json', ], $contentType, diff --git a/samples/client/petstore/php/OpenAPIClient-php/tests/ResponseTypesTest.php b/samples/client/petstore/php/OpenAPIClient-php/tests/ResponseTypesTest.php index 392330b88637..bce5c0e77937 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/tests/ResponseTypesTest.php +++ b/samples/client/petstore/php/OpenAPIClient-php/tests/ResponseTypesTest.php @@ -136,6 +136,22 @@ public function testErrorRangeResponseWithDataType() $this->assertEquals($responseContent['response_code'], $result->getResponseCode()); } + public function testErrorRangeResponseWithoutDataType() + { + $responseCode = mt_rand(400, 499); + $responseContent = []; + $this->expectExceptionCode($responseCode); + $this->expectException(ApiException::class); + + $this->fakeHttpClient->setResponse(new Response($responseCode, [], json_encode($responseContent))); + $api = new FakeApi($this->fakeHttpClient); + + $pet = new Model\Pet([]); + $pet->setId(1234); + + $api->fakeWith4xxRangeResponseNo4xxDatatypeEndpoint($pet); + } + public function testError400ResponseWithDataType() { $responseCode = 400; @@ -173,4 +189,20 @@ public function testErrorRangeAnd400ResponseWithDataType() $this->assertInstanceOf(Model\ErrorResponse::class, $result); $this->assertEquals($responseContent['response_code'], $result->getResponseCode()); } + + public function testErrorRangeAnd400ResponseWithoutDataType() + { + $responseCode = mt_rand(400, 499); + $responseContent = []; + $this->expectExceptionCode($responseCode); + $this->expectException(ApiException::class); + + $this->fakeHttpClient->setResponse(new Response($responseCode, [], json_encode($responseContent))); + $api = new FakeApi($this->fakeHttpClient); + + $pet = new Model\Pet([]); + $pet->setId(1234); + + $api->fakeWith400And4xxRangeResponseNo4xxDatatypeEndpoint($pet); + } } diff --git a/samples/client/petstore/php/psr-18/README.md b/samples/client/petstore/php/psr-18/README.md index 4435ea897b81..c77a0d15c041 100644 --- a/samples/client/petstore/php/psr-18/README.md +++ b/samples/client/petstore/php/psr-18/README.md @@ -95,8 +95,10 @@ Class | Method | HTTP request | Description *FakeApi* | [**fakeOuterStringSerialize**](docs/Api/FakeApi.md#fakeouterstringserialize) | **POST** /fake/outer/string | *FakeApi* | [**fakePropertyEnumIntegerSerialize**](docs/Api/FakeApi.md#fakepropertyenumintegerserialize) | **POST** /fake/property/enum-int | *FakeApi* | [**fakeWith400And4xxRangeResponseEndpoint**](docs/Api/FakeApi.md#fakewith400and4xxrangeresponseendpoint) | **POST** /fake/with_400_and_4xx_range_response/endpoint | test endpoint with 400 and 400-499 range response http code with dataType +*FakeApi* | [**fakeWith400And4xxRangeResponseNo4xxDatatypeEndpoint**](docs/Api/FakeApi.md#fakewith400and4xxrangeresponseno4xxdatatypeendpoint) | **POST** /fake/with_400_and_4xx_range_response_no_4xx_datatype/endpoint | test endpoint with 400 and 400-499 range response http code without dataType *FakeApi* | [**fakeWith400ResponseEndpoint**](docs/Api/FakeApi.md#fakewith400responseendpoint) | **POST** /fake/with_400_response/endpoint | test endpoint with 400 response http code with dataType *FakeApi* | [**fakeWith4xxRangeResponseEndpoint**](docs/Api/FakeApi.md#fakewith4xxrangeresponseendpoint) | **POST** /fake/with_4xx_range_response/endpoint | test endpoint with 400-499 range response http code with dataType +*FakeApi* | [**fakeWith4xxRangeResponseNo4xxDatatypeEndpoint**](docs/Api/FakeApi.md#fakewith4xxrangeresponseno4xxdatatypeendpoint) | **POST** /fake/with_4xx_range_response_no_4xx_datatype/endpoint | test endpoint with 400-499 range response http code without dataType *FakeApi* | [**getParameterNameMapping**](docs/Api/FakeApi.md#getparameternamemapping) | **GET** /fake/parameter-name-mapping | parameter name mapping test *FakeApi* | [**testAdditionalPropertiesReference**](docs/Api/FakeApi.md#testadditionalpropertiesreference) | **POST** /fake/additionalProperties-reference | test referenced additionalProperties *FakeApi* | [**testBodyWithBinary**](docs/Api/FakeApi.md#testbodywithbinary) | **PUT** /fake/body-with-binary | diff --git a/samples/client/petstore/php/psr-18/docs/Api/FakeApi.md b/samples/client/petstore/php/psr-18/docs/Api/FakeApi.md index 326b784cd2f3..7fff81c2a77d 100644 --- a/samples/client/petstore/php/psr-18/docs/Api/FakeApi.md +++ b/samples/client/petstore/php/psr-18/docs/Api/FakeApi.md @@ -14,8 +14,10 @@ Method | HTTP request | Description [**fakeOuterStringSerialize()**](FakeApi.md#fakeOuterStringSerialize) | **POST** /fake/outer/string | [**fakePropertyEnumIntegerSerialize()**](FakeApi.md#fakePropertyEnumIntegerSerialize) | **POST** /fake/property/enum-int | [**fakeWith400And4xxRangeResponseEndpoint()**](FakeApi.md#fakeWith400And4xxRangeResponseEndpoint) | **POST** /fake/with_400_and_4xx_range_response/endpoint | test endpoint with 400 and 400-499 range response http code with dataType +[**fakeWith400And4xxRangeResponseNo4xxDatatypeEndpoint()**](FakeApi.md#fakeWith400And4xxRangeResponseNo4xxDatatypeEndpoint) | **POST** /fake/with_400_and_4xx_range_response_no_4xx_datatype/endpoint | test endpoint with 400 and 400-499 range response http code without dataType [**fakeWith400ResponseEndpoint()**](FakeApi.md#fakeWith400ResponseEndpoint) | **POST** /fake/with_400_response/endpoint | test endpoint with 400 response http code with dataType [**fakeWith4xxRangeResponseEndpoint()**](FakeApi.md#fakeWith4xxRangeResponseEndpoint) | **POST** /fake/with_4xx_range_response/endpoint | test endpoint with 400-499 range response http code with dataType +[**fakeWith4xxRangeResponseNo4xxDatatypeEndpoint()**](FakeApi.md#fakeWith4xxRangeResponseNo4xxDatatypeEndpoint) | **POST** /fake/with_4xx_range_response_no_4xx_datatype/endpoint | test endpoint with 400-499 range response http code without dataType [**getParameterNameMapping()**](FakeApi.md#getParameterNameMapping) | **GET** /fake/parameter-name-mapping | parameter name mapping test [**testAdditionalPropertiesReference()**](FakeApi.md#testAdditionalPropertiesReference) | **POST** /fake/additionalProperties-reference | test referenced additionalProperties [**testBodyWithBinary()**](FakeApi.md#testBodyWithBinary) | **PUT** /fake/body-with-binary | @@ -587,6 +589,60 @@ No authorization required [[Back to Model list]](../../README.md#models) [[Back to README]](../../README.md) +## `fakeWith400And4xxRangeResponseNo4xxDatatypeEndpoint()` + +```php +fakeWith400And4xxRangeResponseNo4xxDatatypeEndpoint($pet): \OpenAPI\Client\Model\Pet +``` + +test endpoint with 400 and 400-499 range response http code without dataType + +### Example + +```php +fakeWith400And4xxRangeResponseNo4xxDatatypeEndpoint($pet); + print_r($result); +} catch (Exception $e) { + echo 'Exception when calling FakeApi->fakeWith400And4xxRangeResponseNo4xxDatatypeEndpoint: ', $e->getMessage(), PHP_EOL; +} +``` + +### Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **pet** | [**\OpenAPI\Client\Model\Pet**](../Model/Pet.md)| Pet object that needs to be added to the store | + +### Return type + +[**\OpenAPI\Client\Model\Pet**](../Model/Pet.md) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: `application/json`, `application/xml` +- **Accept**: `application/json` + +[[Back to top]](#) [[Back to API list]](../../README.md#endpoints) +[[Back to Model list]](../../README.md#models) +[[Back to README]](../../README.md) + ## `fakeWith400ResponseEndpoint()` ```php @@ -695,6 +751,60 @@ No authorization required [[Back to Model list]](../../README.md#models) [[Back to README]](../../README.md) +## `fakeWith4xxRangeResponseNo4xxDatatypeEndpoint()` + +```php +fakeWith4xxRangeResponseNo4xxDatatypeEndpoint($pet): \OpenAPI\Client\Model\Pet +``` + +test endpoint with 400-499 range response http code without dataType + +### Example + +```php +fakeWith4xxRangeResponseNo4xxDatatypeEndpoint($pet); + print_r($result); +} catch (Exception $e) { + echo 'Exception when calling FakeApi->fakeWith4xxRangeResponseNo4xxDatatypeEndpoint: ', $e->getMessage(), PHP_EOL; +} +``` + +### Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **pet** | [**\OpenAPI\Client\Model\Pet**](../Model/Pet.md)| Pet object that needs to be added to the store | + +### Return type + +[**\OpenAPI\Client\Model\Pet**](../Model/Pet.md) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: `application/json`, `application/xml` +- **Accept**: `application/json` + +[[Back to top]](#) [[Back to API list]](../../README.md#endpoints) +[[Back to Model list]](../../README.md#models) +[[Back to README]](../../README.md) + ## `getParameterNameMapping()` ```php diff --git a/samples/client/petstore/php/psr-18/lib/Api/FakeApi.php b/samples/client/petstore/php/psr-18/lib/Api/FakeApi.php index 181c8eb9fc0a..02e1f928ff10 100644 --- a/samples/client/petstore/php/psr-18/lib/Api/FakeApi.php +++ b/samples/client/petstore/php/psr-18/lib/Api/FakeApi.php @@ -2629,6 +2629,262 @@ public function fakeWith400And4xxRangeResponseEndpointRequest($pet) + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + 'application/jsonapplication/xml', + $multipart + ); + + // for model (json/xml) + if (isset($pet)) { + if ($this->headerSelector->isJsonMime($headers['Content-Type'])) { + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($pet)); + } else { + $httpBody = $pet; + } + } elseif (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; + foreach ($formParamValueItems as $formParamValueItem) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValueItem + ]; + } + } + // for HTTP post (form) + $httpBody = new MultipartStream($multipartContents); + + } elseif ($this->headerSelector->isJsonMime($headers['Content-Type'])) { + $httpBody = json_encode($formParams); + + } else { + // for HTTP post (form) + $httpBody = ObjectSerializer::buildQuery($formParams); + } + } + + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $operationHost = $this->config->getHost(); + + $uri = $this->createUri($operationHost, $resourcePath, $queryParams); + + return $this->createRequest('POST', $uri, $headers, $httpBody); + } + + /** + * Operation fakeWith400And4xxRangeResponseNo4xxDatatypeEndpoint + * + * test endpoint with 400 and 400-499 range response http code without dataType + * + * @param \OpenAPI\Client\Model\Pet $pet Pet object that needs to be added to the store (required) + * + * @throws \OpenAPI\Client\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return \OpenAPI\Client\Model\Pet + */ + public function fakeWith400And4xxRangeResponseNo4xxDatatypeEndpoint($pet) + { + list($response) = $this->fakeWith400And4xxRangeResponseNo4xxDatatypeEndpointWithHttpInfo($pet); + return $response; + } + + /** + * Operation fakeWith400And4xxRangeResponseNo4xxDatatypeEndpointWithHttpInfo + * + * test endpoint with 400 and 400-499 range response http code without dataType + * + * @param \OpenAPI\Client\Model\Pet $pet Pet object that needs to be added to the store (required) + * + * @throws \OpenAPI\Client\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of \OpenAPI\Client\Model\Pet, HTTP status code, HTTP response headers (array of strings) + */ + public function fakeWith400And4xxRangeResponseNo4xxDatatypeEndpointWithHttpInfo($pet) + { + $request = $this->fakeWith400And4xxRangeResponseNo4xxDatatypeEndpointRequest($pet); + + try { + try { + $response = $this->httpClient->sendRequest($request); + } catch (HttpException $e) { + $response = $e->getResponse(); + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $response->getStatusCode(), + (string) $request->getUri() + ), + $request, + $response, + $e + ); + } catch (ClientExceptionInterface $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $request, + null, + $e + ); + } + + $statusCode = $response->getStatusCode(); + + + switch($statusCode) { + case 200: + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Pet', + $request, + $response, + ); + } + + + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Pet', + $request, + $response, + ); + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\OpenAPI\Client\Model\Pet', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + throw $e; + } + + + throw $e; + } + } + + /** + * Operation fakeWith400And4xxRangeResponseNo4xxDatatypeEndpointAsync + * + * test endpoint with 400 and 400-499 range response http code without dataType + * + * @param \OpenAPI\Client\Model\Pet $pet Pet object that needs to be added to the store (required) + * + * @throws \InvalidArgumentException + * @return Promise + */ + public function fakeWith400And4xxRangeResponseNo4xxDatatypeEndpointAsync($pet) + { + return $this->fakeWith400And4xxRangeResponseNo4xxDatatypeEndpointAsyncWithHttpInfo($pet) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation fakeWith400And4xxRangeResponseNo4xxDatatypeEndpointAsyncWithHttpInfo + * + * test endpoint with 400 and 400-499 range response http code without dataType + * + * @param \OpenAPI\Client\Model\Pet $pet Pet object that needs to be added to the store (required) + * + * @throws \InvalidArgumentException + * @return Promise + */ + public function fakeWith400And4xxRangeResponseNo4xxDatatypeEndpointAsyncWithHttpInfo($pet) + { + $returnType = '\OpenAPI\Client\Model\Pet'; + $request = $this->fakeWith400And4xxRangeResponseNo4xxDatatypeEndpointRequest($pet); + + return $this->httpAsyncClient->sendAsyncRequest($request) + ->then( + function ($response) use ($returnType) { + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, + function (HttpException $exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $exception->getRequest()->getUri() + ), + $exception->getRequest(), + $exception->getResponse(), + $exception + ); + } + ); + } + + /** + * Create request for operation 'fakeWith400And4xxRangeResponseNo4xxDatatypeEndpoint' + * + * @param \OpenAPI\Client\Model\Pet $pet Pet object that needs to be added to the store (required) + * + * @throws \InvalidArgumentException + * @return RequestInterface + */ + public function fakeWith400And4xxRangeResponseNo4xxDatatypeEndpointRequest($pet) + { + // verify the required parameter 'pet' is set + if ($pet === null || (is_array($pet) && count($pet) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $pet when calling fakeWith400And4xxRangeResponseNo4xxDatatypeEndpoint' + ); + } + + $resourcePath = '/fake/with_400_and_4xx_range_response_no_4xx_datatype/endpoint'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = null; + $multipart = false; + + + + + $headers = $this->headerSelector->selectHeaders( ['application/json'], 'application/jsonapplication/xml', @@ -3172,6 +3428,262 @@ public function fakeWith4xxRangeResponseEndpointRequest($pet) + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + 'application/jsonapplication/xml', + $multipart + ); + + // for model (json/xml) + if (isset($pet)) { + if ($this->headerSelector->isJsonMime($headers['Content-Type'])) { + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($pet)); + } else { + $httpBody = $pet; + } + } elseif (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; + foreach ($formParamValueItems as $formParamValueItem) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValueItem + ]; + } + } + // for HTTP post (form) + $httpBody = new MultipartStream($multipartContents); + + } elseif ($this->headerSelector->isJsonMime($headers['Content-Type'])) { + $httpBody = json_encode($formParams); + + } else { + // for HTTP post (form) + $httpBody = ObjectSerializer::buildQuery($formParams); + } + } + + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $operationHost = $this->config->getHost(); + + $uri = $this->createUri($operationHost, $resourcePath, $queryParams); + + return $this->createRequest('POST', $uri, $headers, $httpBody); + } + + /** + * Operation fakeWith4xxRangeResponseNo4xxDatatypeEndpoint + * + * test endpoint with 400-499 range response http code without dataType + * + * @param \OpenAPI\Client\Model\Pet $pet Pet object that needs to be added to the store (required) + * + * @throws \OpenAPI\Client\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return \OpenAPI\Client\Model\Pet + */ + public function fakeWith4xxRangeResponseNo4xxDatatypeEndpoint($pet) + { + list($response) = $this->fakeWith4xxRangeResponseNo4xxDatatypeEndpointWithHttpInfo($pet); + return $response; + } + + /** + * Operation fakeWith4xxRangeResponseNo4xxDatatypeEndpointWithHttpInfo + * + * test endpoint with 400-499 range response http code without dataType + * + * @param \OpenAPI\Client\Model\Pet $pet Pet object that needs to be added to the store (required) + * + * @throws \OpenAPI\Client\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of \OpenAPI\Client\Model\Pet, HTTP status code, HTTP response headers (array of strings) + */ + public function fakeWith4xxRangeResponseNo4xxDatatypeEndpointWithHttpInfo($pet) + { + $request = $this->fakeWith4xxRangeResponseNo4xxDatatypeEndpointRequest($pet); + + try { + try { + $response = $this->httpClient->sendRequest($request); + } catch (HttpException $e) { + $response = $e->getResponse(); + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $response->getStatusCode(), + (string) $request->getUri() + ), + $request, + $response, + $e + ); + } catch (ClientExceptionInterface $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $request, + null, + $e + ); + } + + $statusCode = $response->getStatusCode(); + + + switch($statusCode) { + case 200: + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Pet', + $request, + $response, + ); + } + + + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Pet', + $request, + $response, + ); + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\OpenAPI\Client\Model\Pet', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + throw $e; + } + + + throw $e; + } + } + + /** + * Operation fakeWith4xxRangeResponseNo4xxDatatypeEndpointAsync + * + * test endpoint with 400-499 range response http code without dataType + * + * @param \OpenAPI\Client\Model\Pet $pet Pet object that needs to be added to the store (required) + * + * @throws \InvalidArgumentException + * @return Promise + */ + public function fakeWith4xxRangeResponseNo4xxDatatypeEndpointAsync($pet) + { + return $this->fakeWith4xxRangeResponseNo4xxDatatypeEndpointAsyncWithHttpInfo($pet) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation fakeWith4xxRangeResponseNo4xxDatatypeEndpointAsyncWithHttpInfo + * + * test endpoint with 400-499 range response http code without dataType + * + * @param \OpenAPI\Client\Model\Pet $pet Pet object that needs to be added to the store (required) + * + * @throws \InvalidArgumentException + * @return Promise + */ + public function fakeWith4xxRangeResponseNo4xxDatatypeEndpointAsyncWithHttpInfo($pet) + { + $returnType = '\OpenAPI\Client\Model\Pet'; + $request = $this->fakeWith4xxRangeResponseNo4xxDatatypeEndpointRequest($pet); + + return $this->httpAsyncClient->sendAsyncRequest($request) + ->then( + function ($response) use ($returnType) { + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, + function (HttpException $exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $exception->getRequest()->getUri() + ), + $exception->getRequest(), + $exception->getResponse(), + $exception + ); + } + ); + } + + /** + * Create request for operation 'fakeWith4xxRangeResponseNo4xxDatatypeEndpoint' + * + * @param \OpenAPI\Client\Model\Pet $pet Pet object that needs to be added to the store (required) + * + * @throws \InvalidArgumentException + * @return RequestInterface + */ + public function fakeWith4xxRangeResponseNo4xxDatatypeEndpointRequest($pet) + { + // verify the required parameter 'pet' is set + if ($pet === null || (is_array($pet) && count($pet) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $pet when calling fakeWith4xxRangeResponseNo4xxDatatypeEndpoint' + ); + } + + $resourcePath = '/fake/with_4xx_range_response_no_4xx_datatype/endpoint'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = null; + $multipart = false; + + + + + $headers = $this->headerSelector->selectHeaders( ['application/json'], 'application/jsonapplication/xml',