Skip to content

Commit d4d1420

Browse files
authored
fix(php-nextgen): always return if not void (#21119)
1 parent a66dd20 commit d4d1420

12 files changed

Lines changed: 1229 additions & 2 deletions

File tree

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpNextgenClientCodegen.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,11 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<Mo
204204
}
205205

206206
if (phpReturnTypeOptions.isEmpty()) {
207+
operation.vendorExtensions.putIfAbsent("x-php-return-type-is-void", true);
207208
operation.vendorExtensions.putIfAbsent("x-php-return-type", "void");
208209
operation.vendorExtensions.putIfAbsent("x-php-doc-return-type", "void");
209210
} else {
211+
operation.vendorExtensions.putIfAbsent("x-php-return-type-is-void", false);
210212
operation.vendorExtensions.putIfAbsent("x-php-return-type", String.join("|", phpReturnTypeOptions));
211213
operation.vendorExtensions.putIfAbsent("x-php-doc-return-type", String.join("|", docReturnTypeOptions));
212214
}

modules/openapi-generator/src/main/resources/php-nextgen/api.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,8 @@ use {{invokerPackage}}\ObjectSerializer;
190190
{{/vendorExtensions.x-group-parameters}}
191191
): {{{vendorExtensions.x-php-return-type}}}
192192
{
193-
{{#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}}
194-
return $response;{{/returnType}}
193+
{{^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}}
194+
return $response;{{/vendorExtensions.x-php-return-type-is-void}}
195195
}
196196

197197
/**

modules/openapi-generator/src/test/resources/3_0/php-nextgen/petstore-with-fake-endpoints-models-for-testing.yaml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,6 +1444,51 @@ paths:
14441444
description: Range of HTTP code 400-499
14451445
requestBody:
14461446
$ref: '#/components/requestBodies/Pet'
1447+
"/error":
1448+
get:
1449+
summary: Will always generate an error
1450+
operationId: error
1451+
responses: &commonErrors
1452+
"400":
1453+
description: The supplied request was not valid
1454+
content:
1455+
application/json:
1456+
schema:
1457+
$ref: "#/components/schemas/Error"
1458+
"404":
1459+
description: Requested item was not found
1460+
content:
1461+
application/json:
1462+
schema:
1463+
$ref: "#/components/schemas/Error"
1464+
"422":
1465+
description: The input to the operation was not valid
1466+
content:
1467+
application/json:
1468+
schema:
1469+
$ref: "#/components/schemas/Error"
1470+
"500":
1471+
description: Internal server error
1472+
content:
1473+
application/json:
1474+
schema:
1475+
$ref: "#/components/schemas/Error"
1476+
"/fake/pet/{pet_id}":
1477+
delete:
1478+
operationId: fakeDeletePet
1479+
tags:
1480+
- fake
1481+
parameters:
1482+
- name: pet_id
1483+
in: path
1484+
required: true
1485+
description: The id of the pet to retrieve
1486+
schema:
1487+
type: string
1488+
responses:
1489+
"204":
1490+
description: "Returns 204 No Content on success."
1491+
<<: *commonErrors
14471492
servers:
14481493
- url: 'http://{server}.swagger.io:{port}/v2'
14491494
description: petstore server
@@ -2230,3 +2275,18 @@ components:
22302275
type: integer
22312276
error:
22322277
type: string
2278+
2279+
Error:
2280+
title: Error
2281+
description: "Returned when the server encounters an error, either in client input or internally"
2282+
properties:
2283+
error:
2284+
type: string
2285+
description: "A human readable error message"
2286+
errors:
2287+
type: array
2288+
items:
2289+
type: string
2290+
description: "Optional array of multiple errors encountered during processing"
2291+
required:
2292+
- error

samples/client/petstore/php-nextgen/OpenAPIClient-php/.openapi-generator/FILES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ docs/Model/EnumArrays.md
3030
docs/Model/EnumClass.md
3131
docs/Model/EnumTest.md
3232
docs/Model/EnumWithNameAndDescription.md
33+
docs/Model/Error.md
3334
docs/Model/ErrorResponse.md
3435
docs/Model/FakeBigDecimalMap200Response.md
3536
docs/Model/File.md
@@ -95,6 +96,7 @@ src/Model/EnumArrays.php
9596
src/Model/EnumClass.php
9697
src/Model/EnumTest.php
9798
src/Model/EnumWithNameAndDescription.php
99+
src/Model/Error.php
98100
src/Model/ErrorResponse.php
99101
src/Model/FakeBigDecimalMap200Response.php
100102
src/Model/File.php

samples/client/petstore/php-nextgen/OpenAPIClient-php/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,10 @@ All URIs are relative to *http://petstore.swagger.io:80/v2*
7272
Class | Method | HTTP request | Description
7373
------------ | ------------- | ------------- | -------------
7474
*AnotherFakeApi* | [**call123TestSpecialTags**](docs/Api/AnotherFakeApi.md#call123testspecialtags) | **PATCH** /another-fake/dummy | To test special tags
75+
*DefaultApi* | [**error**](docs/Api/DefaultApi.md#error) | **GET** /error | Will always generate an error
7576
*DefaultApi* | [**fooGet**](docs/Api/DefaultApi.md#fooget) | **GET** /foo |
7677
*FakeApi* | [**fakeBigDecimalMap**](docs/Api/FakeApi.md#fakebigdecimalmap) | **GET** /fake/BigDecimalMap |
78+
*FakeApi* | [**fakeDeletePet**](docs/Api/FakeApi.md#fakedeletepet) | **DELETE** /fake/pet/{pet_id} |
7779
*FakeApi* | [**fakeEnumEndpoint**](docs/Api/FakeApi.md#fakeenumendpoint) | **GET** /fake/enum/endpoint | test endpoint with enum parameter
7880
*FakeApi* | [**fakeHealthGet**](docs/Api/FakeApi.md#fakehealthget) | **GET** /fake/health | Health check endpoint
7981
*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
145147
- [EnumClass](docs/Model/EnumClass.md)
146148
- [EnumTest](docs/Model/EnumTest.md)
147149
- [EnumWithNameAndDescription](docs/Model/EnumWithNameAndDescription.md)
150+
- [Error](docs/Model/Error.md)
148151
- [ErrorResponse](docs/Model/ErrorResponse.md)
149152
- [FakeBigDecimalMap200Response](docs/Model/FakeBigDecimalMap200Response.md)
150153
- [File](docs/Model/File.md)

samples/client/petstore/php-nextgen/OpenAPIClient-php/docs/Api/DefaultApi.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,60 @@ All URIs are relative to http://petstore.swagger.io:80/v2, except if the operati
44

55
| Method | HTTP request | Description |
66
| ------------- | ------------- | ------------- |
7+
| [**error()**](DefaultApi.md#error) | **GET** /error | Will always generate an error |
78
| [**fooGet()**](DefaultApi.md#fooGet) | **GET** /foo | |
89

910

11+
## `error()`
12+
13+
```php
14+
error()
15+
```
16+
17+
Will always generate an error
18+
19+
### Example
20+
21+
```php
22+
<?php
23+
require_once(__DIR__ . '/vendor/autoload.php');
24+
25+
26+
27+
$apiInstance = new OpenAPI\Client\Api\DefaultApi(
28+
// If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.
29+
// This is optional, `GuzzleHttp\Client` will be used as default.
30+
new GuzzleHttp\Client()
31+
);
32+
33+
try {
34+
$apiInstance->error();
35+
} catch (Exception $e) {
36+
echo 'Exception when calling DefaultApi->error: ', $e->getMessage(), PHP_EOL;
37+
}
38+
```
39+
40+
### Parameters
41+
42+
This endpoint does not need any parameter.
43+
44+
### Return type
45+
46+
void (empty response body)
47+
48+
### Authorization
49+
50+
No authorization required
51+
52+
### HTTP request headers
53+
54+
- **Content-Type**: Not defined
55+
- **Accept**: `application/json`
56+
57+
[[Back to top]](#) [[Back to API list]](../../README.md#endpoints)
58+
[[Back to Model list]](../../README.md#models)
59+
[[Back to README]](../../README.md)
60+
1061
## `fooGet()`
1162

1263
```php

samples/client/petstore/php-nextgen/OpenAPIClient-php/docs/Api/FakeApi.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ All URIs are relative to http://petstore.swagger.io:80/v2, except if the operati
55
| Method | HTTP request | Description |
66
| ------------- | ------------- | ------------- |
77
| [**fakeBigDecimalMap()**](FakeApi.md#fakeBigDecimalMap) | **GET** /fake/BigDecimalMap | |
8+
| [**fakeDeletePet()**](FakeApi.md#fakeDeletePet) | **DELETE** /fake/pet/{pet_id} | |
89
| [**fakeEnumEndpoint()**](FakeApi.md#fakeEnumEndpoint) | **GET** /fake/enum/endpoint | test endpoint with enum parameter |
910
| [**fakeHealthGet()**](FakeApi.md#fakeHealthGet) | **GET** /fake/health | Health check endpoint |
1011
| [**fakeHttpSignatureTest()**](FakeApi.md#fakeHttpSignatureTest) | **GET** /fake/http-signature-test | test http signature authentication |
@@ -87,6 +88,59 @@ No authorization required
8788
[[Back to Model list]](../../README.md#models)
8889
[[Back to README]](../../README.md)
8990

91+
## `fakeDeletePet()`
92+
93+
```php
94+
fakeDeletePet($pet_id)
95+
```
96+
97+
98+
99+
### Example
100+
101+
```php
102+
<?php
103+
require_once(__DIR__ . '/vendor/autoload.php');
104+
105+
106+
107+
$apiInstance = new OpenAPI\Client\Api\FakeApi(
108+
// If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.
109+
// This is optional, `GuzzleHttp\Client` will be used as default.
110+
new GuzzleHttp\Client()
111+
);
112+
$pet_id = 'pet_id_example'; // string | The id of the pet to retrieve
113+
114+
try {
115+
$apiInstance->fakeDeletePet($pet_id);
116+
} catch (Exception $e) {
117+
echo 'Exception when calling FakeApi->fakeDeletePet: ', $e->getMessage(), PHP_EOL;
118+
}
119+
```
120+
121+
### Parameters
122+
123+
| Name | Type | Description | Notes |
124+
| ------------- | ------------- | ------------- | ------------- |
125+
| **pet_id** | **string**| The id of the pet to retrieve | |
126+
127+
### Return type
128+
129+
void (empty response body)
130+
131+
### Authorization
132+
133+
No authorization required
134+
135+
### HTTP request headers
136+
137+
- **Content-Type**: Not defined
138+
- **Accept**: `application/json`
139+
140+
[[Back to top]](#) [[Back to API list]](../../README.md#endpoints)
141+
[[Back to Model list]](../../README.md#models)
142+
[[Back to README]](../../README.md)
143+
90144
## `fakeEnumEndpoint()`
91145

92146
```php
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# # Error
2+
3+
## Properties
4+
5+
Name | Type | Description | Notes
6+
------------ | ------------- | ------------- | -------------
7+
**error** | **string** | A human readable error message |
8+
**errors** | **string[]** | Optional array of multiple errors encountered during processing | [optional]
9+
10+
[[Back to Model list]](../../README.md#models) [[Back to API list]](../../README.md#endpoints) [[Back to README]](../../README.md)

0 commit comments

Comments
 (0)