< Summary - Kestrun — Combined Coverage

Information
Class: Public.OpenAPI.Add-KrOpenApiServer
Assembly: Kestrun.PowerShell.Public
File(s): /home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Public/OpenAPI/Add-KrOpenApiServer.ps1
Tag: Kestrun/Kestrun@0d738bf294e6281b936d031e1979d928007495ff
Line coverage
0%
Covered lines: 0
Uncovered lines: 15
Coverable lines: 15
Total lines: 65
Line coverage: 0%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 12/12/2025 - 17:27:19 Line coverage: 0% (0/15) Total lines: 65 Tag: Kestrun/Kestrun@826bf9dcf9db118c5de4c78a3259bce9549f0dcd

Metrics

File(s)

/home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Public/OpenAPI/Add-KrOpenApiServer.ps1

#LineLine coverage
 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 Server
 7    The Kestrun server instance to which the OpenAPI server will be added.
 8    If not specified, the function will attempt to resolve the current server context.
 9.PARAMETER Description
 10    A description of the server.
 11.PARAMETER DocId
 12    The documentation IDs to which this server will be added.
 13.PARAMETER Url
 14    The URL of the server.
 15.PARAMETER Variables
 16    A dictionary of server variables.
 17.EXAMPLE
 18    $variables = @{
 19        env = New-KrOpenApiServerVariable -Default 'dev' -Enum @('dev', 'staging', 'prod') -Description 'Environment nam
 20    }
 21    $oaServer = New-KrOpenApiServer -Description 'My API Server' -Url 'https://api.example.com' -Variables $variables
 22.NOTES
 23    This cmdlet is part of the Kestrun OpenAPI module.
 24#>
 25function Add-KrOpenApiServer {
 26    [KestrunRuntimeApi('Everywhere')]
 27    param(
 28        [Parameter(Mandatory = $false, ValueFromPipeline = $true)]
 29        [Kestrun.Hosting.KestrunHost]$Server,
 30        [Parameter()]
 31        [string[]]$DocId = [Kestrun.Authentication.IOpenApiAuthenticationOptions]::DefaultDocumentationIds,
 32        [Parameter(Mandatory)]
 33        [string]$Url,
 34        [string]$Description,
 35        [System.Collections.Specialized.OrderedDictionary]$Variables
 36    )
 37    begin {
 38        # Ensure the server instance is resolved
 039        $Server = Resolve-KestrunServer -Server $Server
 40    }
 41    process {
 042        $oaServer = [Microsoft.OpenApi.OpenApiServer]::new()
 043        if ($PsBoundParameters.ContainsKey('Description')) {
 044            $oaServer.Description = $Description
 45        }
 046        $oaServer.Url = $Url
 047        if ($PsBoundParameters.ContainsKey('Variables')) {
 048            $oaServer.Variables = [System.Collections.Generic.Dictionary[string, Microsoft.OpenApi.OpenApiServerVariable
 049            foreach ($key in $Variables.Keys) {
 050                $value = $Variables[$key]
 051                $oaServer.Variables.Add($key, $value)
 52            }
 53        }
 54        # Add the server to the specified OpenAPI documents
 055        foreach ($doc in $DocId) {
 056            $docDescriptor = $Server.GetOrCreateOpenApiDocument($doc)
 057            if ($null -eq $docDescriptor.Document.Servers) {
 58                # Initialize the Servers list if null
 059                $docDescriptor.Document.Servers = [System.Collections.Generic.List[Microsoft.OpenApi.OpenApiServer]]::ne
 60            }
 61            # Add the server to the Servers list
 062            $docDescriptor.Document.Servers.Add($oaServer)
 63        }
 64    }
 65}

Methods/Properties

Add-KrOpenApiServer()