| | | 1 | | <# |
| | | 2 | | .SYNOPSIS |
| | | 3 | | Adds an OpenAPI External Documentation object to specified OpenAPI documents. |
| | | 4 | | .DESCRIPTION |
| | | 5 | | This function adds an OpenAPI External Documentation object to the specified OpenAPI documents in the Kestrun server |
| | | 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 Url |
| | | 12 | | A URI to the external documentation. |
| | | 13 | | .PARAMETER Description |
| | | 14 | | A description of the external documentation. |
| | | 15 | | .PARAMETER Extensions |
| | | 16 | | A collection of OpenAPI extensions to add to the external documentation. |
| | | 17 | | .EXAMPLE |
| | | 18 | | # Add external documentation to the default document |
| | | 19 | | Add-KrOpenApiExternalDoc -Description 'Find out more about our API here.' -Url 'https://example.com/api-docs' |
| | | 20 | | Adds external documentation with the specified description and URL to the default OpenAPI document. |
| | | 21 | | .EXAMPLE |
| | | 22 | | # Add external documentation to multiple documents |
| | | 23 | | Add-KrOpenApiExternalDoc -DocId @('Default', 'v2') -Description 'API Docs' -Url 'https://example.com/docs' |
| | | 24 | | Adds external documentation with the specified description and URL to both the 'Default' and 'v2' OpenAPI documents. |
| | | 25 | | .EXAMPLE |
| | | 26 | | # Add external documentation with extensions |
| | | 27 | | $extensions = [ordered]@{ |
| | | 28 | | 'x-doc-type' = 'comprehensive' |
| | | 29 | | 'x-contact' = 'Admin Team' |
| | | 30 | | } |
| | | 31 | | Add-KrOpenApiExternalDoc -Description 'Comprehensive API docs' -Url 'https://example.com/full-api-docs' -Extensions |
| | | 32 | | Adds external documentation with the specified description, URL, and extensions to the default OpenAPI document. |
| | | 33 | | .NOTES |
| | | 34 | | This cmdlet is part of the OpenAPI module. |
| | | 35 | | #> |
| | | 36 | | function Add-KrOpenApiExternalDoc { |
| | | 37 | | [KestrunRuntimeApi('Definition')] |
| | | 38 | | param( |
| | | 39 | | [Parameter(Mandatory = $false, ValueFromPipeline = $true)] |
| | | 40 | | [Kestrun.Hosting.KestrunHost]$Server, |
| | | 41 | | [Parameter()] |
| | | 42 | | [string[]]$DocId = [Kestrun.OpenApi.OpenApiDocDescriptor]::DefaultDocumentationIds, |
| | | 43 | | |
| | | 44 | | [Parameter(Mandatory = $true)] |
| | | 45 | | [Uri]$Url, |
| | | 46 | | |
| | | 47 | | [Parameter(Mandatory = $false)] |
| | | 48 | | [string]$Description, |
| | | 49 | | |
| | | 50 | | [Parameter()] |
| | | 51 | | [System.Collections.Specialized.OrderedDictionary]$Extensions |
| | | 52 | | ) |
| | | 53 | | begin { |
| | | 54 | | # Ensure the server instance is resolved |
| | 0 | 55 | | $Server = Resolve-KestrunServer -Server $Server |
| | | 56 | | } |
| | | 57 | | process { |
| | | 58 | | # Add the external documentation to the specified OpenAPI documents |
| | 0 | 59 | | foreach ($doc in $DocId) { |
| | 0 | 60 | | $docDescriptor = $Server.GetOrCreateOpenApiDocument($doc) |
| | 0 | 61 | | $docDescriptor.Document.ExternalDocs = $docDescriptor.CreateExternalDocs($Url, $Description, $Extensions) |
| | | 62 | | } |
| | | 63 | | } |
| | | 64 | | } |