Skip to content

[PS] Migrate ProviderHub module to autorest v4 #27864

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Jun 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/ProviderHub/ProviderHub.Autorest/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the ""License"");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an ""AS IS"" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Code generated by Microsoft (R) AutoRest Code Generator.Changes may cause incorrect behavior and will be lost if the code
// is regenerated.

using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

[assembly: System.Reflection.AssemblyCompanyAttribute("Microsoft")]
[assembly: System.Reflection.AssemblyCopyrightAttribute("Copyright © Microsoft")]
[assembly: System.Reflection.AssemblyProductAttribute("Microsoft Azure PowerShell")]
[assembly: System.Reflection.AssemblyTitleAttribute("Microsoft Azure PowerShell - ProviderHub")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("0.3.1")]
[assembly: System.Reflection.AssemblyVersionAttribute("0.3.1")]
[assembly: System.Runtime.InteropServices.ComVisibleAttribute(false)]
[assembly: System.CLSCompliantAttribute(false)]


21 changes: 5 additions & 16 deletions src/ProviderHub/ProviderHub.Autorest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,11 @@ input-file:
module-version: 0.1.0
title: ProviderHub
subject-prefix: $(service-name)
identity-correction-for-post: true

# For new modules, please avoid setting 3.x using the use-extension method and instead, use 4.x as the default option
use-extension:
"@autorest/powershell": "3.x"

directive:
- from: swagger-document
where: $.definitions.Error.properties
transform: delete $.innerError
- from: swagger-document
where: $
transform: $ = $.replace(/"authorizations"/, '"fakefields"');
- from: swagger-document
where: $.definitions.FeaturesRule.properties
transform: >-
Expand All @@ -78,17 +70,14 @@ directive:
- no-inline:
- Error
- where:
variant: ^Create$|^CreateViaIdentity$|^CreateViaIdentityExpanded$|^Update$|^UpdateViaIdentity$|^Manifest$|^ManifestViaIdentity$|^ManifestViaIdentityExpanded$
variant: ^(Create|Update|Manifest)(?!.*?(Expanded|JsonFilePath|JsonString))
remove: true
- where:
variant: ^ManifestViaIdentityExpanded$|^CreateViaIdentityExpanded$
remove: true
- where:
verb: Set
remove: true
- from: source-file-csharp
where: $
transform: $ = $.replace(/fakefield/g, 'authorization');
- from: source-file-csharp
where: $
transform: $ = $.replace(/Fakefield/g, 'Authorization');

# Hide commands to use Custom
- where:
Expand All @@ -108,7 +97,7 @@ directive:
subject: SkuNestedResourceTypeSecond
hide: true
- where:
verb: Get|New|Remove
verb: Get|New|Remove|Update
subject: SkuNestedResourceTypeThird
hide: true
- where:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,16 @@ Gets a resource type details in the given subscription and provider.
.Description
Gets a resource type details in the given subscription and provider.
.Example
PS C:\> {{ Add code here }}

{{ Add output here }}
Get-AzProviderHubResourceTypeRegistration -ProviderNamespace "Microsoft.Contoso"
.Example
PS C:\> {{ Add code here }}

{{ Add output here }}
Get-AzProviderHubResourceTypeRegistration -ProviderNamespace "Microsoft.Contoso" -ResourceType "testResourceType1"
.Example
Get-AzProviderHubResourceTypeRegistration -ProviderNamespace "Microsoft.Contoso" -ResourceType "testResourceType1/nestedResourceType"

.Inputs
Microsoft.Azure.PowerShell.Cmdlets.ProviderHub.Models.IProviderHubIdentity
.Outputs
Microsoft.Azure.PowerShell.Cmdlets.ProviderHub.Models.Api20201120.IResourceTypeRegistration
Microsoft.Azure.PowerShell.Cmdlets.ProviderHub.Models.IResourceTypeRegistration
.Notes
COMPLEX PARAMETER PROPERTIES

