| | | 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. |
| | | 15 | | .PARAMETER Identifier |
| | | 16 | | The SPDX identifier of the license. |
| | | 17 | | .EXAMPLE |
| | | 18 | | # Add license information to the default document |
| | | 19 | | Add-KrOpenApiLicense -Name 'MIT License' -Url 'https://opensource.org/licenses/MIT' -Identifier 'MIT' |
| | | 20 | | .NOTES |
| | | 21 | | This cmdlet is part of the OpenAPI module. |
| | | 22 | | #> |
| | | 23 | | function Add-KrOpenApiLicense { |
| | | 24 | | [KestrunRuntimeApi('Everywhere')] |
| | | 25 | | param( |
| | | 26 | | [Parameter(Mandatory = $false, ValueFromPipeline = $true)] |
| | | 27 | | [Kestrun.Hosting.KestrunHost]$Server, |
| | | 28 | | [Parameter()] |
| | | 29 | | [string[]]$DocId = [Kestrun.Authentication.IOpenApiAuthenticationOptions]::DefaultDocumentationIds, |
| | | 30 | | [Parameter(Mandatory)] |
| | | 31 | | [string]$Name, |
| | | 32 | | [Parameter()] |
| | | 33 | | [Uri]$Url, |
| | | 34 | | [Parameter()] |
| | | 35 | | [string]$Identifier |
| | | 36 | | ) |
| | | 37 | | begin { |
| | | 38 | | # Ensure the server instance is resolved |
| | 0 | 39 | | $Server = Resolve-KestrunServer -Server $Server |
| | | 40 | | } |
| | | 41 | | process { |
| | | 42 | | # Add the server to the specified OpenAPI documents |
| | 0 | 43 | | foreach ($doc in $DocId) { |
| | 0 | 44 | | $docDescriptor = $Server.GetOrCreateOpenApiDocument($doc) |
| | 0 | 45 | | if ($null -eq $docDescriptor.Document.Info) { |
| | | 46 | | # Initialize the Info object if null |
| | 0 | 47 | | $docDescriptor.Document.Info = [Microsoft.OpenApi.OpenApiInfo]::new() |
| | | 48 | | } |
| | 0 | 49 | | if ($null -eq $docDescriptor.Document.Info.License) { |
| | | 50 | | # Initialize the License object if null |
| | 0 | 51 | | $docDescriptor.Document.Info.License = [Microsoft.OpenApi.OpenApiLicense]::new() |
| | | 52 | | } |
| | | 53 | | # Set the license information |
| | 0 | 54 | | $docDescriptor.Document.Info.License.Name = $Name |
| | | 55 | | # Set optional properties if provided |
| | 0 | 56 | | if ($PsBoundParameters.ContainsKey('Url')) { |
| | 0 | 57 | | $docDescriptor.Document.Info.License.Url = $Url |
| | | 58 | | } |
| | 0 | 59 | | if ($PsBoundParameters.ContainsKey('Identifier')) { |
| | 0 | 60 | | $docDescriptor.Document.Info.License.Identifier = $Identifier |
| | | 61 | | } |
| | | 62 | | } |
| | | 63 | | } |
| | | 64 | | } |