< Summary - Kestrun — Combined Coverage

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

Metrics

File(s)

/home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Public/OpenAPI/Get-KrOpenApiDocument.ps1

#LineLine coverage
 1<#
 2.SYNOPSIS
 3    Retrieves the OpenAPI document for the specified Kestrun server.
 4.DESCRIPTION
 5    This function retrieves the OpenAPI document for the specified Kestrun server using the discovered components.
 6.PARAMETER Server
 7    The Kestrun server instance for which the OpenAPI document will be retrieved.
 8    If not specified, the function will attempt to resolve the current server context.
 9.PARAMETER DocId
 10    The ID of the OpenAPI document to retrieve. Default is 'default'.
 11.PARAMETER Version
 12    The OpenAPI specification version to use for retrieval. Default is OpenApi3_1.
 13.PARAMETER Yaml
 14    If specified, the function will return the OpenAPI document in YAML format.
 15.PARAMETER Json
 16    If specified, the function will return the OpenAPI document in JSON format.
 17    If neither Yaml nor Json is specified, the function will return the document as a PowerShell ordered hashtable.
 18.EXAMPLE
 19    # Retrieve the OpenAPI document as a hashtable
 20    $openApiDoc = Get-KrOpenApiDocument -Server $myServer -DocId 'default'
 21.EXAMPLE
 22    # Retrieve the OpenAPI document in JSON format
 23    $openApiJson = Get-KrOpenApiDocument -Server $myServer -Doc Id 'default' -Json
 24.EXAMPLE
 25    # Retrieve the OpenAPI document in YAML format
 26    $openApiYaml = Get-KrOpenApiDocument -Server $myServer -DocId 'default' -Yaml
 27.OUTPUTS
 28    [string] (if Yaml or Json is specified)
 29    [System.Management.Automation.OrderedHashtable] (if neither Yaml nor Json is specified)
 30#>
 31function Get-KrOpenApiDocument {
 32    [KestrunRuntimeApi('Everywhere')]
 33    [CmdletBinding(DefaultParameterSetName = 'HashTable')]
 34    [OutputType([string])]
 35    [OutputType([System.Management.Automation.OrderedHashtable])]
 36    param(
 37        [Parameter(Mandatory = $false, ValueFromPipeline = $true)]
 38        [Kestrun.Hosting.KestrunHost]$Server,
 39
 40        [Parameter()]
 41        [string]$DocId = [Kestrun.Authentication.IOpenApiAuthenticationOptions]::DefaultSchemeName,
 42
 43        [Parameter()]
 44        [Microsoft.OpenApi.OpenApiSpecVersion]$Version = [Microsoft.OpenApi.OpenApiSpecVersion]::OpenApi3_1,
 45
 46        [Parameter(ParameterSetName = 'Yaml')]
 47        [switch]$Yaml,
 48
 49        [Parameter(ParameterSetName = 'Json')]
 50        [switch]$Json
 51    )
 52    begin {
 53        # Ensure the server instance is resolved
 054        $Server = Resolve-KestrunServer -Server $Server
 55    }
 56    process {
 057        if ( -not $Server.OpenApiDocumentDescriptor.ContainsKey($DocId)) {
 058            throw "OpenAPI document with ID '$DocId' does not exist on the server."
 59        }
 60        # Log the start of the validation process
 061        Write-KrLog -Level Information -Message "Starting OpenAPI document retrieval for DocId: '{DocId}' Version: '{Ver
 62        # Retrieve the document descriptor
 063        $doc = $Server.OpenApiDocumentDescriptor[$DocId]
 064        if ( $Yaml.IsPresent) {
 065            return $doc.ToYaml($Version)
 066        } elseif ( $Json.IsPresent) {
 067            return $doc.ToJson($Version)
 68        }
 069        return $doc.ToJson($Version) | ConvertFrom-Json -AsHashtable
 70    }
 71}

Methods/Properties

Get-KrOpenApiDocument()