< Summary - Kestrun — Combined Coverage

Information
Class: Public.OpenAPI.Add-KrOpenApiComponent
Assembly: Kestrun.PowerShell.Public
File(s): /home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Public/OpenAPI/Add-KrOpenApiComponent.ps1
Tag: Kestrun/Kestrun@ca54e35c77799b76774b3805b6f075cdbc0c5fbe
Line coverage
0%
Covered lines: 0
Uncovered lines: 12
Coverable lines: 12
Total lines: 78
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/23/2025 - 19:23:04 Line coverage: 0% (0/9) Total lines: 75 Tag: Kestrun/Kestrun@d062f281460e6c123c372aef61f8d957bbb6c90112/25/2025 - 19:20:44 Line coverage: 0% (0/11) Total lines: 77 Tag: Kestrun/Kestrun@5251f12f253e29f8a1dfb77edc2ef50b90a4f26f01/17/2026 - 04:33:35 Line coverage: 0% (0/12) Total lines: 78 Tag: Kestrun/Kestrun@aca34ea8d284564e2f9f6616dc937668dce926ba

Metrics

File(s)

/home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Public/OpenAPI/Add-KrOpenApiComponent.ps1

#LineLine coverage
 1<#
 2.SYNOPSIS
 3    Adds an OpenAPI component (Example or Link) to the specified OpenAPI document(s).
 4.DESCRIPTION
 5    This cmdlet adds an OpenAPI component, either an Example or a Link, to one or more OpenAPI documents managed by the 
 6.PARAMETER Server
 7    The Kestrun server instance where the OpenAPI documents are managed. If not specified, the default server instance i
 8.PARAMETER DocId
 9    An array of OpenAPI document IDs to which the component will be added. Defaults to the standard documentation IDs.
 10.PARAMETER Name
 11    The name of the component to be added. This can be provided via the pipeline or as a parameter.
 12.PARAMETER Component
 13    The OpenAPI component object to be added. This can be an OpenApiExample or OpenApiLink object.
 14.PARAMETER IfExists
 15    Specifies the conflict resolution strategy if a component with the same name already exists in the document. Options
 16.EXAMPLE
 17    $example = New-KrOpenApiExample -Summary "User Example" -Description "An example of a user object." -Value @{ id = 1
 18    Add-KrOpenApiComponent -Name "UserExample" -Component $example -DocId "MyApiDoc"
 19    This example creates a new OpenAPI Component Example and adds it to the "MyApiDoc" OpenAPI document.
 20.EXAMPLE
 21    $link = New-KrOpenApiLink -OperationId "getUser" -Description "Link to get user details" -Parameters @{ "userId" = "
 22    Add-KrOpenApiComponent -Name "GetUserLink" -Component $link -DocId "MyApiDoc"
 23    This example creates a new OpenAPI Link and adds it to the "MyApiDoc" OpenAPI document.
 24.EXAMPLE
 25    New-KrOpenApiExample -Summary "Product Example" -Value @{ id = 101; name = "Widget"; price = 9.99 } | Add-KrOpenApiC
 26    This example creates a new OpenAPI Component Example for a product and pipes it directly to the Add-KrOpenApiCompone
 27.EXAMPLE
 28    New-KrOpenApiLink -OperationId "getOrder" -Description "Link to get order details" -Parameters @{ "orderId" = "$resp
 29    This example creates a new OpenAPI Link for getting order details and pipes it directly to the Add-KrOpenApiComponen
 30.OUTPUTS
 31    None
 32#>
 33function Add-KrOpenApiComponent {
 34    [KestrunRuntimeApi('Definition')]
 35    [CmdletBinding()]
 36    param(
 37        [Parameter(Mandatory = $false )]
 38        [Kestrun.Hosting.KestrunHost]$Server,
 39
 40        [Parameter()]
 41        [string[]]$DocId = [Kestrun.OpenApi.OpenApiDocDescriptor]::DefaultDocumentationIds,
 42
 43        [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)]
 44        [Alias('Key', 'Id')]
 45        [ValidatePattern('^[A-Za-z0-9\.\-_]+$')]
 46        [string] $Name,
 47
 48        [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
 49        [object] $Component,
 50
 51        [Parameter()]
 52        [Kestrun.OpenApi.OpenApiComponentConflictResolution] $IfExists = [Kestrun.OpenApi.OpenApiComponentConflictResolu
 53    )
 54    begin {
 55        # Ensure the server instance is resolved
 056        $Server = Resolve-KestrunServer -Server $Server
 57    }
 58    process {
 059        if ($Server.IsConfigured) {
 060            Write-KrError -ErrorMessage 'The Kestrun server configuration is already set. Please add components before e
 61            return
 62        }
 63        # Add the server to the specified OpenAPI documents
 064        foreach ($doc in $DocId) {
 065            $docDescriptor = $Server.GetOrCreateOpenApiDocument($doc)
 66
 067            if ($Component -is [Microsoft.OpenApi.OpenApiExample]) {
 068                $docDescriptor.AddComponentExample($Name, $Component, $IfExists)
 069            } elseif ($Component -is [Microsoft.OpenApi.OpenApiLink]) {
 070                $docDescriptor.AddComponentLink($Name, $Component, $IfExists)
 071            } elseif ($Component -is [Microsoft.OpenApi.OpenApiHeader]) {
 072                $docDescriptor.AddComponentHeader($Name, $Component, $IfExists)
 73            } else {
 074                Write-KrError -ErrorMessage "OpenApi $($doc): Unsupported component type: $($Component.GetType().FullNam
 75            }
 76        }
 77    }
 78}

Methods/Properties

Add-KrOpenApiComponent()