| | | 1 | | <# |
| | | 2 | | .SYNOPSIS |
| | | 3 | | Creates a new OpenAPI Link object. |
| | | 4 | | .DESCRIPTION |
| | | 5 | | This function creates a new OpenAPI Link object that can be used to define relationships between operations |
| | | 6 | | in an OpenAPI specification. Links allow you to specify how the output of one operation can be used as input to anot |
| | | 7 | | .PARAMETER Server |
| | | 8 | | The Kestrun server instance to which the OpenAPI link will be associated. |
| | | 9 | | If not specified, the function will attempt to resolve the current server context. |
| | | 10 | | .PARAMETER OperationRef |
| | | 11 | | A reference to an existing operation in the OpenAPI specification using a JSON Reference. |
| | | 12 | | .PARAMETER OperationId |
| | | 13 | | The operationId of an existing operation in the OpenAPI specification. |
| | | 14 | | .PARAMETER Description |
| | | 15 | | A description of the link. |
| | | 16 | | .PARAMETER OpenApiServer |
| | | 17 | | An OpenAPI Server object that specifies the server to be used for the linked operation. |
| | | 18 | | .PARAMETER Parameters |
| | | 19 | | A hashtable mapping parameter names to runtime expressions or literal objects that define the parameters for the lin |
| | | 20 | | .PARAMETER RequestBody |
| | | 21 | | A runtime expression or literal object that defines the request body for the linked operation. |
| | | 22 | | .PARAMETER Extensions |
| | | 23 | | A collection of OpenAPI extensions to add to the link. |
| | | 24 | | .EXAMPLE |
| | | 25 | | $link = New-KrOpenApiLink -OperationId "getUser" -Description "Link to get user details" -Parameters @{ "userId" = " |
| | | 26 | | This link creates a new OpenAPI Link object that links to the "getUser" operation, with a description and parameters |
| | | 27 | | .EXAMPLE |
| | | 28 | | $link = New-KrOpenApiLink -OperationRef "#/paths/~1users~1{userId}/get" -Description "Link to get user details" |
| | | 29 | | This link creates a new OpenAPI Link object that links to the operation referenced by the provided JSON Reference, w |
| | | 30 | | .OUTPUTS |
| | | 31 | | Microsoft.OpenApi.OpenApiLink object. |
| | | 32 | | .NOTES |
| | | 33 | | This function is part of the Kestrun PowerShell module for working with OpenAPI specifications. |
| | | 34 | | #> |
| | | 35 | | function New-KrOpenApiLink { |
| | | 36 | | [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '')] |
| | | 37 | | [KestrunRuntimeApi('Definition')] |
| | | 38 | | [OutputType([Microsoft.OpenApi.OpenApiLink])] |
| | | 39 | | [CmdletBinding(DefaultParameterSetName = 'ByOperationId')] |
| | | 40 | | param( |
| | | 41 | | [Parameter(Mandatory = $false, ValueFromPipeline = $true)] |
| | | 42 | | [Kestrun.Hosting.KestrunHost]$Server, |
| | | 43 | | |
| | | 44 | | [Parameter(Mandatory = $true, ParameterSetName = 'ByOperationRef')] |
| | | 45 | | [ValidateNotNullOrEmpty()] |
| | | 46 | | [string]$OperationRef, |
| | | 47 | | |
| | | 48 | | [Parameter(Mandatory = $true, ParameterSetName = 'ByOperationId')] |
| | | 49 | | [ValidateNotNullOrEmpty()] |
| | | 50 | | [string]$OperationId, |
| | | 51 | | |
| | | 52 | | [Parameter()] |
| | | 53 | | [string]$Description, |
| | | 54 | | |
| | | 55 | | [Parameter()] |
| | | 56 | | [Microsoft.OpenApi.OpenApiServer]$OpenApiServer, |
| | | 57 | | |
| | | 58 | | [Parameter()] |
| | | 59 | | [System.Collections.IDictionary]$Parameters, |
| | | 60 | | |
| | | 61 | | [Parameter()] |
| | | 62 | | [object] $RequestBody, |
| | | 63 | | |
| | | 64 | | [Parameter()] |
| | | 65 | | [System.Collections.IDictionary]$Extensions |
| | | 66 | | ) |
| | | 67 | | |
| | | 68 | | begin { |
| | | 69 | | # Ensure the server instance is resolved |
| | 0 | 70 | | $Server = Resolve-KestrunServer -Server $Server |
| | | 71 | | } |
| | | 72 | | process { |
| | | 73 | | # Create link for the specified OpenAPI document |
| | 0 | 74 | | if ($Server.OpenApiDocumentDescriptor.Count -gt 0 ) { |
| | 0 | 75 | | $docDescriptor = $Server.DefaultOpenApiDocumentDescriptor |
| | 0 | 76 | | $link = $docDescriptor.NewOpenApiLink( |
| | | 77 | | $OperationRef, |
| | | 78 | | $OperationId, |
| | | 79 | | $Description, |
| | | 80 | | $OpenApiServer, |
| | | 81 | | $Parameters, |
| | | 82 | | $RequestBody, |
| | | 83 | | $Extensions) |
| | 0 | 84 | | return $link |
| | | 85 | | } |
| | | 86 | | } |
| | | 87 | | } |