| | | 1 | | <# |
| | | 2 | | .SYNOPSIS |
| | | 3 | | Adds external documentation to the OpenAPI document. |
| | | 4 | | .DESCRIPTION |
| | | 5 | | This function adds external documentation to the OpenAPI document using the provided parameters in the specified Ope |
| | | 6 | | .PARAMETER Server |
| | | 7 | | The Kestrun server instance to which the OpenAPI external documentation 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 external documentation will be added. Default is 'default'. |
| | | 11 | | .PARAMETER Description |
| | | 12 | | A description of the external documentation. |
| | | 13 | | .PARAMETER Url |
| | | 14 | | A URI to the external documentation. |
| | | 15 | | .EXAMPLE |
| | | 16 | | # Add external documentation to the default document |
| | | 17 | | Add-KrOpenApiExternalDoc -Description 'Find out more about our API here.' -Url 'https://example.com/api-docs' |
| | | 18 | | .NOTES |
| | | 19 | | This cmdlet is part of the OpenAPI module. |
| | | 20 | | #> |
| | | 21 | | function Add-KrOpenApiExternalDoc { |
| | | 22 | | [KestrunRuntimeApi('Everywhere')] |
| | | 23 | | param( |
| | | 24 | | [Parameter(Mandatory = $false, ValueFromPipeline = $true)] |
| | | 25 | | [Kestrun.Hosting.KestrunHost]$Server, |
| | | 26 | | [Parameter()] |
| | | 27 | | [string[]]$DocId = [Kestrun.Authentication.IOpenApiAuthenticationOptions]::DefaultDocumentationIds, |
| | | 28 | | [Parameter(Mandatory = $true)] |
| | | 29 | | [string]$Description, |
| | | 30 | | [Parameter(Mandatory = $true)] |
| | | 31 | | [Uri]$Url |
| | | 32 | | ) |
| | | 33 | | begin { |
| | | 34 | | # Ensure the server instance is resolved |
| | 0 | 35 | | $Server = Resolve-KestrunServer -Server $Server |
| | | 36 | | } |
| | | 37 | | process { |
| | | 38 | | # Add the server to the specified OpenAPI documents |
| | 0 | 39 | | foreach ($doc in $DocId) { |
| | 0 | 40 | | $docDescriptor = $Server.GetOrCreateOpenApiDocument($doc) |
| | 0 | 41 | | $docDescriptor.Document.ExternalDocs = [Microsoft.OpenApi.OpenApiExternalDocs]::new() |
| | | 42 | | |
| | 0 | 43 | | if ($PsBoundParameters.ContainsKey('Description')) { |
| | 0 | 44 | | $docDescriptor.Document.ExternalDocs.Description = $Description |
| | | 45 | | } |
| | 0 | 46 | | if ($PsBoundParameters.ContainsKey('Url')) { |
| | 0 | 47 | | $docDescriptor.Document.ExternalDocs.Url = $Url |
| | | 48 | | } |
| | | 49 | | } |
| | | 50 | | } |
| | | 51 | | } |