< Summary - Kestrun — Combined Coverage

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

Metrics

File(s)

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

#LineLine coverage
 1<#
 2.SYNOPSIS
 3    Exports the OpenAPI document for the specified Kestrun server in the desired format.
 4.DESCRIPTION
 5    This function exports the OpenAPI document for the specified Kestrun server in either JSON or YAML format.
 6.PARAMETER Server
 7    The Kestrun server instance for which the OpenAPI document will be exported.
 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 export. Default is 'default'.
 11.PARAMETER Format
 12    The format in which to export the OpenAPI document. Valid values are 'Json' and 'Yaml'. Default is 'Json'.
 13.PARAMETER Version
 14    The OpenAPI specification version to use for the export. Default is OpenApi3_1.
 15.EXAMPLE
 16    # Export the OpenAPI document for the default document ID in JSON format
 17    $openApiJson = Export-KrGenerateOpenApiDocument -Server $myServer -DocId 'default' -Format 'Json'
 18.OUTPUTS
 19    string representing the OpenAPI document in the specified format.
 20    This will be the JSON or YAML representation of the OpenAPI document.
 21#>
 22function Export-KrOpenApiDocument {
 23    [KestrunRuntimeApi('Everywhere')]
 24    [CmdletBinding()]
 25    param(
 26        [Parameter(Mandatory = $false, ValueFromPipeline = $true)]
 27        [Kestrun.Hosting.KestrunHost]$Server,
 28        [Parameter()]
 29        [string]$DocId = [Kestrun.Authentication.IOpenApiAuthenticationOptions]::DefaultSchemeName,
 30        [Parameter(Mandatory = $false)]
 31        [ValidateSet('Json', 'Yaml')]
 32        [string]$Format = 'Json',
 33        [Parameter(Mandatory = $false)]
 34        [Microsoft.OpenApi.OpenApiSpecVersion]$Version = [Microsoft.OpenApi.OpenApiSpecVersion]::OpenApi3_1
 35    )
 36    begin {
 37        # Ensure the server instance is resolved
 038        $Server = Resolve-KestrunServer -Server $Server
 39    }
 40    process {
 041        if ( -not $Server.OpenApiDocumentDescriptor.ContainsKey($DocId)) {
 042            throw "OpenAPI document with ID '$DocId' does not exist on the server."
 43        }
 044        if ($Format -eq 'Json') {
 045            return $Server.OpenApiDocumentDescriptor[$DocId].ToJson($Version)
 46        } else {
 047            return $Server.OpenApiDocumentDescriptor[$DocId].ToYaml($Version)
 48        }
 49    }
 50}

Methods/Properties

Export-KrOpenApiDocument()