Expand All @@ -51,7 +49,7 @@ INPUTOBJECT <IProviderHubIdentity>: Identity Parameter
https://learn.microsoft.com/powershell/module/az.providerhub/get-azproviderhubresourcetyperegistration
#>
function Get-AzProviderHubResourceTypeRegistration {
[OutputType([Microsoft.Azure.PowerShell.Cmdlets.ProviderHub.Models.Api20201120.IResourceTypeRegistration])]
[OutputType([Microsoft.Azure.PowerShell.Cmdlets.ProviderHub.Models.IResourceTypeRegistration])]
[CmdletBinding(DefaultParameterSetName='List', PositionalBinding=$false)]
param(
[Parameter(ParameterSetName='Get', Mandatory)]
Expand All @@ -62,6 +60,7 @@ param(
${ProviderNamespace},

[Parameter(ParameterSetName='Get', Mandatory)]
[Parameter(ParameterSetName='GetViaIdentityProviderRegistration', Mandatory)]
[Microsoft.Azure.PowerShell.Cmdlets.ProviderHub.Category('Path')]
[System.String]
# The resource type.
Expand All @@ -79,15 +78,21 @@ param(
[Microsoft.Azure.PowerShell.Cmdlets.ProviderHub.Category('Path')]
[Microsoft.Azure.PowerShell.Cmdlets.ProviderHub.Models.IProviderHubIdentity]
# Identity Parameter
# To construct, see NOTES section for INPUTOBJECT properties and create a hash table.
${InputObject},

[Parameter(ParameterSetName='GetViaIdentityProviderRegistration', Mandatory, ValueFromPipeline)]
[Microsoft.Azure.PowerShell.Cmdlets.ProviderHub.Category('Path')]
[Microsoft.Azure.PowerShell.Cmdlets.ProviderHub.Models.IProviderHubIdentity]
# Identity Parameter
${ProviderRegistrationInputObject},

[Parameter()]
[Alias('AzureRMContext', 'AzureCredential')]
[ValidateNotNull()]
[Microsoft.Azure.PowerShell.Cmdlets.ProviderHub.Category('Azure')]
[System.Management.Automation.PSObject]
# The credentials, account, tenant, and subscription used for communication with Azure.
# The DefaultProfile parameter is not functional.
# Use the SubscriptionId parameter when available if executing the cmdlet against a different subscription.
${DefaultProfile},

[Parameter(DontShow)]
Expand Down Expand Up @@ -137,19 +142,31 @@ begin {
$PSBoundParameters['OutBuffer'] = 1
}
$parameterSet = $PSCmdlet.ParameterSetName

$testPlayback = $false
$PSBoundParameters['HttpPipelinePrepend'] | Foreach-Object { if ($_) { $testPlayback = $testPlayback -or ('Microsoft.Azure.PowerShell.Cmdlets.ProviderHub.Runtime.PipelineMock' -eq $_.Target.GetType().FullName -and 'Playback' -eq $_.Target.Mode) } }

$mapping = @{
Get = 'Az.ProviderHub.private\Get-AzProviderHubResourceTypeRegistration_Get';
GetViaIdentity = 'Az.ProviderHub.private\Get-AzProviderHubResourceTypeRegistration_GetViaIdentity';
GetViaIdentityProviderRegistration = 'Az.ProviderHub.private\Get-AzProviderHubResourceTypeRegistration_GetViaIdentityProviderRegistration';
List = 'Az.ProviderHub.private\Get-AzProviderHubResourceTypeRegistration_List';
}
if (('Get', 'List') -contains $parameterSet -and -not $PSBoundParameters.ContainsKey('SubscriptionId')) {
$PSBoundParameters['SubscriptionId'] = (Get-AzContext).Subscription.Id
if (('Get', 'List') -contains $parameterSet -and -not $PSBoundParameters.ContainsKey('SubscriptionId') ) {
if ($testPlayback) {
$PSBoundParameters['SubscriptionId'] = . (Join-Path $PSScriptRoot '..' 'utils' 'Get-SubscriptionIdTestSafe.ps1')
} else {
$PSBoundParameters['SubscriptionId'] = (Get-AzContext).Subscription.Id
}
}
if ($PSBoundParameters.ContainsKey('ResourceType')) {
$resourceTypePath = $PSBoundParameters['ResourceType'] -Split "/" -Join "/resourcetyperegistrations/"
$PSBoundParameters['ResourceType'] = $resourceTypePath
}
$wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand(($mapping[$parameterSet]), [System.Management.Automation.CommandTypes]::Cmdlet)
if ($null -eq $wrappedCmd) {
$wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand(($mapping[$parameterSet]), [System.Management.Automation.CommandTypes]::Function)
}
$scriptCmd = {& $wrappedCmd @PSBoundParameters}
$steppablePipeline = $scriptCmd.GetSteppablePipeline($MyInvocation.CommandOrigin)
$steppablePipeline.Begin($PSCmdlet)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,14 @@ Gets the sku details for the given resource type and sku name.
.Description
Gets the sku details for the given resource type and sku name.
.Example
PS C:\> {{ Add code here }}

{{ Add output here }}
Get-AzProviderHubSku -ProviderNamespace "Microsoft.Contoso" -ResourceType "testResourceType" -Sku "default"
.Example
PS C:\> {{ Add code here }}

{{ Add output here }}
Get-AzProviderHubSku -ProviderNamespace "Microsoft.Contoso" -ResourceType "testResourceType/nestedResourceType" -Sku "default"

.Inputs
Microsoft.Azure.PowerShell.Cmdlets.ProviderHub.Models.IProviderHubIdentity
.Outputs
Microsoft.Azure.PowerShell.Cmdlets.ProviderHub.Models.Api20201120.ISkuResource
Microsoft.Azure.PowerShell.Cmdlets.ProviderHub.Models.ISkuResource
.Notes
COMPLEX PARAMETER PROPERTIES

Expand All @@ -51,7 +47,7 @@ INPUTOBJECT <IProviderHubIdentity>: Identity Parameter
https://learn.microsoft.com/powershell/module/az.providerhub/get-azproviderhubsku
#>
function Get-AzProviderHubSku {
[OutputType([Microsoft.Azure.PowerShell.Cmdlets.ProviderHub.Models.Api20201120.ISkuResource])]
[OutputType([Microsoft.Azure.PowerShell.Cmdlets.ProviderHub.Models.ISkuResource])]
[CmdletBinding(DefaultParameterSetName='List', PositionalBinding=$false)]
param(
[Parameter(ParameterSetName='Get', Mandatory)]
Expand All @@ -65,6 +61,7 @@ param(
${ProviderNamespace},

[Parameter(ParameterSetName='Get', Mandatory)]
[Parameter(ParameterSetName='GetViaIdentityProviderRegistration', Mandatory)]
[Parameter(ParameterSetName='List', Mandatory)]
[Parameter(ParameterSetName='List1', Mandatory)]
[Parameter(ParameterSetName='List2', Mandatory)]
Expand All @@ -75,6 +72,8 @@ param(
${ResourceType},

[Parameter(ParameterSetName='Get', Mandatory)]
[Parameter(ParameterSetName='GetViaIdentityProviderRegistration', Mandatory)]
[Parameter(ParameterSetName='GetViaIdentityResourcetypeRegistration', Mandatory)]
[Microsoft.Azure.PowerShell.Cmdlets.ProviderHub.Category('Path')]
[System.String]
# The SKU.
Expand All @@ -95,9 +94,20 @@ param(
[Microsoft.Azure.PowerShell.Cmdlets.ProviderHub.Category('Path')]
[Microsoft.Azure.PowerShell.Cmdlets.ProviderHub.Models.IProviderHubIdentity]
# Identity Parameter
# To construct, see NOTES section for INPUTOBJECT properties and create a hash table.
${InputObject},

[Parameter(ParameterSetName='GetViaIdentityProviderRegistration', Mandatory, ValueFromPipeline)]
[Microsoft.Azure.PowerShell.Cmdlets.ProviderHub.Category('Path')]
[Microsoft.Azure.PowerShell.Cmdlets.ProviderHub.Models.IProviderHubIdentity]
# Identity Parameter
${ProviderRegistrationInputObject},

[Parameter(ParameterSetName='GetViaIdentityResourcetypeRegistration', Mandatory, ValueFromPipeline)]
[Microsoft.Azure.PowerShell.Cmdlets.ProviderHub.Category('Path')]
[Microsoft.Azure.PowerShell.Cmdlets.ProviderHub.Models.IProviderHubIdentity]
# Identity Parameter
${ResourcetypeRegistrationInputObject},

[Parameter(ParameterSetName='List1', Mandatory)]
[Parameter(ParameterSetName='List2', Mandatory)]
[Parameter(ParameterSetName='List3', Mandatory)]
Expand All @@ -124,7 +134,8 @@ param(
[ValidateNotNull()]
[Microsoft.Azure.PowerShell.Cmdlets.ProviderHub.Category('Azure')]
[System.Management.Automation.PSObject]
# The credentials, account, tenant, and subscription used for communication with Azure.
# The DefaultProfile parameter is not functional.
# Use the SubscriptionId parameter when available if executing the cmdlet against a different subscription.
${DefaultProfile},

[Parameter(DontShow)]
Expand Down Expand Up @@ -174,22 +185,35 @@ begin {
$PSBoundParameters['OutBuffer'] = 1
}
$parameterSet = $PSCmdlet.ParameterSetName

$testPlayback = $false
$PSBoundParameters['HttpPipelinePrepend'] | Foreach-Object { if ($_) { $testPlayback = $testPlayback -or ('Microsoft.Azure.PowerShell.Cmdlets.ProviderHub.Runtime.PipelineMock' -eq $_.Target.GetType().FullName -and 'Playback' -eq $_.Target.Mode) } }

$mapping = @{
Get = 'Az.ProviderHub.private\Get-AzProviderHubSku_Get';
GetViaIdentity = 'Az.ProviderHub.private\Get-AzProviderHubSku_GetViaIdentity';
GetViaIdentityProviderRegistration = 'Az.ProviderHub.private\Get-AzProviderHubSku_GetViaIdentityProviderRegistration';
GetViaIdentityResourcetypeRegistration = 'Az.ProviderHub.private\Get-AzProviderHubSku_GetViaIdentityResourcetypeRegistration';
List = 'Az.ProviderHub.private\Get-AzProviderHubSku_List';
List1 = 'Az.ProviderHub.private\Get-AzProviderHubSku_List1';
List2 = 'Az.ProviderHub.private\Get-AzProviderHubSku_List2';
List3 = 'Az.ProviderHub.private\Get-AzProviderHubSku_List3';
}
if (('Get', 'List', 'List1', 'List2', 'List3') -contains $parameterSet -and -not $PSBoundParameters.ContainsKey('SubscriptionId')) {
$PSBoundParameters['SubscriptionId'] = (Get-AzContext).Subscription.Id
if (('Get', 'List', 'List1', 'List2', 'List3') -contains $parameterSet -and -not $PSBoundParameters.ContainsKey('SubscriptionId') ) {
if ($testPlayback) {
$PSBoundParameters['SubscriptionId'] = . (Join-Path $PSScriptRoot '..' 'utils' 'Get-SubscriptionIdTestSafe.ps1')
} else {
$PSBoundParameters['SubscriptionId'] = (Get-AzContext).Subscription.Id
}
}
if ($PSBoundParameters.ContainsKey('ResourceType')) {
$resourceTypePath = $PSBoundParameters['ResourceType'] -Split "/" -Join "/resourcetyperegistrations/"
$PSBoundParameters['ResourceType'] = $resourceTypePath
}
$wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand(($mapping[$parameterSet]), [System.Management.Automation.CommandTypes]::Cmdlet)
if ($null -eq $wrappedCmd) {
$wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand(($mapping[$parameterSet]), [System.Management.Automation.CommandTypes]::Function)
}
$scriptCmd = {& $wrappedCmd @PSBoundParameters}
$steppablePipeline = $scriptCmd.GetSteppablePipeline($MyInvocation.CommandOrigin)
$steppablePipeline.Begin($PSCmdlet)
Expand Down
Loading