|
34 | 34 | import org.slf4j.LoggerFactory;
|
35 | 35 |
|
36 | 36 | import java.io.File;
|
37 |
| -import java.util.ArrayList; |
38 |
| -import java.util.Collections; |
39 |
| -import java.util.EnumSet; |
40 |
| -import java.util.List; |
41 |
| -import java.util.Map; |
| 37 | +import java.util.*; |
42 | 38 |
|
43 | 39 | public class PhpNextgenClientCodegen extends AbstractPhpCodegen {
|
44 | 40 | @SuppressWarnings("hiding")
|
@@ -189,14 +185,29 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<Mo
|
189 | 185 | objs = super.postProcessOperationsWithModels(objs, allModels);
|
190 | 186 | OperationMap operations = objs.getOperations();
|
191 | 187 | for (CodegenOperation operation : operations.getOperation()) {
|
192 |
| - if (operation.returnType == null) { |
| 188 | + Set<String> phpReturnTypeOptions = new LinkedHashSet<>(); |
| 189 | + Set<String> docReturnTypeOptions = new LinkedHashSet<>(); |
| 190 | + |
| 191 | + for (CodegenResponse response : operation.responses) { |
| 192 | + if (response.dataType != null) { |
| 193 | + String returnType = response.dataType; |
| 194 | + if (response.isArray || response.isMap) { |
| 195 | + // PHP does not understand array type hinting so we strip it |
| 196 | + // The phpdoc will still contain the array type hinting |
| 197 | + returnType = "array"; |
| 198 | + } |
| 199 | + |
| 200 | + phpReturnTypeOptions.add(returnType); |
| 201 | + docReturnTypeOptions.add(response.dataType); |
| 202 | + } |
| 203 | + } |
| 204 | + |
| 205 | + if (phpReturnTypeOptions.isEmpty()) { |
193 | 206 | operation.vendorExtensions.putIfAbsent("x-php-return-type", "void");
|
| 207 | + operation.vendorExtensions.putIfAbsent("x-php-doc-return-type", "void"); |
194 | 208 | } else {
|
195 |
| - if (operation.returnProperty.isContainer) { // array or map |
196 |
| - operation.vendorExtensions.putIfAbsent("x-php-return-type", "array"); |
197 |
| - } else { |
198 |
| - operation.vendorExtensions.putIfAbsent("x-php-return-type", operation.returnType); |
199 |
| - } |
| 209 | + operation.vendorExtensions.putIfAbsent("x-php-return-type", String.join("|", phpReturnTypeOptions)); |
| 210 | + operation.vendorExtensions.putIfAbsent("x-php-doc-return-type", String.join("|", docReturnTypeOptions)); |
200 | 211 | }
|
201 | 212 |
|
202 | 213 | for (CodegenParameter param : operation.allParams) {
|
|
0 commit comments