< 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@ca54e35c77799b76774b3805b6f075cdbc0c5fbe
Line coverage
0%
Covered lines: 0
Uncovered lines: 24
Coverable lines: 24
Total lines: 126
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@826bf9dcf9db118c5de4c78a3259bce9549f0dcd12/26/2025 - 18:43:06 Line coverage: 0% (0/24) Total lines: 126 Tag: Kestrun/Kestrun@66a9a3a4461391825b9a1ffc8190f76adb1bb67f

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 DocId
 15        The OpenAPI document ID to be served by this route.
 16    .PARAMETER SpecVersion
 17        An array of OpenAPI specification versions to support (e.g., OpenApi2_0 or OpenApi3_0).
 18    .PARAMETER VersionVarName
 19        The name of the route variable used to specify the OpenAPI version.
 20    .PARAMETER FormatVarName
 21        The name of the route variable used to specify the OpenAPI format (e.g., json or yaml).
 22    .PARAMETER RefreshVarName
 23        The name of the route variable used to trigger a refresh of the OpenAPI document.
 24    .PARAMETER DefaultFormat
 25        The default format for the OpenAPI document if not specified in the route.
 26    .PARAMETER DefaultVersion
 27        The default version for the OpenAPI document if not specified in the route.
 28    .PARAMETER PassThru
 29        If specified, the function will return the created route object.
 30    .OUTPUTS
 31       [Kestrun.Hosting.KestrunHost] representing the created route.
 32    .EXAMPLE
 33        Add-KrOpenApiRoute -Server $myServer -Pattern "/openapi/{version}/{format}" -SpecVersion @('OpenApi3_0') `
 34            -VersionVarName "version" -FormatVarName "format" -DefaultFormat "json" -DefaultVersion "v3.0"
 35        Adds a new OpenAPI map route to the specified Kestrun server with the given pattern and options.
 36    .EXAMPLE
 37        Get-KrServer | Add-KrOpenApiRoute -Pattern "/openapi/{version}/{format}" -SpecVersion @('OpenApi3_0') `
 38            -VersionVarName "version" -FormatVarName "format" -DefaultFormat "json" -DefaultVersion "v3.0" -PassThru
 39        Adds a new OpenAPI map route to the specified Kestrun server with the given pattern and options.
 40  .NOTES
 41        This function is part of the Kestrun PowerShell module and is used to manage routes
 42#>
 43function Add-KrOpenApiRoute {
 44    [KestrunRuntimeApi('Definition')]
 45    [CmdletBinding()]
 46    [OutputType([Kestrun.Hosting.KestrunHost])]
 47    param(
 48        [Parameter(Mandatory = $false, ValueFromPipeline = $true)]
 49        [Kestrun.Hosting.KestrunHost]$Server,
 50
 51        [Parameter()]
 52        [Kestrun.Hosting.Options.MapRouteOptions]$Options,
 53
 54        [Parameter()]
 55        [alias('Path')]
 56        [string]$Pattern,
 57
 58        [Parameter()]
 59        [Alias('DocumentId')]
 60        [string]$DocId = [Kestrun.OpenApi.OpenApiDocDescriptor]::DefaultDocumentationId,
 61
 62        [Parameter()]
 63        [Microsoft.OpenApi.OpenApiSpecVersion[]]$SpecVersion,
 64
 65        [Parameter()]
 66        [string]$VersionVarName,
 67
 68        [Parameter()]
 69        [string]$FormatVarName,
 70
 71        [Parameter()]
 72        [string]$RefreshVarName,
 73
 74        [Parameter()]
 75        [string]$DefaultFormat,
 76
 77        [Parameter()]
 78        [string]$DefaultVersion,
 79
 80        [Parameter()]
 81        [switch]$PassThru
 82    )
 83    begin {
 84        # Ensure the server instance is resolved
 085        $Server = Resolve-KestrunServer -Server $Server
 86    }
 87    process {
 088        if ($null -eq $Options) {
 089            $Options = [Kestrun.Hosting.Options.MapRouteOptions]::new()
 90        }
 091        if (-not [string]::IsNullOrEmpty($Pattern)) {
 092            $Options.Pattern = $Pattern
 93        }
 094        $Options.HttpVerbs = @('GET')
 095        $OpenApiMapRouteOptions = [Kestrun.Hosting.Options.OpenApiMapRouteOptions]::new($Options)
 096        if ($PsBoundParameters.ContainsKey('DefaultFormat')) {
 097            $OpenApiMapRouteOptions.DefaultFormat = $DefaultFormat
 98        }
 099        if ($PsBoundParameters.ContainsKey('DefaultVersion')) {
 0100            $OpenApiMapRouteOptions.DefaultVersion = $DefaultVersion
 101        }
 0102        if ($PsBoundParameters.ContainsKey('FormatVarName')) {
 0103            $OpenApiMapRouteOptions.FormatVarName = $FormatVarName
 104        }
 0105        if ($PsBoundParameters.ContainsKey('VersionVarName')) {
 0106            $OpenApiMapRouteOptions.VersionVarName = $VersionVarName
 107        }
 0108        if ($PsBoundParameters.ContainsKey('RefreshVarName')) {
 0109            $OpenApiMapRouteOptions.RefreshVarName = $RefreshVarName
 110        }
 0111        if ($PsBoundParameters.ContainsKey('SpecVersion')) {
 0112            $OpenApiMapRouteOptions.SpecVersions = $SpecVersion
 113        }
 0114        if ($PsBoundParameters.ContainsKey('DocId')) {
 0115            $OpenApiMapRouteOptions.DocId = $DocId
 116        }
 117
 118        # Call the C# extension method to add the OpenAPI map route
 0119        [Kestrun.Hosting.KestrunHostMapExtensions]::AddOpenApiMapRoute($Server, $OpenApiMapRouteOptions) | Out-Null
 120
 121        # Return the server if PassThru is specified
 0122        if ($PassThru) {
 0123            return $Server
 124        }
 125    }
 126}

Methods/Properties

Add-KrOpenApiRoute()