Skip to content

Commit cb14acf

Browse files
committed
Include service operation in report.xml while auto-resolving reserved parameter names.
1 parent 963d8ff commit cb14acf

File tree

5 files changed

+63
-8
lines changed

5 files changed

+63
-8
lines changed

buildtools/Build.ps1

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

generator/AWSPSGeneratorLib/Analysis/AnalysisError.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,5 +447,10 @@ public static void NounAssignmentMethodPrefixTransformationApplied(ConfigModel s
447447
{
448448
new InfoMessage(service, operation, $"noun assignment: Method prefix transformation applied - '{originalNoun}' transformed to '{transformedNoun}' using '{methodPrefix}' prefix pattern.");
449449
}
450+
451+
public static void ReservedParameterNameConflictResolved(ConfigModel service, ServiceOperation operation, SimplePropertyInfo candidateParameter)
452+
{
453+
new InfoMessage(service, operation, $"Reserved paramater name conflict {candidateParameter.AnalyzedName} found. Automatically resolved as {candidateParameter.CmdletParameterName}.");
454+
}
450455
}
451456
}

generator/AWSPSGeneratorLib/Analysis/OperationAnalyzer.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2423,7 +2423,13 @@ private void FinalizeParameterNames()
24232423
}
24242424

24252425
// Attempt to automatically resolve reserved parameter name conflicts. We should attempt auto rename if resolution was not done.
2426-
ResolveReservedParameterName(property);
2426+
if (ResolveReservedParameterName(property))
2427+
{
2428+
CurrentOperation.IsReservedParameterNameHandled = true;
2429+
InfoMessage.ReservedParameterNameConflictResolved(CurrentModel, CurrentOperation, property);
2430+
2431+
// For new operations, the CurrentOperation.CustomParameters would not contain the resolved reserved parameter name. During report serialization, we should emit new parameter customization.
2432+
}
24272433
}
24282434
}
24292435

generator/AWSPSGeneratorLib/ConfigModel/ConfigModel.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,6 +1245,13 @@ public enum LegacyPaginationType
12451245
[XmlIgnore]
12461246
public bool IsAutoConfiguring;
12471247

1248+
/// <summary>
1249+
/// Set when the generator detects a parameter which conflicts with reserved parameter name.
1250+
/// The generator will take a try to handle the reserved parameter name based on configured mappings.
1251+
/// </summary>
1252+
[XmlIgnore]
1253+
public bool IsReservedParameterNameHandled;
1254+
12481255
/// <summary>
12491256
/// Stores the VerbNounTransformationPattern that was applied during verb processing.
12501257
/// 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)