forked from loafle/openapi-generator-original
* [PHP][php-nextgen] List all possible return types (fix #17113) * Switch to LinkedHashSet
This commit is contained in:
parent
6180fea305
commit
806b99e43a
@ -34,11 +34,7 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.EnumSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class PhpNextgenClientCodegen extends AbstractPhpCodegen {
|
public class PhpNextgenClientCodegen extends AbstractPhpCodegen {
|
||||||
@SuppressWarnings("hiding")
|
@SuppressWarnings("hiding")
|
||||||
@ -189,16 +185,31 @@ public class PhpNextgenClientCodegen extends AbstractPhpCodegen {
|
|||||||
objs = super.postProcessOperationsWithModels(objs, allModels);
|
objs = super.postProcessOperationsWithModels(objs, allModels);
|
||||||
OperationMap operations = objs.getOperations();
|
OperationMap operations = objs.getOperations();
|
||||||
for (CodegenOperation operation : operations.getOperation()) {
|
for (CodegenOperation operation : operations.getOperation()) {
|
||||||
if (operation.returnType == null) {
|
Set<String> phpReturnTypeOptions = new LinkedHashSet<>();
|
||||||
operation.vendorExtensions.putIfAbsent("x-php-return-type", "void");
|
Set<String> docReturnTypeOptions = new LinkedHashSet<>();
|
||||||
} else {
|
|
||||||
if (operation.returnProperty.isContainer) { // array or map
|
for (CodegenResponse response : operation.responses) {
|
||||||
operation.vendorExtensions.putIfAbsent("x-php-return-type", "array");
|
if (response.dataType != null) {
|
||||||
} else {
|
String returnType = response.dataType;
|
||||||
operation.vendorExtensions.putIfAbsent("x-php-return-type", operation.returnType);
|
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 {
|
||||||
|
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) {
|
for (CodegenParameter param : operation.allParams) {
|
||||||
if (param.isArray || param.isMap) {
|
if (param.isArray || param.isMap) {
|
||||||
param.vendorExtensions.putIfAbsent("x-php-param-type", "array");
|
param.vendorExtensions.putIfAbsent("x-php-param-type", "array");
|
||||||
|
@ -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 ApiException on non-2xx response or if the response body is not in the expected format
|
||||||
* @throws InvalidArgumentException
|
* @throws InvalidArgumentException
|
||||||
* @return {{#returnType}}{{#responses}}{{#dataType}}{{^-first}}|{{/-first}}{{/dataType}}{{{dataType}}}{{/responses}}{{/returnType}}{{^returnType}}void{{/returnType}}
|
* @return {{{vendorExtensions.x-php-doc-return-type}}}
|
||||||
{{#isDeprecated}}
|
{{#isDeprecated}}
|
||||||
* @deprecated
|
* @deprecated
|
||||||
{{/isDeprecated}}
|
{{/isDeprecated}}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user