< Summary - Kestrun — Combined Coverage

Information
Class: Public.Response.Write-KrYamlResponse
Assembly: Kestrun.PowerShell.Public
File(s): /home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Public/Response/Write-KrYamlResponse.ps1
Tag: Kestrun/Kestrun@5f1d2b981c9d7292c11fd448428c6ab6c811c5de
Line coverage
0%
Covered lines: 0
Uncovered lines: 6
Coverable lines: 6
Total lines: 55
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 11/19/2025 - 17:40:50 Line coverage: 0% (0/6) Total lines: 55 Tag: Kestrun/Kestrun@fcf33342333cef0516fe0d0912a86709874fd026

Metrics

File(s)

/home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Public/Response/Write-KrYamlResponse.ps1

#LineLine coverage
 1<#
 2    .SYNOPSIS
 3        Writes an object to the HTTP response body as YAML.
 4
 5    .DESCRIPTION
 6        Serializes the provided object to YAML using the underlying C# helper and
 7        sets the specified status code on the response.
 8    .PARAMETER InputObject
 9        The object to serialize and write to the response body. This can be any
 10        PowerShell object, including complex types.
 11    .PARAMETER StatusCode
 12        The HTTP status code to set for the response. Defaults to 200 (OK).
 13    .PARAMETER ContentType
 14        The content type of the response. If not specified, defaults to "application/yaml".
 15    .EXAMPLE
 16        Write-KrYamlResponse -InputObject $myObject -StatusCode 200 -ContentType "application/x-yaml"
 17        Writes the $myObject serialized as YAML to the response with a 200 status code
 18        and content type "application/x-yaml".
 19    .NOTES
 20        This function is designed to be used in the context of a Kestrun server response.
 21#>
 22function Write-KrYamlResponse {
 23    [KestrunRuntimeApi('Route')]
 24    [CmdletBinding()]
 25    param(
 26        [Parameter(Mandatory = $true, ValueFromPipeline = $true)]
 27        [object]$InputObject,
 28        [Parameter()]
 29        [int]$StatusCode = 200,
 30        [Parameter()]
 31        [string]$ContentType
 32    )
 33    begin {
 34        # Collect all piped items
 035        $items = [System.Collections.Generic.List[object]]::new()
 36    }
 37    process {
 38        # Accumulate; no output yet
 039        $items.Add($InputObject)
 40    }
 41    end {
 42        # Only works inside a route script block where $Context is available
 043        if ($null -eq $Context -or $null -eq $Context.Response) {
 044            Write-KrOutsideRouteWarning
 45            return
 46        }
 47        #  - single item by default when only one was piped
 48        #  - array if multiple items were piped
 049        $payload = if ($items.Count -eq 1) { $items[0] } else { $items.ToArray() }
 50
 51        # Write the YAML response
 052        $Context.Response.WriteYamlResponse($payload, $StatusCode, $ContentType)
 53    }
 54}
 55

Methods/Properties

Write-KrYamlResponse()