Skip to content

Commit

Permalink
more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
andreaTP committed Sep 11, 2023
1 parent 4a63318 commit 759d68f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/Kiota.Builder/Refiners/CommonLanguageRefiner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ current.Parent is CodeClass parentClass &&
var refinedName = refineAccessorName(currentProperty.Name);

if (!refinedName.Equals(currentProperty.Name, StringComparison.Ordinal) &&
!parentClass.Properties.Any(property => !property.Name.Equals(property.Name, StringComparison.Ordinal) && refinedName.Equals(property.Name, StringComparison.Ordinal)))// ensure the refinement won't generate a duplicate
!parentClass.Properties.Any(property => !currentProperty.Name.Equals(property.Name, StringComparison.Ordinal) &&
refinedName.Equals(property.Name, StringComparison.OrdinalIgnoreCase)))// ensure the refinement won't generate a duplicate
{
if (string.IsNullOrEmpty(currentProperty.SerializationName))
currentProperty.SerializationName = currentProperty.Name;
Expand Down
12 changes: 6 additions & 6 deletions tests/Kiota.Builder.Tests/Refiners/CSharpLanguageRefinerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public async Task InlineParentOnErrorClassesWhichAlreadyInherit()
};
await ILanguageRefiner.Refine(new GenerationConfiguration { Language = GenerationLanguage.CSharp }, root);

Assert.Contains(model.Properties, x => x.Name.Equals("otherProp"));
Assert.Contains(model.Properties, x => x.Name.Equals("OtherProp"));
Assert.Contains(model.Methods, x => x.Name.Equals("otherMethod"));
Assert.Contains(model.Usings, x => x.Name.Equals("otherNs"));
}
Expand Down Expand Up @@ -230,10 +230,10 @@ public async Task DoesNotEscapesReservedKeywordsForClassOrPropertyKindEnhanced()
// Assert
Assert.Equal("fileObject1", reservedModel.Name);// classes/models will be renamed if reserved without conflicts
Assert.Equal("fileObject", reservedObjectModel.Name);// original stays the same
Assert.Equal("alias", property.Name);// property names don't bring issue in dotnet
Assert.Equal("file", secondProperty.Name);// property names don't bring issue in dotnet
Assert.Equal("Alias", property.Name);// property names don't bring issue in dotnet
Assert.Equal("File", secondProperty.Name);// property names don't bring issue in dotnet
Assert.Equal("fileObject1", secondProperty.Type.Name);// property type was renamed
Assert.Equal("fileObject", thirdProperty.Name);// property names don't bring issue in dotnet
Assert.Equal("FileObject", thirdProperty.Name);// property names don't bring issue in dotnet
Assert.Equal("fileObject", thirdProperty.Type.Name);// property type was renamed

}
Expand Down Expand Up @@ -494,7 +494,7 @@ public async Task DisambiguatePropertiesWithClassNames()
}
}).First();
await ILanguageRefiner.Refine(new GenerationConfiguration { Language = GenerationLanguage.CSharp }, root);
Assert.Equal("modelProp", propToAdd.Name);
Assert.Equal("ModelProp", propToAdd.Name);
Assert.Equal("model", propToAdd.SerializationName);
}
[Fact]
Expand Down Expand Up @@ -530,7 +530,7 @@ public async Task AvoidsPropertyNameReplacementIfDuplicatedGenerated()
}
}).First();
await ILanguageRefiner.Refine(new GenerationConfiguration { Language = GenerationLanguage.CSharp }, root);
Assert.Equal("summary", firstProperty.Name);// remains as is. No refinement needed
Assert.Equal("Summary", firstProperty.Name);// remains as is. No refinement needed
Assert.Equal("_summary", secondProperty.Name);// No refinement as it will create a duplicate with firstProperty
Assert.Equal("Replaced", thirdProperty.Name);// Base case. Proper refinements
}
Expand Down

0 comments on commit 759d68f

Please sign in to comment.