| | | 1 | | <# |
| | | 2 | | .SYNOPSIS |
| | | 3 | | Creates a new OpenAPI External Documentation object. |
| | | 4 | | .DESCRIPTION |
| | | 5 | | This function creates a new OpenAPI External Documentation object using the provided parameters. |
| | | 6 | | .PARAMETER Server |
| | | 7 | | The Kestrun server instance to which the OpenAPI external documentation will be associated. |
| | | 8 | | If not specified, the function will attempt to resolve the current server context. |
| | | 9 | | .PARAMETER Url |
| | | 10 | | A URI to the external documentation. |
| | | 11 | | .PARAMETER Description |
| | | 12 | | A description of the external documentation. |
| | | 13 | | .PARAMETER Extensions |
| | | 14 | | A collection of OpenAPI extensions to add to the external documentation. |
| | | 15 | | .EXAMPLE |
| | | 16 | | # Create external documentation |
| | | 17 | | $externalDoc = New-KrOpenApiExternalDoc -Description 'Find out more about our API here.' -Url 'https://example.com/a |
| | | 18 | | Creates an external documentation object with the specified description and URL. |
| | | 19 | | .EXAMPLE |
| | | 20 | | # Create external documentation with extensions |
| | | 21 | | $extensions = [ordered]@{ |
| | | 22 | | 'x-doc-type' = 'comprehensive' |
| | | 23 | | 'x-contact' = 'Admin Team' |
| | | 24 | | } |
| | | 25 | | $externalDoc = New-KrOpenApiExternalDoc -Description 'Comprehensive API docs' -Url 'https://example.com/full-api-doc |
| | | 26 | | Creates an external documentation object with the specified description, URL, and extensions. |
| | | 27 | | .NOTES |
| | | 28 | | This cmdlet is part of the OpenAPI module. |
| | | 29 | | #> |
| | | 30 | | function New-KrOpenApiExternalDoc { |
| | | 31 | | [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '')] |
| | | 32 | | [KestrunRuntimeApi('Definition')] |
| | | 33 | | param( |
| | | 34 | | [Parameter(Mandatory = $false, ValueFromPipeline = $true)] |
| | | 35 | | [Kestrun.Hosting.KestrunHost]$Server, |
| | | 36 | | |
| | | 37 | | [Parameter(Mandatory = $true)] |
| | | 38 | | [Uri]$Url, |
| | | 39 | | |
| | | 40 | | [Parameter(Mandatory = $false)] |
| | | 41 | | [string]$Description, |
| | | 42 | | |
| | | 43 | | [Parameter(Mandatory = $false)] |
| | | 44 | | [System.Collections.IDictionary]$Extensions |
| | | 45 | | ) |
| | | 46 | | begin { |
| | | 47 | | # Ensure the server instance is resolved |
| | 0 | 48 | | $Server = Resolve-KestrunServer -Server $Server |
| | | 49 | | } |
| | | 50 | | process { |
| | | 51 | | # Create external documentation for the specified OpenAPI document |
| | 0 | 52 | | if ($Server.OpenApiDocumentDescriptor.Count -gt 0 ) { |
| | 0 | 53 | | $docDescriptor = $Server.DefaultOpenApiDocumentDescriptor |
| | 0 | 54 | | return $docDescriptor.CreateExternalDocs($Url, $Description, $Extensions) |
| | | 55 | | } else { |
| | 0 | 56 | | Write-KrLog -Level Warning 'New-KrOpenApiExternalDoc: No OpenAPI documents exist on the server.Create an Ope |
| | | 57 | | } |
| | | 58 | | } |
| | | 59 | | } |