forked from loafle/openapi-generator-original
Fix bugs (string comparison) in csharp generators (#15663)
* fix bugs in csharp generators * undo change
This commit is contained in:
parent
784c700d37
commit
431cc2ec8e
@ -472,7 +472,7 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
|
||||
if (Boolean.TRUE.equals(this.zeroBasedEnums)) {
|
||||
property.vendorExtensions.put(this.zeroBasedEnumVendorExtension, true);
|
||||
} else if (!Boolean.FALSE.equals(this.zeroBasedEnums)) {
|
||||
if (property.allowableValues.containsKey("values")){
|
||||
if (property.allowableValues.containsKey("values")) {
|
||||
final List<Object> allowableValues = (List<Object>) property.allowableValues.get("values");
|
||||
boolean isZeroBased = String.valueOf(allowableValues.get(0)).toLowerCase(Locale.ROOT).equals("unknown");
|
||||
property.vendorExtensions.put(this.zeroBasedEnumVendorExtension, isZeroBased);
|
||||
@ -497,7 +497,7 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
|
||||
if (Boolean.TRUE.equals(this.zeroBasedEnums)) {
|
||||
cm.vendorExtensions.put(this.zeroBasedEnumVendorExtension, true);
|
||||
} else if (!Boolean.FALSE.equals(this.zeroBasedEnums)) {
|
||||
if (cm.allowableValues.containsKey("values")){
|
||||
if (cm.allowableValues.containsKey("values")) {
|
||||
final List<Object> allowableValues = (List<Object>) cm.allowableValues.get("values");
|
||||
boolean isZeroBased = String.valueOf(allowableValues.get(0)).toLowerCase(Locale.ROOT).equals("unknown");
|
||||
cm.vendorExtensions.put(this.zeroBasedEnumVendorExtension, isZeroBased);
|
||||
|
@ -1399,35 +1399,35 @@ public class CSharpNetCoreClientCodegen extends AbstractCSharpCodegen {
|
||||
properties.put(frameworkStrategy.name, strategies.stream().anyMatch(s -> s.name.equals(frameworkStrategy.name)));
|
||||
}
|
||||
|
||||
if (strategies.stream().anyMatch(p -> Boolean.FALSE.equals(p.name == "netstandard1.3"))) {
|
||||
if (strategies.stream().anyMatch(p -> Boolean.TRUE.equals(p.name == "netstandard1.4"))) {
|
||||
if (strategies.stream().anyMatch(p -> !"netstandard1.3".equals(p.name))) {
|
||||
if (strategies.stream().anyMatch(p -> "netstandard1.4".equals(p.name))) {
|
||||
properties.put(NET_STANDARD_14_OR_LATER, true);
|
||||
} else if (strategies.stream().anyMatch(p -> Boolean.TRUE.equals(p.name == "netstandard1.5"))) {
|
||||
} else if (strategies.stream().anyMatch(p -> "netstandard1.5".equals(p.name))) {
|
||||
properties.put(NET_STANDARD_14_OR_LATER, true);
|
||||
properties.put(NET_STANDARD_15_OR_LATER, true);
|
||||
} else if (strategies.stream().anyMatch(p -> Boolean.TRUE.equals(p.name == "netstandard1.6"))) {
|
||||
} else if (strategies.stream().anyMatch(p -> "netstandard1.6".equals(p.name))) {
|
||||
properties.put(NET_STANDARD_14_OR_LATER, true);
|
||||
properties.put(NET_STANDARD_15_OR_LATER, true);
|
||||
properties.put(NET_STANDARD_16_OR_LATER, true);
|
||||
} else if (strategies.stream().anyMatch(p -> Boolean.TRUE.equals(p.name == "netstandard2.0"))) {
|
||||
} else if (strategies.stream().anyMatch(p -> "netstandard2.0".equals(p.name))) {
|
||||
properties.put(NET_STANDARD_14_OR_LATER, true);
|
||||
properties.put(NET_STANDARD_15_OR_LATER, true);
|
||||
properties.put(NET_STANDARD_16_OR_LATER, true);
|
||||
properties.put(NET_STANDARD_20_OR_LATER, true);
|
||||
} else if (strategies.stream().anyMatch(p -> Boolean.TRUE.equals(p.name == "netstandard2.1"))) {
|
||||
} else if (strategies.stream().anyMatch(p -> "netstandard2.1".equals(p.name))) {
|
||||
properties.put(NET_STANDARD_14_OR_LATER, true);
|
||||
properties.put(NET_STANDARD_15_OR_LATER, true);
|
||||
properties.put(NET_STANDARD_16_OR_LATER, true);
|
||||
properties.put(NET_STANDARD_20_OR_LATER, true);
|
||||
properties.put(NET_STANDARD_21_OR_LATER, true);
|
||||
} else if (strategies.stream().anyMatch(p -> Boolean.TRUE.equals(p.name == "net47"))) {
|
||||
} else if (strategies.stream().anyMatch(p -> "net47".equals(p.name))) {
|
||||
properties.put(NET_STANDARD_14_OR_LATER, true);
|
||||
properties.put(NET_STANDARD_15_OR_LATER, true);
|
||||
properties.put(NET_STANDARD_16_OR_LATER, true);
|
||||
properties.put(NET_STANDARD_20_OR_LATER, true);
|
||||
properties.put(NET_STANDARD_21_OR_LATER, true);
|
||||
properties.put(NET_47_OR_LATER, true);
|
||||
} else if (strategies.stream().anyMatch(p -> Boolean.TRUE.equals(p.name == "net48"))) {
|
||||
} else if (strategies.stream().anyMatch(p -> "net48".equals(p.name))) {
|
||||
properties.put(NET_STANDARD_14_OR_LATER, true);
|
||||
properties.put(NET_STANDARD_15_OR_LATER, true);
|
||||
properties.put(NET_STANDARD_16_OR_LATER, true);
|
||||
@ -1435,7 +1435,7 @@ public class CSharpNetCoreClientCodegen extends AbstractCSharpCodegen {
|
||||
properties.put(NET_STANDARD_21_OR_LATER, true);
|
||||
properties.put(NET_47_OR_LATER, true);
|
||||
properties.put(NET_48_OR_LATER, true);
|
||||
} else if (strategies.stream().anyMatch(p -> Boolean.TRUE.equals(p.name == "net6.0"))) {
|
||||
} else if (strategies.stream().anyMatch(p -> "net6.0".equals(p.name))) {
|
||||
properties.put(NET_STANDARD_14_OR_LATER, true);
|
||||
properties.put(NET_STANDARD_15_OR_LATER, true);
|
||||
properties.put(NET_STANDARD_16_OR_LATER, true);
|
||||
@ -1444,7 +1444,7 @@ public class CSharpNetCoreClientCodegen extends AbstractCSharpCodegen {
|
||||
properties.put(NET_47_OR_LATER, true);
|
||||
properties.put(NET_48_OR_LATER, true);
|
||||
properties.put(NET_60_OR_LATER, true);
|
||||
} else if (strategies.stream().anyMatch(p -> Boolean.TRUE.equals(p.name == "net7.0"))){
|
||||
} else if (strategies.stream().anyMatch(p -> "net7.0".equals(p.name))) {
|
||||
properties.put(NET_STANDARD_14_OR_LATER, true);
|
||||
properties.put(NET_STANDARD_15_OR_LATER, true);
|
||||
properties.put(NET_STANDARD_16_OR_LATER, true);
|
||||
@ -1529,7 +1529,7 @@ public class CSharpNetCoreClientCodegen extends AbstractCSharpCodegen {
|
||||
// some properties do not have isInherited set correctly
|
||||
// see modules\openapi-generator\src\test\resources\3_0\allOf.yaml
|
||||
// Child properties Type, LastName, FirstName will have isInherited set to false when it should be true
|
||||
if (cp.isInherited){
|
||||
if (cp.isInherited) {
|
||||
continue;
|
||||
}
|
||||
if (Boolean.TRUE.equals(cm.parentVars.stream().anyMatch(v -> v.baseName.equals(cp.baseName) && v.dataType.equals(cp.dataType)))) {
|
||||
@ -1551,15 +1551,15 @@ public class CSharpNetCoreClientCodegen extends AbstractCSharpCodegen {
|
||||
private void ensureInheritedPropertiesArePresent(CodegenModel derivedModel) {
|
||||
// every c# generator should definitely want this, or we should fix the issue
|
||||
// still, lets avoid breaking changes :(
|
||||
if (Boolean.FALSE.equals(GENERICHOST.equals(getLibrary()))){
|
||||
if (Boolean.FALSE.equals(GENERICHOST.equals(getLibrary()))) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (derivedModel.parentModel == null){
|
||||
if (derivedModel.parentModel == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (CodegenProperty parentProperty : derivedModel.parentModel.allVars){
|
||||
for (CodegenProperty parentProperty : derivedModel.parentModel.allVars) {
|
||||
if (Boolean.FALSE.equals(derivedModel.allVars.stream().anyMatch(v -> v.baseName.equals(parentProperty.baseName)))) {
|
||||
CodegenProperty clone = parentProperty.clone();
|
||||
clone.isInherited = true;
|
||||
@ -1582,7 +1582,7 @@ public class CSharpNetCoreClientCodegen extends AbstractCSharpCodegen {
|
||||
objs = super.postProcessAllModels(objs);
|
||||
|
||||
// other libraries probably want these fixes, but lets avoid breaking changes for now
|
||||
if (Boolean.FALSE.equals(GENERICHOST.equals(getLibrary()))){
|
||||
if (Boolean.FALSE.equals(GENERICHOST.equals(getLibrary()))) {
|
||||
return objs;
|
||||
}
|
||||
|
||||
@ -1599,7 +1599,7 @@ public class CSharpNetCoreClientCodegen extends AbstractCSharpCodegen {
|
||||
|
||||
if (cm.getComposedSchemas() != null && cm.getComposedSchemas().getAllOf() != null && !cm.getComposedSchemas().getAllOf().isEmpty()) {
|
||||
cm.getComposedSchemas().getAllOf().forEach(allOf -> {
|
||||
if (allOf.dataType.equals(cm.parent)){
|
||||
if (allOf.dataType.equals(cm.parent)) {
|
||||
allOf.isInherited = true;
|
||||
}
|
||||
});
|
||||
@ -1607,28 +1607,28 @@ public class CSharpNetCoreClientCodegen extends AbstractCSharpCodegen {
|
||||
|
||||
ensureInheritedPropertiesArePresent(cm);
|
||||
|
||||
for (CodegenProperty property : cm.allVars){
|
||||
for (CodegenProperty property : cm.allVars) {
|
||||
fixInvalidPropertyName(cm, property);
|
||||
}
|
||||
for (CodegenProperty property : cm.vars){
|
||||
for (CodegenProperty property : cm.vars) {
|
||||
fixInvalidPropertyName(cm, property);
|
||||
}
|
||||
for (CodegenProperty property : cm.readWriteVars){
|
||||
for (CodegenProperty property : cm.readWriteVars) {
|
||||
fixInvalidPropertyName(cm, property);
|
||||
}
|
||||
for (CodegenProperty property : cm.optionalVars){
|
||||
for (CodegenProperty property : cm.optionalVars) {
|
||||
fixInvalidPropertyName(cm, property);
|
||||
}
|
||||
for (CodegenProperty property : cm.parentVars){
|
||||
for (CodegenProperty property : cm.parentVars) {
|
||||
fixInvalidPropertyName(cm, property);
|
||||
}
|
||||
for (CodegenProperty property : cm.requiredVars){
|
||||
for (CodegenProperty property : cm.requiredVars) {
|
||||
fixInvalidPropertyName(cm, property);
|
||||
}
|
||||
for (CodegenProperty property : cm.readOnlyVars){
|
||||
for (CodegenProperty property : cm.readOnlyVars) {
|
||||
fixInvalidPropertyName(cm, property);
|
||||
}
|
||||
for (CodegenProperty property : cm.nonNullableVars){
|
||||
for (CodegenProperty property : cm.nonNullableVars) {
|
||||
fixInvalidPropertyName(cm, property);
|
||||
}
|
||||
}
|
||||
@ -1636,7 +1636,7 @@ public class CSharpNetCoreClientCodegen extends AbstractCSharpCodegen {
|
||||
return objs;
|
||||
}
|
||||
|
||||
private void fixInvalidPropertyName(CodegenModel model, CodegenProperty property){
|
||||
private void fixInvalidPropertyName(CodegenModel model, CodegenProperty property) {
|
||||
// TODO: remove once https://github.com/OpenAPITools/openapi-generator/pull/13681 is merged
|
||||
if (property.name.equalsIgnoreCase(model.classname) ||
|
||||
reservedWords().contains(property.name) ||
|
||||
@ -1654,7 +1654,7 @@ public class CSharpNetCoreClientCodegen extends AbstractCSharpCodegen {
|
||||
*/
|
||||
private void removePropertiesDeclaredInComposedClass(String className, List<CodegenModel> allModels, CodegenModel cm) {
|
||||
CodegenModel otherModel = allModels.stream().filter(m -> m.classname.equals(className)).findFirst().orElse(null);
|
||||
if (otherModel == null){
|
||||
if (otherModel == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user