Skip to content

Commit 21532f1

Browse files
committed
Include service operation in report.xml while auto-resolving reserved parameter names.
1 parent 76c6608 commit 21532f1

File tree

5 files changed

+64
-9
lines changed

5 files changed

+64
-9
lines changed

buildtools/Build.ps1

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,9 @@ try {
201201
# if the report.xml is generated, rename it to overrides.xml so that auto-configured operations are included during cmdlet generation.
202202
try {
203203
Write-Host "Generating report.xml"
204-
# build-report-only generates report.xml only when there is a new operation and
205-
# there are no errors during auto-generation of the buildconfig
204+
# build-report-only generates report.xml only when there is a new operation
205+
# or existing operation introduced a parameter which conflicted with reserved parameter name that was auto-resolved
206+
# and there are no errors during auto-generation of the buildconfig
206207
dotnet msbuild ./buildtools/build.proj /t:build-report-only `
207208
/p:CleanSdkReferences=false `
208209
/p:BreakOnNewOperations=false `

generator/AWSPSGeneratorLib/Analysis/AnalysisError.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,5 +462,10 @@ public static void NounAssignmentMethodPrefixTransformationApplied(ConfigModel s
462462
{
463463
new InfoMessage(service, operation, $"noun assignment: Method prefix transformation applied - '{originalNoun}' transformed to '{transformedNoun}' using '{methodPrefix}' prefix pattern.");
464464
}
465+
466+
public static void ReservedParameterNameConflictResolved(ConfigModel service, ServiceOperation operation, SimplePropertyInfo candidateParameter)
467+
{
468+
new InfoMessage(service, operation, $"Reserved paramater name conflict {candidateParameter.AnalyzedName} found. Automatically resolved as {candidateParameter.CmdletParameterName}.");
469+
}
465470
}
466471
}

generator/AWSPSGeneratorLib/Analysis/OperationAnalyzer.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2457,8 +2457,14 @@ private void FinalizeParameterNames()
24572457
}
24582458
}
24592459

2460-
// Attempt to automatically resolve reserved parameter name conflicts.
2461-
ResolveReservedParameterName(property);
2460+
// Attempt to automatically resolve reserved parameter name conflicts. We should attempt auto rename if resolution was not done.
2461+
if (ResolveReservedParameterName(property))
2462+
{
2463+
CurrentOperation.IsReservedParameterNameHandled = true;
2464+
InfoMessage.ReservedParameterNameConflictResolved(CurrentModel, CurrentOperation, property);
2465+
2466+
// For new operations, the CurrentOperation.CustomParameters would not contain the resolved reserved parameter name. During report serialization, we should emit new parameter customization.
2467+
}
24622468
}
24632469
}
24642470

generator/AWSPSGeneratorLib/ConfigModel/ConfigModel.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,6 +1233,13 @@ public enum LegacyPaginationType
12331233
[XmlIgnore]
12341234
public bool IsAutoConfiguring;
12351235

1236+
/// <summary>
1237+
/// Set when the generator detects a parameter which conflicts with reserved parameter name.
1238+
/// The generator will take a try to handle the reserved parameter name based on configured mappings.
1239+
/// </summary>
1240+
[XmlIgnore]
1241+
public bool IsReservedParameterNameHandled;
1242+
12361243
/// <summary>
12371244
/// Stores the VerbNounTransformationPattern that was applied during verb processing.
12381245
/// Used to defer noun transformation to the AssignNoun method.

generator/AWSPSGeneratorLib/ConfigModel/XmlReportWriter.cs

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public static void SerializeReport(string folderPath, IEnumerable<ConfigModel> m
3737
var configModelsToOutput = models.Where(configModel =>
3838
configModel.AnalysisErrors.Any() ||
3939
overrides.ContainsKey(configModel.C2jFilename) ||
40-
configModel.ServiceOperationsList.Where(op => op.IsAutoConfiguring || op.AnalysisErrors.Any()).Any())
40+
configModel.ServiceOperationsList.Where(op => op.IsAutoConfiguring || op.AnalysisErrors.Any() || op.IsReservedParameterNameHandled).Any())
4141
.ToArray();
4242

4343
bool hasErrors = models.Any(configModel =>
@@ -52,6 +52,7 @@ public static void SerializeReport(string folderPath, IEnumerable<ConfigModel> m
5252
}
5353

5454
bool hasNewOperations = models.Any(model => model.ServiceOperationsList.Any(op => op.IsAutoConfiguring));
55+
bool isReservedParameterNameHandled = models.Any(model => model.ServiceOperationsList.Any(op => op.IsReservedParameterNameHandled));
5556

5657
var doc = new XDocument();
5758

@@ -141,11 +142,12 @@ public static void SerializeReport(string folderPath, IEnumerable<ConfigModel> m
141142
{
142143
var isConfigurationOverridden = modelOverrides?.MethodNames.Contains(operation.operation.MethodName) ?? false;
143144

144-
//We only include in the report new operations (IsAutoConfiguring=true) and operations requiring configuration updated. We also retain in the report
145-
//any operation that was manually configured.
145+
// We only include in the report new operations (IsAutoConfiguring=true) and operations requiring configuration updated (e.g. reserved parameter name handling).
146+
// We also retain in the report any operation that was manually configured.
146147
if (operation.operation.IsAutoConfiguring ||
147148
operation.operation.AnalysisErrors.Any() ||
148-
isConfigurationOverridden)
149+
isConfigurationOverridden ||
150+
operation.operation.IsReservedParameterNameHandled)
149151
{
150152
var firstOperationChildElement = operation.element.Elements().FirstOrDefault();
151153

@@ -173,6 +175,35 @@ public static void SerializeReport(string folderPath, IEnumerable<ConfigModel> m
173175
{
174176
if (operation.operation.Analyzer.AnalyzedParameters.Any())
175177
{
178+
// If reserved parameter name was handled, then we need to update or add Param element for the parameter customization in the report XML.
179+
var analyzedParametersWithCustomization = operation.operation.Analyzer.AnalyzedParameters.Where(p => p.Customization != null);
180+
if (operation.operation.IsReservedParameterNameHandled && analyzedParametersWithCustomization.Any())
181+
{
182+
var paramsElement = operation.element.Element("Params");
183+
if (paramsElement == null)
184+
{
185+
paramsElement = new XElement("Params");
186+
operation.element.Add(paramsElement);
187+
}
188+
189+
foreach (var analyzedParameter in analyzedParametersWithCustomization)
190+
{
191+
var parameterElement = paramsElement.Elements("Param").FirstOrDefault(child => (string)child.Attribute("Name") == analyzedParameter.Customization.Name);
192+
if (parameterElement == null)
193+
{
194+
parameterElement = new XElement("Param", new XAttribute("Name", analyzedParameter.Customization.Name));
195+
paramsElement.Add(parameterElement);
196+
}
197+
198+
parameterElement.SetAttributeValue("NewName", analyzedParameter.Customization.NewName);
199+
parameterElement.SetAttributeValue("AutoApplyAlias", analyzedParameter.Customization.AutoApplyAlias);
200+
201+
// We can add a XML comment before Param element if customization is due to reserved parameter handling. But we cannot rely on analyzedParameter.Customization.Origin
202+
// as DuringGeneration since it could happen for other shortning scenarios. We are already adding info message if reserved parameter handling was done, which is good enough.
203+
}
204+
}
205+
206+
// Add XML comment about parameters information.
176207
var parametersComments = operation.operation.Analyzer.AnalyzedParameters.Select(PropertyChangedEventArgs => GetParameterCommentForReport(PropertyChangedEventArgs, operation.operation.Analyzer));
177208
operation.element.Add(new XComment($"INFO - Parameters:\n {string.Join(";\n ", parametersComments)}."));
178209
}
@@ -205,9 +236,14 @@ public static void SerializeReport(string folderPath, IEnumerable<ConfigModel> m
205236
Console.WriteLine("New operations were auto-configured without errors and saved in report.xml");
206237
doc.Save(filename);
207238
}
239+
else if (isReservedParameterNameHandled && !hasErrors)
240+
{
241+
Console.WriteLine("Operations had parameters which conflicted with reserved parameter name that were automatically resolved without errors and saved in report.xml");
242+
doc.Save(filename);
243+
}
208244
else
209245
{
210-
Console.WriteLine($"Skipping saving report: hasNewOperations:{hasNewOperations}, hasErrors: {hasErrors} ");
246+
Console.WriteLine($"Skipping saving report: hasNewOperations:{hasNewOperations}, isReservedParameterNameHandled: {isReservedParameterNameHandled}, hasErrors: {hasErrors} ");
211247
}
212248
}
213249
catch (Exception e)

0 commit comments

Comments
 (0)