Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Java] Move (most of) the name mangling logic to the Refiner #3265

Merged
merged 9 commits into from
Sep 21, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
more fixes
andreaTP committed Sep 20, 2023
commit 237a8ac538110fcad623a5afe965a85d3bd58643
3 changes: 2 additions & 1 deletion src/Kiota.Builder/Refiners/CommonLanguageRefiner.cs
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
@@ -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"));
}
@@ -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

}
@@ -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]
@@ -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
}