< Summary - Kestrun — Combined Coverage

Information
Class: Public.OpenAPI.Add-KrOpenApiLicense
Assembly: Kestrun.PowerShell.Public
File(s): /home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Public/OpenAPI/Add-KrOpenApiLicense.ps1
Tag: Kestrun/Kestrun@ca54e35c77799b76774b3805b6f075cdbc0c5fbe
Line coverage
0%
Covered lines: 0
Uncovered lines: 10
Coverable lines: 10
Total lines: 79
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/12) Total lines: 64 Tag: Kestrun/Kestrun@826bf9dcf9db118c5de4c78a3259bce9549f0dcd12/28/2025 - 06:48:51 Line coverage: 0% (0/10) Total lines: 79 Tag: Kestrun/Kestrun@4939cb68f5bc90e7d415ff811c4182dc0e086f3c

Metrics

File(s)

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

#LineLine coverage
 1<#
 2.SYNOPSIS
 3    Adds license information to the OpenAPI document.
 4.DESCRIPTION
 5    This function adds license information to the OpenAPI Info section using the provided parameters in the specified Op
 6.PARAMETER Server
 7    The Kestrun server instance to which the OpenAPI license information will be added.
 8    If not specified, the function will attempt to resolve the current server context.
 9.PARAMETER DocId
 10    An array of OpenAPI document IDs to which the license information will be added. Default is 'default'.
 11.PARAMETER Name
 12    The name of the license.
 13.PARAMETER Url
 14    The URL of the license. This parameter is used in the 'WithUrl' parameter set and is mutually exclusive with the 'Id
 15.PARAMETER Identifier
 16    The SPDX identifier of the license. This parameter is used in the 'WithIdentifier' parameter set and is mutually exc
 17.EXAMPLE
 18    # Add license information to the default document
 19    Add-KrOpenApiLicense -Name 'MIT License' -Url 'https://opensource.org/licenses/MIT'
 20.EXAMPLE
 21    # Add license information using SPDX identifier to the default document
 22    Add-KrOpenApiLicense -Name 'Apache 2.0' -Identifier 'Apache-2.0'
 23.EXAMPLE
 24    # Add license information using URL to the default document
 25    Add-KrOpenApiLicense -Name 'GPLv3' -Url 'https://www.gnu.org/licenses/gpl-3.0.en.html' -DocId 'customDoc1','customDo
 26.NOTES
 27    This cmdlet is part of the OpenAPI module.
 28#>
 29function Add-KrOpenApiLicense {
 30    [KestrunRuntimeApi('Definition')]
 31    [CmdletBinding(DefaultParameterSetName = 'Default')]
 32    param(
 33        [Parameter(Mandatory = $false, ValueFromPipeline = $true)]
 34        [Kestrun.Hosting.KestrunHost]$Server,
 35
 36        [Parameter()]
 37        [string[]]$DocId = [Kestrun.OpenApi.OpenApiDocDescriptor]::DefaultDocumentationIds,
 38
 39        [Parameter(Mandatory = $true)]
 40        [string]$Name,
 41
 42        [Parameter(Mandatory = $true, ParameterSetName = 'WithUrl')]
 43        [Uri]$Url,
 44
 45        [Parameter(Mandatory = $true, ParameterSetName = 'WithIdentifier')]
 46        [ValidateNotNullOrEmpty()]
 47        [ValidatePattern('^(?!\s)(?!.*\s$)(?!.*:\/\/)(?:\(?\s*[A-Za-z0-9.-]+[+]?(?:\s+WITH\s+[A-Za-z0-9.-]+)?\s*\)?)(?:\
 48        [string]$Identifier
 49    )
 50    begin {
 51        # Ensure the server instance is resolved
 052        $Server = Resolve-KestrunServer -Server $Server
 53    }
 54    process {
 55
 56        # Add the license information to the specified OpenAPI documents
 057        foreach ($doc in $DocId) {
 058            $docDescriptor = $Server.GetOrCreateOpenApiDocument($doc)
 59
 60            # Initialize the Info object if null
 061            $docDescriptor.Document.Info ??= [Microsoft.OpenApi.OpenApiInfo]::new()
 62
 63            # Initialize the License object if null
 064            $docDescriptor.Document.Info.License ??= [Microsoft.OpenApi.OpenApiLicense]::new()
 65
 66            # Set the license information
 067            $docDescriptor.Document.Info.License.Name = $Name
 68            # Set optional properties if provided
 069            if ($PSCmdlet.ParameterSetName -eq 'WithUrl') {
 070                $docDescriptor.Document.Info.License.Url = $Url
 71            }
 72
 073            if ($PSCmdlet.ParameterSetName -eq 'WithIdentifier') {
 74                # Assign the SPDX identifier
 075                $docDescriptor.Document.Info.License.Identifier = $Identifier
 76            }
 77        }
 78    }
 79}

Methods/Properties

Add-KrOpenApiLicense()