Skip to content

Commit 4370c96

Browse files
committed
Fix auto-generator for Service Management.
1 parent 40932c5 commit 4370c96

27 files changed

+420
-138
lines changed

src/ServiceManagement/Common/Commands.ScenarioTest/Resources/ServiceManagement/ServiceManagementTests.ps1

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ function Run-AutoGeneratedHostedServiceCmdletTests
166166
$svcCreateParams.Label = $svcName;
167167

168168
# Invoke Create
169-
$st = Invoke-AzureComputeMethod -MethodName 'HostedServiceCreate' -HostedServiceCreateParameters $svcCreateParams;
169+
$st = Invoke-AzureComputeMethod -MethodName 'HostedServiceCreate' -HostedServiceCreateParameter $svcCreateParams;
170170

171171
Assert-AreEqual $st.StatusCode 'Created';
172172
Assert-NotNull $st.RequestId;
@@ -183,7 +183,7 @@ function Run-AutoGeneratedHostedServiceCmdletTests
183183
$svcUpdateParams.Label = 'update2';
184184

185185
# Invoke Update
186-
$svcGetResult2 = Invoke-AzureComputeMethod -MethodName 'HostedServiceUpdate' -ServiceName $svcName -HostedServiceUpdateParameters $svcUpdateParams;
186+
$svcGetResult2 = Invoke-AzureComputeMethod -MethodName 'HostedServiceUpdate' -ServiceName $svcName -HostedServiceUpdateParameter $svcUpdateParams;
187187

188188
# Invoke Get
189189
$svcGetResult2 = Invoke-AzureComputeMethod -MethodName 'HostedServiceGet' -ServiceName $svcName;
@@ -420,26 +420,28 @@ function Run-AutoGeneratedServiceExtensionCmdletTests
420420

421421
# Invoke Hosted Service Add Extension
422422
$p1 = New-AzureComputeArgumentList -MethodName HostedServiceAddExtension;
423-
$p1[0].Value = $svcName;
424-
$p1[1].Value.Id = 'test';
425-
$p1[1].Value.PublicConfiguration =
423+
$p1[0].Value = $svcName; #ServiceName
424+
$p1[1].Value = 'test'; #Id
425+
#PrivateConfiguration
426+
$p1[2].Value =
427+
@"
428+
<?xml version="1.0" encoding="UTF-8"?>
429+
<PrivateConfig>
430+
<Password>pstestuser</Password>
431+
</PrivateConfig>
432+
"@;
433+
$p1[3].Value = 'Microsoft.Windows.Azure.Extensions'; #ProviderNamespace
434+
#PublicConfiguration
435+
$p1[4].Value =
426436
@"
427437
<?xml version="1.0" encoding="UTF-8"?>
428438
<PublicConfig>
429439
<UserName>pstestuser</UserName>
430440
<Expiration></Expiration>
431441
</PublicConfig>
432442
"@;
433-
$p1[1].Value.PrivateConfiguration =
434-
@"
435-
<?xml version="1.0" encoding="UTF-8"?>
436-
<PrivateConfig>
437-
<Password>pstestuser</Password>
438-
</PrivateConfig>
439-
"@;
440-
$p1[1].Value.ProviderNamespace = 'Microsoft.Windows.Azure.Extensions';
441-
$p1[1].Value.Type = 'RDP';
442-
$p1[1].Value.Version = '1.*';
443+
$p1[7].Value = 'RDP'; #Type
444+
$p1[8].Value = '1.*'; #Version
443445
$d1 = ($p1 | select -ExpandProperty Value);
444446
$st = Invoke-AzureComputeMethod -MethodName HostedServiceAddExtension -ArgumentList $d1;
445447

src/ServiceManagement/Compute/Commands.ServiceManagement.Preview/Automation/Generate-ParameterCommand.ps1

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ function Generate-PowershellParameterCommandImpl
520520
[string] $fileOutputFolder = $null
521521
)
522522

523-
$powershell_object_name = Get-SingleNoun $OperationName;
523+
$powershell_object_name = Get-SingularNoun $OperationName;
524524

