Skip to content
This repository was archived by the owner on Sep 27, 2019. It is now read-only.

Commit 59b33ef

Browse files
authored
Support for custom mapping of plural to singular words in PluralizationService instance (#270)
* Added support for custom mapping of plural to singular words in PluralizationService instance
1 parent 7abfdde commit 59b33ef

File tree

3 files changed

+33
-10
lines changed

3 files changed

+33
-10
lines changed

PSSwagger/PluralToSingularMap.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"CustomPluralToSingularMapping": [
3+
{
4+
"Databases": "Database"
5+
},
6+
{
7+
"databases": "database"
8+
}
9+
]
10+
}

PSSwagger/SwaggerUtils.psm1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@ if(-not (Get-OperatingSystemInfo).IsCore)
2929
}
3030

3131
$script:PluralizationService = [System.Data.Entity.Design.PluralizationServices.PluralizationService]::CreateService([System.Globalization.CultureInfo]::CurrentCulture)
32+
33+
$PluralToSingularMapPath = Join-Path -Path $PSScriptRoot -ChildPath 'PluralToSingularMap.json'
34+
if(Test-Path -Path $PluralToSingularMapPath -PathType Leaf)
35+
{
36+
$PluralToSingularMapJsonObject = ConvertFrom-Json -InputObject ((Get-Content -Path $PluralToSingularMapPath) -join [Environment]::NewLine) -ErrorAction Stop
37+
$PluralToSingularMapJsonObject.CustomPluralToSingularMapping | ForEach-Object {
38+
$script:PluralizationService.AddWord($_.PSObject.Properties.Value, $_.PSObject.Properties.Name)
39+
}
40+
}
3241
}
3342

3443
$script:IgnoredAutoRestParameters = @(@('Modeler', 'm'), @('AddCredentials'), @('CodeGenerator', 'g'))

Tests/PSSwagger.Unit.Tests.ps1

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,49 +18,53 @@ Describe "PSSwagger Unit Tests" -Tag @('BVT', 'DRT', 'UnitTest', 'P0') {
1818
InModuleScope PSSwagger {
1919
Context "Get-PathCommandName Unit Tests" {
2020
It "Get-PathCommandName should return command names with proper verb for VM_CreateOrUpdateWithNounSuffix operationid" {
21-
$CommandNames = Get-PathCommandName -OperationId VM_CreateOrUpdateWithNounSuffix | %{ $_.name }
21+
$CommandNames = Get-PathCommandName -OperationId VM_CreateOrUpdateWithNounSuffix | Foreach-Object { $_.name }
2222
$CommandNames -CContains 'New-VMWithNounSuffix' | Should Be $True
2323
$CommandNames -CContains 'Set-VMWithNounSuffix' | Should Be $True
2424
}
2525

2626
It "Get-PathCommandName should return command names with proper verb for VM_createorupdatewithnounsuffix operationid" {
27-
$CommandNames = Get-PathCommandName -OperationId VM_createorupdatewithnounsuffix | %{ $_.name }
27+
$CommandNames = Get-PathCommandName -OperationId VM_createorupdatewithnounsuffix | Foreach-Object { $_.name }
2828
$CommandNames -CContains 'New-VMWithnounsuffix' | Should Be $True
2929
$CommandNames -CContains 'Set-VMWithnounsuffix' | Should Be $True
3030
}
3131

3232
It "Get-PathCommandName should return command name with proper verb for VM_createOrWithNounSuffix operationid" {
33-
Get-PathCommandName -OperationId VM_createOrWithNounSuffix | %{ $_.name } | Should BeExactly 'New-VMOrWithNounSuffix'
33+
Get-PathCommandName -OperationId VM_createOrWithNounSuffix | Foreach-Object { $_.name } | Should BeExactly 'New-VMOrWithNounSuffix'
3434
}
3535

3636
It "Get-PathCommandName should return command name with proper verb for VM_migrateWithNounSuffix operationid" {
37-
Get-PathCommandName -OperationId VM_migrateWithNounSuffix | %{ $_.name } | Should BeExactly 'Move-VMWithNounSuffix'
37+
Get-PathCommandName -OperationId VM_migrateWithNounSuffix | Foreach-Object { $_.name } | Should BeExactly 'Move-VMWithNounSuffix'
3838
}
3939

4040
It "Get-PathCommandName should return command name with proper verb for CreateFooResource operationid" {
41-
Get-PathCommandName -OperationId CreateFooResource | %{ $_.name } | Should BeExactly 'New-FooResource'
41+
Get-PathCommandName -OperationId CreateFooResource | Foreach-Object { $_.name } | Should BeExactly 'New-FooResource'
4242
}
4343

4444
It "Get-PathCommandName should return command names with proper verb for createorupdatebarResource operationid" {
45-
$CommandNames = Get-PathCommandName -OperationId createorupdatebarResource | %{ $_.name }
45+
$CommandNames = Get-PathCommandName -OperationId createorupdatebarResource | Foreach-Object { $_.name }
4646
$CommandNames -CContains 'New-BarResource' | Should BeExactly $True
4747
$CommandNames -CContains 'Set-BarResource' | Should BeExactly $True
4848
}
4949

5050
It "Get-PathCommandName should return command name with proper verb for anotherFooResource_createFoo operationid" {
51-
Get-PathCommandName -OperationId anotherFooResource_createFoo | %{ $_.name } | Should BeExactly 'New-AnotherFooResource'
51+
Get-PathCommandName -OperationId anotherFooResource_createFoo | Foreach-Object { $_.name } | Should BeExactly 'New-AnotherFooResource'
5252
}
5353

5454
It "Get-PathCommandName should return command name with proper verb for FooResource_createresource operationid" {
55-
Get-PathCommandName -OperationId FooResource_createresource | %{ $_.name } | Should BeExactly 'New-FooResource'
55+
Get-PathCommandName -OperationId FooResource_createresource | Foreach-Object { $_.name } | Should BeExactly 'New-FooResource'
5656
}
5757

5858
It "Get-PathCommandName should return proper command name for abcd operationid" {
59-
Get-PathCommandName -OperationId abcd | %{ $_.name } | Should BeExactly 'Abcd'
59+
Get-PathCommandName -OperationId abcd | Foreach-Object { $_.name } | Should BeExactly 'Abcd'
6060
}
6161

6262
It "Get-PathCommandName with NetworkInterfaces_ListVirtualMachineScaleSetVMNetworkInterfaces" {
63-
Get-PathCommandName -OperationId NetworkInterfaces_ListVirtualMachineScaleSetVMNetworkInterfaces | %{ $_.name } | Should BeExactly 'Get-VirtualMachineScaleSetVMNetworkInterface'
63+
Get-PathCommandName -OperationId NetworkInterfaces_ListVirtualMachineScaleSetVMNetworkInterfaces | Foreach-Object { $_.name } | Should BeExactly 'Get-VirtualMachineScaleSetVMNetworkInterface'
64+
}
65+
66+
It "Get-PathCommandName with Databases_Pause" {
67+
Get-PathCommandName -OperationId Databases_Pause | ForEach-Object { $_.name } | Should BeExactly 'Suspend-Database'
6468
}
6569
}
6670

0 commit comments

Comments
 (0)