< Summary - Kestrun — Combined Coverage

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

Metrics

File(s)

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

#LineLine coverage
 1<#
 2    .SYNOPSIS
 3        Adds a new API documentation route (Redoc or Swagger UI) to the Kestrun server.
 4    .DESCRIPTION
 5        This function allows you to add a new API documentation route to the Kestrun server by specifying the route path
 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 API documentation route.
 13        Default is '/docs/redoc' for Redoc and '/docs/swagger' for Swagger UI.
 14    .PARAMETER DocumentType
 15        The type of API documentation to add. Valid values are 'Redoc', 'Swagger', 'Scalar', 'Rapidoc', and 'Elements'. 
 16    .PARAMETER OpenApiEndpoint
 17        The OpenAPI endpoint URI that the documentation UI will use to fetch the API documentation. Default is '/openapi
 18    .PARAMETER PassThru
 19        If specified, the function will return the created route object.
 20    .OUTPUTS
 21        [Microsoft.AspNetCore.Builder.IEndpointConventionBuilder] representing the created route.
 22    .EXAMPLE
 23        Add-KrApiDocumentationRoute -Server $myServer -Pattern "/docs/redoc" -DocumentType "Redoc" -OpenApiEndpoint "/op
 24        Adds a new Redoc UI route to the specified Kestrun server with the given pattern and OpenAPI endpoint.
 25    .EXAMPLE
 26        Get-KrServer | Add-KrApiDocumentationRoute -Pattern "/docs/swagger" -DocumentType "Swagger" -OpenApiEndpoint "/o
 27    .NOTES
 28        This function is part of the Kestrun PowerShell module and is used to manage routes
 29#>
 30function Add-KrApiDocumentationRoute {
 31    [KestrunRuntimeApi('Definition')]
 32    [CmdletBinding()]
 33    [OutputType([Kestrun.Hosting.KestrunHost])]
 34    param(
 35        [Parameter(Mandatory = $false, ValueFromPipeline = $true)]
 36        [Kestrun.Hosting.KestrunHost]$Server,
 37        [Parameter()]
 38        [Kestrun.Hosting.Options.MapRouteOptions]$Options,
 39        [Parameter()]
 40        [alias('Path')]
 41        [string]$Pattern,
 42        [Parameter()]
 43        [ValidateSet('Redoc', 'Swagger', 'Scalar', 'Rapidoc', 'Elements')]
 44        [string]$DocumentType = 'Swagger',
 45        [Parameter()]
 46        [Uri]$OpenApiEndpoint = [Uri]::new('/openapi/v3.0/openapi.json', [UriKind]::Relative),
 47        [Parameter()]
 48        [switch]$PassThru
 49    )
 50    begin {
 51        # Ensure the server instance is resolved
 052        $Server = Resolve-KestrunServer -Server $Server
 53    }
 54    process {
 055        if ($null -eq $Options) {
 056            $Options = [Kestrun.Hosting.Options.MapRouteOptions]::new()
 57        }
 58
 059        $Options.Pattern = $Pattern
 060        switch ($DocumentType) {
 61            'Swagger' {
 62                # Call the C# extension method to add the Swagger UI route
 063                [Kestrun.Hosting.KestrunHostMapExtensions]::AddSwaggerUiRoute($Server, $Options, $OpenApiEndpoint) | Out
 64            }
 65            'Redoc' {
 66                # Call the C# extension method to add the Redoc UI route
 067                [Kestrun.Hosting.KestrunHostMapExtensions]::AddRedocUiRoute($Server, $Options, $OpenApiEndpoint) | Out-N
 68            }
 69            'Scalar' {
 70                # Call the C# extension method to add the Scalar UI route
 071                [Kestrun.Hosting.KestrunHostMapExtensions]::AddScalarUiRoute($Server, $Options, $OpenApiEndpoint) | Out-
 72            }
 73            'Rapidoc' {
 74                # Call the C# extension method to add the Rapidoc UI route
 075                [Kestrun.Hosting.KestrunHostMapExtensions]::AddRapidocUiRoute($Server, $Options, $OpenApiEndpoint) | Out
 76            }
 77            'Elements' {
 78                # Call the C# extension method to add the Elements UI route
 079                [Kestrun.Hosting.KestrunHostMapExtensions]::AddElementsUiRoute($Server, $Options, $OpenApiEndpoint) | Ou
 80            }
 81            default {
 082                throw "Unsupported DocumentType: $DocumentType. Supported types are 'Swagger', 'Redoc', 'Scalar', 'Rapid
 83            }
 84        }
 085        if ($PassThru) {
 086            return $Server
 87        }
 88    }
 89}

Methods/Properties

Add-KrApiDocumentationRoute()