mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2026-03-24 03:19:07 +00:00
Fix logic of getNullableType of csharp server and client. (#3537)
* Fix default nullable * Fix tests * Update samples * Fix template default value * Update samples * Also fix for interface * update samples
This commit is contained in:
committed by
William Cheng
parent
2bbebf9752
commit
5ab1c9c75b
@@ -160,6 +160,7 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
|
||||
"Int64",
|
||||
"Float",
|
||||
"Guid?",
|
||||
"Guid",
|
||||
"System.IO.Stream", // not really a primitive, we include it to avoid model import
|
||||
"Object")
|
||||
);
|
||||
|
||||
@@ -22,6 +22,7 @@ import io.swagger.v3.oas.models.OpenAPI;
|
||||
import io.swagger.v3.oas.models.media.Schema;
|
||||
import io.swagger.v3.parser.util.SchemaTypeUtil;
|
||||
import org.openapitools.codegen.*;
|
||||
import org.openapitools.codegen.utils.ModelUtils;
|
||||
import org.openapitools.codegen.utils.URLPathUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -353,7 +354,7 @@ public class AspNetCoreServerCodegen extends AbstractCSharpCodegen {
|
||||
supportingFiles.add(new SupportingFile("Filters" + File.separator + "GeneratePathParamsValidationFilter.mustache",
|
||||
packageFolder + File.separator + "Filters", "GeneratePathParamsValidationFilter.cs"));
|
||||
}
|
||||
|
||||
|
||||
supportingFiles.add(new SupportingFile("Authentication" + File.separator + "ApiAuthentication.mustache",packageFolder + File.separator + "Authentication", "ApiAuthentication.cs"));
|
||||
}
|
||||
|
||||
@@ -407,12 +408,12 @@ public class AspNetCoreServerCodegen extends AbstractCSharpCodegen {
|
||||
|
||||
@Override
|
||||
public String getNullableType(Schema p, String type) {
|
||||
boolean isNullableExpected = p.getNullable() == null || (p.getNullable() != null && p.getNullable());
|
||||
|
||||
if (isNullableExpected && languageSpecificPrimitives.contains(type + "?")) {
|
||||
return type + "?";
|
||||
} else if (languageSpecificPrimitives.contains(type)) {
|
||||
return type;
|
||||
if (languageSpecificPrimitives.contains(type)) {
|
||||
if (isSupportNullable() && ModelUtils.isNullable(p) && nullableType.contains(type)) {
|
||||
return type + "?";
|
||||
} else {
|
||||
return type;
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -879,15 +879,15 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getNullableType(Schema p, String type) {
|
||||
boolean isNullableExpected = p.getNullable() == null || (p.getNullable() != null && p.getNullable());
|
||||
|
||||
if (isNullableExpected && languageSpecificPrimitives.contains(type + "?")) {
|
||||
return type + "?";
|
||||
} else if (languageSpecificPrimitives.contains(type)) {
|
||||
return type;
|
||||
if (languageSpecificPrimitives.contains(type)) {
|
||||
if (isSupportNullable() && ModelUtils.isNullable(p) && nullableType.contains(type)) {
|
||||
return type + "?";
|
||||
} else {
|
||||
return type;
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user