| | | 1 | | <# |
| | | 2 | | .SYNOPSIS |
| | | 3 | | Creates a new OpenAPI server variable. |
| | | 4 | | .DESCRIPTION |
| | | 5 | | This function creates a new OpenAPI server variable using the provided parameters. |
| | | 6 | | .PARAMETER Variables |
| | | 7 | | An optional OrderedDictionary to accumulate server variables. |
| | | 8 | | .PARAMETER Name |
| | | 9 | | The name of the server variable. |
| | | 10 | | .PARAMETER Default |
| | | 11 | | The default value for the server variable. |
| | | 12 | | .PARAMETER Enum |
| | | 13 | | An array of possible values for the server variable. |
| | | 14 | | .PARAMETER Description |
| | | 15 | | A description of the server variable. |
| | | 16 | | .EXAMPLE |
| | | 17 | | $variable = New-KrOpenApiServerVariable -Default 'dev' -Enum @('dev', 'staging', 'prod') -Description 'Environment n |
| | | 18 | | .OUTPUTS |
| | | 19 | | Microsoft.OpenApi.OpenApiServerVariable |
| | | 20 | | #> |
| | | 21 | | function New-KrOpenApiServerVariable { |
| | | 22 | | [Diagnostics.CodeAnalysis.SuppressMessage('PSUseShouldProcessForStateChangingFunctions', '')] |
| | | 23 | | [KestrunRuntimeApi('Everywhere')] |
| | | 24 | | [CmdletBinding()] |
| | | 25 | | param( |
| | | 26 | | [Parameter(ValueFromPipeline = $true, Position = 0)] |
| | | 27 | | [System.Collections.Specialized.OrderedDictionary] $Variables, |
| | | 28 | | |
| | | 29 | | [Parameter(Mandatory = $true)] |
| | | 30 | | [string] $Name, |
| | | 31 | | |
| | | 32 | | [Parameter()] |
| | | 33 | | [string] $Default, |
| | | 34 | | [Parameter()] |
| | | 35 | | [string[]] $Enum, |
| | | 36 | | [Parameter()] |
| | | 37 | | [string] $Description |
| | | 38 | | ) |
| | | 39 | | |
| | | 40 | | begin { |
| | 0 | 41 | | $dict = $null |
| | | 42 | | } |
| | | 43 | | |
| | | 44 | | process { |
| | | 45 | | # Adopt or create the accumulator dictionary |
| | 0 | 46 | | if ($PSBoundParameters.ContainsKey('Variables') -and $Variables) { |
| | 0 | 47 | | if (-not $dict) { $dict = $Variables } |
| | | 48 | | } |
| | 0 | 49 | | if (-not $dict) { |
| | 0 | 50 | | $dict = [ordered]@{} |
| | | 51 | | } |
| | 0 | 52 | | $dict[$Name] = [Microsoft.OpenApi.OpenApiServerVariable]::new() |
| | | 53 | | } |
| | | 54 | | end { |
| | 0 | 55 | | if ($PSBoundParameters.ContainsKey('Default')) { $dict[$Name].default = $Default } |
| | 0 | 56 | | if ($PSBoundParameters.ContainsKey('Description')) { $dict[$Name].description = $Description } |
| | 0 | 57 | | if ($PSBoundParameters.ContainsKey('Enum') -and $Enum) { |
| | 0 | 58 | | $dict[$Name].enum = $Enum |
| | | 59 | | } |
| | | 60 | | |
| | | 61 | | # Always emit an OrderedDictionary |
| | 0 | 62 | | return $dict |
| | | 63 | | } |
| | | 64 | | } |