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);
|
||||
|
@ -775,7 +775,7 @@ public class CSharpNetCoreClientCodegen extends AbstractCSharpCodegen {
|
||||
setNetCoreProjectFileFlag(true);
|
||||
|
||||
if (!additionalProperties.containsKey(CodegenConstants.NULLABLE_REFERENCE_TYPES) && !strategies.stream().anyMatch(s ->
|
||||
s.equals(FrameworkStrategy.NETFRAMEWORK_4_8) ||
|
||||
s.equals(FrameworkStrategy.NETFRAMEWORK_4_8) ||
|
||||
s.equals(FrameworkStrategy.NETFRAMEWORK_4_7))) {
|
||||
// starting in .net 6.0, NRT is enabled by default. If not specified, lets enable NRT to match the framework's default
|
||||
setNullableReferenceTypes(true);
|
||||
@ -973,7 +973,7 @@ public class CSharpNetCoreClientCodegen extends AbstractCSharpCodegen {
|
||||
}
|
||||
|
||||
public void addGenericHostSupportingFiles(final String clientPackageDir, final String packageDir,
|
||||
final AtomicReference<Boolean> excludeTests, final String testPackageDir, final String testPackageName, final String modelPackageDir) {
|
||||
final AtomicReference<Boolean> excludeTests, final String testPackageDir, final String testPackageName, final String modelPackageDir) {
|
||||
supportingFiles.add(new SupportingFile("README.test.mustache", testPackageDir, "README.md"));
|
||||
|
||||
supportingFiles.add(new SupportingFile("README.solution.mustache", "", "README.md"));
|
||||
@ -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)))) {
|
||||
@ -1543,23 +1543,23 @@ public class CSharpNetCoreClientCodegen extends AbstractCSharpCodegen {
|
||||
}
|
||||
|
||||
/**
|
||||
* ISSUE: https://github.com/OpenAPITools/openapi-generator/issues/11846
|
||||
* Ensures that a model has all inherited properties
|
||||
* Check modules\openapi-generator\src\test\resources\3_0\java\petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml
|
||||
* Without this method, property petType in GrandparentAnimal will not make it through ParentPet and into ChildCat
|
||||
*/
|
||||
* ISSUE: https://github.com/OpenAPITools/openapi-generator/issues/11846
|
||||
* Ensures that a model has all inherited properties
|
||||
* Check modules\openapi-generator\src\test\resources\3_0\java\petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml
|
||||
* Without this method, property petType in GrandparentAnimal will not make it through ParentPet and into ChildCat
|
||||
*/
|
||||
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,11 +1636,11 @@ 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) ||
|
||||
reservedWords().contains(camelize(sanitizeName(property.name), LOWERCASE_FIRST_LETTER))) {
|
||||
reservedWords().contains(property.name) ||
|
||||
reservedWords().contains(camelize(sanitizeName(property.name), LOWERCASE_FIRST_LETTER))) {
|
||||
property.name = property.name + "Property";
|
||||
}
|
||||
}
|
||||
@ -1650,23 +1650,23 @@ public class CSharpNetCoreClientCodegen extends AbstractCSharpCodegen {
|
||||
*
|
||||
* @param className The name which may be a composed model
|
||||
* @param allModels A collection of all CodegenModel
|
||||
* @param cm The CodegenModel to correct
|
||||
* @param cm The CodegenModel to correct
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
otherModel.readWriteVars.stream().filter(v -> cm.readWriteVars.stream().anyMatch(cmV -> cmV.baseName.equals(v.baseName))).collect(Collectors.toList())
|
||||
.forEach(v -> {
|
||||
cm.readWriteVars.removeIf(item -> item.baseName.equals(v.baseName));
|
||||
cm.vars.removeIf(item -> item.baseName.equals(v.baseName));
|
||||
cm.readOnlyVars.removeIf(item -> item.baseName.equals(v.baseName));
|
||||
cm.requiredVars.removeIf(item -> item.baseName.equals(v.baseName));
|
||||
cm.allVars.removeIf(item -> item.baseName.equals(v.baseName));
|
||||
cm.nonNullableVars.removeIf(item -> item.baseName.equals(v.baseName));
|
||||
});
|
||||
.forEach(v -> {
|
||||
cm.readWriteVars.removeIf(item -> item.baseName.equals(v.baseName));
|
||||
cm.vars.removeIf(item -> item.baseName.equals(v.baseName));
|
||||
cm.readOnlyVars.removeIf(item -> item.baseName.equals(v.baseName));
|
||||
cm.requiredVars.removeIf(item -> item.baseName.equals(v.baseName));
|
||||
cm.allVars.removeIf(item -> item.baseName.equals(v.baseName));
|
||||
cm.nonNullableVars.removeIf(item -> item.baseName.equals(v.baseName));
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
x
Reference in New Issue
Block a user