< Summary - Kestrun — Combined Coverage

Information
Class: Private.Assembly.Resolve-KrSchemaTypeLiteral
Assembly: Kestrun.PowerShell.Private
File(s): /home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Private/Assembly/Resolve-KrSchemaTypeLiteral.ps1
Tag: Kestrun/Kestrun@ca54e35c77799b76774b3805b6f075cdbc0c5fbe
Line coverage
0%
Covered lines: 0
Uncovered lines: 13
Coverable lines: 13
Total lines: 51
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/26/2025 - 04:28:42 Line coverage: 0% (0/13) Total lines: 51 Tag: Kestrun/Kestrun@078efbc0494329762e193e7b43b6ce82e4942764

Metrics

File(s)

/home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Private/Assembly/Resolve-KrSchemaTypeLiteral.ps1

#LineLine coverage
 1
 2<#
 3.SYNOPSIS
 4    Safely resolves a schema input to a .NET [Type], supporting generics and arrays.
 5.DESCRIPTION
 6    This function takes a schema input that can be either a PowerShell type literal string (e.g., '[System.Collections.G
 7    or a [Type] object, and resolves it to a .NET [Type]. It includes validation to ensure the input is in the correct f
 8.PARAMETER Schema
 9    The schema input to resolve, either as a PowerShell type literal string or a [Type] object.
 10.OUTPUTS
 11    [Type]
 12.EXAMPLE
 13    $type = Resolve-KrSchemaTypeLiteral -Schema '[System.Collections.Generic.List[System.String]]'
 14    This example resolves the schema string to the corresponding .NET [Type] for a list of strings.
 15.NOTES
 16    This function is part of the Kestrun PowerShell module for working with OpenAPI specifications
 17#>
 18function Resolve-KrSchemaTypeLiteral {
 19    [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingInvokeExpression', '')]
 20    [CmdletBinding()]
 21    param(
 22        [Parameter(Mandatory)]
 23        [object] $Schema
 24    )
 25
 026    if ($Schema -is [type]) {
 027        return $Schema
 028    } elseif ($Schema -is [string]) {
 029        $s = $Schema.Trim()
 30
 31        # Require PowerShell type-literal form: [TypeName] or [Namespace.TypeName]
 32        # Disallow generics, arrays, scripts, whitespace, operators, etc.
 033        if ($s -notmatch '^\[[A-Za-z_][A-Za-z0-9_]*(\.[A-Za-z_][A-Za-z0-9_]*)*\]$') {
 034            throw "Invalid -Schema '$Schema'. Only type literals like '[OpenApiDate]' are allowed."
 35        }
 36
 37        # Optional: reject some known-dangerous tokens defensively (belt + suspenders)
 038        if ($s -match '[\s;|&`$(){}<>]') {
 039            throw "Invalid -Schema '$Schema'. Disallowed characters detected."
 40        }
 41
 042        $Schema = Invoke-Expression $s
 43
 044        if ($Schema -isnot [type]) {
 045            throw "Invalid -Schema '$Schema'. Evaluation did not produce a [Type]."
 46        }
 047        return $Schema
 48    } else {
 049        throw "Invalid -Schema type '$($Schema.GetType().FullName)'. Use ([string]) or 'System.String'."
 50    }
 51}

Methods/Properties

Resolve-KrSchemaTypeLiteral()