Skip to content

Commit 217d1fc

Browse files
authored
Fix the issue of compare type with API version in namespace (#16363)
Co-authored-by: wyunchi-ms <[email protected]>
1 parent 40b58bc commit 217d1fc

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

tools/StaticAnalysis/BreakingChangeAnalyzer/TypeMetadataHelper.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ public bool CompareTypeMetadata(
101101
continue;
102102
}
103103

104+
oldPropertyType = oldTypeMetadata.GetClassNameWithoutApiVersion(oldPropertyType);
105+
newPropertyType = newTypeMetadata.GetClassNameWithoutApiVersion(newPropertyType);
104106
// If the types are the same, compare their properties
105107
if (oldPropertyType.Equals(newPropertyType, StringComparison.OrdinalIgnoreCase))
106108
{
@@ -237,7 +239,9 @@ public void CheckParameterType(
237239
}
238240

239241
// If the types are different, log an issue
240-
if (!oldTypeMetadata.Name.Equals(newTypeMetadata.Name, StringComparison.OrdinalIgnoreCase))
242+
string oldTypeName = oldTypeMetadata.GetClassNameWithoutApiVersion(oldTypeMetadata.Name);
243+
string newTypeName = newTypeMetadata.GetClassNameWithoutApiVersion(newTypeMetadata.Name);
244+
if (!oldTypeName.Equals(newTypeName, StringComparison.OrdinalIgnoreCase))
241245
{
242246
issueLogger?.LogBreakingChangeIssue(
243247
cmdlet: cmdlet,
@@ -313,8 +317,10 @@ private bool IsElementType(
313317
// Check if the type is an array
314318
if (oldTypeMetadata.ElementType != null && newTypeMetadata.ElementType != null)
315319
{
320+
string oldTypeName = oldTypeMetadata.GetClassNameWithoutApiVersion(oldTypeMetadata.ElementType);
321+
string newTypeName = newTypeMetadata.GetClassNameWithoutApiVersion(newTypeMetadata.ElementType);
316322
// Check if the element of the array is the same in the old and new metadata
317-
if (oldTypeMetadata.ElementType.Equals(newTypeMetadata.ElementType, StringComparison.OrdinalIgnoreCase))
323+
if (oldTypeName.Equals(newTypeName, StringComparison.OrdinalIgnoreCase))
318324
{
319325
// If we have not previously seen this element type,
320326
// run this method on the type
@@ -431,7 +437,9 @@ private bool HasSameGenericType(
431437
ReportLogger<BreakingChangeIssue> issueLogger)
432438
{
433439
// If the type of the generics are the same, return true
434-
if (oldTypeMetadata.Name.Equals(newTypeMetadata.Name, StringComparison.OrdinalIgnoreCase))
440+
string oldTypeName = oldTypeMetadata.GetClassNameWithoutApiVersion(oldTypeMetadata.Name);
441+
string newTypeName = newTypeMetadata.GetClassNameWithoutApiVersion(newTypeMetadata.Name);
442+
if (oldTypeName.Equals(newTypeName, StringComparison.OrdinalIgnoreCase))
435443
{
436444
return true;
437445
}

tools/Tools.Common/Models/TypeMetadata.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ public TypeMetadata(Type inputType)
217217

218218
public List<MethodSignature> Constructors { get { return _constructors; } }
219219

220-
private string GetClassNameWithoutApiVersion(string className)
220+
public string GetClassNameWithoutApiVersion(string className)
221221
{
222222
var matcher = Regex.Match(className, @"Microsoft\.Azure\.PowerShell\.Cmdlets\.([\w\.]+)\.Api[\w\d]+\.([\w\.]+)");
223223
if (!matcher.Success || matcher.Groups.Count < 3)

0 commit comments

Comments
 (0)