525525
if ($TreeNode -eq $null)
526526
{
@@ -586,7 +586,7 @@ function Generate-PowershellParameterCommandImpl
586586
$property_type = Get-ProperTypeName $propertyItem["Type"];
587587
if ($propertyItem["CanWrite"])
588588
{
589-
$param_name = Get-SingleNoun $propertyItem["Name"];
589+
$param_name = Get-SingularNoun $propertyItem["Name"];
590590
$param = @{Name = $param_name; Type = $property_type; OriginalName = $propertyItem["Name"]; Chain = $pathFromRoot};
591591
$parameters += $param;
592592
}
@@ -615,7 +615,7 @@ function Generate-PowershellParameterCommandImpl
615615

616616
if ($nonSingleSubNode.OnlySimple)
617617
{
618-
$param_name = Get-SingleNoun ($nonSingleSubNode.Name + $propertyItem["Name"]);
618+
$param_name = Get-SingularNoun ($nonSingleSubNode.Name + $propertyItem["Name"]);
619619
$param = @{Name = $param_name; Type = $property_type; OriginalName = $propertyItem["Name"]; Chain = $chain};
620620
$parameters += $param;
621621
}
@@ -650,7 +650,7 @@ function Generate-PowershellParameterCommandImpl
650650

651651
if ($propertyItem["CanWrite"])
652652
{
653-
$param_name = Get-SingleNoun $propertyItem["Name"];
653+
$param_name = Get-SingularNoun $propertyItem["Name"];
654654
$param = @{Name = $param_name; Type = $paramterType; OriginalName = $parameter["Name"]; Chain = $chain};
655655
$parameters += $param;
656656
}
@@ -667,7 +667,7 @@ function Generate-PowershellParameterCommandImpl
667667
$property_type = Get-ProperTypeName $realsubsub.TypeInfo;
668668
$paramterType = $property_type;
669669
}
670-
$param_name = Get-SingleNoun $realsubsub.Name;
670+
$param_name = Get-SingularNoun $realsubsub.Name;
671671
$param = @{Name = $param_name; Type = $paramterType; OriginalName = $realsubsub.Name; Chain = $chain};
672672
$parameters += $param;
673673

@@ -677,7 +677,7 @@ function Generate-PowershellParameterCommandImpl
677677
}
678678
else
679679
{
680-
$param_name = Get-SingleNoun $propertyItem["Name"];
680+
$param_name = Get-SingularNoun $propertyItem["Name"];
681681
$param = @{Name = $param_name; Type = $property_type; OriginalName = $propertyItem["Name"]; Chain = $chain};
682682
$parameters += $param;
683683
}
@@ -695,7 +695,7 @@ function Generate-PowershellParameterCommandImpl
695695
$property_type = Get-ProperTypeName $onlyProperty["Type"];
696696
if ($onlyProperty["CanWrite"])
697697
{
698-
$param_name = Get-SingleNoun ($nonSingleSubNode.Name + $onlyProperty["Name"]);
698+
$param_name = Get-SingularNoun ($nonSingleSubNode.Name + $onlyProperty["Name"]);
699699
$param = @{Name = $param_name; Type = "Array:" + $property_type; OriginalName = $onlyProperty["Name"]; Chain = $chain};
700700
$parameters += $param;
701701
}
@@ -705,7 +705,7 @@ function Generate-PowershellParameterCommandImpl
705705
$chain = $nonSingleSubNodeResult["Chain"];
706706
$property_type = Get-ProperTypeName $nonSingleSubNode.TypeInfo;
707707

708-
$param_name = Get-SingleNoun $nonSingleSubNode.Name;
708+
$param_name = Get-SingularNoun $nonSingleSubNode.Name;
709709
$param = @{Name = $param_name; Type = "Array:" + $property_type; OriginalName = $nonSingleSubNode.Name; Chain = $chain};
710710
$parameters += $param;
711711
$binding = Generate-PowershellParameterCommandImpl $nonSingleSubNode $fileOutputFolder;

src/ServiceManagement/Compute/Commands.ServiceManagement.Preview/Automation/Generate-PowershellParameterCmdlet.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ function Write-PowershellCmdlet
409409

410410
if ($TreeNode.Name -ne ${ObjectName})
411411
{
412-
$cmdlet_noun += Get-SingleNoun $TreeNode.Name;
412+
$cmdlet_noun += Get-SingularNoun $TreeNode.Name;
413413
}
414414

415415
if ($cmdlet_verb.Equals("New"))

src/ServiceManagement/Compute/Commands.ServiceManagement.Preview/Automation/RunCodeGeneration.ps1

Lines changed: 9 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -997,9 +997,7 @@ function Write-OperationCmdletFile
997997
$indents = " " * 8;
998998
$get_set_block = '{ get; set; }';
999999
$invoke_input_params_name = 'invokeMethodInputParameters';
1000-
10011000
$cmdlet_generated_code = '';
1002-
# $cmdlet_generated_code += $indents + '// ' + $operation_method_info + $NEW_LINE;
10031001

