Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,35 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<Mo
objs = super.postProcessOperationsWithModels(objs, allModels);
OperationMap operations = objs.getOperations();
for (CodegenOperation operation : operations.getOperation()) {
if (operation.returnType == null) {
// Once we upgrade to java 21 we can use SequencedSet instead
Comment thread
JulianVennen marked this conversation as resolved.
Outdated
List<String> phpReturnTypeOptions = new ArrayList<>();
List<String> docReturnTypeOptions = new ArrayList<>();

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";
}

if (!phpReturnTypeOptions.contains(returnType)) {
phpReturnTypeOptions.add(returnType);
}

if (!docReturnTypeOptions.contains(response.dataType)) {
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down