Skip to content

Commit e991238

Browse files
authored
Exclude the api-version in typename when checking the breaking change of cmdlet output (#22495)
* Exclude the api-version in typename when checking the breaking change of cmdlet output * Rename the function
1 parent 5b9e6d6 commit e991238

File tree

1 file changed

+33
-12
lines changed

1 file changed

+33
-12
lines changed

tools/StaticAnalysis/BreakingChangeAnalyzer/CmdletMetadataHelper.cs

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -247,26 +247,47 @@ private void CheckForChangedOutputType(
247247

248248
_typeMetadataHelper.CheckOutputType(oldCmdlet, oldOutput.Type, newOutputType, issueLogger);
249249
}
250-
// If the output cannot be found by name, check if the old output can be mapped
251-
// to any of the new output types
252250
else
253251
{
254-
var foundOutput = outputDictionary.Values.Any(o => _typeMetadataHelper.CompareTypeMetadata(oldCmdlet, oldOutput.Type, o, null));
255-
if (!foundOutput)
252+
string oldOutputTypeName = RemoveApiVersionInTypeName(oldOutput.Type.Name);
253+
bool foundTypeNameWithoutApiVersion = false;
254+
foreach (var newOutput in outputDictionary.Values)
256255
{
257-
issueLogger?.LogBreakingChangeIssue(
258-
cmdlet: oldCmdlet,
259-
severity: 0,
260-
problemId: ProblemIds.BreakingChangeProblemId.ChangedOutputType,
261-
description: string.Format(Resources.ChangedOutputTypeDescription,
262-
oldCmdlet.Name, oldOutput.Type.Name),
263-
remediation: string.Format(Resources.ChangedOutputTypeRemediation,
264-
oldCmdlet.Name, oldOutput.Type.Name));
256+
string newOutputTypeName = RemoveApiVersionInTypeName(newOutput.Name);
257+
System.Console.WriteLine(newOutputTypeName);
258+
if (oldOutputTypeName.Equals(newOutputTypeName, StringComparison.OrdinalIgnoreCase))
259+
{
260+
_typeMetadataHelper.CheckOutputType(oldCmdlet, oldOutput.Type, newOutput, issueLogger);
261+
foundTypeNameWithoutApiVersion = true;
262+
break;
263+
}
264+
}
265+
if (!foundTypeNameWithoutApiVersion)
266+
{
267+
// If the output cannot be found by name, check if the old output can be mapped
268+
// to any of the new output types
269+
var foundOutput = outputDictionary.Values.Any(o => _typeMetadataHelper.CompareTypeMetadata(oldCmdlet, oldOutput.Type, o, null));
270+
if (!foundOutput)
271+
{
272+
issueLogger?.LogBreakingChangeIssue(
273+
cmdlet: oldCmdlet,
274+
severity: 0,
275+
problemId: ProblemIds.BreakingChangeProblemId.ChangedOutputType,
276+
description: string.Format(Resources.ChangedOutputTypeDescription,
277+
oldCmdlet.Name, oldOutput.Type.Name),
278+
remediation: string.Format(Resources.ChangedOutputTypeRemediation,
279+
oldCmdlet.Name, oldOutput.Type.Name));
280+
}
265281
}
266282
}
267283
}
268284
}
269285

286+
private string RemoveApiVersionInTypeName(string typeName)
287+
{
288+
return Regex.Replace(typeName, @"\.Api\d+(Preview)?", "");
289+
}
290+
270291
/// <summary>
271292
/// Check if the default parameter set has changed, and if so, make sure
272293
/// that the parameters are the same

0 commit comments

Comments
 (0)