@@ -96,7 +96,13 @@ public HashSet<string> GetAllParameterAliases(SimplePropertyInfo property)
9696 var globalAliases = CurrentModel . CustomParameters [ property . AnalyzedName ] . Aliases ;
9797 foreach ( var a in globalAliases )
9898 {
99- aliases . Add ( a ) ;
99+ var aliasToUse = ResolveAliasWithReservedParameterName ( a ) ;
100+
101+ // If new alias is not equivalent to CmdLet parameter name that would be used, then add it to aliases list.
102+ if ( aliasToUse != property . CmdletParameterName )
103+ {
104+ aliases . Add ( aliasToUse ) ;
105+ }
100106 }
101107 }
102108
@@ -109,7 +115,13 @@ public HashSet<string> GetAllParameterAliases(SimplePropertyInfo property)
109115 var propAliases = property . Customization . Aliases ;
110116 foreach ( var a in propAliases )
111117 {
112- aliases . Add ( a ) ;
118+ var aliasToUse = ResolveAliasWithReservedParameterName ( a ) ;
119+
120+ // If new alias is not equivalent to CmdLet parameter name that would be used, then add it to aliases list.
121+ if ( aliasToUse != property . CmdletParameterName )
122+ {
123+ aliases . Add ( aliasToUse ) ;
124+ }
113125 }
114126
115127 if ( property . Customization . AutoApplyAlias && property . CmdletParameterName != property . AnalyzedName )
@@ -124,7 +136,15 @@ public HashSet<string> GetAllParameterAliases(SimplePropertyInfo property)
124136 {
125137 var iterAlias = autoIteration . GetIterationParameterAlias ( property . AnalyzedName ) ;
126138 if ( ! string . IsNullOrEmpty ( iterAlias ) )
127- aliases . Add ( iterAlias ) ;
139+ {
140+ var aliasToUse = ResolveAliasWithReservedParameterName ( iterAlias ) ;
141+
142+ // If new alias is not equivalent to CmdLet parameter name that would be used, then add it to aliases list.
143+ if ( aliasToUse != property . CmdletParameterName )
144+ {
145+ aliases . Add ( aliasToUse ) ;
146+ }
147+ }
128148 }
129149
130150 return aliases ;
@@ -2407,6 +2427,8 @@ private void FinalizeParameterNames()
24072427 }
24082428 }
24092429
2430+ // In auto-rename, we attempt to shorten the name. In case there is a new service where there are similar end properties
2431+ // under different paths (e.g. EmailSettings_EmailMessage for Amplify Backend), then this could generate duplicate parameters.
24102432 if ( attemptAutoRename )
24112433 {
24122434 // inspect the name to determine if it can be reduced in length if we flattened a deep
@@ -2434,9 +2456,81 @@ private void FinalizeParameterNames()
24342456 RecordParameterRename ( property , alternateName ) ;
24352457 }
24362458 }
2459+
2460+ // Attempt to automatically resolve reserved parameter name conflicts.
2461+ ResolveReservedParameterName ( property ) ;
24372462 }
24382463 }
24392464
2465+ /// <summary>
2466+ /// Automatically resolves reserved parameter name conflict.
2467+ /// </summary>
2468+ /// <param name="property">Property representing parameter.</param>
2469+ /// <returns>Flag indicating if resolution was done.</returns>
2470+ private bool ResolveReservedParameterName ( SimplePropertyInfo property )
2471+ {
2472+ string parameterNameToResolve = property . Customization ? . NewName ?? property . AnalyzedName ;
2473+
2474+ // Parameter Name conflicts with one of the reserved parameter names. We want to use reserved parameter name from existing list for proper casing.
2475+ string reservedParameterName = ReservedParameterNames . FirstOrDefault ( r => r . Equals ( parameterNameToResolve , StringComparison . OrdinalIgnoreCase ) ) ;
2476+ if ( reservedParameterName != null )
2477+ {
2478+ // We want to use reserved parameter name from existing list for proper casing.
2479+ if ( AllModels . ReservedParameterNameMappings . TryGetValue ( reservedParameterName , out var newResolvedName ) )
2480+ {
2481+ newResolvedName = newResolvedName . Replace ( "{Noun}" , CurrentOperation . SelectedNoun ) . Replace ( "{Verb}" , CurrentOperation . SelectedVerb ) ;
2482+
2483+ var customization = property . Customization ;
2484+ if ( customization == null )
2485+ {
2486+ customization = new Param
2487+ {
2488+ Origin = Param . CustomizationOrigin . DuringGeneration ,
2489+ Name = property . AnalyzedName
2490+ } ;
2491+ property . Customization = customization ;
2492+ }
2493+
2494+ property . Customization . NewName = newResolvedName ;
2495+
2496+ // We should not auto apply alias since it would apply an alias of the original name which we have already transformed.
2497+ property . Customization . AutoApplyAlias = false ;
2498+
2499+ // We should override this even if there was NewName specified in customization.
2500+ property . Customization . Origin = Param . CustomizationOrigin . DuringGeneration ;
2501+
2502+ return true ;
2503+ }
2504+ }
2505+
2506+ return false ;
2507+ }
2508+
2509+ /// <summary>
2510+ /// Automatically resolves alias reserved parameter name conflict.
2511+ /// </summary>
2512+ /// <param name="alias">Parameter alias.</param>
2513+ /// <returns>Resolved alias.</returns>
2514+ private string ResolveAliasWithReservedParameterName ( string alias )
2515+ {
2516+ string newAlias = alias ;
2517+
2518+ if ( ! string . IsNullOrEmpty ( alias ) )
2519+ {
2520+ // Alias conflicts with one of the reserved parameter names. We want to use reserved parameter name from existing list for proper casing.
2521+ string reservedParameterName = ReservedParameterNames . FirstOrDefault ( r => r . Equals ( alias , StringComparison . OrdinalIgnoreCase ) ) ;
2522+ if ( reservedParameterName != null )
2523+ {
2524+ // We want to use reserved parameter name from existing list for proper casing.
2525+ if ( AllModels . ReservedParameterNameMappings . TryGetValue ( reservedParameterName , out var newResolvedName ) )
2526+ {
2527+ newAlias = newResolvedName . Replace ( "{Noun}" , CurrentOperation . SelectedNoun ) . Replace ( "{Verb}" , CurrentOperation . SelectedVerb ) ;
2528+ }
2529+ }
2530+ }
2531+
2532+ return newAlias ;
2533+ }
24402534
24412535 /// <summary>
24422536 /// Register fields derived from the SDK's ConstantClass 'enum' type
0 commit comments