| | | 1 | | <# |
| | | 2 | | .SYNOPSIS |
| | | 3 | | Adds an OpenAPI extension to specified OpenAPI documents. |
| | | 4 | | .DESCRIPTION |
| | | 5 | | This function adds an OpenAPI extension to the specified OpenAPI documents in the Kestrun server. |
| | | 6 | | .PARAMETER Server |
| | | 7 | | The Kestrun server instance to which the OpenAPI extension 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 extension will be added. Default is 'default'. |
| | | 11 | | .PARAMETER Extensions |
| | | 12 | | A collection of OpenAPI extensions to add. |
| | | 13 | | .EXAMPLE |
| | | 14 | | # Add an extension to the default document |
| | | 15 | | $extensions = [ordered]@{ |
| | | 16 | | 'x-logo' = @{ |
| | | 17 | | 'url' = 'https://example.com/logo.png' |
| | | 18 | | 'backgroundColor' = '#FFFFFF' |
| | | 19 | | 'altText' = 'Company Logo' |
| | | 20 | | } |
| | | 21 | | } |
| | | 22 | | Add-KrOpenApiExtension -Extensions $extensions |
| | | 23 | | Adds the specified extension to the default OpenAPI document. |
| | | 24 | | .EXAMPLE |
| | | 25 | | # Add an extension to multiple documents |
| | | 26 | | $extensions = [ordered]@{ |
| | | 27 | | 'x-api-status' = 'beta' |
| | | 28 | | } |
| | | 29 | | Add-KrOpenApiExtension -DocId @('Default', 'v2') -Extensions $extensions |
| | | 30 | | Adds the specified extension to both the 'Default' and 'v2' OpenAPI documents. |
| | | 31 | | .NOTES |
| | | 32 | | This cmdlet is part of the OpenAPI module. |
| | | 33 | | #> |
| | | 34 | | function Add-KrOpenApiExtension { |
| | | 35 | | [KestrunRuntimeApi('Definition')] |
| | | 36 | | param( |
| | | 37 | | [Parameter(Mandatory = $false, ValueFromPipeline = $true)] |
| | | 38 | | [Kestrun.Hosting.KestrunHost]$Server, |
| | | 39 | | |
| | | 40 | | [Parameter()] |
| | | 41 | | [string[]]$DocId = [Kestrun.OpenApi.OpenApiDocDescriptor]::DefaultDocumentationIds, |
| | | 42 | | |
| | | 43 | | [Parameter(Mandatory = $true)] |
| | | 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 | | # Add the extension to the specified OpenAPI documents |
| | 0 | 52 | | foreach ($doc in $DocId) { |
| | 0 | 53 | | $docDescriptor = $Server.GetOrCreateOpenApiDocument($doc) |
| | 0 | 54 | | $docDescriptor.AddOpenApiExtension($Extensions) |
| | | 55 | | } |
| | | 56 | | } |
| | | 57 | | } |