diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpNextgenClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpNextgenClientCodegen.java index b2412714681..5f84bab486d 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpNextgenClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpNextgenClientCodegen.java @@ -204,9 +204,11 @@ public class PhpNextgenClientCodegen extends AbstractPhpCodegen { } if (phpReturnTypeOptions.isEmpty()) { + operation.vendorExtensions.putIfAbsent("x-php-return-type-is-void", true); operation.vendorExtensions.putIfAbsent("x-php-return-type", "void"); operation.vendorExtensions.putIfAbsent("x-php-doc-return-type", "void"); } else { + operation.vendorExtensions.putIfAbsent("x-php-return-type-is-void", false); operation.vendorExtensions.putIfAbsent("x-php-return-type", String.join("|", phpReturnTypeOptions)); operation.vendorExtensions.putIfAbsent("x-php-doc-return-type", String.join("|", docReturnTypeOptions)); } 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 066db4a9e59..368faec4270 100644 --- a/modules/openapi-generator/src/main/resources/php-nextgen/api.mustache +++ b/modules/openapi-generator/src/main/resources/php-nextgen/api.mustache @@ -190,8 +190,8 @@ use {{invokerPackage}}\ObjectSerializer; {{/vendorExtensions.x-group-parameters}} ): {{{vendorExtensions.x-php-return-type}}} { - {{#returnType}}list($response) = {{/returnType}}$this->{{operationId}}WithHttpInfo({{^vendorExtensions.x-group-parameters}}{{#allParams}}${{paramName}}, {{/allParams}}{{#servers}}{{#-first}}$hostIndex, $variables, {{/-first}}{{/servers}}$contentType{{/vendorExtensions.x-group-parameters}}{{#vendorExtensions.x-group-parameters}}$associative_array{{/vendorExtensions.x-group-parameters}});{{#returnType}} - return $response;{{/returnType}} + {{^vendorExtensions.x-php-return-type-is-void}}list($response) = {{/vendorExtensions.x-php-return-type-is-void}}$this->{{operationId}}WithHttpInfo({{^vendorExtensions.x-group-parameters}}{{#allParams}}${{paramName}}, {{/allParams}}{{#servers}}{{#-first}}$hostIndex, $variables, {{/-first}}{{/servers}}$contentType{{/vendorExtensions.x-group-parameters}}{{#vendorExtensions.x-group-parameters}}$associative_array{{/vendorExtensions.x-group-parameters}});{{^vendorExtensions.x-php-return-type-is-void}} + return $response;{{/vendorExtensions.x-php-return-type-is-void}} } /** 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 0b74a7aa046..5ab53cee08b 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 @@ -1444,6 +1444,51 @@ paths: description: Range of HTTP code 400-499 requestBody: $ref: '#/components/requestBodies/Pet' + "/error": + get: + summary: Will always generate an error + operationId: error + responses: &commonErrors + "400": + description: The supplied request was not valid + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "404": + description: Requested item was not found + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "422": + description: The input to the operation was not valid + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "500": + description: Internal server error + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "/fake/pet/{pet_id}": + delete: + operationId: fakeDeletePet + tags: + - fake + parameters: + - name: pet_id + in: path + required: true + description: The id of the pet to retrieve + schema: + type: string + responses: + "204": + description: "Returns 204 No Content on success." + <<: *commonErrors servers: - url: 'http://{server}.swagger.io:{port}/v2' description: petstore server @@ -2230,3 +2275,18 @@ components: type: integer error: type: string + + Error: + title: Error + description: "Returned when the server encounters an error, either in client input or internally" + properties: + error: + type: string + description: "A human readable error message" + errors: + type: array + items: + type: string + description: "Optional array of multiple errors encountered during processing" + required: + - error 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 235705a8ad2..66030f86f31 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/Error.md docs/Model/ErrorResponse.md docs/Model/FakeBigDecimalMap200Response.md docs/Model/File.md @@ -95,6 +96,7 @@ src/Model/EnumArrays.php src/Model/EnumClass.php src/Model/EnumTest.php src/Model/EnumWithNameAndDescription.php +src/Model/Error.php src/Model/ErrorResponse.php src/Model/FakeBigDecimalMap200Response.php src/Model/File.php diff --git a/samples/client/petstore/php-nextgen/OpenAPIClient-php/README.md b/samples/client/petstore/php-nextgen/OpenAPIClient-php/README.md index 103d2a59c10..05dd8d2e7e9 100644 --- a/samples/client/petstore/php-nextgen/OpenAPIClient-php/README.md +++ b/samples/client/petstore/php-nextgen/OpenAPIClient-php/README.md @@ -72,8 +72,10 @@ All URIs are relative to *http://petstore.swagger.io:80/v2* Class | Method | HTTP request | Description ------------ | ------------- | ------------- | ------------- *AnotherFakeApi* | [**call123TestSpecialTags**](docs/Api/AnotherFakeApi.md#call123testspecialtags) | **PATCH** /another-fake/dummy | To test special tags +*DefaultApi* | [**error**](docs/Api/DefaultApi.md#error) | **GET** /error | Will always generate an error *DefaultApi* | [**fooGet**](docs/Api/DefaultApi.md#fooget) | **GET** /foo | *FakeApi* | [**fakeBigDecimalMap**](docs/Api/FakeApi.md#fakebigdecimalmap) | **GET** /fake/BigDecimalMap | +*FakeApi* | [**fakeDeletePet**](docs/Api/FakeApi.md#fakedeletepet) | **DELETE** /fake/pet/{pet_id} | *FakeApi* | [**fakeEnumEndpoint**](docs/Api/FakeApi.md#fakeenumendpoint) | **GET** /fake/enum/endpoint | test endpoint with enum parameter *FakeApi* | [**fakeHealthGet**](docs/Api/FakeApi.md#fakehealthget) | **GET** /fake/health | Health check endpoint *FakeApi* | [**fakeHttpSignatureTest**](docs/Api/FakeApi.md#fakehttpsignaturetest) | **GET** /fake/http-signature-test | test http signature authentication @@ -145,6 +147,7 @@ Class | Method | HTTP request | Description - [EnumClass](docs/Model/EnumClass.md) - [EnumTest](docs/Model/EnumTest.md) - [EnumWithNameAndDescription](docs/Model/EnumWithNameAndDescription.md) +- [Error](docs/Model/Error.md) - [ErrorResponse](docs/Model/ErrorResponse.md) - [FakeBigDecimalMap200Response](docs/Model/FakeBigDecimalMap200Response.md) - [File](docs/Model/File.md) diff --git a/samples/client/petstore/php-nextgen/OpenAPIClient-php/docs/Api/DefaultApi.md b/samples/client/petstore/php-nextgen/OpenAPIClient-php/docs/Api/DefaultApi.md index d603956cfaf..4309c38f39c 100644 --- a/samples/client/petstore/php-nextgen/OpenAPIClient-php/docs/Api/DefaultApi.md +++ b/samples/client/petstore/php-nextgen/OpenAPIClient-php/docs/Api/DefaultApi.md @@ -4,9 +4,60 @@ All URIs are relative to http://petstore.swagger.io:80/v2, except if the operati | Method | HTTP request | Description | | ------------- | ------------- | ------------- | +| [**error()**](DefaultApi.md#error) | **GET** /error | Will always generate an error | | [**fooGet()**](DefaultApi.md#fooGet) | **GET** /foo | | +## `error()` + +```php +error() +``` + +Will always generate an error + +### Example + +```php +error(); +} catch (Exception $e) { + echo 'Exception when calling DefaultApi->error: ', $e->getMessage(), PHP_EOL; +} +``` + +### Parameters + +This endpoint does not need any parameter. + +### Return type + +void (empty response body) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: Not defined +- **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) + ## `fooGet()` ```php 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 74de3fcede1..9e3a212955f 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 @@ -5,6 +5,7 @@ All URIs are relative to http://petstore.swagger.io:80/v2, except if the operati | Method | HTTP request | Description | | ------------- | ------------- | ------------- | | [**fakeBigDecimalMap()**](FakeApi.md#fakeBigDecimalMap) | **GET** /fake/BigDecimalMap | | +| [**fakeDeletePet()**](FakeApi.md#fakeDeletePet) | **DELETE** /fake/pet/{pet_id} | | | [**fakeEnumEndpoint()**](FakeApi.md#fakeEnumEndpoint) | **GET** /fake/enum/endpoint | test endpoint with enum parameter | | [**fakeHealthGet()**](FakeApi.md#fakeHealthGet) | **GET** /fake/health | Health check endpoint | | [**fakeHttpSignatureTest()**](FakeApi.md#fakeHttpSignatureTest) | **GET** /fake/http-signature-test | test http signature authentication | @@ -87,6 +88,59 @@ No authorization required [[Back to Model list]](../../README.md#models) [[Back to README]](../../README.md) +## `fakeDeletePet()` + +```php +fakeDeletePet($pet_id) +``` + + + +### Example + +```php +fakeDeletePet($pet_id); +} catch (Exception $e) { + echo 'Exception when calling FakeApi->fakeDeletePet: ', $e->getMessage(), PHP_EOL; +} +``` + +### Parameters + +| Name | Type | Description | Notes | +| ------------- | ------------- | ------------- | ------------- | +| **pet_id** | **string**| The id of the pet to retrieve | | + +### Return type + +void (empty response body) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: Not defined +- **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) + ## `fakeEnumEndpoint()` ```php diff --git a/samples/client/petstore/php-nextgen/OpenAPIClient-php/docs/Model/Error.md b/samples/client/petstore/php-nextgen/OpenAPIClient-php/docs/Model/Error.md new file mode 100644 index 00000000000..9e3479db475 --- /dev/null +++ b/samples/client/petstore/php-nextgen/OpenAPIClient-php/docs/Model/Error.md @@ -0,0 +1,10 @@ +# # Error + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**error** | **string** | A human readable error message | +**errors** | **string[]** | Optional array of multiple errors encountered during processing | [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/DefaultApi.php b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/DefaultApi.php index 3d148ab72e8..439e8883eaf 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 @@ -74,6 +74,9 @@ class DefaultApi /** @var string[] $contentTypes **/ public const contentTypes = [ + 'error' => [ + 'application/json', + ], 'fooGet' => [ 'application/json', ], @@ -125,6 +128,246 @@ class DefaultApi return $this->config; } + /** + * Operation error + * + * Will always generate an error + * + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['error'] 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\Error + */ + public function error( + string $contentType = self::contentTypes['error'][0] + ): \OpenAPI\Client\Model\Error + { + list($response) = $this->errorWithHttpInfo($contentType); + return $response; + } + + /** + * Operation errorWithHttpInfo + * + * Will always generate an error + * + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['error'] 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 null, HTTP status code, HTTP response headers (array of strings) + */ + public function errorWithHttpInfo( + string $contentType = self::contentTypes['error'][0] + ): array + { + $request = $this->errorRequest($contentType); + + try { + $options = $this->createHttpClientOption(); + try { + $response = $this->client->send($request, $options); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null, + $e->getResponse() ? (string) $e->getResponse()->getBody() : null + ); + } catch (ConnectException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + null, + null + ); + } + + $statusCode = $response->getStatusCode(); + + + return [null, $statusCode, $response->getHeaders()]; + } catch (ApiException $e) { + switch ($e->getCode()) { + case 400: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\OpenAPI\Client\Model\Error', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + throw $e; + case 404: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\OpenAPI\Client\Model\Error', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + throw $e; + case 422: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\OpenAPI\Client\Model\Error', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + throw $e; + case 500: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\OpenAPI\Client\Model\Error', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + throw $e; + } + + throw $e; + } + } + + /** + * Operation errorAsync + * + * Will always generate an error + * + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['error'] to see the possible values for this operation + * + * @throws InvalidArgumentException + * @return PromiseInterface + */ + public function errorAsync( + string $contentType = self::contentTypes['error'][0] + ): PromiseInterface + { + return $this->errorAsyncWithHttpInfo($contentType) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation errorAsyncWithHttpInfo + * + * Will always generate an error + * + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['error'] to see the possible values for this operation + * + * @throws InvalidArgumentException + * @return PromiseInterface + */ + public function errorAsyncWithHttpInfo( + string $contentType = self::contentTypes['error'][0] + ): PromiseInterface + { + $returnType = ''; + $request = $this->errorRequest($contentType); + + return $this->client + ->sendAsync($request, $this->createHttpClientOption()) + ->then( + function ($response) use ($returnType) { + return [null, $response->getStatusCode(), $response->getHeaders()]; + }, + function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $exception->getRequest()->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + ); + } + + /** + * Create request for operation 'error' + * + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['error'] to see the possible values for this operation + * + * @throws InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + public function errorRequest( + string $contentType = self::contentTypes['error'][0] + ): Request + { + + + $resourcePath = '/error'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + + + + + $headers = $this->headerSelector->selectHeaders( + ['application/json', ], + $contentType, + $multipart + ); + + // for model (json/xml) + if (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( + 'GET', + $operationHost . $resourcePath . ($query ? "?{$query}" : ''), + $headers, + $httpBody + ); + } + /** * Operation fooGet * 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 b1c87f2bfab..5f0123a5e18 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 @@ -77,6 +77,9 @@ class FakeApi 'fakeBigDecimalMap' => [ 'application/json', ], + 'fakeDeletePet' => [ + 'application/json', + ], 'fakeEnumEndpoint' => [ 'application/json', ], @@ -459,6 +462,263 @@ class FakeApi ); } + /** + * Operation fakeDeletePet + * + * @param string $pet_id The id of the pet to retrieve (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeDeletePet'] 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\Error + */ + public function fakeDeletePet( + string $pet_id, + string $contentType = self::contentTypes['fakeDeletePet'][0] + ): \OpenAPI\Client\Model\Error + { + list($response) = $this->fakeDeletePetWithHttpInfo($pet_id, $contentType); + return $response; + } + + /** + * Operation fakeDeletePetWithHttpInfo + * + * @param string $pet_id The id of the pet to retrieve (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeDeletePet'] 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 null, HTTP status code, HTTP response headers (array of strings) + */ + public function fakeDeletePetWithHttpInfo( + string $pet_id, + string $contentType = self::contentTypes['fakeDeletePet'][0] + ): array + { + $request = $this->fakeDeletePetRequest($pet_id, $contentType); + + try { + $options = $this->createHttpClientOption(); + try { + $response = $this->client->send($request, $options); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null, + $e->getResponse() ? (string) $e->getResponse()->getBody() : null + ); + } catch (ConnectException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + null, + null + ); + } + + $statusCode = $response->getStatusCode(); + + + return [null, $statusCode, $response->getHeaders()]; + } catch (ApiException $e) { + switch ($e->getCode()) { + case 400: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\OpenAPI\Client\Model\Error', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + throw $e; + case 404: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\OpenAPI\Client\Model\Error', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + throw $e; + case 422: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\OpenAPI\Client\Model\Error', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + throw $e; + case 500: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\OpenAPI\Client\Model\Error', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + throw $e; + } + + throw $e; + } + } + + /** + * Operation fakeDeletePetAsync + * + * @param string $pet_id The id of the pet to retrieve (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeDeletePet'] to see the possible values for this operation + * + * @throws InvalidArgumentException + * @return PromiseInterface + */ + public function fakeDeletePetAsync( + string $pet_id, + string $contentType = self::contentTypes['fakeDeletePet'][0] + ): PromiseInterface + { + return $this->fakeDeletePetAsyncWithHttpInfo($pet_id, $contentType) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation fakeDeletePetAsyncWithHttpInfo + * + * @param string $pet_id The id of the pet to retrieve (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeDeletePet'] to see the possible values for this operation + * + * @throws InvalidArgumentException + * @return PromiseInterface + */ + public function fakeDeletePetAsyncWithHttpInfo( + string $pet_id, + string $contentType = self::contentTypes['fakeDeletePet'][0] + ): PromiseInterface + { + $returnType = ''; + $request = $this->fakeDeletePetRequest($pet_id, $contentType); + + return $this->client + ->sendAsync($request, $this->createHttpClientOption()) + ->then( + function ($response) use ($returnType) { + return [null, $response->getStatusCode(), $response->getHeaders()]; + }, + function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $exception->getRequest()->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + ); + } + + /** + * Create request for operation 'fakeDeletePet' + * + * @param string $pet_id The id of the pet to retrieve (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeDeletePet'] to see the possible values for this operation + * + * @throws InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + public function fakeDeletePetRequest( + string $pet_id, + string $contentType = self::contentTypes['fakeDeletePet'][0] + ): Request + { + + // verify the required parameter 'pet_id' is set + if ($pet_id === null || (is_array($pet_id) && count($pet_id) === 0)) { + throw new InvalidArgumentException( + 'Missing the required parameter $pet_id when calling fakeDeletePet' + ); + } + + + $resourcePath = '/fake/pet/{pet_id}'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + + + // path params + if ($pet_id !== null) { + $resourcePath = str_replace( + '{' . 'pet_id' . '}', + ObjectSerializer::toPathValue($pet_id), + $resourcePath + ); + } + + + $headers = $this->headerSelector->selectHeaders( + ['application/json', ], + $contentType, + $multipart + ); + + // for model (json/xml) + if (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( + 'DELETE', + $operationHost . $resourcePath . ($query ? "?{$query}" : ''), + $headers, + $httpBody + ); + } + /** * Operation fakeEnumEndpoint * diff --git a/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Model/Error.php b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Model/Error.php new file mode 100644 index 00000000000..a20fb624928 --- /dev/null +++ b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Model/Error.php @@ -0,0 +1,445 @@ + + */ +class Error implements ModelInterface, ArrayAccess, JsonSerializable +{ + public const DISCRIMINATOR = null; + + /** + * The original name of the model. + * + * @var string + */ + protected static string $openAPIModelName = 'Error'; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @var array + */ + protected static array $openAPITypes = [ + 'error' => 'string', + 'errors' => 'string[]' + ]; + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @var array + */ + protected static array $openAPIFormats = [ + 'error' => null, + 'errors' => null + ]; + + /** + * Array of nullable properties. Used for (de)serialization + * + * @var array + */ + protected static array $openAPINullables = [ + 'error' => false, + 'errors' => 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 = [ + 'error' => 'error', + 'errors' => 'errors' + ]; + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @var array + */ + protected static array $setters = [ + 'error' => 'setError', + 'errors' => 'setErrors' + ]; + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @var array + */ + protected static array $getters = [ + 'error' => 'getError', + 'errors' => 'getErrors' + ]; + + /** + * 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('error', $data ?? [], null); + $this->setIfExists('errors', $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 = []; + + if ($this->container['error'] === null) { + $invalidProperties[] = "'error' can't be null"; + } + 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 error + * + * @return string + */ + public function getError(): string + { + return $this->container['error']; + } + + /** + * Sets error + * + * @param string $error A human readable error message + * + * @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; + } + + /** + * Gets errors + * + * @return string[]|null + */ + public function getErrors(): ?array + { + return $this->container['errors']; + } + + /** + * Sets errors + * + * @param string[]|null $errors Optional array of multiple errors encountered during processing + * + * @return $this + */ + public function setErrors(?array $errors): static + { + if (is_null($errors)) { + throw new InvalidArgumentException('non-nullable errors cannot be null'); + } + $this->container['errors'] = $errors; + + 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/ErrorTest.php b/samples/client/petstore/php-nextgen/OpenAPIClient-php/tests/Model/ErrorTest.php new file mode 100644 index 00000000000..c1b8c85311c --- /dev/null +++ b/samples/client/petstore/php-nextgen/OpenAPIClient-php/tests/Model/ErrorTest.php @@ -0,0 +1,97 @@ +