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..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,8 @@ 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; use {{invokerPackage}}\HeaderSelector; @@ -289,42 +291,28 @@ 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}}}', + $request, + $response, + );{{/isRange}} {{/dataType}} {{#-last}} } {{/-last}} {{/responses}} + {{#responses}}{{#dataType}}{{#isRange}}{{^isWildcard}} + if ($this->responseWithinRangeCode('{{code}}', $statusCode)) { + return $this->handleResponseWithDataType( + '{{{dataType}}}', + $request, + $response, + ); + }{{/isWildcard}}{{/isRange}}{{/dataType}}{{/responses}} if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -339,39 +327,16 @@ 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}}}', + $request, + $response, + ); {{/returnType}} {{^returnType}} return [null, $statusCode, $response->getHeaders()]; {{/returnType}} - } catch (ApiException $e) { switch ($e->getCode()) { {{#responses}} @@ -383,10 +348,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 +913,48 @@ use {{invokerPackage}}\ObjectSerializer; return $options; } + + private function handleResponseWithDataType( + string $dataType, + RequestInterface $request, + 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..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,8 @@ 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; use {{invokerPackage}}\HeaderSelector; @@ -262,38 +264,25 @@ 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}}}', + $request, + $response, + );{{/isRange}} {{/dataType}} {{#-last}} } {{/-last}} {{/responses}} + {{#responses}}{{#dataType}}{{#isRange}}{{^isWildcard}}if ($this->responseWithinRangeCode('{{code}}', $statusCode)) { + return $this->handleResponseWithDataType( + '{{{dataType}}}', + $request, + $response, + ); + }{{/isWildcard}}{{/isRange}}{{/dataType}}{{/responses}} + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( sprintf( @@ -307,39 +296,16 @@ 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}}}', + $request, + $response, + ); {{/returnType}} {{^returnType}} return [null, $statusCode, $response->getHeaders()]; {{/returnType}} - } catch (ApiException $e) { switch ($e->getCode()) { {{#responses}} @@ -351,10 +317,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 +836,48 @@ use {{invokerPackage}}\ObjectSerializer; return $options; } + + private function handleResponseWithDataType( + string $dataType, + RequestInterface $request, + 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..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 @@ -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,75 @@ 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}}}', + $request, + $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}}}', + $request, + $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}}}', + $request, + $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 +789,48 @@ use function sprintf; return $uri; } + + private function handleResponseWithDataType( + string $dataType, + RequestInterface $request, + 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-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..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 @@ -1339,6 +1339,111 @@ 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_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: + - 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' + /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 @@ -2118,3 +2223,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/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..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 @@ -1394,6 +1394,111 @@ 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_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: + - 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' + /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 @@ -2206,3 +2311,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..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,8 @@ 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; use OpenAPI\Client\HeaderSelector; @@ -184,36 +186,15 @@ 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', + $request, + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -228,34 +209,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -265,8 +223,9 @@ public function testAuthHttpBasicWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -486,36 +445,15 @@ 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', + $request, + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -530,34 +468,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -567,8 +482,9 @@ public function testAuthHttpBearerWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -748,4 +664,47 @@ protected function createHttpClientOption(): array return $options; } + + private function handleResponseWithDataType( + string $dataType, + RequestInterface $request, + 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..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,8 @@ 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; use OpenAPI\Client\HeaderSelector; @@ -208,36 +210,15 @@ 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', + $request, + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -252,34 +233,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -289,8 +247,9 @@ public function testBinaryGifWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -510,36 +469,15 @@ 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', + $request, + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -554,34 +492,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -591,8 +506,9 @@ public function testBodyApplicationOctetstreamBinaryWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -826,36 +742,15 @@ 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', + $request, + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -870,34 +765,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -907,8 +779,9 @@ public function testBodyMultipartFormdataArrayOfBinaryWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -1155,36 +1028,15 @@ 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', + $request, + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -1199,34 +1051,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -1236,8 +1065,9 @@ public function testBodyMultipartFormdataSingleBinaryWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -1478,36 +1308,15 @@ 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', + $request, + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -1522,34 +1331,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -1559,8 +1345,9 @@ public function testEchoBodyAllOfPetWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -1794,36 +1581,15 @@ 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', + $request, + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -1838,34 +1604,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -1875,8 +1618,9 @@ public function testEchoBodyFreeFormObjectResponseStringWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -2110,36 +1854,15 @@ 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', + $request, + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -2154,34 +1877,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -2191,8 +1891,9 @@ public function testEchoBodyPetWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -2426,36 +2127,15 @@ 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', + $request, + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -2470,34 +2150,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -2507,8 +2164,9 @@ public function testEchoBodyPetResponseStringWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -2742,36 +2400,15 @@ 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', + $request, + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -2786,34 +2423,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -2823,8 +2437,9 @@ public function testEchoBodyStringEnumWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -3058,36 +2673,15 @@ 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', + $request, + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -3102,34 +2696,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -3139,8 +2710,9 @@ public function testEchoBodyTagResponseStringWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -3330,4 +2902,47 @@ protected function createHttpClientOption(): array return $options; } + + private function handleResponseWithDataType( + string $dataType, + RequestInterface $request, + 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..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,8 @@ 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; use OpenAPI\Client\HeaderSelector; @@ -199,36 +201,15 @@ 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', + $request, + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -243,34 +224,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -280,8 +238,9 @@ public function testFormIntegerBooleanStringWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -534,36 +493,15 @@ 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', + $request, + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -578,34 +516,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -615,8 +530,9 @@ public function testFormObjectMultipartWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -873,36 +789,15 @@ 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', + $request, + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -917,34 +812,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -954,8 +826,9 @@ public function testFormOneofWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -1197,4 +1070,47 @@ protected function createHttpClientOption(): array return $options; } + + private function handleResponseWithDataType( + string $dataType, + RequestInterface $request, + 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..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,8 @@ 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; use OpenAPI\Client\HeaderSelector; @@ -201,36 +203,15 @@ 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', + $request, + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -245,34 +226,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -282,8 +240,9 @@ public function testHeaderIntegerBooleanStringEnumsWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -514,4 +473,47 @@ protected function createHttpClientOption(): array return $options; } + + private function handleResponseWithDataType( + string $dataType, + RequestInterface $request, + 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..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,8 @@ 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; use OpenAPI\Client\HeaderSelector; @@ -197,36 +199,15 @@ 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', + $request, + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -241,34 +222,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -278,8 +236,9 @@ public function testsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathE $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -539,4 +498,47 @@ protected function createHttpClientOption(): array return $options; } + + private function handleResponseWithDataType( + string $dataType, + RequestInterface $request, + 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..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,8 @@ 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; use OpenAPI\Client\HeaderSelector; @@ -216,36 +218,15 @@ 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', + $request, + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -260,34 +241,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -297,8 +255,9 @@ public function testEnumRefStringWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -558,36 +517,15 @@ 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', + $request, + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -602,34 +540,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -639,8 +554,9 @@ public function testQueryDatetimeDateStringWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -916,36 +832,15 @@ 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', + $request, + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -960,34 +855,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -997,8 +869,9 @@ public function testQueryIntegerBooleanStringWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -1266,36 +1139,15 @@ 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', + $request, + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -1310,34 +1162,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -1347,8 +1176,9 @@ public function testQueryStyleDeepObjectExplodeTrueObjectWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -1584,36 +1414,15 @@ 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', + $request, + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -1628,34 +1437,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -1665,8 +1451,9 @@ public function testQueryStyleDeepObjectExplodeTrueObjectAllOfWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -1902,36 +1689,15 @@ 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', + $request, + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -1946,34 +1712,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -1983,8 +1726,9 @@ public function testQueryStyleFormExplodeFalseArrayIntegerWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -2220,36 +1964,15 @@ 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', + $request, + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -2264,34 +1987,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -2301,8 +2001,9 @@ public function testQueryStyleFormExplodeFalseArrayStringWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -2538,36 +2239,15 @@ 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', + $request, + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -2582,34 +2262,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -2619,8 +2276,9 @@ public function testQueryStyleFormExplodeTrueArrayStringWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -2856,36 +2514,15 @@ 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', + $request, + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -2900,34 +2537,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -2937,8 +2551,9 @@ public function testQueryStyleFormExplodeTrueObjectWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -3174,36 +2789,15 @@ 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', + $request, + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -3218,34 +2812,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -3255,8 +2826,9 @@ public function testQueryStyleFormExplodeTrueObjectAllOfWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -3448,4 +3020,47 @@ protected function createHttpClientOption(): array return $options; } + + private function handleResponseWithDataType( + string $dataType, + RequestInterface $request, + 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..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,8 @@ 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; use OpenAPI\Client\HeaderSelector; @@ -184,36 +186,15 @@ 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', + $request, + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -228,34 +209,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -265,8 +223,9 @@ public function testAuthHttpBasicWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -486,36 +445,15 @@ 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', + $request, + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -530,34 +468,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -567,8 +482,9 @@ public function testAuthHttpBearerWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -748,4 +664,47 @@ protected function createHttpClientOption(): array return $options; } + + private function handleResponseWithDataType( + string $dataType, + RequestInterface $request, + 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..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,8 @@ 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; use OpenAPI\Client\HeaderSelector; @@ -208,36 +210,15 @@ 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', + $request, + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -252,34 +233,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -289,8 +247,9 @@ public function testBinaryGifWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -510,36 +469,15 @@ 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', + $request, + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -554,34 +492,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -591,8 +506,9 @@ public function testBodyApplicationOctetstreamBinaryWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -826,36 +742,15 @@ 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', + $request, + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -870,34 +765,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -907,8 +779,9 @@ public function testBodyMultipartFormdataArrayOfBinaryWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -1155,36 +1028,15 @@ 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', + $request, + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -1199,34 +1051,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -1236,8 +1065,9 @@ public function testBodyMultipartFormdataSingleBinaryWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -1478,36 +1308,15 @@ 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', + $request, + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -1522,34 +1331,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -1559,8 +1345,9 @@ public function testEchoBodyAllOfPetWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -1794,36 +1581,15 @@ 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', + $request, + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -1838,34 +1604,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -1875,8 +1618,9 @@ public function testEchoBodyFreeFormObjectResponseStringWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -2110,36 +1854,15 @@ 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', + $request, + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -2154,34 +1877,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -2191,8 +1891,9 @@ public function testEchoBodyPetWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -2426,36 +2127,15 @@ 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', + $request, + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -2470,34 +2150,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -2507,8 +2164,9 @@ public function testEchoBodyPetResponseStringWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -2742,36 +2400,15 @@ 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', + $request, + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -2786,34 +2423,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -2823,8 +2437,9 @@ public function testEchoBodyStringEnumWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -3058,36 +2673,15 @@ 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', + $request, + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -3102,34 +2696,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -3139,8 +2710,9 @@ public function testEchoBodyTagResponseStringWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -3330,4 +2902,47 @@ protected function createHttpClientOption(): array return $options; } + + private function handleResponseWithDataType( + string $dataType, + RequestInterface $request, + 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..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,8 @@ 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; use OpenAPI\Client\HeaderSelector; @@ -199,36 +201,15 @@ 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', + $request, + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -243,34 +224,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -280,8 +238,9 @@ public function testFormIntegerBooleanStringWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -534,36 +493,15 @@ 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', + $request, + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -578,34 +516,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -615,8 +530,9 @@ public function testFormObjectMultipartWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -873,36 +789,15 @@ 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', + $request, + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -917,34 +812,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -954,8 +826,9 @@ public function testFormOneofWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -1197,4 +1070,47 @@ protected function createHttpClientOption(): array return $options; } + + private function handleResponseWithDataType( + string $dataType, + RequestInterface $request, + 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..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,8 @@ 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; use OpenAPI\Client\HeaderSelector; @@ -201,36 +203,15 @@ 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', + $request, + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -245,34 +226,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -282,8 +240,9 @@ public function testHeaderIntegerBooleanStringEnumsWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -514,4 +473,47 @@ protected function createHttpClientOption(): array return $options; } + + private function handleResponseWithDataType( + string $dataType, + RequestInterface $request, + 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..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,8 @@ 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; use OpenAPI\Client\HeaderSelector; @@ -197,36 +199,15 @@ 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', + $request, + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -241,34 +222,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -278,8 +236,9 @@ public function testsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathE $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -539,4 +498,47 @@ protected function createHttpClientOption(): array return $options; } + + private function handleResponseWithDataType( + string $dataType, + RequestInterface $request, + 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..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,8 @@ 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; use OpenAPI\Client\HeaderSelector; @@ -216,36 +218,15 @@ 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', + $request, + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -260,34 +241,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -297,8 +255,9 @@ public function testEnumRefStringWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -558,36 +517,15 @@ 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', + $request, + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -602,34 +540,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -639,8 +554,9 @@ public function testQueryDatetimeDateStringWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -916,36 +832,15 @@ 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', + $request, + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -960,34 +855,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -997,8 +869,9 @@ public function testQueryIntegerBooleanStringWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -1266,36 +1139,15 @@ 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', + $request, + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -1310,34 +1162,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -1347,8 +1176,9 @@ public function testQueryStyleDeepObjectExplodeTrueObjectWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -1584,36 +1414,15 @@ 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', + $request, + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -1628,34 +1437,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -1665,8 +1451,9 @@ public function testQueryStyleDeepObjectExplodeTrueObjectAllOfWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -1902,36 +1689,15 @@ 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', + $request, + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -1946,34 +1712,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -1983,8 +1726,9 @@ public function testQueryStyleFormExplodeFalseArrayIntegerWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -2220,36 +1964,15 @@ 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', + $request, + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -2264,34 +1987,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -2301,8 +2001,9 @@ public function testQueryStyleFormExplodeFalseArrayStringWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -2538,36 +2239,15 @@ 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', + $request, + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -2582,34 +2262,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -2619,8 +2276,9 @@ public function testQueryStyleFormExplodeTrueArrayStringWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -2856,36 +2514,15 @@ 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', + $request, + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -2900,34 +2537,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -2937,8 +2551,9 @@ public function testQueryStyleFormExplodeTrueObjectWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -3174,36 +2789,15 @@ 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', + $request, + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -3218,34 +2812,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -3255,8 +2826,9 @@ public function testQueryStyleFormExplodeTrueObjectAllOfWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -3448,4 +3020,47 @@ protected function createHttpClientOption(): array return $options; } + + private function handleResponseWithDataType( + string $dataType, + RequestInterface $request, + 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/.openapi-generator/FILES b/samples/client/petstore/php-nextgen/OpenAPIClient-php/.openapi-generator/FILES index ebd39c9d9de9..15feb03a699f 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 @@ -93,6 +94,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 diff --git a/samples/client/petstore/php-nextgen/OpenAPIClient-php/README.md b/samples/client/petstore/php-nextgen/OpenAPIClient-php/README.md index a58f453c3355..103d2a59c10d 100644 --- a/samples/client/petstore/php-nextgen/OpenAPIClient-php/README.md +++ b/samples/client/petstore/php-nextgen/OpenAPIClient-php/README.md @@ -82,6 +82,11 @@ 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* | [**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 | @@ -140,6 +145,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..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 @@ -13,6 +13,11 @@ 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 | +| [**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 | | @@ -530,6 +535,276 @@ 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) + +## `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 +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) + +## `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/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/AnotherFakeApi.php b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/AnotherFakeApi.php index c69a68e49f40..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,8 @@ 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; use OpenAPI\Client\HeaderSelector; @@ -184,36 +186,15 @@ 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', + $request, + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -228,34 +209,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -265,8 +223,9 @@ public function call123TestSpecialTagsWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -462,4 +421,47 @@ protected function createHttpClientOption(): array return $options; } + + private function handleResponseWithDataType( + string $dataType, + RequestInterface $request, + 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..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,8 @@ 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; use OpenAPI\Client\HeaderSelector; @@ -176,36 +178,15 @@ 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', + $request, + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -220,34 +201,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { default: @@ -257,8 +215,9 @@ public function fooGetWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -430,4 +389,47 @@ protected function createHttpClientOption(): array return $options; } + + private function handleResponseWithDataType( + string $dataType, + RequestInterface $request, + 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..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 @@ -35,6 +35,8 @@ 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; use OpenAPI\Client\HeaderSelector; @@ -99,6 +101,26 @@ class FakeApi 'fakePropertyEnumIntegerSerialize' => [ 'application/json', ], + 'fakeWith400And4xxRangeResponseEndpoint' => [ + 'application/json', + 'application/xml', + ], + 'fakeWith400And4xxRangeResponseNo4xxDatatypeEndpoint' => [ + 'application/json', + 'application/xml', + ], + 'fakeWith400ResponseEndpoint' => [ + 'application/json', + 'application/xml', + ], + 'fakeWith4xxRangeResponseEndpoint' => [ + 'application/json', + 'application/xml', + ], + 'fakeWith4xxRangeResponseNo4xxDatatypeEndpoint' => [ + 'application/json', + 'application/xml', + ], 'testAdditionalPropertiesReference' => [ 'application/json', ], @@ -243,36 +265,15 @@ 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', + $request, + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -287,34 +288,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -324,8 +302,9 @@ public function fakeBigDecimalMapWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -549,36 +528,15 @@ 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', + $request, + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -593,34 +551,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -630,8 +565,9 @@ public function fakeEnumEndpointWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -913,36 +849,15 @@ 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', + $request, + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -957,34 +872,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -994,8 +886,9 @@ public function fakeHealthGetWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -1224,10 +1117,10 @@ public function fakeHttpSignatureTestWithHttpInfo( return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + throw $e; } } @@ -1477,36 +1370,15 @@ 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', + $request, + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -1521,34 +1393,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -1558,8 +1407,9 @@ public function fakeOuterBooleanSerializeWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -1785,36 +1635,15 @@ 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', + $request, + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -1829,34 +1658,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -1866,8 +1672,9 @@ public function fakeOuterCompositeSerializeWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -2093,36 +1900,15 @@ 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', + $request, + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -2137,34 +1923,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -2174,8 +1937,9 @@ public function fakeOuterNumberSerializeWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -2272,7 +2036,1426 @@ public function fakeOuterNumberSerializeRequest( - $resourcePath = '/fake/outer/number'; + $resourcePath = '/fake/outer/number'; + $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 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 ApiException on non-2xx response or if the response body is not in the expected format + * @throws InvalidArgumentException + * @return string + */ + public function fakeOuterStringSerialize( + ?string $body = null, + string $contentType = self::contentTypes['fakeOuterStringSerialize'][0] + ): string + { + list($response) = $this->fakeOuterStringSerializeWithHttpInfo($body, $contentType); + return $response; + } + + /** + * Operation fakeOuterStringSerializeWithHttpInfo + * + * @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 ApiException on non-2xx response or if the response body is not in the expected format + * @throws InvalidArgumentException + * @return array of string, HTTP status code, HTTP response headers (array of strings) + */ + public function fakeOuterStringSerializeWithHttpInfo( + ?string $body = null, + string $contentType = self::contentTypes['fakeOuterStringSerialize'][0] + ): array + { + $request = $this->fakeOuterStringSerializeRequest($body, $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( + 'string', + $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( + 'string', + $request, + $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 PromiseInterface + */ + public function fakeOuterStringSerializeAsync( + ?string $body = null, + string $contentType = self::contentTypes['fakeOuterStringSerialize'][0] + ): PromiseInterface + { + 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 PromiseInterface + */ + public function fakeOuterStringSerializeAsyncWithHttpInfo( + ?string $body = null, + string $contentType = self::contentTypes['fakeOuterStringSerialize'][0] + ): PromiseInterface + { + $returnType = 'string'; + $request = $this->fakeOuterStringSerializeRequest($body, $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 '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( + ?string $body = null, + string $contentType = self::contentTypes['fakeOuterStringSerialize'][0] + ): Request + { + + + + $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 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( + \OpenAPI\Client\Model\OuterObjectWithEnumProperty $outer_object_with_enum_property, + string $contentType = self::contentTypes['fakePropertyEnumIntegerSerialize'][0] + ): \OpenAPI\Client\Model\OuterObjectWithEnumProperty + { + 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 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( + \OpenAPI\Client\Model\OuterObjectWithEnumProperty $outer_object_with_enum_property, + string $contentType = self::contentTypes['fakePropertyEnumIntegerSerialize'][0] + ): array + { + $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', + $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\OuterObjectWithEnumProperty', + $request, + $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 PromiseInterface + */ + public function fakePropertyEnumIntegerSerializeAsync( + \OpenAPI\Client\Model\OuterObjectWithEnumProperty $outer_object_with_enum_property, + string $contentType = self::contentTypes['fakePropertyEnumIntegerSerialize'][0] + ): PromiseInterface + { + 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 PromiseInterface + */ + public function fakePropertyEnumIntegerSerializeAsyncWithHttpInfo( + \OpenAPI\Client\Model\OuterObjectWithEnumProperty $outer_object_with_enum_property, + string $contentType = self::contentTypes['fakePropertyEnumIntegerSerialize'][0] + ): PromiseInterface + { + $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 (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 '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( + \OpenAPI\Client\Model\OuterObjectWithEnumProperty $outer_object_with_enum_property, + string $contentType = self::contentTypes['fakePropertyEnumIntegerSerialize'][0] + ): Request + { + + // 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 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', + $request, + $response, + ); + case 400: + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\ErrorResponse', + $request, + $response, + ); + + } + + if ($this->responseWithinRangeCode('4xx', $statusCode)) { + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\ErrorResponse', + $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; + 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 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, + $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', + $request, + $response, + ); + case 400: + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\ErrorResponse', + $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; + 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 = []; @@ -2284,18 +3467,18 @@ public function fakeOuterNumberSerializeRequest( $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) { @@ -2344,40 +3527,44 @@ public function fakeOuterNumberSerializeRequest( } /** - * Operation fakeOuterStringSerialize + * Operation fakeWith4xxRangeResponseEndpoint * - * @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-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 string + * @return \OpenAPI\Client\Model\Pet|\OpenAPI\Client\Model\ErrorResponse */ - public function fakeOuterStringSerialize( - ?string $body = null, - string $contentType = self::contentTypes['fakeOuterStringSerialize'][0] - ): string + 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->fakeOuterStringSerializeWithHttpInfo($body, $contentType); + list($response) = $this->fakeWith4xxRangeResponseEndpointWithHttpInfo($pet, $contentType); return $response; } /** - * Operation fakeOuterStringSerializeWithHttpInfo + * Operation fakeWith4xxRangeResponseEndpointWithHttpInfo * - * @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-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 string, 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 fakeOuterStringSerializeWithHttpInfo( - ?string $body = null, - string $contentType = self::contentTypes['fakeOuterStringSerialize'][0] + public function fakeWith4xxRangeResponseEndpointWithHttpInfo( + \OpenAPI\Client\Model\Pet $pet, + string $contentType = self::contentTypes['fakeWith4xxRangeResponseEndpoint'][0] ): array { - $request = $this->fakeOuterStringSerializeRequest($body, $contentType); + $request = $this->fakeWith4xxRangeResponseEndpointRequest($pet, $contentType); try { $options = $this->createHttpClientOption(); @@ -2401,35 +3588,22 @@ 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( + '\OpenAPI\Client\Model\Pet', + $request, + $response, + ); + + } + + if ($this->responseWithinRangeCode('4xx', $statusCode)) { + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\ErrorResponse', + $request, + $response, + ); } if ($statusCode < 200 || $statusCode > 299) { @@ -2445,64 +3619,54 @@ 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( + '\OpenAPI\Client\Model\Pet', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: $data = ObjectSerializer::deserialize( $e->getResponseBody(), - 'string', + '\OpenAPI\Client\Model\Pet', $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + 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 fakeOuterStringSerializeAsync + * Operation fakeWith4xxRangeResponseEndpointAsync * - * @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-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 fakeOuterStringSerializeAsync( - ?string $body = null, - string $contentType = self::contentTypes['fakeOuterStringSerialize'][0] + public function fakeWith4xxRangeResponseEndpointAsync( + \OpenAPI\Client\Model\Pet $pet, + string $contentType = self::contentTypes['fakeWith4xxRangeResponseEndpoint'][0] ): PromiseInterface { - return $this->fakeOuterStringSerializeAsyncWithHttpInfo($body, $contentType) + return $this->fakeWith4xxRangeResponseEndpointAsyncWithHttpInfo($pet, $contentType) ->then( function ($response) { return $response[0]; @@ -2511,21 +3675,23 @@ function ($response) { } /** - * Operation fakeOuterStringSerializeAsyncWithHttpInfo + * Operation fakeWith4xxRangeResponseEndpointAsyncWithHttpInfo * - * @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-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 fakeOuterStringSerializeAsyncWithHttpInfo( - ?string $body = null, - string $contentType = self::contentTypes['fakeOuterStringSerialize'][0] + public function fakeWith4xxRangeResponseEndpointAsyncWithHttpInfo( + \OpenAPI\Client\Model\Pet $pet, + string $contentType = self::contentTypes['fakeWith4xxRangeResponseEndpoint'][0] ): PromiseInterface { - $returnType = 'string'; - $request = $this->fakeOuterStringSerializeRequest($body, $contentType); + $returnType = '\OpenAPI\Client\Model\Pet'; + $request = $this->fakeWith4xxRangeResponseEndpointRequest($pet, $contentType); return $this->client ->sendAsync($request, $this->createHttpClientOption()) @@ -2564,23 +3730,29 @@ function ($exception) { } /** - * Create request for operation 'fakeOuterStringSerialize' + * Create request for operation 'fakeWith4xxRangeResponseEndpoint' * - * @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['fakeWith4xxRangeResponseEndpoint'] to see the possible values for this operation * * @throws InvalidArgumentException * @return \GuzzleHttp\Psr7\Request */ - public function fakeOuterStringSerializeRequest( - ?string $body = null, - string $contentType = self::contentTypes['fakeOuterStringSerialize'][0] + 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/outer/string'; + $resourcePath = '/fake/with_4xx_range_response/endpoint'; $formParams = []; $queryParams = []; $headerParams = []; @@ -2592,18 +3764,18 @@ public function fakeOuterStringSerializeRequest( $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) { @@ -2652,40 +3824,44 @@ public function fakeOuterStringSerializeRequest( } /** - * Operation fakePropertyEnumIntegerSerialize + * Operation fakeWith4xxRangeResponseNo4xxDatatypeEndpoint * - * @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 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\OuterObjectWithEnumProperty + * @return \OpenAPI\Client\Model\Pet */ - public function fakePropertyEnumIntegerSerialize( - \OpenAPI\Client\Model\OuterObjectWithEnumProperty $outer_object_with_enum_property, - string $contentType = self::contentTypes['fakePropertyEnumIntegerSerialize'][0] - ): \OpenAPI\Client\Model\OuterObjectWithEnumProperty + public function fakeWith4xxRangeResponseNo4xxDatatypeEndpoint( + \OpenAPI\Client\Model\Pet $pet, + string $contentType = self::contentTypes['fakeWith4xxRangeResponseNo4xxDatatypeEndpoint'][0] + ): \OpenAPI\Client\Model\Pet { - list($response) = $this->fakePropertyEnumIntegerSerializeWithHttpInfo($outer_object_with_enum_property, $contentType); + list($response) = $this->fakeWith4xxRangeResponseNo4xxDatatypeEndpointWithHttpInfo($pet, $contentType); return $response; } /** - * Operation fakePropertyEnumIntegerSerializeWithHttpInfo + * Operation fakeWith4xxRangeResponseNo4xxDatatypeEndpointWithHttpInfo * - * @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 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\OuterObjectWithEnumProperty, HTTP status code, HTTP response headers (array of strings) + * @return array of \OpenAPI\Client\Model\Pet, HTTP status code, HTTP response headers (array of strings) */ - public function fakePropertyEnumIntegerSerializeWithHttpInfo( - \OpenAPI\Client\Model\OuterObjectWithEnumProperty $outer_object_with_enum_property, - string $contentType = self::contentTypes['fakePropertyEnumIntegerSerialize'][0] + public function fakeWith4xxRangeResponseNo4xxDatatypeEndpointWithHttpInfo( + \OpenAPI\Client\Model\Pet $pet, + string $contentType = self::contentTypes['fakeWith4xxRangeResponseNo4xxDatatypeEndpoint'][0] ): array { - $request = $this->fakePropertyEnumIntegerSerializeRequest($outer_object_with_enum_property, $contentType); + $request = $this->fakeWith4xxRangeResponseNo4xxDatatypeEndpointRequest($pet, $contentType); try { $options = $this->createHttpClientOption(); @@ -2709,36 +3885,15 @@ 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\Pet', + $request, + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -2753,64 +3908,44 @@ 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\Pet', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: $data = ObjectSerializer::deserialize( $e->getResponseBody(), - '\OpenAPI\Client\Model\OuterObjectWithEnumProperty', + '\OpenAPI\Client\Model\Pet', $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } /** - * Operation fakePropertyEnumIntegerSerializeAsync + * Operation fakeWith4xxRangeResponseNo4xxDatatypeEndpointAsync * - * @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 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 fakePropertyEnumIntegerSerializeAsync( - \OpenAPI\Client\Model\OuterObjectWithEnumProperty $outer_object_with_enum_property, - string $contentType = self::contentTypes['fakePropertyEnumIntegerSerialize'][0] + public function fakeWith4xxRangeResponseNo4xxDatatypeEndpointAsync( + \OpenAPI\Client\Model\Pet $pet, + string $contentType = self::contentTypes['fakeWith4xxRangeResponseNo4xxDatatypeEndpoint'][0] ): PromiseInterface { - return $this->fakePropertyEnumIntegerSerializeAsyncWithHttpInfo($outer_object_with_enum_property, $contentType) + return $this->fakeWith4xxRangeResponseNo4xxDatatypeEndpointAsyncWithHttpInfo($pet, $contentType) ->then( function ($response) { return $response[0]; @@ -2819,21 +3954,23 @@ function ($response) { } /** - * Operation fakePropertyEnumIntegerSerializeAsyncWithHttpInfo + * Operation fakeWith4xxRangeResponseNo4xxDatatypeEndpointAsyncWithHttpInfo * - * @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 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 fakePropertyEnumIntegerSerializeAsyncWithHttpInfo( - \OpenAPI\Client\Model\OuterObjectWithEnumProperty $outer_object_with_enum_property, - string $contentType = self::contentTypes['fakePropertyEnumIntegerSerialize'][0] + public function fakeWith4xxRangeResponseNo4xxDatatypeEndpointAsyncWithHttpInfo( + \OpenAPI\Client\Model\Pet $pet, + string $contentType = self::contentTypes['fakeWith4xxRangeResponseNo4xxDatatypeEndpoint'][0] ): PromiseInterface { - $returnType = '\OpenAPI\Client\Model\OuterObjectWithEnumProperty'; - $request = $this->fakePropertyEnumIntegerSerializeRequest($outer_object_with_enum_property, $contentType); + $returnType = '\OpenAPI\Client\Model\Pet'; + $request = $this->fakeWith4xxRangeResponseNo4xxDatatypeEndpointRequest($pet, $contentType); return $this->client ->sendAsync($request, $this->createHttpClientOption()) @@ -2872,29 +4009,29 @@ function ($exception) { } /** - * Create request for operation 'fakePropertyEnumIntegerSerialize' + * Create request for operation 'fakeWith4xxRangeResponseNo4xxDatatypeEndpoint' * - * @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['fakeWith4xxRangeResponseNo4xxDatatypeEndpoint'] to see the possible values for this operation * * @throws InvalidArgumentException * @return \GuzzleHttp\Psr7\Request */ - public function fakePropertyEnumIntegerSerializeRequest( - \OpenAPI\Client\Model\OuterObjectWithEnumProperty $outer_object_with_enum_property, - string $contentType = self::contentTypes['fakePropertyEnumIntegerSerialize'][0] + public function fakeWith4xxRangeResponseNo4xxDatatypeEndpointRequest( + \OpenAPI\Client\Model\Pet $pet, + string $contentType = self::contentTypes['fakeWith4xxRangeResponseNo4xxDatatypeEndpoint'][0] ): Request { - // 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 fakeWith4xxRangeResponseNo4xxDatatypeEndpoint' ); } - $resourcePath = '/fake/property/enum-int'; + $resourcePath = '/fake/with_4xx_range_response_no_4xx_datatype/endpoint'; $formParams = []; $queryParams = []; $headerParams = []; @@ -2906,18 +4043,18 @@ public function fakePropertyEnumIntegerSerializeRequest( $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) { @@ -3028,10 +4165,10 @@ public function testAdditionalPropertiesReferenceWithHttpInfo( return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + throw $e; } } @@ -3255,10 +4392,10 @@ public function testBodyWithBinaryWithHttpInfo( return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + throw $e; } } @@ -3478,10 +4615,10 @@ public function testBodyWithFileSchemaWithHttpInfo( return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + throw $e; } } @@ -3705,10 +4842,10 @@ public function testBodyWithQueryParamsWithHttpInfo( return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + throw $e; } } @@ -3953,36 +5090,15 @@ 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', + $request, + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -3997,34 +5113,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -4034,8 +5127,9 @@ public function testClientModelWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -4328,10 +5422,10 @@ public function testEndpointParametersWithHttpInfo( return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + throw $e; } } @@ -4802,10 +5896,10 @@ public function testEnumParametersWithHttpInfo( return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + throw $e; } } @@ -5152,10 +6246,10 @@ public function testGroupParametersWithHttpInfo( return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + throw $e; } } @@ -5467,10 +6561,10 @@ public function testInlineAdditionalPropertiesWithHttpInfo( return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + throw $e; } } @@ -5698,10 +6792,10 @@ public function testInlineFreeformAdditionalPropertiesWithHttpInfo( return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + throw $e; } } @@ -5933,10 +7027,10 @@ public function testJsonFormDataWithHttpInfo( return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + throw $e; } } @@ -6178,10 +7272,10 @@ public function testNullableWithHttpInfo( return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + throw $e; } } @@ -6429,10 +7523,10 @@ public function testQueryParameterCollectionFormatWithHttpInfo( return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + throw $e; } } @@ -6784,10 +7878,10 @@ public function testStringMapReferenceWithHttpInfo( return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + throw $e; } } @@ -6970,4 +8064,47 @@ protected function createHttpClientOption(): array return $options; } + + private function handleResponseWithDataType( + string $dataType, + RequestInterface $request, + 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..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,8 @@ 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; use OpenAPI\Client\HeaderSelector; @@ -184,36 +186,15 @@ 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', + $request, + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -228,34 +209,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -265,8 +223,9 @@ public function testClassnameWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -467,4 +426,47 @@ protected function createHttpClientOption(): array return $options; } + + private function handleResponseWithDataType( + string $dataType, + RequestInterface $request, + 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..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,8 @@ 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; use OpenAPI\Client\HeaderSelector; @@ -251,10 +253,10 @@ public function addPetWithHttpInfo( return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + throw $e; } } @@ -602,10 +604,10 @@ public function deletePetWithHttpInfo( return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + throw $e; } } @@ -848,36 +850,15 @@ 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[]', + $request, + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -892,34 +873,11 @@ 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[]', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -929,8 +887,9 @@ public function findPetsByStatusWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -1178,36 +1137,15 @@ 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[]', + $request, + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -1222,34 +1160,11 @@ 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[]', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -1259,8 +1174,9 @@ public function findPetsByTagsWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -1509,36 +1425,15 @@ 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', + $request, + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -1553,34 +1448,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -1590,8 +1462,9 @@ public function getPetByIdWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -1878,10 +1751,10 @@ public function updatePetWithHttpInfo( return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + throw $e; } } @@ -2233,10 +2106,10 @@ public function updatePetWithFormWithHttpInfo( return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + throw $e; } } @@ -2498,36 +2371,15 @@ 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', + $request, + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -2542,34 +2394,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -2579,8 +2408,9 @@ public function uploadFileWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -2865,36 +2695,15 @@ 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', + $request, + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -2909,34 +2718,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -2946,8 +2732,9 @@ public function uploadFileWithRequiredFileWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -3186,4 +2973,47 @@ protected function createHttpClientOption(): array return $options; } + + private function handleResponseWithDataType( + string $dataType, + RequestInterface $request, + 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..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,8 @@ 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; use OpenAPI\Client\HeaderSelector; @@ -194,10 +196,10 @@ public function deleteOrderWithHttpInfo( return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + throw $e; } } @@ -421,36 +423,15 @@ 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', + $request, + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -465,34 +446,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -502,8 +460,9 @@ public function getInventoryWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -728,36 +687,15 @@ 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', + $request, + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -772,34 +710,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -809,8 +724,9 @@ public function getOrderByIdWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -1057,36 +973,15 @@ 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', + $request, + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -1101,34 +996,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -1138,8 +1010,9 @@ public function placeOrderWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -1335,4 +1208,47 @@ protected function createHttpClientOption(): array return $options; } + + private function handleResponseWithDataType( + string $dataType, + RequestInterface $request, + 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..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,8 @@ 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; use OpenAPI\Client\HeaderSelector; @@ -206,10 +208,10 @@ public function createUserWithHttpInfo( return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + throw $e; } } @@ -437,10 +439,10 @@ public function createUsersWithArrayInputWithHttpInfo( return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + throw $e; } } @@ -668,10 +670,10 @@ public function createUsersWithListInputWithHttpInfo( return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + throw $e; } } @@ -899,10 +901,10 @@ public function deleteUserWithHttpInfo( return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + throw $e; } } @@ -1130,36 +1132,15 @@ 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', + $request, + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -1174,34 +1155,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -1211,8 +1169,9 @@ public function getUserByNameWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -1457,36 +1416,15 @@ 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', + $request, + $response, + ); } + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( @@ -1501,34 +1439,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -1538,8 +1453,9 @@ public function loginUserWithHttpInfo( $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + throw $e; } } @@ -1800,10 +1716,10 @@ public function logoutUserWithHttpInfo( return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + throw $e; } } @@ -2015,10 +1931,10 @@ public function updateUserWithHttpInfo( return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + throw $e; } } @@ -2222,4 +2138,47 @@ protected function createHttpClientOption(): array return $options; } + + private function handleResponseWithDataType( + string $dataType, + RequestInterface $request, + 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/Model/ErrorResponse.php b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Model/ErrorResponse.php new file mode 100644 index 000000000000..45fc8ad004d8 --- /dev/null +++ b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Model/ErrorResponse.php @@ -0,0 +1,441 @@ + + */ +class ErrorResponse implements ModelInterface, ArrayAccess, JsonSerializable +{ + public const DISCRIMINATOR = null; + + /** + * The original name of the model. + * + * @var string + */ + protected static string $openAPIModelName = 'ErrorResponse'; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @var array + */ + protected static array $openAPITypes = [ + 'response_code' => 'int', + 'error' => 'string' + ]; + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @var array + */ + protected static array $openAPIFormats = [ + 'response_code' => null, + 'error' => null + ]; + + /** + * Array of nullable properties. Used for (de)serialization + * + * @var array + */ + protected static array $openAPINullables = [ + 'response_code' => false, + 'error' => false + ]; + + /** + * If a nullable field gets set to null, insert it here + * + * @var array + */ + protected array $openAPINullablesSetToNull = []; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPITypes(): array + { + return self::$openAPITypes; + } + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPIFormats(): array + { + 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 array + */ + private function getOpenAPINullablesSetToNull(): array + { + return $this->openAPINullablesSetToNull; + } + + /** + * Setter - Array of nullable field names deliberately set to null + * + * @param array $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 array + */ + protected static array $attributeMap = [ + 'response_code' => 'response_code', + 'error' => 'error' + ]; + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @var array + */ + protected static array $setters = [ + 'response_code' => 'setResponseCode', + 'error' => 'setError' + ]; + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @var array + */ + protected static array $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(): array + { + return self::$attributeMap; + } + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @return array + */ + public static function setters(): array + { + return self::$setters; + } + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @return array + */ + public static function getters(): array + { + return self::$getters; + } + + /** + * The original name of the model. + * + * @return string + */ + public function getModelName(): string + { + return self::$openAPIModelName; + } + + + /** + * Associative array for storing property values + * + * @var array + */ + protected array $container = []; + + /** + * Constructor + * + * @param array $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, mixed $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 string[] invalid properties with reasons + */ + public function listInvalidProperties(): array + { + $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(): bool + { + return count($this->listInvalidProperties()) === 0; + } + + + /** + * Gets response_code + * + * @return int|null + */ + public function getResponseCode(): ?int + { + return $this->container['response_code']; + } + + /** + * Sets response_code + * + * @param int|null $response_code response_code + * + * @return $this + */ + public function setResponseCode(?int $response_code): static + { + 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(): ?string + { + return $this->container['error']; + } + + /** + * Sets error + * + * @param string|null $error error + * + * @return $this + */ + public function setError(?string $error): static + { + 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(mixed $offset): bool + { + return isset($this->container[$offset]); + } + + /** + * Gets offset. + * + * @param integer $offset Offset + * + * @return mixed|null + */ + #[ReturnTypeWillChange] + public function offsetGet(mixed $offset): mixed + { + 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(mixed $offset, mixed $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(mixed $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(): mixed + { + return ObjectSerializer::sanitizeForSerialization($this); + } + + /** + * Gets the string presentation of the object + * + * @return string + */ + public function __toString(): string + { + return json_encode( + ObjectSerializer::sanitizeForSerialization($this), + JSON_PRETTY_PRINT + ); + } + + /** + * Gets a header-safe presentation of the object + * + * @return string + */ + 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 @@ +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) + +## `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 +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) + +## `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/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..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,8 @@ 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; use OpenAPI\Client\HeaderSelector; @@ -181,34 +183,15 @@ 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', + $request, + $response, + ); } + + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( sprintf( @@ -222,34 +205,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -259,8 +219,10 @@ public function call123TestSpecialTagsWithHttpInfo($client, string $contentType $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -447,4 +409,47 @@ protected function createHttpClientOption() return $options; } + + private function handleResponseWithDataType( + string $dataType, + RequestInterface $request, + 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..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,8 @@ 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; use OpenAPI\Client\HeaderSelector; @@ -175,34 +177,15 @@ 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', + $request, + $response, + ); } + + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( sprintf( @@ -216,34 +199,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { default: @@ -253,8 +213,10 @@ public function fooGetWithHttpInfo(string $contentType = self::contentTypes['foo $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -420,4 +382,47 @@ protected function createHttpClientOption() return $options; } + + private function handleResponseWithDataType( + string $dataType, + RequestInterface $request, + 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..762e9d7a1849 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,8 @@ 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; use OpenAPI\Client\HeaderSelector; @@ -99,6 +101,26 @@ class FakeApi 'fakePropertyEnumIntegerSerialize' => [ 'application/json', ], + 'fakeWith400And4xxRangeResponseEndpoint' => [ + 'application/json', + 'application/xml', + ], + 'fakeWith400And4xxRangeResponseNo4xxDatatypeEndpoint' => [ + 'application/json', + 'application/xml', + ], + 'fakeWith400ResponseEndpoint' => [ + 'application/json', + 'application/xml', + ], + 'fakeWith4xxRangeResponseEndpoint' => [ + 'application/json', + 'application/xml', + ], + 'fakeWith4xxRangeResponseNo4xxDatatypeEndpoint' => [ + 'application/json', + 'application/xml', + ], 'getParameterNameMapping' => [ 'application/json', ], @@ -242,34 +264,15 @@ 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', + $request, + $response, + ); } + + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( sprintf( @@ -283,34 +286,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -320,8 +300,10 @@ public function fakeBigDecimalMapWithHttpInfo(string $contentType = self::conten $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -532,34 +514,15 @@ 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', + $request, + $response, + ); } + + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( sprintf( @@ -573,34 +536,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -610,8 +550,10 @@ public function fakeEnumEndpointWithHttpInfo($enum_class, $enum_class_array, $en $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -877,34 +819,15 @@ 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', + $request, + $response, + ); } + + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( sprintf( @@ -918,34 +841,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -955,8 +855,10 @@ public function fakeHealthGetWithHttpInfo(string $contentType = self::contentTyp $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -1169,10 +1071,11 @@ public function fakeHttpSignatureTestWithHttpInfo($pet, $query_1 = null, $header return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + + throw $e; } } @@ -1404,34 +1307,15 @@ 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', + $request, + $response, + ); } + + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( sprintf( @@ -1445,34 +1329,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -1482,8 +1343,10 @@ public function fakeOuterBooleanSerializeWithHttpInfo($body = null, string $cont $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -1697,34 +1560,15 @@ 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', + $request, + $response, + ); } + + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( sprintf( @@ -1738,34 +1582,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -1775,8 +1596,10 @@ public function fakeOuterCompositeSerializeWithHttpInfo($outer_composite = null, $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -1990,34 +1813,15 @@ 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', + $request, + $response, + ); } + + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( sprintf( @@ -2031,34 +1835,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -2068,8 +1849,10 @@ public function fakeOuterNumberSerializeWithHttpInfo($body = null, string $conte $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -2083,9 +1866,1359 @@ public function fakeOuterNumberSerializeWithHttpInfo($body = null, string $conte * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ - public function fakeOuterNumberSerializeAsync($body = null, string $contentType = self::contentTypes['fakeOuterNumberSerialize'][0]) + public function fakeOuterNumberSerializeAsync($body = null, string $contentType = self::contentTypes['fakeOuterNumberSerialize'][0]) + { + return $this->fakeOuterNumberSerializeAsyncWithHttpInfo($body, $contentType) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation fakeOuterNumberSerializeAsyncWithHttpInfo + * + * @param float|null $body Input number as post body (optional) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeOuterNumberSerialize'] to see the possible values for this operation + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function fakeOuterNumberSerializeAsyncWithHttpInfo($body = null, string $contentType = self::contentTypes['fakeOuterNumberSerialize'][0]) + { + $returnType = 'float'; + $request = $this->fakeOuterNumberSerializeRequest($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 'fakeOuterNumberSerialize' + * + * @param float|null $body Input number as post body (optional) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeOuterNumberSerialize'] to see the possible values for this operation + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + public function fakeOuterNumberSerializeRequest($body = null, string $contentType = self::contentTypes['fakeOuterNumberSerialize'][0]) + { + + + + $resourcePath = '/fake/outer/number'; + $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 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 \OpenAPI\Client\ApiException on non-2xx response or if the response body is not in the expected format + * @throws \InvalidArgumentException + * @return string + */ + public function fakeOuterStringSerialize($body = null, string $contentType = self::contentTypes['fakeOuterStringSerialize'][0]) + { + list($response) = $this->fakeOuterStringSerializeWithHttpInfo($body, $contentType); + return $response; + } + + /** + * Operation fakeOuterStringSerializeWithHttpInfo + * + * @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 \OpenAPI\Client\ApiException on non-2xx response or if the response body is not in the expected format + * @throws \InvalidArgumentException + * @return array of string, HTTP status code, HTTP response headers (array of strings) + */ + public function fakeOuterStringSerializeWithHttpInfo($body = null, string $contentType = self::contentTypes['fakeOuterStringSerialize'][0]) + { + $request = $this->fakeOuterStringSerializeRequest($body, $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( + 'string', + $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( + 'string', + $request, + $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', + $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\OuterObjectWithEnumProperty', + $request, + $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 \OpenAPI\Client\Model\Pet|\OpenAPI\Client\Model\ErrorResponse|\OpenAPI\Client\Model\ErrorResponse + */ + public function fakeWith400And4xxRangeResponseEndpoint($pet, string $contentType = self::contentTypes['fakeWith400And4xxRangeResponseEndpoint'][0]) + { + 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 \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|\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]) + { + $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', + $request, + $response, + ); + case 400: + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\ErrorResponse', + $request, + $response, + ); + + } + + if ($this->responseWithinRangeCode('4xx', $statusCode)) { + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\ErrorResponse', + $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; + 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 = '\OpenAPI\Client\Model\Pet'; + $request = $this->fakeWith400And4xxRangeResponseEndpointRequest($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 '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 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, + $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 \OpenAPI\Client\Model\Pet|\OpenAPI\Client\Model\ErrorResponse + */ + public function fakeWith400ResponseEndpoint($pet, string $contentType = self::contentTypes['fakeWith400ResponseEndpoint'][0]) + { + 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 \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|\OpenAPI\Client\Model\ErrorResponse, 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(); + + + switch($statusCode) { + case 200: + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Pet', + $request, + $response, + ); + case 400: + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\ErrorResponse', + $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; + 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 \GuzzleHttp\Promise\PromiseInterface + */ + public function fakeWith400ResponseEndpointAsync($pet, string $contentType = self::contentTypes['fakeWith400ResponseEndpoint'][0]) { - return $this->fakeOuterNumberSerializeAsyncWithHttpInfo($body, $contentType) + return $this->fakeWith400ResponseEndpointAsyncWithHttpInfo($pet, $contentType) ->then( function ($response) { return $response[0]; @@ -2094,18 +3227,20 @@ function ($response) { } /** - * Operation fakeOuterNumberSerializeAsyncWithHttpInfo + * Operation fakeWith400ResponseEndpointAsyncWithHttpInfo * - * @param float|null $body Input number as post body (optional) - * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeOuterNumberSerialize'] 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 fakeOuterNumberSerializeAsyncWithHttpInfo($body = null, string $contentType = self::contentTypes['fakeOuterNumberSerialize'][0]) + public function fakeWith400ResponseEndpointAsyncWithHttpInfo($pet, string $contentType = self::contentTypes['fakeWith400ResponseEndpoint'][0]) { - $returnType = 'float'; - $request = $this->fakeOuterNumberSerializeRequest($body, $contentType); + $returnType = '\OpenAPI\Client\Model\Pet'; + $request = $this->fakeWith400ResponseEndpointRequest($pet, $contentType); return $this->client ->sendAsync($request, $this->createHttpClientOption()) @@ -2144,20 +3279,26 @@ function ($exception) { } /** - * Create request for operation 'fakeOuterNumberSerialize' + * Create request for operation 'fakeWith400ResponseEndpoint' * - * @param float|null $body Input number as post body (optional) - * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeOuterNumberSerialize'] 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 fakeOuterNumberSerializeRequest($body = null, string $contentType = self::contentTypes['fakeOuterNumberSerialize'][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/number'; + $resourcePath = '/fake/with_400_response/endpoint'; $formParams = []; $queryParams = []; $headerParams = []; @@ -2169,18 +3310,18 @@ public function fakeOuterNumberSerializeRequest($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) { @@ -2229,34 +3370,38 @@ public function fakeOuterNumberSerializeRequest($body = null, string $contentTyp } /** - * Operation fakeOuterStringSerialize + * Operation fakeWith4xxRangeResponseEndpoint * - * @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-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 string + * @return \OpenAPI\Client\Model\Pet|\OpenAPI\Client\Model\ErrorResponse */ - public function fakeOuterStringSerialize($body = null, string $contentType = self::contentTypes['fakeOuterStringSerialize'][0]) + public function fakeWith4xxRangeResponseEndpoint($pet, string $contentType = self::contentTypes['fakeWith4xxRangeResponseEndpoint'][0]) { - list($response) = $this->fakeOuterStringSerializeWithHttpInfo($body, $contentType); + list($response) = $this->fakeWith4xxRangeResponseEndpointWithHttpInfo($pet, $contentType); return $response; } /** - * Operation fakeOuterStringSerializeWithHttpInfo + * Operation fakeWith4xxRangeResponseEndpointWithHttpInfo * - * @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-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 string, 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 fakeOuterStringSerializeWithHttpInfo($body = null, string $contentType = self::contentTypes['fakeOuterStringSerialize'][0]) + public function fakeWith4xxRangeResponseEndpointWithHttpInfo($pet, string $contentType = self::contentTypes['fakeWith4xxRangeResponseEndpoint'][0]) { - $request = $this->fakeOuterStringSerializeRequest($body, $contentType); + $request = $this->fakeWith4xxRangeResponseEndpointRequest($pet, $contentType); try { $options = $this->createHttpClientOption(); @@ -2283,32 +3428,20 @@ 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 $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Pet', + $request, + $response, + ); + + } - return [ - ObjectSerializer::deserialize($content, 'string', []), - $response->getStatusCode(), - $response->getHeaders() - ]; + if ($this->responseWithinRangeCode('4xx', $statusCode)) { + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\ErrorResponse', + $request, + $response, + ); } if ($statusCode < 200 || $statusCode > 299) { @@ -2324,61 +3457,52 @@ 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 [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Pet', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: $data = ObjectSerializer::deserialize( $e->getResponseBody(), - 'string', + '\OpenAPI\Client\Model\Pet', $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + 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 fakeOuterStringSerializeAsync + * Operation fakeWith4xxRangeResponseEndpointAsync * - * @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-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 fakeOuterStringSerializeAsync($body = null, string $contentType = self::contentTypes['fakeOuterStringSerialize'][0]) + public function fakeWith4xxRangeResponseEndpointAsync($pet, string $contentType = self::contentTypes['fakeWith4xxRangeResponseEndpoint'][0]) { - return $this->fakeOuterStringSerializeAsyncWithHttpInfo($body, $contentType) + return $this->fakeWith4xxRangeResponseEndpointAsyncWithHttpInfo($pet, $contentType) ->then( function ($response) { return $response[0]; @@ -2387,18 +3511,20 @@ function ($response) { } /** - * Operation fakeOuterStringSerializeAsyncWithHttpInfo + * Operation fakeWith4xxRangeResponseEndpointAsyncWithHttpInfo * - * @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-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 fakeOuterStringSerializeAsyncWithHttpInfo($body = null, string $contentType = self::contentTypes['fakeOuterStringSerialize'][0]) + public function fakeWith4xxRangeResponseEndpointAsyncWithHttpInfo($pet, string $contentType = self::contentTypes['fakeWith4xxRangeResponseEndpoint'][0]) { - $returnType = 'string'; - $request = $this->fakeOuterStringSerializeRequest($body, $contentType); + $returnType = '\OpenAPI\Client\Model\Pet'; + $request = $this->fakeWith4xxRangeResponseEndpointRequest($pet, $contentType); return $this->client ->sendAsync($request, $this->createHttpClientOption()) @@ -2437,20 +3563,26 @@ function ($exception) { } /** - * Create request for operation 'fakeOuterStringSerialize' + * Create request for operation 'fakeWith4xxRangeResponseEndpoint' * - * @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['fakeWith4xxRangeResponseEndpoint'] 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 fakeWith4xxRangeResponseEndpointRequest($pet, string $contentType = self::contentTypes['fakeWith4xxRangeResponseEndpoint'][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 fakeWith4xxRangeResponseEndpoint' + ); + } - $resourcePath = '/fake/outer/string'; + $resourcePath = '/fake/with_4xx_range_response/endpoint'; $formParams = []; $queryParams = []; $headerParams = []; @@ -2462,18 +3594,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 +3654,38 @@ public function fakeOuterStringSerializeRequest($body = null, string $contentTyp } /** - * Operation fakePropertyEnumIntegerSerialize + * Operation fakeWith4xxRangeResponseNo4xxDatatypeEndpoint * - * @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 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\OuterObjectWithEnumProperty + * @return \OpenAPI\Client\Model\Pet */ - public function fakePropertyEnumIntegerSerialize($outer_object_with_enum_property, string $contentType = self::contentTypes['fakePropertyEnumIntegerSerialize'][0]) + public function fakeWith4xxRangeResponseNo4xxDatatypeEndpoint($pet, string $contentType = self::contentTypes['fakeWith4xxRangeResponseNo4xxDatatypeEndpoint'][0]) { - list($response) = $this->fakePropertyEnumIntegerSerializeWithHttpInfo($outer_object_with_enum_property, $contentType); + list($response) = $this->fakeWith4xxRangeResponseNo4xxDatatypeEndpointWithHttpInfo($pet, $contentType); return $response; } /** - * Operation fakePropertyEnumIntegerSerializeWithHttpInfo + * Operation fakeWith4xxRangeResponseNo4xxDatatypeEndpointWithHttpInfo * - * @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 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\OuterObjectWithEnumProperty, HTTP status code, HTTP response headers (array of strings) + * @return array of \OpenAPI\Client\Model\Pet, 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 fakeWith4xxRangeResponseNo4xxDatatypeEndpointWithHttpInfo($pet, string $contentType = self::contentTypes['fakeWith4xxRangeResponseNo4xxDatatypeEndpoint'][0]) { - $request = $this->fakePropertyEnumIntegerSerializeRequest($outer_object_with_enum_property, $contentType); + $request = $this->fakeWith4xxRangeResponseNo4xxDatatypeEndpointRequest($pet, $contentType); try { $options = $this->createHttpClientOption(); @@ -2576,34 +3712,15 @@ public function fakePropertyEnumIntegerSerializeWithHttpInfo($outer_object_with_ 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 $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Pet', + $request, + $response, + ); } + + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( sprintf( @@ -2617,61 +3734,42 @@ public function fakePropertyEnumIntegerSerializeWithHttpInfo($outer_object_with_ ); } - $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() - ]; - + 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\OuterObjectWithEnumProperty', + '\OpenAPI\Client\Model\Pet', $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } /** - * Operation fakePropertyEnumIntegerSerializeAsync + * Operation fakeWith4xxRangeResponseNo4xxDatatypeEndpointAsync * - * @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 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 fakePropertyEnumIntegerSerializeAsync($outer_object_with_enum_property, string $contentType = self::contentTypes['fakePropertyEnumIntegerSerialize'][0]) + public function fakeWith4xxRangeResponseNo4xxDatatypeEndpointAsync($pet, string $contentType = self::contentTypes['fakeWith4xxRangeResponseNo4xxDatatypeEndpoint'][0]) { - return $this->fakePropertyEnumIntegerSerializeAsyncWithHttpInfo($outer_object_with_enum_property, $contentType) + return $this->fakeWith4xxRangeResponseNo4xxDatatypeEndpointAsyncWithHttpInfo($pet, $contentType) ->then( function ($response) { return $response[0]; @@ -2680,18 +3778,20 @@ function ($response) { } /** - * Operation fakePropertyEnumIntegerSerializeAsyncWithHttpInfo + * Operation fakeWith4xxRangeResponseNo4xxDatatypeEndpointAsyncWithHttpInfo * - * @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 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 fakePropertyEnumIntegerSerializeAsyncWithHttpInfo($outer_object_with_enum_property, string $contentType = self::contentTypes['fakePropertyEnumIntegerSerialize'][0]) + public function fakeWith4xxRangeResponseNo4xxDatatypeEndpointAsyncWithHttpInfo($pet, string $contentType = self::contentTypes['fakeWith4xxRangeResponseNo4xxDatatypeEndpoint'][0]) { - $returnType = '\OpenAPI\Client\Model\OuterObjectWithEnumProperty'; - $request = $this->fakePropertyEnumIntegerSerializeRequest($outer_object_with_enum_property, $contentType); + $returnType = '\OpenAPI\Client\Model\Pet'; + $request = $this->fakeWith4xxRangeResponseNo4xxDatatypeEndpointRequest($pet, $contentType); return $this->client ->sendAsync($request, $this->createHttpClientOption()) @@ -2730,26 +3830,26 @@ function ($exception) { } /** - * Create request for operation 'fakePropertyEnumIntegerSerialize' + * Create request for operation 'fakeWith4xxRangeResponseNo4xxDatatypeEndpoint' * - * @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['fakeWith4xxRangeResponseNo4xxDatatypeEndpoint'] 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 fakeWith4xxRangeResponseNo4xxDatatypeEndpointRequest($pet, string $contentType = self::contentTypes['fakeWith4xxRangeResponseNo4xxDatatypeEndpoint'][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 fakeWith4xxRangeResponseNo4xxDatatypeEndpoint' ); } - $resourcePath = '/fake/property/enum-int'; + $resourcePath = '/fake/with_4xx_range_response_no_4xx_datatype/endpoint'; $formParams = []; $queryParams = []; $headerParams = []; @@ -2761,18 +3861,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 +3985,11 @@ public function getParameterNameMappingWithHttpInfo($underscore_type, $type, $ty return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + + throw $e; } } @@ -3164,10 +4265,11 @@ public function testAdditionalPropertiesReferenceWithHttpInfo($request_body, str return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + + throw $e; } } @@ -3376,10 +4478,11 @@ public function testBodyWithBinaryWithHttpInfo($body, string $contentType = self return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + + throw $e; } } @@ -3584,10 +4687,11 @@ public function testBodyWithFileSchemaWithHttpInfo($file_schema_test_class, stri return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + + throw $e; } } @@ -3794,10 +4898,11 @@ public function testBodyWithQueryParamsWithHttpInfo($query, $user, string $conte return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + + throw $e; } } @@ -4027,34 +5132,15 @@ 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', + $request, + $response, + ); } + + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( sprintf( @@ -4068,34 +5154,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -4105,8 +5168,10 @@ public function testClientModelWithHttpInfo($client, string $contentType = self: $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -4358,10 +5423,11 @@ public function testEndpointParametersWithHttpInfo($number, $double, $pattern_wi return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + + throw $e; } } @@ -4760,10 +5826,11 @@ public function testEnumParametersWithHttpInfo($enum_header_string_array = null, return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + + throw $e; } } @@ -5073,10 +6140,11 @@ public function testGroupParametersWithHttpInfo($associative_array) return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + + throw $e; } } @@ -5376,10 +6444,11 @@ public function testInlineAdditionalPropertiesWithHttpInfo($request_body, string return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + + throw $e; } } @@ -5592,10 +6661,11 @@ public function testInlineFreeformAdditionalPropertiesWithHttpInfo($test_inline_ return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + + throw $e; } } @@ -5810,10 +6880,11 @@ public function testJsonFormDataWithHttpInfo($param, $param2, string $contentTyp return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + + throw $e; } } @@ -6045,10 +7116,11 @@ public function testQueryParameterCollectionFormatWithHttpInfo($pipe, $ioutil, $ return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + + throw $e; } } @@ -6367,10 +7439,11 @@ public function testStringMapReferenceWithHttpInfo($request_body, string $conten return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + + throw $e; } } @@ -6544,4 +7617,47 @@ protected function createHttpClientOption() return $options; } + + private function handleResponseWithDataType( + string $dataType, + RequestInterface $request, + 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..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,8 @@ 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; use OpenAPI\Client\HeaderSelector; @@ -181,34 +183,15 @@ 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', + $request, + $response, + ); } + + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( sprintf( @@ -222,34 +205,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -259,8 +219,10 @@ public function testClassnameWithHttpInfo($client, string $contentType = self::c $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -452,4 +414,47 @@ protected function createHttpClientOption() return $options; } + + private function handleResponseWithDataType( + string $dataType, + RequestInterface $request, + 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..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,8 @@ 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; use OpenAPI\Client\HeaderSelector; @@ -244,10 +246,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 +575,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 +807,15 @@ 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[]', + $request, + $response, + ); } + + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( sprintf( @@ -844,34 +829,11 @@ 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[]', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -881,8 +843,10 @@ public function findPetsByStatusWithHttpInfo($status, string $contentType = self $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -1118,34 +1082,15 @@ 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[]', + $request, + $response, + ); } + + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( sprintf( @@ -1159,34 +1104,11 @@ 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[]', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -1196,8 +1118,10 @@ public function findPetsByTagsWithHttpInfo($tags, string $contentType = self::co $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -1434,34 +1358,15 @@ 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', + $request, + $response, + ); } + + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( sprintf( @@ -1475,34 +1380,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -1512,8 +1394,10 @@ public function getPetByIdWithHttpInfo($pet_id, string $contentType = self::cont $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -1781,10 +1665,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 +1996,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 +2240,15 @@ 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', + $request, + $response, + ); } + + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( sprintf( @@ -2395,34 +2262,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -2432,8 +2276,10 @@ public function uploadFileWithHttpInfo($pet_id, $additional_metadata = null, $fi $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -2695,34 +2541,15 @@ 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', + $request, + $response, + ); } + + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( sprintf( @@ -2736,34 +2563,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -2773,8 +2577,10 @@ public function uploadFileWithRequiredFileWithHttpInfo($pet_id, $required_file, $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -3054,34 +2860,15 @@ 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', + $request, + $response, + ); } + + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( sprintf( @@ -3095,34 +2882,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -3132,8 +2896,10 @@ public function uploadImageFullFormDataWithHttpInfo($pet_id, $name, $photo_urls, $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -3418,4 +3184,47 @@ protected function createHttpClientOption() return $options; } + + private function handleResponseWithDataType( + string $dataType, + RequestInterface $request, + 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..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,8 @@ 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; use OpenAPI\Client\HeaderSelector; @@ -188,10 +190,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 +408,15 @@ 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', + $request, + $response, + ); } + + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( sprintf( @@ -446,34 +430,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -483,8 +444,10 @@ public function getInventoryWithHttpInfo(string $contentType = self::contentType $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -700,34 +663,15 @@ 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', + $request, + $response, + ); } + + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( sprintf( @@ -741,34 +685,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -778,8 +699,10 @@ public function getOrderByIdWithHttpInfo($order_id, string $contentType = self:: $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -1014,34 +937,15 @@ 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', + $request, + $response, + ); } + + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( sprintf( @@ -1055,34 +959,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -1092,8 +973,10 @@ public function placeOrderWithHttpInfo($order, string $contentType = self::conte $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -1280,4 +1163,47 @@ protected function createHttpClientOption() return $options; } + + private function handleResponseWithDataType( + string $dataType, + RequestInterface $request, + 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..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,8 @@ 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; use OpenAPI\Client\HeaderSelector; @@ -200,10 +202,11 @@ public function createUserWithHttpInfo($user, string $contentType = self::conten return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + + throw $e; } } @@ -416,10 +419,11 @@ public function createUsersWithArrayInputWithHttpInfo($user, string $contentType return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + + throw $e; } } @@ -632,10 +636,11 @@ public function createUsersWithListInputWithHttpInfo($user, string $contentType return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + + throw $e; } } @@ -848,10 +853,11 @@ public function deleteUserWithHttpInfo($username, string $contentType = self::co return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + + throw $e; } } @@ -1067,34 +1073,15 @@ 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', + $request, + $response, + ); } + + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( sprintf( @@ -1108,34 +1095,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -1145,8 +1109,10 @@ public function getUserByNameWithHttpInfo($username, string $contentType = self: $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -1377,34 +1343,15 @@ 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', + $request, + $response, + ); } + + if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( sprintf( @@ -1418,34 +1365,11 @@ 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -1455,8 +1379,10 @@ public function loginUserWithHttpInfo($username, $password, string $contentType $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -1701,10 +1627,11 @@ public function logoutUserWithHttpInfo(string $contentType = self::contentTypes[ return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + + throw $e; } } @@ -1902,10 +1829,11 @@ public function updateUserWithHttpInfo($username, $user, string $contentType = s return [null, $statusCode, $response->getHeaders()]; - } catch (ApiException $e) { switch ($e->getCode()) { } + + throw $e; } } @@ -2097,4 +2025,47 @@ protected function createHttpClientOption() return $options; } + + private function handleResponseWithDataType( + string $dataType, + RequestInterface $request, + 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/ErrorResponse.php b/samples/client/petstore/php/OpenAPIClient-php/lib/Model/ErrorResponse.php new file mode 100644 index 000000000000..458660568ffd --- /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/ErrorResponseTest.php b/samples/client/petstore/php/OpenAPIClient-php/test/Model/ErrorResponseTest.php new file mode 100644 index 000000000000..b7d0409b3a0c --- /dev/null +++ b/samples/client/petstore/php/OpenAPIClient-php/test/Model/ErrorResponseTest.php @@ -0,0 +1,99 @@ +fakeHttpClient->setResponse(new Response($statusCode, [], $responseBody)); $this->api->getPetById(123); } + + public function testErrorRangeResponseWithDataType() + { + $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->fakeWith4xxRangeResponseEndpoint($pet); + + $this->assertInstanceOf(Model\ErrorResponse::class, $result); + $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; + $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->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()); + } + + 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/.openapi-generator/FILES b/samples/client/petstore/php/psr-18/.openapi-generator/FILES index 26dfe36c4c49..37dca3df0af8 100644 --- a/samples/client/petstore/php/psr-18/.openapi-generator/FILES +++ b/samples/client/petstore/php/psr-18/.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 @@ -90,6 +91,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 diff --git a/samples/client/petstore/php/psr-18/README.md b/samples/client/petstore/php/psr-18/README.md index 1c8d4f2541ce..c77a0d15c041 100644 --- a/samples/client/petstore/php/psr-18/README.md +++ b/samples/client/petstore/php/psr-18/README.md @@ -94,6 +94,11 @@ 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* | [**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 | @@ -152,6 +157,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/psr-18/docs/Api/FakeApi.md b/samples/client/petstore/php/psr-18/docs/Api/FakeApi.md index 5c75d390debe..7fff81c2a77d 100644 --- a/samples/client/petstore/php/psr-18/docs/Api/FakeApi.md +++ b/samples/client/petstore/php/psr-18/docs/Api/FakeApi.md @@ -13,6 +13,11 @@ Method | HTTP request | Description [**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 +[**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 | @@ -530,6 +535,276 @@ 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) + +## `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 +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) + +## `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/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..62a8fceab5f1 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,36 @@ 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', + $request, + $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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -267,8 +270,10 @@ public function call123TestSpecialTagsWithHttpInfo($client) $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -489,4 +494,47 @@ private function createUri( return $uri; } + + private function handleResponseWithDataType( + string $dataType, + RequestInterface $request, + 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..888725830578 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,36 @@ 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', + $request, + $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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { default: @@ -261,8 +264,10 @@ public function fooGetWithHttpInfo() $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -464,4 +469,47 @@ private function createUri( return $uri; } + + private function handleResponseWithDataType( + string $dataType, + RequestInterface $request, + 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..02e1f928ff10 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,36 @@ 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', + $request, + $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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -261,8 +264,10 @@ public function fakeBigDecimalMapWithHttpInfo() $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -461,34 +466,36 @@ 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', + $request, + $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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -498,8 +505,10 @@ public function fakeEnumEndpointWithHttpInfo($enum_class, $enum_class_array, $en $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -756,34 +765,36 @@ 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', + $request, + $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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -793,8 +804,10 @@ public function fakeHealthGetWithHttpInfo() $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -996,11 +1009,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 +1236,36 @@ 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', + $request, + $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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -1258,8 +1275,10 @@ public function fakeOuterBooleanSerializeWithHttpInfo($body = null) $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -1459,34 +1478,36 @@ 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', + $request, + $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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -1496,8 +1517,10 @@ public function fakeOuterCompositeSerializeWithHttpInfo($outer_composite = null) $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -1697,60 +1720,1359 @@ public function fakeOuterNumberSerializeWithHttpInfo($body = null) $statusCode = $response->getStatusCode(); + switch($statusCode) { case 200: - if ('float' === '\SplFileObject') { + return $this->handleResponseWithDataType( + 'float', + $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( + 'float', + $request, + $response, + ); + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + 'float', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + throw $e; + } + + + throw $e; + } + } + + /** + * Operation fakeOuterNumberSerializeAsync + * + * @param float $body Input number as post body (optional) + * + * @throws \InvalidArgumentException + * @return Promise + */ + public function fakeOuterNumberSerializeAsync($body = null) + { + return $this->fakeOuterNumberSerializeAsyncWithHttpInfo($body) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation fakeOuterNumberSerializeAsyncWithHttpInfo + * + * @param float $body Input number as post body (optional) + * + * @throws \InvalidArgumentException + * @return Promise + */ + public function fakeOuterNumberSerializeAsyncWithHttpInfo($body = null) + { + $returnType = 'float'; + $request = $this->fakeOuterNumberSerializeRequest($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, 'float', []), + 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 'fakeOuterNumberSerialize' + * + * @param float $body Input number as post body (optional) + * + * @throws \InvalidArgumentException + * @return RequestInterface + */ + public function fakeOuterNumberSerializeRequest($body = null) + { + + $resourcePath = '/fake/outer/number'; + $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); - $returnType = 'float'; - if ($returnType === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer } else { - $content = (string) $response->getBody(); + // for HTTP post (form) + $httpBody = ObjectSerializer::buildQuery($formParams); } + } - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; + $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', + $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( + 'string', + $request, + $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', + $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\OuterObjectWithEnumProperty', + $request, + $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 \OpenAPI\Client\Model\Pet|\OpenAPI\Client\Model\ErrorResponse|\OpenAPI\Client\Model\ErrorResponse + */ + public function fakeWith400And4xxRangeResponseEndpoint($pet) + { + list($response) = $this->fakeWith400And4xxRangeResponseEndpointWithHttpInfo($pet); + 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) + * + * @throws \OpenAPI\Client\ApiException on non-2xx response + * @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($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(); + + + switch($statusCode) { + case 200: + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Pet', + $request, + $response, + ); + case 400: + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\ErrorResponse', + $request, + $response, + ); + + } + + if ($this->responseWithinRangeCode('4xx', $statusCode)) { + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\ErrorResponse', + $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; + 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 = '\OpenAPI\Client\Model\Pet'; + $request = $this->fakeWith400And4xxRangeResponseEndpointRequest($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 '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($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', + $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 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) + * + * @throws \OpenAPI\Client\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return \OpenAPI\Client\Model\Pet|\OpenAPI\Client\Model\ErrorResponse + */ + public function fakeWith400ResponseEndpoint($pet) + { + list($response) = $this->fakeWith400ResponseEndpointWithHttpInfo($pet); + 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) + * + * @throws \OpenAPI\Client\ApiException on non-2xx response + * @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($pet) + { + $request = $this->fakeWith400ResponseEndpointRequest($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, + ); + case 400: + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\ErrorResponse', + $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(), - 'float', + '\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); - break; + throw $e; } + + throw $e; } } /** - * Operation fakeOuterNumberSerializeAsync + * Operation fakeWith400ResponseEndpointAsync * - * @param float $body Input number 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 fakeOuterNumberSerializeAsync($body = null) + public function fakeWith400ResponseEndpointAsync($pet) { - return $this->fakeOuterNumberSerializeAsyncWithHttpInfo($body) + return $this->fakeWith400ResponseEndpointAsyncWithHttpInfo($pet) ->then( function ($response) { return $response[0]; @@ -1759,17 +3081,19 @@ function ($response) { } /** - * Operation fakeOuterNumberSerializeAsyncWithHttpInfo + * Operation fakeWith400ResponseEndpointAsyncWithHttpInfo * - * @param float $body Input number 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 fakeOuterNumberSerializeAsyncWithHttpInfo($body = null) + public function fakeWith400ResponseEndpointAsyncWithHttpInfo($pet) { - $returnType = 'float'; - $request = $this->fakeOuterNumberSerializeRequest($body); + $returnType = '\OpenAPI\Client\Model\Pet'; + $request = $this->fakeWith400ResponseEndpointRequest($pet); return $this->httpAsyncClient->sendAsyncRequest($request) ->then( @@ -1804,17 +3128,23 @@ function (HttpException $exception) { } /** - * Create request for operation 'fakeOuterNumberSerialize' + * Create request for operation 'fakeWith400ResponseEndpoint' * - * @param float $body Input number 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 fakeOuterNumberSerializeRequest($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/number'; + $resourcePath = '/fake/with_400_response/endpoint'; $formParams = []; $queryParams = []; $headerParams = []; @@ -1826,17 +3156,17 @@ public function fakeOuterNumberSerializeRequest($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) { @@ -1882,32 +3212,36 @@ public function fakeOuterNumberSerializeRequest($body = null) } /** - * Operation fakeOuterStringSerialize + * Operation fakeWith4xxRangeResponseEndpoint * - * @param string $body Input string as post body (optional) + * 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 string + * @return \OpenAPI\Client\Model\Pet|\OpenAPI\Client\Model\ErrorResponse */ - public function fakeOuterStringSerialize($body = null) + public function fakeWith4xxRangeResponseEndpoint($pet) { - list($response) = $this->fakeOuterStringSerializeWithHttpInfo($body); + list($response) = $this->fakeWith4xxRangeResponseEndpointWithHttpInfo($pet); return $response; } /** - * Operation fakeOuterStringSerializeWithHttpInfo + * Operation fakeWith4xxRangeResponseEndpointWithHttpInfo * - * @param string $body Input string as post body (optional) + * 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 string, 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 fakeOuterStringSerializeWithHttpInfo($body = null) + public function fakeWith4xxRangeResponseEndpointWithHttpInfo($pet) { - $request = $this->fakeOuterStringSerializeRequest($body); + $request = $this->fakeWith4xxRangeResponseEndpointRequest($pet); try { try { @@ -1935,60 +3269,83 @@ 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() - ]; + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Pet', + $request, + $response, + ); + } - $returnType = 'string'; - if ($returnType === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); + if ($this->responseWithinRangeCode('4xx', $statusCode)) { + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\ErrorResponse', + $request, + $response, + ); } - 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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: $data = ObjectSerializer::deserialize( $e->getResponseBody(), - 'string', + '\OpenAPI\Client\Model\Pet', $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + 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 fakeOuterStringSerializeAsync + * Operation fakeWith4xxRangeResponseEndpointAsync * - * @param string $body Input string as post body (optional) + * 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 fakeOuterStringSerializeAsync($body = null) + public function fakeWith4xxRangeResponseEndpointAsync($pet) { - return $this->fakeOuterStringSerializeAsyncWithHttpInfo($body) + return $this->fakeWith4xxRangeResponseEndpointAsyncWithHttpInfo($pet) ->then( function ($response) { return $response[0]; @@ -1997,17 +3354,19 @@ function ($response) { } /** - * Operation fakeOuterStringSerializeAsyncWithHttpInfo + * Operation fakeWith4xxRangeResponseEndpointAsyncWithHttpInfo * - * @param string $body Input string as post body (optional) + * 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 fakeOuterStringSerializeAsyncWithHttpInfo($body = null) + public function fakeWith4xxRangeResponseEndpointAsyncWithHttpInfo($pet) { - $returnType = 'string'; - $request = $this->fakeOuterStringSerializeRequest($body); + $returnType = '\OpenAPI\Client\Model\Pet'; + $request = $this->fakeWith4xxRangeResponseEndpointRequest($pet); return $this->httpAsyncClient->sendAsyncRequest($request) ->then( @@ -2042,17 +3401,23 @@ function (HttpException $exception) { } /** - * Create request for operation 'fakeOuterStringSerialize' + * Create request for operation 'fakeWith4xxRangeResponseEndpoint' * - * @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 fakeWith4xxRangeResponseEndpointRequest($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 fakeWith4xxRangeResponseEndpoint' + ); + } - $resourcePath = '/fake/outer/string'; + $resourcePath = '/fake/with_4xx_range_response/endpoint'; $formParams = []; $queryParams = []; $headerParams = []; @@ -2064,17 +3429,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 +3485,36 @@ public function fakeOuterStringSerializeRequest($body = null) } /** - * Operation fakePropertyEnumIntegerSerialize + * Operation fakeWith4xxRangeResponseNo4xxDatatypeEndpoint * - * @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 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\OuterObjectWithEnumProperty + * @return \OpenAPI\Client\Model\Pet */ - public function fakePropertyEnumIntegerSerialize($outer_object_with_enum_property) + public function fakeWith4xxRangeResponseNo4xxDatatypeEndpoint($pet) { - list($response) = $this->fakePropertyEnumIntegerSerializeWithHttpInfo($outer_object_with_enum_property); + list($response) = $this->fakeWith4xxRangeResponseNo4xxDatatypeEndpointWithHttpInfo($pet); return $response; } /** - * Operation fakePropertyEnumIntegerSerializeWithHttpInfo + * Operation fakeWith4xxRangeResponseNo4xxDatatypeEndpointWithHttpInfo * - * @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 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\OuterObjectWithEnumProperty, HTTP status code, HTTP response headers (array of strings) + * @return array of \OpenAPI\Client\Model\Pet, HTTP status code, HTTP response headers (array of strings) */ - public function fakePropertyEnumIntegerSerializeWithHttpInfo($outer_object_with_enum_property) + public function fakeWith4xxRangeResponseNo4xxDatatypeEndpointWithHttpInfo($pet) { - $request = $this->fakePropertyEnumIntegerSerializeRequest($outer_object_with_enum_property); + $request = $this->fakeWith4xxRangeResponseNo4xxDatatypeEndpointRequest($pet); try { try { @@ -2173,60 +3542,66 @@ 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() - ]; + return $this->handleResponseWithDataType( + '\OpenAPI\Client\Model\Pet', + $request, + $response, + ); } - $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() - ]; + 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\OuterObjectWithEnumProperty', + '\OpenAPI\Client\Model\Pet', $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } /** - * Operation fakePropertyEnumIntegerSerializeAsync + * Operation fakeWith4xxRangeResponseNo4xxDatatypeEndpointAsync * - * @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 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 fakePropertyEnumIntegerSerializeAsync($outer_object_with_enum_property) + public function fakeWith4xxRangeResponseNo4xxDatatypeEndpointAsync($pet) { - return $this->fakePropertyEnumIntegerSerializeAsyncWithHttpInfo($outer_object_with_enum_property) + return $this->fakeWith4xxRangeResponseNo4xxDatatypeEndpointAsyncWithHttpInfo($pet) ->then( function ($response) { return $response[0]; @@ -2235,17 +3610,19 @@ function ($response) { } /** - * Operation fakePropertyEnumIntegerSerializeAsyncWithHttpInfo + * Operation fakeWith4xxRangeResponseNo4xxDatatypeEndpointAsyncWithHttpInfo * - * @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 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 fakePropertyEnumIntegerSerializeAsyncWithHttpInfo($outer_object_with_enum_property) + public function fakeWith4xxRangeResponseNo4xxDatatypeEndpointAsyncWithHttpInfo($pet) { - $returnType = '\OpenAPI\Client\Model\OuterObjectWithEnumProperty'; - $request = $this->fakePropertyEnumIntegerSerializeRequest($outer_object_with_enum_property); + $returnType = '\OpenAPI\Client\Model\Pet'; + $request = $this->fakeWith4xxRangeResponseNo4xxDatatypeEndpointRequest($pet); return $this->httpAsyncClient->sendAsyncRequest($request) ->then( @@ -2280,23 +3657,23 @@ function (HttpException $exception) { } /** - * Create request for operation 'fakePropertyEnumIntegerSerialize' + * Create request for operation 'fakeWith4xxRangeResponseNo4xxDatatypeEndpoint' * - * @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 fakeWith4xxRangeResponseNo4xxDatatypeEndpointRequest($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 fakeWith4xxRangeResponseNo4xxDatatypeEndpoint' ); } - $resourcePath = '/fake/property/enum-int'; + $resourcePath = '/fake/with_4xx_range_response_no_4xx_datatype/endpoint'; $formParams = []; $queryParams = []; $headerParams = []; @@ -2308,17 +3685,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 +3805,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 +4078,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 +4283,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 +4484,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 +4687,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 +4913,36 @@ 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', + $request, + $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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -3563,8 +4952,10 @@ public function testClientModelWithHttpInfo($client) $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -3803,11 +5194,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 +5585,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 +5894,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 +6194,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 +6403,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 +6614,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 +6842,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 +7150,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 +7367,47 @@ private function createUri( return $uri; } + + private function handleResponseWithDataType( + string $dataType, + RequestInterface $request, + 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..100429551e05 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,36 @@ 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', + $request, + $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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -267,8 +270,10 @@ public function testClassnameWithHttpInfo($client) $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -494,4 +499,47 @@ private function createUri( return $uri; } + + private function handleResponseWithDataType( + string $dataType, + RequestInterface $request, + 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..62abe18f2bd1 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,36 @@ 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[]', + $request, + $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[]', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -729,8 +736,10 @@ public function findPetsByStatusWithHttpInfo($status) $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -949,34 +958,36 @@ 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[]', + $request, + $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[]', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -986,8 +997,10 @@ public function findPetsByTagsWithHttpInfo($tags) $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -1207,34 +1220,36 @@ 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', + $request, + $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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -1244,8 +1259,10 @@ public function getPetByIdWithHttpInfo($pet_id) $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -1475,11 +1492,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 +1728,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 +1962,36 @@ 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', + $request, + $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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -1978,8 +2001,10 @@ public function uploadFileWithHttpInfo($pet_id, $additional_metadata = null, $fi $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -2225,34 +2250,36 @@ 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', + $request, + $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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -2262,8 +2289,10 @@ public function uploadFileWithRequiredFileWithHttpInfo($pet_id, $required_file, $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -2527,34 +2556,36 @@ 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', + $request, + $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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -2564,8 +2595,10 @@ public function uploadImageFullFormDataWithHttpInfo($pet_id, $name, $photo_urls, $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -2877,4 +2910,47 @@ private function createUri( return $uri; } + + private function handleResponseWithDataType( + string $dataType, + RequestInterface $request, + 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..387bd9864a30 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,36 @@ 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', + $request, + $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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -474,8 +479,10 @@ public function getInventoryWithHttpInfo() $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -679,34 +686,36 @@ 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', + $request, + $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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -716,8 +725,10 @@ public function getOrderByIdWithHttpInfo($order_id) $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -940,34 +951,36 @@ 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', + $request, + $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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -977,8 +990,10 @@ public function placeOrderWithHttpInfo($order) $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -1199,4 +1214,47 @@ private function createUri( return $uri; } + + private function handleResponseWithDataType( + string $dataType, + RequestInterface $request, + 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..e0c744726ed9 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,36 @@ 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', + $request, + $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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -1097,8 +1108,10 @@ public function getUserByNameWithHttpInfo($username) $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -1316,34 +1329,36 @@ 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', + $request, + $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', + $request, + $response, + ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -1353,8 +1368,10 @@ public function loginUserWithHttpInfo($username, $password) $e->getResponseHeaders() ); $e->setResponseObject($data); - break; + throw $e; } + + throw $e; } } @@ -1590,11 +1607,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 +1803,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 +2037,47 @@ private function createUri( return $uri; } + + private function handleResponseWithDataType( + string $dataType, + RequestInterface $request, + 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/ErrorResponse.php b/samples/client/petstore/php/psr-18/lib/Model/ErrorResponse.php new file mode 100644 index 000000000000..458660568ffd --- /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/ErrorResponseTest.php b/samples/client/petstore/php/psr-18/test/Model/ErrorResponseTest.php new file mode 100644 index 000000000000..b7d0409b3a0c --- /dev/null +++ b/samples/client/petstore/php/psr-18/test/Model/ErrorResponseTest.php @@ -0,0 +1,99 @@ +