< Summary - Kestrun — Combined Coverage

Information
Class: Public.Route.Add-KrOpenApiRoute
Assembly: Kestrun.PowerShell.Public
File(s): /home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Public/Route/Add-KrOpenApiRoute.ps1
Tag: Kestrun/Kestrun@0d738bf294e6281b936d031e1979d928007495ff
Line coverage
0%
Covered lines: 0
Uncovered lines: 22
Coverable lines: 22
Total lines: 108
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/22) Total lines: 108 Tag: Kestrun/Kestrun@826bf9dcf9db118c5de4c78a3259bce9549f0dcd

Metrics

File(s)

/home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Public/Route/Add-KrOpenApiRoute.ps1

#LineLine coverage
 1<#
 2    .SYNOPSIS
 3        Adds a new OpenAPI map route to the Kestrun server.
 4    .DESCRIPTION
 5        This function allows you to add a new OpenAPI map route to the Kestrun server by specifying the route path, Open
 6    .PARAMETER Server
 7        The Kestrun server instance to which the route will be added.
 8        If not specified, the function will attempt to resolve the current server context.
 9    .PARAMETER Options
 10        The MapRouteOptions object to configure the route.
 11    .PARAMETER Pattern
 12        The URL path for the new OpenAPI map route.
 13        Default is '/openapi/{version}/openapi.{format}'.
 14    .PARAMETER SpecVersion
 15        An array of OpenAPI specification versions to support (e.g., OpenApi2_0 or OpenApi3_0).
 16    .PARAMETER VersionVarName
 17        The name of the route variable used to specify the OpenAPI version.
 18    .PARAMETER FormatVarName
 19        The name of the route variable used to specify the OpenAPI format (e.g., json or yaml).
 20    .PARAMETER RefreshVarName
 21        The name of the route variable used to trigger a refresh of the OpenAPI document.
 22    .PARAMETER DefaultFormat
 23        The default format for the OpenAPI document if not specified in the route.
 24    .PARAMETER DefaultVersion
 25        The default version for the OpenAPI document if not specified in the route.
 26    .PARAMETER PassThru
 27        If specified, the function will return the created route object.
 28    .OUTPUTS
 29       [Kestrun.Hosting.KestrunHost] representing the created route.
 30    .EXAMPLE
 31        Add-KrOpenApiRoute -Server $myServer -Pattern "/openapi/{version}/{format}" -SpecVersion @('OpenApi3_0') `
 32            -VersionVarName "version" -FormatVarName "format" -DefaultFormat "json" -DefaultVersion "v3.0"
 33        Adds a new OpenAPI map route to the specified Kestrun server with the given pattern and options.
 34    .EXAMPLE
 35        Get-KrServer | Add-KrOpenApiRoute -Pattern "/openapi/{version}/{format}" -SpecVersion @('OpenApi3_0') `
 36            -VersionVarName "version" -FormatVarName "format" -DefaultFormat "json" -DefaultVersion "v3.0" -PassThru
 37        Adds a new OpenAPI map route to the specified Kestrun server with the given pattern and options.
 38  .NOTES
 39        This function is part of the Kestrun PowerShell module and is used to manage routes
 40#>
 41function Add-KrOpenApiRoute {
 42    [KestrunRuntimeApi('Definition')]
 43    [CmdletBinding()]
 44    [OutputType([Kestrun.Hosting.KestrunHost])]
 45    param(
 46        [Parameter(Mandatory = $false, ValueFromPipeline = $true)]
 47        [Kestrun.Hosting.KestrunHost]$Server,
 48        [Parameter()]
 49        [Kestrun.Hosting.Options.MapRouteOptions]$Options,
 50        [Parameter()]
 51        [alias('Path')]
 52        [string]$Pattern,
 53        [Parameter()]
 54        [Microsoft.OpenApi.OpenApiSpecVersion[]]$SpecVersion,
 55        [Parameter()]
 56        [string]$VersionVarName,
 57        [Parameter()]
 58        [string]$FormatVarName,
 59        [Parameter()]
 60        [string]$RefreshVarName,
 61        [Parameter()]
 62        [string]$DefaultFormat,
 63        [Parameter()]
 64        [string]$DefaultVersion,
 65        [Parameter()]
 66        [switch]$PassThru
 67    )
 68    begin {
 69        # Ensure the server instance is resolved
 070        $Server = Resolve-KestrunServer -Server $Server
 71    }
 72    process {
 073        if ($null -eq $Options) {
 074            $Options = [Kestrun.Hosting.Options.MapRouteOptions]::new()
 75        }
 076        if (-not [string]::IsNullOrEmpty($Pattern)) {
 077            $Options.Pattern = $Pattern
 78        }
 079        $Options.HttpVerbs = @('GET')
 080        $OpenApiMapRouteOptions = [Kestrun.Hosting.Options.OpenApiMapRouteOptions]::new($Options)
 081        if ($PsBoundParameters.ContainsKey('DefaultFormat')) {
 082            $OpenApiMapRouteOptions.DefaultFormat = $DefaultFormat
 83        }
 084        if ($PsBoundParameters.ContainsKey('DefaultVersion')) {
 085            $OpenApiMapRouteOptions.DefaultVersion = $DefaultVersion
 86        }
 087        if ($PsBoundParameters.ContainsKey('FormatVarName')) {
 088            $OpenApiMapRouteOptions.FormatVarName = $FormatVarName
 89        }
 090        if ($PsBoundParameters.ContainsKey('VersionVarName')) {
 091            $OpenApiMapRouteOptions.VersionVarName = $VersionVarName
 92        }
 093        if ($PsBoundParameters.ContainsKey('RefreshVarName')) {
 094            $OpenApiMapRouteOptions.RefreshVarName = $RefreshVarName
 95        }
 096        if ($PsBoundParameters.ContainsKey('SpecVersion')) {
 097            $OpenApiMapRouteOptions.SpecVersions = $SpecVersion
 98        }
 99
 100        # Call the C# extension method to add the OpenAPI map route
 0101        [Kestrun.Hosting.KestrunHostMapExtensions]::AddOpenApiMapRoute($Server, $OpenApiMapRouteOptions) | Out-Null
 102
 103        # Return the server if PassThru is specified
 0104        if ($PassThru) {
 0105            return $Server
 106        }
 107    }
 108}

Methods/Properties

Add-KrOpenApiRoute()