| | | 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 | | .PARAMETER Extensions |
| | | 18 | | A collection of OpenAPI extensions to add to the contact information. |
| | | 19 | | .EXAMPLE |
| | | 20 | | # Add contact information to the default document |
| | | 21 | | Add-KrOpenApiContact -Name "John Doe" -Url "https://johndoe.com" -Email "john.doe@example.com" |
| | | 22 | | Adds contact information with the specified name, URL, and email to the default OpenAPI document. |
| | | 23 | | .EXAMPLE |
| | | 24 | | # Add contact information to multiple documents |
| | | 25 | | Add-KrOpenApiContact -DocId @('Default', 'v2') -Name "API Support" -Email "support@example.com" |
| | | 26 | | Adds contact information with the specified name and email to both the 'Default' and 'v2' OpenAPI documents. |
| | | 27 | | .EXAMPLE |
| | | 28 | | # Add contact information with extensions |
| | | 29 | | $extensions = [ordered]@{ |
| | | 30 | | 'x-contact-type' = 'technical' |
| | | 31 | | 'x-timezone' = 'PST' |
| | | 32 | | } |
| | | 33 | | Add-KrOpenApiContact -Name "Tech Support" -Email "techsupport@example.com" -Extensions $extensions |
| | | 34 | | Adds contact information with the specified name, email, and extensions to the default OpenAPI document. |
| | | 35 | | .NOTES |
| | | 36 | | This cmdlet is part of the OpenAPI module. |
| | | 37 | | #> |
| | | 38 | | function Add-KrOpenApiContact { |
| | | 39 | | [KestrunRuntimeApi('Definition')] |
| | | 40 | | param( |
| | | 41 | | [Parameter(Mandatory = $false, ValueFromPipeline = $true)] |
| | | 42 | | [Kestrun.Hosting.KestrunHost]$Server, |
| | | 43 | | |
| | | 44 | | [Parameter()] |
| | | 45 | | [string[]]$DocId = [Kestrun.OpenApi.OpenApiDocDescriptor]::DefaultDocumentationIds, |
| | | 46 | | |
| | | 47 | | [Parameter()] |
| | | 48 | | [string]$Name, |
| | | 49 | | |
| | | 50 | | [Parameter()] |
| | | 51 | | [Uri]$Url, |
| | | 52 | | |
| | | 53 | | [Parameter()] |
| | | 54 | | [string]$Email, |
| | | 55 | | |
| | | 56 | | [Parameter()] |
| | | 57 | | [System.Collections.IDictionary]$Extensions = $null |
| | | 58 | | ) |
| | | 59 | | begin { |
| | | 60 | | # Ensure the server instance is resolved |
| | 0 | 61 | | $Server = Resolve-KestrunServer -Server $Server |
| | | 62 | | } |
| | | 63 | | process { |
| | | 64 | | # Add the server to the specified OpenAPI documents |
| | 0 | 65 | | foreach ($doc in $DocId) { |
| | 0 | 66 | | $docDescriptor = $Server.GetOrCreateOpenApiDocument($doc) |
| | 0 | 67 | | if ($null -eq $docDescriptor.Document.Info) { |
| | | 68 | | # Initialize the Info object if null |
| | 0 | 69 | | $docDescriptor.Document.Info = [Microsoft.OpenApi.OpenApiInfo]::new() |
| | | 70 | | } |
| | 0 | 71 | | $docDescriptor.Document.Info.Contact = $docDescriptor.CreateInfoContact($Name, $Url, $Email, $Extensions) |
| | | 72 | | } |
| | | 73 | | } |
| | | 74 | | } |