Skip to content

Commit

Permalink
Tsp - Fixed an enum related issue
Browse files Browse the repository at this point in the history
  • Loading branch information
dolauli committed Dec 25, 2024
1 parent bcb7e88 commit 23eb231
Show file tree
Hide file tree
Showing 225 changed files with 2,508 additions and 2,500 deletions.
4 changes: 1 addition & 3 deletions packages/typespec-powershell/src/utils/modelUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1128,10 +1128,8 @@ function getSchemaForEnum(dpgContext: SdkContext, e: Enum) {
function enumMemberType(member: EnumMember | undefined) {
if (typeof member?.value === "number") {
return "number";
} else if (typeof member?.value === "string") {
return "string";
}
return undefined;
return "string";
}
/**
* Map TypeSpec intrinsic models to open api definitions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
<LangVersion>7.1</LangVersion>
<TargetFramework>netstandard2.0</TargetFramework>
<OutputType>Library</OutputType>
<AssemblyName>Az.DeviceRegistry.private</AssemblyName>
<AssemblyName>Az.EdgeZones.private</AssemblyName>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<RootNamespace>Microsoft.Azure.PowerShell.Cmdlets.DeviceRegistry</RootNamespace>
<RootNamespace>Microsoft.Azure.PowerShell.Cmdlets.EdgeZones</RootNamespace>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<OutputPath>./bin</OutputPath>
<PublishDir>$(OutputPath)</PublishDir>
<NuspecFile>Az.DeviceRegistry.nuspec</NuspecFile>
<NuspecFile>Az.EdgeZones.nuspec</NuspecFile>
<NoPackageAnalysis>true</NoPackageAnalysis>
<!-- Some methods are marked async and don't have an await in them -->
<!-- warning CS1591: Missing XML comment for publicly visible type or member -->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata>
<id>Az.DeviceRegistry</id>
<id>Az.EdgeZones</id>
<version>0.1.0</version>
<authors>Microsoft Corporation</authors>
<owners>Microsoft Corporation</owners>
<requireLicenseAcceptance>true</requireLicenseAcceptance>
<licenseUrl>https://aka.ms/azps-license</licenseUrl>
<projectUrl>https://github.com/Azure/azure-powershell</projectUrl>
<description>Microsoft Azure PowerShell: DeviceRegistry cmdlets</description>
<description>Microsoft Azure PowerShell: EdgeZones cmdlets</description>
<releaseNotes></releaseNotes>
<copyright>Microsoft Corporation. All rights reserved.</copyright>
<tags>Azure ResourceManager ARM PSModule Sphere</tags>
Expand All @@ -17,12 +17,12 @@
</dependencies>
</metadata>
<files>
<file src="Az.DeviceRegistry.format.ps1xml" />
<file src="Az.DeviceRegistry.psd1" />
<file src="Az.DeviceRegistry.psm1" />
<file src="Az.EdgeZones.format.ps1xml" />
<file src="Az.EdgeZones.psd1" />
<file src="Az.EdgeZones.psm1" />
<!-- https://github.com/NuGet/Home/issues/3584 -->
<file src="bin/Az.DeviceRegistry.private.dll" target="bin" />
<file src="bin\Az.DeviceRegistry.private.deps.json" target="bin" />
<file src="bin/Az.EdgeZones.private.dll" target="bin" />
<file src="bin\Az.EdgeZones.private.deps.json" target="bin" />
<file src="internal\**\*.*" exclude="internal\README.md" target="internal" />
<file src="custom\**\*.*" exclude="custom\README.md;custom\**\*.cs" target="custom" />
<file src="docs\**\*.md" exclude="docs\README.md" target="docs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@
Write-Information "Loaded Module '$($accountsModule.Name)'"

# Load the private module dll
$null = Import-Module -Name (Join-Path $PSScriptRoot './bin/Az.DeviceRegistry.private.dll')
$null = Import-Module -Name (Join-Path $PSScriptRoot './bin/Az.EdgeZones.private.dll')

# Get the private module's instance
$instance = [Microsoft.Azure.PowerShell.Cmdlets.DeviceRegistry.Module]::Instance
$instance = [Microsoft.Azure.PowerShell.Cmdlets.EdgeZones.Module]::Instance

# Ask for the shared functionality table
$VTable = Register-AzModule
Expand Down Expand Up @@ -77,7 +77,7 @@
$instance.ProfileName = $VTable.ProfileName

# Load the custom module
$customModulePath = Join-Path $PSScriptRoot './custom/Az.DeviceRegistry.custom.psm1'
$customModulePath = Join-Path $PSScriptRoot './custom/Az.EdgeZones.custom.psm1'
if(Test-Path $customModulePath) {
$null = Import-Module -Name $customModulePath
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!-- region Generated -->
# Az.DeviceRegistry
This directory contains the PowerShell module for the DeviceRegistry service.
# Az.EdgeZones
This directory contains the PowerShell module for the EdgeZones service.

---
## Info
Expand All @@ -20,5 +20,5 @@ This module was primarily generated via [AutoRest](https://github.com/Azure/auto
AutoRest does not generate authentication code for the module. Authentication is handled via Az.Accounts by altering the HTTP payload before it is sent.

## Development
For information on how to develop for `Az.DeviceRegistry`, see [how-to.md](how-to.md).
For information on how to develop for `Az.EdgeZones`, see [how-to.md](how-to.md).
<!-- endregion -->
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ if(-not $Debugger) {
$null = Remove-Item -Recurse -ErrorAction SilentlyContinue -Path (Join-Path $binFolder 'Debug'), (Join-Path $binFolder 'Release')
}

$dll = Join-Path $PSScriptRoot 'bin\Az.DeviceRegistry.private.dll'
$dll = Join-Path $PSScriptRoot 'bin\Az.EdgeZones.private.dll'
if(-not (Test-Path $dll)) {
Write-Error "Unable to find output assembly in '$binFolder'."
}
Expand All @@ -108,7 +108,7 @@ if(-not (Test-Path $dll)) {
$null = Import-Module -Name $dll

$modulePaths = $dll
$customPsm1 = Join-Path $PSScriptRoot 'custom\Az.DeviceRegistry.custom.psm1'
$customPsm1 = Join-Path $PSScriptRoot 'custom\Az.EdgeZones.custom.psm1'
if(Test-Path $customPsm1) {
$modulePaths = @($dll, $customPsm1)
}
Expand All @@ -125,9 +125,9 @@ if(Test-Path $internalFolder) {
}
$null = New-Item -ItemType Directory -Force -Path $internalFolder

$psd1 = Join-Path $PSScriptRoot './Az.DeviceRegistry.psd1'
$psd1 = Join-Path $PSScriptRoot './Az.EdgeZones.psd1'
$guid = Get-ModuleGuid -Psd1Path $psd1
$moduleName = 'Az.DeviceRegistry'
$moduleName = 'Az.EdgeZones'
$examplesFolder = Join-Path $PSScriptRoot 'examples'
$null = New-Item -ItemType Directory -Force -Path $examplesFolder

Expand All @@ -147,7 +147,7 @@ if($NoDocs) {
Export-ProxyCmdlet -ModuleName $moduleName -ModulePath $modulePaths -ExportsFolder $exportsFolder -InternalFolder $internalFolder -ExcludeDocs -ExamplesFolder $examplesFolder
} else {
Write-Host -ForegroundColor Green 'Creating exports and docs...'
$moduleDescription = 'Microsoft Azure PowerShell: DeviceRegistry cmdlets'
$moduleDescription = 'Microsoft Azure PowerShell: EdgeZones cmdlets'
$docsFolder = Join-Path $PSScriptRoot 'docs'
if(Test-Path $docsFolder) {
$null = Get-ChildItem -Path $docsFolder -Recurse -Exclude 'README.md' | Remove-Item -Recurse -ErrorAction SilentlyContinue
Expand All @@ -158,7 +158,7 @@ if($NoDocs) {
}

Write-Host -ForegroundColor Green 'Creating format.ps1xml...'
$formatPs1xml = Join-Path $PSScriptRoot './Az.DeviceRegistry.format.ps1xml'
$formatPs1xml = Join-Path $PSScriptRoot './Az.EdgeZones.format.ps1xml'
Export-FormatPs1xml -FilePath $formatPs1xml

Write-Host -ForegroundColor Green 'Creating psd1...'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function CreateModelCmdlet {
if (''.length -gt 0) {
$ModuleName = ''
} else {
$ModuleName = 'Az.DeviceRegistry'
$ModuleName = 'Az.EdgeZones'
}
$CsFiles = Get-ChildItem -Path $ModelCsPath -Recurse -Filter *.cs
$Content = ''
Expand Down Expand Up @@ -86,10 +86,10 @@ function CreateModelCmdlet {
$ObjectType = $ModelName
$ObjectTypeWithNamespace = "${Namespace}.${ObjectType}"
# remove duplicated module name
if ($ObjectType.StartsWith('DeviceRegistry')) {
if ($ObjectType.StartsWith('EdgeZones')) {
$ModulePrefix = ''
} else {
$ModulePrefix = 'DeviceRegistry'
$ModulePrefix = 'EdgeZones'
}
$OutputPath = Join-Path -ChildPath "New-Az${ModulePrefix}${ObjectType}Object.ps1" -Path $OutputDir

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# region Generated
# Load the private module dll
$null = Import-Module -PassThru -Name (Join-Path $PSScriptRoot '..\bin\Az.EdgeZones.private.dll')

# Load the internal module
$internalModulePath = Join-Path $PSScriptRoot '..\internal\Az.EdgeZones.internal.psm1'
if(Test-Path $internalModulePath) {
$null = Import-Module -Name $internalModulePath
}

# Export nothing to clear implicit exports
Export-ModuleMember

# Export script cmdlets
Get-ChildItem -Path $PSScriptRoot -Recurse -Include '*.ps1' -File | ForEach-Object { . $_.FullName }
Export-ModuleMember -Function (Get-ScriptCmdlet -ScriptFolder $PSScriptRoot) -Alias (Get-ScriptCmdlet -ScriptFolder $PSScriptRoot -AsAlias)
# endregion
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Custom
This directory contains custom implementation for non-generated cmdlets for the `Az.DeviceRegistry` module. Both scripts (`.ps1`) and C# files (`.cs`) can be implemented here. They will be used during the build process in `build-module.ps1`, and create cmdlets into the `..\exports` folder. The only generated file into this folder is the `Az.DeviceRegistry.custom.psm1`. This file should not be modified.
This directory contains custom implementation for non-generated cmdlets for the `Az.EdgeZones` module. Both scripts (`.ps1`) and C# files (`.cs`) can be implemented here. They will be used during the build process in `build-module.ps1`, and create cmdlets into the `..\exports` folder. The only generated file into this folder is the `Az.EdgeZones.custom.psm1`. This file should not be modified.

## Info
- Modifiable: yes
Expand All @@ -8,11 +8,11 @@ This directory contains custom implementation for non-generated cmdlets for the
- Packaged: yes

## Details
For `Az.DeviceRegistry` to use custom cmdlets, it does this two different ways. We **highly recommend** creating script cmdlets, as they are easier to write and allow access to the other exported cmdlets. C# cmdlets *cannot access exported cmdlets*.
For `Az.EdgeZones` to use custom cmdlets, it does this two different ways. We **highly recommend** creating script cmdlets, as they are easier to write and allow access to the other exported cmdlets. C# cmdlets *cannot access exported cmdlets*.

For C# cmdlets, they are compiled with the rest of the generated low-level cmdlets into the `./bin/Az.DeviceRegistry.private.dll`. The names of the cmdlets (methods) and files must follow the `[cmdletName]_[variantName]` syntax used for generated cmdlets. The `variantName` is used as the `ParameterSetName`, so use something appropriate that doesn't clash with already created variant or parameter set names. You cannot use the `ParameterSetName` property in the `Parameter` attribute on C# cmdlets. Each cmdlet must be separated into variants using the same pattern as seen in the `generated/cmdlets` folder.
For C# cmdlets, they are compiled with the rest of the generated low-level cmdlets into the `./bin/Az.EdgeZones.private.dll`. The names of the cmdlets (methods) and files must follow the `[cmdletName]_[variantName]` syntax used for generated cmdlets. The `variantName` is used as the `ParameterSetName`, so use something appropriate that doesn't clash with already created variant or parameter set names. You cannot use the `ParameterSetName` property in the `Parameter` attribute on C# cmdlets. Each cmdlet must be separated into variants using the same pattern as seen in the `generated/cmdlets` folder.

For script cmdlets, these are loaded via the `Az.DeviceRegistry.custom.psm1`. Then, during the build process, this module is loaded and processed in the same manner as the C# cmdlets. The fundamental difference is the script cmdlets use the `ParameterSetName` attribute and C# cmdlets do not. To create a script cmdlet variant of a generated cmdlet, simply decorate all parameters in the script with the new `ParameterSetName` in the `Parameter` attribute. This will appropriately treat each parameter set as a separate variant when processed to be exported during the build.
For script cmdlets, these are loaded via the `Az.EdgeZones.custom.psm1`. Then, during the build process, this module is loaded and processed in the same manner as the C# cmdlets. The fundamental difference is the script cmdlets use the `ParameterSetName` attribute and C# cmdlets do not. To create a script cmdlet variant of a generated cmdlet, simply decorate all parameters in the script with the new `ParameterSetName` in the `Parameter` attribute. This will appropriately treat each parameter set as a separate variant when processed to be exported during the build.

## Purpose
This allows the modules to have cmdlets that were not defined in the REST specification. It also allows combining logic using generated cmdlets. This is a level of customization beyond what can be done using the [readme configuration options](https://github.com/Azure/autorest/blob/master/docs/powershell/options.md) that are currently available. These custom cmdlets are then referenced by the cmdlets created at build-time in the `..\exports` folder.
Expand All @@ -27,15 +27,15 @@ The easiest way currently to start developing custom cmdlets is to copy an exist
- ProxyCredential
- ProxyUseDefaultCredentials

These provide functionality to our HTTP pipeline and other useful features. In script, you can forward these parameters using `$PSBoundParameters` to the other cmdlets you're calling within `Az.DeviceRegistry`. For C#, follow the usage seen in the `ProcessRecordAsync` method.
These provide functionality to our HTTP pipeline and other useful features. In script, you can forward these parameters using `$PSBoundParameters` to the other cmdlets you're calling within `Az.EdgeZones`. For C#, follow the usage seen in the `ProcessRecordAsync` method.

### Attributes
For processing the cmdlets, we've created some additional attributes:
- `Microsoft.Azure.PowerShell.Cmdlets.DeviceRegistry.DescriptionAttribute`
- `Microsoft.Azure.PowerShell.Cmdlets.EdgeZones.DescriptionAttribute`
- Used in C# cmdlets to provide a high-level description of the cmdlet. This is propagated to reference documentation via [help comments](https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_comment_based_help) in the exported scripts.
- `Microsoft.Azure.PowerShell.Cmdlets.DeviceRegistry.DoNotExportAttribute`
- Used in C# and script cmdlets to suppress creating an exported cmdlet at build-time. These cmdlets will *not be exposed* by `Az.DeviceRegistry`.
- `Microsoft.Azure.PowerShell.Cmdlets.DeviceRegistry.InternalExportAttribute`
- Used in C# cmdlets to route exported cmdlets to the `..\internal`, which are *not exposed* by `Az.DeviceRegistry`. For more information, see [README.md](..\internal/README.md) in the `..\internal` folder.
- `Microsoft.Azure.PowerShell.Cmdlets.DeviceRegistry.ProfileAttribute`
- `Microsoft.Azure.PowerShell.Cmdlets.EdgeZones.DoNotExportAttribute`
- Used in C# and script cmdlets to suppress creating an exported cmdlet at build-time. These cmdlets will *not be exposed* by `Az.EdgeZones`.
- `Microsoft.Azure.PowerShell.Cmdlets.EdgeZones.InternalExportAttribute`
- Used in C# cmdlets to route exported cmdlets to the `..\internal`, which are *not exposed* by `Az.EdgeZones`. For more information, see [README.md](..\internal/README.md) in the `..\internal` folder.
- `Microsoft.Azure.PowerShell.Cmdlets.EdgeZones.ProfileAttribute`
- Used in C# and script cmdlets to define which Azure profiles the cmdlet supports. This is only supported for Azure (`--azure`) modules.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Docs
This directory contains the documentation of the cmdlets for the `Az.DeviceRegistry` module. To run documentation generation, use the `generate-help.ps1` script at the root module folder. Files in this folder will *always be overridden on regeneration*. To update documentation examples, please use the `..\examples` folder.
This directory contains the documentation of the cmdlets for the `Az.EdgeZones` module. To run documentation generation, use the `generate-help.ps1` script at the root module folder. Files in this folder will *always be overridden on regeneration*. To update documentation examples, please use the `..\examples` folder.

## Info
- Modifiable: no
Expand All @@ -8,4 +8,4 @@ This directory contains the documentation of the cmdlets for the `Az.DeviceRegis
- Packaged: yes

## Details
The process of documentation generation loads `Az.DeviceRegistry` and analyzes the exported cmdlets from the module. It recognizes the [help comments](https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_comment_based_help) that are generated into the scripts in the `..\exports` folder. Additionally, when writing custom cmdlets in the `..\custom` folder, you can use the help comments syntax, which decorate the exported scripts at build-time. The documentation examples are taken from the `..\examples` folder.
The process of documentation generation loads `Az.EdgeZones` and analyzes the exported cmdlets from the module. It recognizes the [help comments](https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_comment_based_help) that are generated into the scripts in the `..\exports` folder. Additionally, when writing custom cmdlets in the `..\custom` folder, you can use the help comments syntax, which decorate the exported scripts at build-time. The documentation examples are taken from the `..\examples` folder.
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ if(-not $NotIsolated) {
return
}

$dll = Join-Path $PSScriptRoot 'bin\Az.DeviceRegistry.private.dll'
$dll = Join-Path $PSScriptRoot 'bin\Az.EdgeZones.private.dll'
if(-not (Test-Path $dll)) {
Write-Error "Unable to find output assembly in '$binFolder'."
}
$null = Import-Module -Name $dll

$moduleName = 'Az.DeviceRegistry'
$moduleName = 'Az.EdgeZones'
$exportsFolder = Join-Path $PSScriptRoot 'exports'
$resourcesFolder = Join-Path $PSScriptRoot 'resources'

Expand Down
Loading

0 comments on commit 23eb231

Please sign in to comment.