| | | 1 | | <# |
| | | 2 | | .SYNOPSIS |
| | | 3 | | Creates a new OpenAPI Header object. |
| | | 4 | | .DESCRIPTION |
| | | 5 | | This cmdlet creates a new OpenAPI Header object that can be used in OpenAPI specifications. |
| | | 6 | | .PARAMETER Server |
| | | 7 | | The Kestrun server instance to use. If not specified, the default server instance is used. |
| | | 8 | | .PARAMETER Description |
| | | 9 | | A brief description of the header. |
| | | 10 | | .PARAMETER Required |
| | | 11 | | Indicates whether the header is required. |
| | | 12 | | .PARAMETER Deprecated |
| | | 13 | | Indicates whether the header is deprecated. |
| | | 14 | | .PARAMETER AllowEmptyValue |
| | | 15 | | Indicates whether the header allows empty values. |
| | | 16 | | .PARAMETER Explode |
| | | 17 | | Indicates whether the header should be exploded. |
| | | 18 | | .PARAMETER AllowReserved |
| | | 19 | | Indicates whether the header allows reserved characters. |
| | | 20 | | .PARAMETER Style |
| | | 21 | | The style of the header (e.g., simple, matrix, label, etc.). |
| | | 22 | | .PARAMETER Example |
| | | 23 | | A single example of the header value. |
| | | 24 | | .PARAMETER Examples |
| | | 25 | | A dictionary of multiple examples for the header. |
| | | 26 | | .PARAMETER Schema |
| | | 27 | | The schema defining the type of the header value. This can be a .NET type literal (e.g., [string], [int], etc.). |
| | | 28 | | .PARAMETER Content |
| | | 29 | | A dictionary representing the content of the header, mapping media types to OpenAPI MediaType objects. |
| | | 30 | | .PARAMETER Extensions |
| | | 31 | | A dictionary of OpenAPI extensions to add to the header. |
| | | 32 | | .OUTPUTS |
| | | 33 | | Microsoft.OpenApi.OpenApiHeader object. |
| | | 34 | | .EXAMPLE |
| | | 35 | | $header = New-KrOpenApiHeader -Description "Custom Header" -Required -Schema [string] |
| | | 36 | | This example creates a new OpenAPI Header object with a description, marks it as required, and sets its schema to st |
| | | 37 | | .EXAMPLE |
| | | 38 | | $content = @{ |
| | | 39 | | "application/json" = New-KrOpenApiMediaType -Schema [hashtable] |
| | | 40 | | } |
| | | 41 | | $header = New-KrOpenApiHeader -Description "JSON Header" -Content $content |
| | | 42 | | This example creates a new OpenAPI Header object with a description and sets its content to application/json with a |
| | | 43 | | .EXAMPLE |
| | | 44 | | $examples = @{ |
| | | 45 | | "example1" = New-KrOpenApiExample -Summary "Example 1" -Value "Value1" |
| | | 46 | | "example2" = New-KrOpenApiExample -Summary "Example 2" -Value "Value2" |
| | | 47 | | } |
| | | 48 | | $header = New-KrOpenApiHeader -Description "Header with Examples" -Examples $examples -Schema [string] |
| | | 49 | | This example creates a new OpenAPI Header object with a description, multiple examples, and sets its schema to strin |
| | | 50 | | .OUTPUTS |
| | | 51 | | Microsoft.OpenApi.OpenApiHeader object. |
| | | 52 | | .NOTES |
| | | 53 | | This function is part of the Kestrun PowerShell module for working with OpenAPI specifications. |
| | | 54 | | #> |
| | | 55 | | function New-KrOpenApiHeader { |
| | | 56 | | [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '')] |
| | | 57 | | [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingInvokeExpression', '')] |
| | | 58 | | [KestrunRuntimeApi('Definition')] |
| | | 59 | | [CmdletBinding(defaultParameterSetName = 'Schema')] |
| | | 60 | | [OutputType([Microsoft.OpenApi.OpenApiHeader])] |
| | | 61 | | param( |
| | | 62 | | [Parameter(Mandatory = $false, ValueFromPipeline = $true)] |
| | | 63 | | [Kestrun.Hosting.KestrunHost]$Server, |
| | | 64 | | |
| | | 65 | | [Parameter()] |
| | | 66 | | [string]$Description, |
| | | 67 | | |
| | | 68 | | [Parameter()] |
| | | 69 | | [switch]$Required, |
| | | 70 | | |
| | | 71 | | [Parameter()] |
| | | 72 | | [switch]$Deprecated, |
| | | 73 | | |
| | | 74 | | [Parameter()] |
| | | 75 | | [switch]$AllowEmptyValue, |
| | | 76 | | |
| | | 77 | | [Parameter()] |
| | | 78 | | [switch]$Explode, |
| | | 79 | | |
| | | 80 | | [Parameter()] |
| | | 81 | | [switch]$AllowReserved, |
| | | 82 | | |
| | | 83 | | [Parameter()] |
| | | 84 | | [System.Nullable[Microsoft.OpenApi.ParameterStyle]]$Style = $null, |
| | | 85 | | |
| | | 86 | | [Parameter()] |
| | | 87 | | [object]$Example, |
| | | 88 | | |
| | | 89 | | [Parameter()] |
| | | 90 | | [hashtable]$Examples, |
| | | 91 | | |
| | | 92 | | [Parameter(ParameterSetName = 'Schema')] |
| | | 93 | | [object]$Schema, |
| | | 94 | | |
| | | 95 | | [Parameter(ParameterSetName = 'Content')] |
| | | 96 | | [System.Collections.IDictionary]$Content, |
| | | 97 | | |
| | | 98 | | [Parameter()] |
| | | 99 | | [System.Collections.IDictionary]$Extensions |
| | | 100 | | ) |
| | | 101 | | begin { |
| | | 102 | | # Ensure the server instance is resolved |
| | 0 | 103 | | $Server = Resolve-KestrunServer -Server $Server |
| | 0 | 104 | | if ($PSCmdlet.ParameterSetName -eq 'Schema' -and $null -ne $Schema) { |
| | 0 | 105 | | $Schema = Resolve-KrSchemaTypeLiteral -Schema $Schema |
| | | 106 | | } |
| | | 107 | | } |
| | | 108 | | process { |
| | | 109 | | # Create header for the specified OpenAPI document |
| | 0 | 110 | | if ($Server.OpenApiDocumentDescriptor.Count -gt 0 ) { |
| | 0 | 111 | | $docDescriptor = $Server.DefaultOpenApiDocumentDescriptor |
| | 0 | 112 | | $header = $docDescriptor.NewOpenApiHeader( |
| | | 113 | | $Description, |
| | | 114 | | $Required.IsPresent, |
| | | 115 | | $Deprecated.IsPresent, |
| | | 116 | | $AllowEmptyValue.IsPresent, |
| | | 117 | | $Style, |
| | | 118 | | $Explode.IsPresent, |
| | | 119 | | $AllowReserved.IsPresent, |
| | | 120 | | $Example, |
| | | 121 | | $Examples, |
| | | 122 | | $Schema, |
| | | 123 | | $Content, |
| | | 124 | | $Extensions |
| | | 125 | | ) |
| | 0 | 126 | | return $header |
| | | 127 | | } |
| | | 128 | | } |
| | | 129 | | } |