| | | 1 | | <# |
| | | 2 | | .SYNOPSIS |
| | | 3 | | Creates a new OpenAPI server. |
| | | 4 | | .DESCRIPTION |
| | | 5 | | This function creates a new OpenAPI server using the provided parameters. |
| | | 6 | | .PARAMETER Description |
| | | 7 | | A description of the server. |
| | | 8 | | .PARAMETER Url |
| | | 9 | | The URL of the server. |
| | | 10 | | .PARAMETER Variables |
| | | 11 | | A dictionary of server variables. |
| | | 12 | | .EXAMPLE |
| | | 13 | | $variables = @{ |
| | | 14 | | env = New-KrOpenApiServerVariable -Default 'dev' -Enum @('dev', 'staging', 'prod') -Description 'Environment nam |
| | | 15 | | } |
| | | 16 | | $server = New-KrOpenApiServer -Description 'My API Server' -Url 'https://api.example.com' -Variables $variables |
| | | 17 | | .OUTPUTS |
| | | 18 | | Microsoft.OpenApi.OpenApiServer |
| | | 19 | | #> |
| | | 20 | | function New-KrOpenApiServer { |
| | | 21 | | [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '')] |
| | | 22 | | [KestrunRuntimeApi('Everywhere')] |
| | | 23 | | param( |
| | | 24 | | [Parameter(Mandatory)] |
| | | 25 | | [string]$Url, |
| | | 26 | | [string]$Description, |
| | | 27 | | [System.Collections.Specialized.OrderedDictionary]$Variables |
| | | 28 | | ) |
| | 0 | 29 | | $server = [Microsoft.OpenApi.OpenApiServer]::new() |
| | 0 | 30 | | if ($PsBoundParameters.ContainsKey('Description')) { |
| | 0 | 31 | | $server.Description = $Description |
| | | 32 | | } |
| | 0 | 33 | | $server.Url = $Url |
| | 0 | 34 | | if ($PsBoundParameters.ContainsKey('Variables')) { |
| | 0 | 35 | | $server.Variables = [System.Collections.Generic.Dictionary[string, Microsoft.OpenApi.OpenApiServerVariable]]::ne |
| | 0 | 36 | | foreach ($key in $Variables.Keys) { |
| | 0 | 37 | | $value = $Variables[$key] |
| | 0 | 38 | | $server.Variables.Add($key, $value) |
| | | 39 | | } |
| | | 40 | | } |
| | 0 | 41 | | return $server |
| | | 42 | | } |