| | | 1 | | <# |
| | | 2 | | .SYNOPSIS |
| | | 3 | | Adds contact information to the OpenAPI document. |
| | | 4 | | .DESCRIPTION |
| | | 5 | | This function adds contact 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 contact 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 contact information will be added. Default is 'default'. |
| | | 11 | | .PARAMETER Name |
| | | 12 | | The name of the contact person/organization. |
| | | 13 | | .PARAMETER Url |
| | | 14 | | The URL of the contact person/organization. |
| | | 15 | | .PARAMETER Email |
| | | 16 | | The email address of the contact person/organization. |
| | | 17 | | .EXAMPLE |
| | | 18 | | # Add contact information to the default document |
| | | 19 | | Add-KrOpenApiContact -Name "John Doe" -Url "https://johndoe.com" -Email "john.doe@example.com" |
| | | 20 | | .NOTES |
| | | 21 | | This cmdlet is part of the OpenAPI module. |
| | | 22 | | #> |
| | | 23 | | function Add-KrOpenApiContact { |
| | | 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()] |
| | | 31 | | [string]$Name, |
| | | 32 | | [Parameter()] |
| | | 33 | | [Uri]$Url, |
| | | 34 | | [Parameter()] |
| | | 35 | | [string]$Email |
| | | 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.Contact) { |
| | | 50 | | # Initialize the Contact object if null |
| | 0 | 51 | | $docDescriptor.Document.Info.Contact = [Microsoft.OpenApi.OpenApiContact]::new() |
| | | 52 | | } |
| | 0 | 53 | | if ($PsBoundParameters.ContainsKey('Name')) { |
| | 0 | 54 | | $docDescriptor.Document.Info.Contact.Name = $Name |
| | | 55 | | } |
| | 0 | 56 | | if ($PsBoundParameters.ContainsKey('Url')) { |
| | 0 | 57 | | $docDescriptor.Document.Info.Contact.Url = $Url |
| | | 58 | | } |
| | 0 | 59 | | if ($PsBoundParameters.ContainsKey('Email')) { |
| | 0 | 60 | | $docDescriptor.Document.Info.Contact.Email = $Email |
| | | 61 | | } |
| | | 62 | | } |
| | | 63 | | } |
| | | 64 | | } |