10041002
$method_param_list = $operation_method_info.GetParameters();
10051003
$method_return_type = $operation_method_info.ReturnType;
@@ -1010,6 +1008,7 @@ function Write-OperationCmdletFile
10101008
[System.Collections.ArrayList]$create_local_param_names = @();
10111009
[System.Collections.ArrayList]$cli_command_param_names = @();
10121010
$position_index = 1;
1011+
$has_properties = $false;
10131012
foreach ($pt in $method_param_list)
10141013
{
10151014
if (($pt.ParameterType.Name -like "I*Operations") -and ($pt.Name -eq 'operations'))
@@ -1030,30 +1029,10 @@ function Write-OperationCmdletFile
10301029
$paramTypeNormalizedName = Get-NormalizedTypeName $pt.ParameterType;
10311030
$param_constructor_code = Get-ConstructorCodeByNormalizedTypeName -inputName $paramTypeNormalizedName;
10321031

1033-
$is_special_type = $paramTypeFullName.StartsWith($client_model_namespace_prefix);
10341032
$has_properties = $true;
1035-
if ($is_special_type)
1036-
{
1037-
$properties_of_special_type = $pt.ParameterType.GetProperties();
1038-
if ($properties_of_special_type.Count -eq 0)
1039-
{
1040-
$has_properties = $false;
1041-
}
1042-
}
1043-
1044-
$is_string_list = $false;
1045-
$does_contain_only_strings = $null;
1046-
if ($has_properties)
1047-
{
1048-
$is_string_list = Is-ListStringType $pt.ParameterType;
1049-
$does_contain_only_strings = Get-StringTypes $pt.ParameterType;
1050-
}
1051-
1052-
$only_strings = $true;
1053-
if (($does_contain_only_strings -eq $null) -or ($does_contain_only_strings.Count -eq 0))
1054-
{
1055-
$only_strings = $false;
1056-
}
1033+
$is_string_list = Is-ListStringType $pt.ParameterType;
1034+
$does_contain_only_strings = Get-StringTypes $pt.ParameterType;
1035+
$only_strings = (($does_contain_only_strings -ne $null) -and ($does_contain_only_strings.Count -ne 0));
10571036

10581037
$param_attributes = $indents + "[Parameter(Mandatory = true";
10591038
$invoke_param_attributes = $indents + "[Parameter(ParameterSetName = `"${invoke_param_set_name}`", Position = ${position_index}, Mandatory = true";
@@ -1082,7 +1061,7 @@ function Write-OperationCmdletFile
10821061
$position_index += 1;
10831062
}
10841063
}
1085-
elseif ($has_properties -and $is_string_list)
1064+
elseif ($is_string_list)
10861065
{
10871066
# Case 2: the parameter type contains only a list of strings.
10881067
$list_of_strings_property = ($pt.ParameterType.GetProperties())[0].Name;
@@ -1093,37 +1072,28 @@ function Write-OperationCmdletFile
10931072
$invoke_local_param_definition += $indents + (' ' * 8) + "var inputArray${param_index} = Array.ConvertAll((object[]) ParseParameter(${invoke_input_params_name}[${param_index}]), e => e.ToString());" + $NEW_LINE;
10941073
if ($paramTypeNormalizedName -like 'System.Collections.Generic.IList*')
10951074
{
1096-
#$invoke_local_param_definition += $indents + (' ' * 4) + "${paramTypeNormalizedName} " + $pt.Name + " = inputArray${param_index}.ToList();" + $NEW_LINE;
10971075
$invoke_local_param_definition += $indents + (' ' * 8) + $pt.Name + " = inputArray${param_index}.ToList();" + $NEW_LINE;
10981076
}
10991077
else
11001078
{
1101-
#$invoke_local_param_definition += $indents + (' ' * 4) + "${paramTypeNormalizedName} " + $pt.Name + " = new ${paramTypeNormalizedName}();" + $NEW_LINE;
11021079
$invoke_local_param_definition += $indents + (' ' * 8) + $pt.Name + " = new ${paramTypeNormalizedName}();" + $NEW_LINE;
11031080
$invoke_local_param_definition += $indents + (' ' * 8) + $pt.Name + ".${list_of_strings_property} = inputArray${param_index}.ToList();" + $NEW_LINE;
11041081
}
11051082
$invoke_local_param_definition += $indents + (' ' * 4) + "}" + $NEW_LINE;
11061083
}
1107-
elseif ($has_properties)
1084+
else
11081085
{
11091086
# Case 3: this is the most general case.
11101087
if ($normalized_param_name -eq 'ODataQuery')
11111088
{
11121089
$paramTypeNormalizedName = "Microsoft.Rest.Azure.OData.ODataQuery<VirtualMachineScaleSetVM>";
1113-
#$invoke_local_param_definition = $indents + (' ' * 4) + "string " + $pt.Name + " = null;" + $NEW_LINE;
11141090
$invoke_local_param_definition = $indents + (' ' * 4) + "${paramTypeNormalizedName} " + $pt.Name + " = (${paramTypeNormalizedName})ParseParameter(${invoke_input_params_name}[${param_index}]);" + $NEW_LINE;
11151091
}
11161092
else
11171093
{
11181094
$invoke_local_param_definition = $indents + (' ' * 4) + "${paramTypeNormalizedName} " + $pt.Name + " = (${paramTypeNormalizedName})ParseParameter(${invoke_input_params_name}[${param_index}]);" + $NEW_LINE;
11191095
}
11201096
}
1121-
else
1122-
{
1123-
# Case 4: the parameter does not contain anything.
1124-
$invoke_local_param_definition = $indents + (' ' * 4) + "${paramTypeNormalizedName} " + $pt.Name + " = new ${paramTypeNormalizedName}();" + $NEW_LINE;
1125-
}
1126-
11271097

11281098
if ($only_strings)
11291099
{
@@ -1178,7 +1148,7 @@ function Write-OperationCmdletFile
11781148
$st = $invoke_param_names.Add($pt.Name);
11791149

11801150
$position_index += 1;
1181-
if ($has_properties -and (-not ($normalized_param_name -eq 'ODataQuery')))
1151+
if (-not ($normalized_param_name -eq 'ODataQuery'))
11821152
{
11831153
$pruned_params.Add($pt);
11841154
}
@@ -1251,7 +1221,7 @@ function Write-OperationCmdletFile
12511221
$expose_param_name = $invoke_param_set_name + $expose_param_name;
12521222
}
12531223

1254-
$expose_param_name = Get-SingleNoun $expose_param_name;
1224+
$expose_param_name = Get-SingularNoun $expose_param_name;
12551225

12561226
if (($does_contain_only_strings -eq $null) -or ($does_contain_only_strings.Count -eq 0))
12571227
{
@@ -1288,7 +1258,7 @@ function Write-OperationCmdletFile
12881258
{
12891259
foreach ($s in $does_contain_only_strings)
12901260
{
1291-
$s = Get-SingleNoun $s;
1261+
$s = Get-SingularNoun $s;
12921262
$dynamic_param_assignment_code_lines +=
12931263
@"
12941264
var p${s} = new RuntimeDefinedParameter();

src/ServiceManagement/Compute/Commands.ServiceManagement.Preview/Automation/StringProcessingHelper.ps1

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ function Get-SplitTextLines
293293
return $lines;
294294
}
295295

296-
function Get-SingleNoun
296+
function Get-SingularNoun
297297
{
298298
param(
299299
[Parameter(Mandatory = $true)]
@@ -305,6 +305,11 @@ function Get-SingleNoun
305305
return $noun;
306306
}
307307

308+
if ($noun.ToLower().EndsWith("address"))
309+
{
310+
return $noun;
311+
}
312+
308313
if ($noun.EndsWith("s"))
309314
{
310315
return $noun.Substring(0, $noun.Length - 1);

src/ServiceManagement/Compute/Commands.ServiceManagement.Preview/Generated/DNSServer/DNSServerAddDNSServerMethod.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,17 @@ protected object CreateDNSServerAddDNSServerDynamicParameters()
5959
pDeploymentName.Attributes.Add(new AllowNullAttribute());
6060
dynamicParameters.Add("DeploymentName", pDeploymentName);
6161

62-
var pAddres = new RuntimeDefinedParameter();
63-
pAddres.Name = "Addres";
64-
pAddres.ParameterType = typeof(string);
65-
pAddres.Attributes.Add(new ParameterAttribute
62+
var pAddress = new RuntimeDefinedParameter();
63+
pAddress.Name = "Address";
64+
pAddress.ParameterType = typeof(string);
65+
pAddress.Attributes.Add(new ParameterAttribute
6666
{
6767
ParameterSetName = "InvokeByDynamicParameters",
6868
Position = 3,
6969
Mandatory = false
7070
});
71-
pAddres.Attributes.Add(new AllowNullAttribute());
72-
dynamicParameters.Add("Addres", pAddres);
71+
pAddress.Attributes.Add(new AllowNullAttribute());
72+
dynamicParameters.Add("Address", pAddress);
7373

7474
var pName = new RuntimeDefinedParameter();
7575
pName.Name = "Name";

src/ServiceManagement/Compute/Commands.ServiceManagement.Preview/Generated/DNSServer/DNSServerUpdateDNSServerMethod.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,17 @@ protected object CreateDNSServerUpdateDNSServerDynamicParameters()
7171
pDnsServerName.Attributes.Add(new AllowNullAttribute());
7272
dynamicParameters.Add("DnsServerName", pDnsServerName);
7373

74-
var pAddres = new RuntimeDefinedParameter();
75-
pAddres.Name = "Addres";
76-
pAddres.ParameterType = typeof(string);
77-
pAddres.Attributes.Add(new ParameterAttribute
74+
var pAddress = new RuntimeDefinedParameter();
75+
pAddress.Name = "Address";
76+
pAddress.ParameterType = typeof(string);
77+
pAddress.Attributes.Add(new ParameterAttribute
7878
{
7979
ParameterSetName = "InvokeByDynamicParameters",
8080
Position = 4,
8181
Mandatory = false
8282
});
83-
pAddres.Attributes.Add(new AllowNullAttribute());
84-
dynamicParameters.Add("Addres", pAddres);
83+
pAddress.Attributes.Add(new AllowNullAttribute());
84+
dynamicParameters.Add("Address", pAddress);
8585

8686
var pName = new RuntimeDefinedParameter();
8787
pName.Name = "Name";

src/ServiceManagement/Compute/Commands.ServiceManagement.Preview/Generated/Deployment/DeploymentChangeConfigurationBySlotMethod.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,25 @@ protected object CreateDeploymentChangeConfigurationBySlotDynamicParameters()
4747
pServiceName.Attributes.Add(new AllowNullAttribute());
4848
dynamicParameters.Add("ServiceName", pServiceName);
4949

50+
var pDeploymentSlot = new RuntimeDefinedParameter();
51+
pDeploymentSlot.Name = "DeploymentSlot";
52+
pDeploymentSlot.ParameterType = typeof(DeploymentSlot);
53+
pDeploymentSlot.Attributes.Add(new ParameterAttribute
54+
{
55+
ParameterSetName = "InvokeByDynamicParameters",
56+
Position = 2,
57+
Mandatory = false
58+
});
59+
pDeploymentSlot.Attributes.Add(new AllowNullAttribute());
60+
dynamicParameters.Add("DeploymentSlot", pDeploymentSlot);
61+
5062
var pParameters = new RuntimeDefinedParameter();
5163
pParameters.Name = "DeploymentChangeConfigurationBySlotParameter";
5264
pParameters.ParameterType = typeof(DeploymentChangeConfigurationParameters);
5365
pParameters.Attributes.Add(new ParameterAttribute
5466
{
5567
ParameterSetName = "InvokeByDynamicParameters",
56-
Position = 2,
68+
Position = 3,
5769
Mandatory = false
5870
});
5971
pParameters.Attributes.Add(new AllowNullAttribute());
@@ -65,7 +77,7 @@ protected object CreateDeploymentChangeConfigurationBySlotDynamicParameters()
6577
pArgumentList.Attributes.Add(new ParameterAttribute
6678
{
6779
ParameterSetName = "InvokeByStaticParameters",
68-
Position = 3,
80+
Position = 4,
6981
Mandatory = true
7082
});
7183
pArgumentList.Attributes.Add(new AllowNullAttribute());
@@ -77,7 +89,7 @@ protected object CreateDeploymentChangeConfigurationBySlotDynamicParameters()
7789
protected void ExecuteDeploymentChangeConfigurationBySlotMethod(object[] invokeMethodInputParameters)
7890
{
7991
string serviceName = (string)ParseParameter(invokeMethodInputParameters[0]);
80-
DeploymentSlot deploymentSlot = new DeploymentSlot();
92+
DeploymentSlot deploymentSlot = (DeploymentSlot)ParseParameter(invokeMethodInputParameters[1]);
8193
DeploymentChangeConfigurationParameters parameters = (DeploymentChangeConfigurationParameters)ParseParameter(invokeMethodInputParameters[2]);
8294

8395
var result = DeploymentClient.ChangeConfigurationBySlot(serviceName, deploymentSlot, parameters);

0 commit comments

Comments
 (0)