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

Exclude the api-version in typename when checking the breaking change of cmdlet output #22495

Merged
merged 2 commits into from
Aug 8, 2023
Merged
Changes from all commits
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
45 changes: 33 additions & 12 deletions tools/StaticAnalysis/BreakingChangeAnalyzer/CmdletMetadataHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -247,26 +247,47 @@ private void CheckForChangedOutputType(

_typeMetadataHelper.CheckOutputType(oldCmdlet, oldOutput.Type, newOutputType, issueLogger);
}
// If the output cannot be found by name, check if the old output can be mapped
// to any of the new output types
else
{
var foundOutput = outputDictionary.Values.Any(o => _typeMetadataHelper.CompareTypeMetadata(oldCmdlet, oldOutput.Type, o, null));
if (!foundOutput)
string oldOutputTypeName = RemoveApiVersionInTypeName(oldOutput.Type.Name);
bool foundTypeNameWithoutApiVersion = false;
foreach (var newOutput in outputDictionary.Values)
{
issueLogger?.LogBreakingChangeIssue(
cmdlet: oldCmdlet,
severity: 0,
problemId: ProblemIds.BreakingChangeProblemId.ChangedOutputType,
description: string.Format(Resources.ChangedOutputTypeDescription,
oldCmdlet.Name, oldOutput.Type.Name),
remediation: string.Format(Resources.ChangedOutputTypeRemediation,
oldCmdlet.Name, oldOutput.Type.Name));
string newOutputTypeName = RemoveApiVersionInTypeName(newOutput.Name);
System.Console.WriteLine(newOutputTypeName);
if (oldOutputTypeName.Equals(newOutputTypeName, StringComparison.OrdinalIgnoreCase))
{
_typeMetadataHelper.CheckOutputType(oldCmdlet, oldOutput.Type, newOutput, issueLogger);
foundTypeNameWithoutApiVersion = true;
break;
}
}
if (!foundTypeNameWithoutApiVersion)
{
// If the output cannot be found by name, check if the old output can be mapped
// to any of the new output types
var foundOutput = outputDictionary.Values.Any(o => _typeMetadataHelper.CompareTypeMetadata(oldCmdlet, oldOutput.Type, o, null));
if (!foundOutput)
{
issueLogger?.LogBreakingChangeIssue(
cmdlet: oldCmdlet,
severity: 0,
problemId: ProblemIds.BreakingChangeProblemId.ChangedOutputType,
description: string.Format(Resources.ChangedOutputTypeDescription,
oldCmdlet.Name, oldOutput.Type.Name),
remediation: string.Format(Resources.ChangedOutputTypeRemediation,
oldCmdlet.Name, oldOutput.Type.Name));
}
}
}
}
}

private string RemoveApiVersionInTypeName(string typeName)
{
return Regex.Replace(typeName, @"\.Api\d+(Preview)?", "");
}

/// <summary>
/// Check if the default parameter set has changed, and if so, make sure
/// that the parameters are the same
Expand Down