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 6f79932b56fe..55c3cb95d106 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 @@ -34,11 +34,7 @@ import org.slf4j.LoggerFactory; import java.io.File; -import java.util.ArrayList; -import java.util.Collections; -import java.util.EnumSet; -import java.util.List; -import java.util.Map; +import java.util.*; public class PhpNextgenClientCodegen extends AbstractPhpCodegen { @SuppressWarnings("hiding") @@ -189,14 +185,29 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List phpReturnTypeOptions = new LinkedHashSet<>(); + Set docReturnTypeOptions = new LinkedHashSet<>(); + + for (CodegenResponse response : operation.responses) { + if (response.dataType != null) { + String returnType = response.dataType; + if (response.isArray || response.isMap) { + // PHP does not understand array type hinting so we strip it + // The phpdoc will still contain the array type hinting + returnType = "array"; + } + + phpReturnTypeOptions.add(returnType); + docReturnTypeOptions.add(response.dataType); + } + } + + if (phpReturnTypeOptions.isEmpty()) { operation.vendorExtensions.putIfAbsent("x-php-return-type", "void"); + operation.vendorExtensions.putIfAbsent("x-php-doc-return-type", "void"); } else { - if (operation.returnProperty.isContainer) { // array or map - operation.vendorExtensions.putIfAbsent("x-php-return-type", "array"); - } else { - operation.vendorExtensions.putIfAbsent("x-php-return-type", operation.returnType); - } + operation.vendorExtensions.putIfAbsent("x-php-return-type", String.join("|", phpReturnTypeOptions)); + operation.vendorExtensions.putIfAbsent("x-php-doc-return-type", String.join("|", docReturnTypeOptions)); } for (CodegenParameter param : operation.allParams) { 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 006cbbc7523e..8b01cbe0f79b 100644 --- a/modules/openapi-generator/src/main/resources/php-nextgen/api.mustache +++ b/modules/openapi-generator/src/main/resources/php-nextgen/api.mustache @@ -164,7 +164,7 @@ use {{invokerPackage}}\ObjectSerializer; * * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException - * @return {{#returnType}}{{#responses}}{{#dataType}}{{^-first}}|{{/-first}}{{/dataType}}{{{dataType}}}{{/responses}}{{/returnType}}{{^returnType}}void{{/returnType}} + * @return {{{vendorExtensions.x-php-doc-return-type}}} {{#isDeprecated}} * @deprecated {{/isDeprecated}}