| | | 1 | | <# |
| | | 2 | | .SYNOPSIS |
| | | 3 | | Merges two MapRouteOptions objects. |
| | | 4 | | .DESCRIPTION |
| | | 5 | | This function takes two MapRouteOptions objects and merges them into a single object. |
| | | 6 | | The properties from the parent object will be preserved, and the properties from the child |
| | | 7 | | object will override any matching properties in the parent object. |
| | | 8 | | .PARAMETER Parent |
| | | 9 | | The parent MapRouteOptions object. |
| | | 10 | | .PARAMETER Child |
| | | 11 | | The child MapRouteOptions object. |
| | | 12 | | .OUTPUTS |
| | | 13 | | Kestrun.Hosting.Options.MapRouteOptions |
| | | 14 | | #> |
| | | 15 | | function _KrMerge-MRO { |
| | | 16 | | [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseApprovedVerbs', '')] |
| | | 17 | | param( |
| | | 18 | | [Parameter(Mandatory)][Kestrun.Hosting.Options.MapRouteOptions]$Parent, |
| | | 19 | | [Parameter(Mandatory)][Kestrun.Hosting.Options.MapRouteOptions]$Child |
| | | 20 | | ) |
| | 0 | 21 | | $pattern = if ($Child.Pattern) { |
| | 0 | 22 | | if ($Parent.Pattern) { "$($Parent.Pattern)/$($Child.Pattern)" } else { $Child.Pattern } |
| | 0 | 23 | | } else { $Parent.Pattern } |
| | | 24 | | |
| | 0 | 25 | | $extraRefs = if ($null -ne $Child.ScriptCode.ExtraRefs) { |
| | 0 | 26 | | if ($Parent.ScriptCode.ExtraRefs) { |
| | 0 | 27 | | $Parent.ScriptCode.ExtraRefs + $Child.ScriptCode.ExtraRefs |
| | | 28 | | } else { |
| | 0 | 29 | | $Child.ScriptCode.ExtraRefs |
| | | 30 | | } |
| | 0 | 31 | | } else { $Parent.ScriptCode.ExtraRefs } |
| | | 32 | | |
| | 0 | 33 | | $merged = @{ |
| | 0 | 34 | | Pattern = $pattern.Replace('//', '/') |
| | 0 | 35 | | HttpVerbs = if ($null -ne $Child.HttpVerbs -and ($Child.HttpVerbs.Count -gt 0)) { $Child.HttpVerbs } else { $Par |
| | 0 | 36 | | RequireSchemes = _KrMerge-Unique $Parent.RequireSchemes $Child.RequireSchemes |
| | 0 | 37 | | RequirePolicies = _KrMerge-Unique $Parent.RequirePolicies $Child.RequirePolicies |
| | 0 | 38 | | CorsPolicyName = if ($Child.CorsPolicyName) { $Child.CorsPolicyName } else { $Parent.CorsPolicyName } |
| | 0 | 39 | | OpenAPI = if ($Child.OpenAPI) { $Child.OpenAPI } else { $Parent.OpenAPI } |
| | 0 | 40 | | ThrowOnDuplicate = $Child.ThrowOnDuplicate -or $Parent.ThrowOnDuplicate |
| | 0 | 41 | | ScriptCode = @{ |
| | 0 | 42 | | Code = if ($Child.ScriptCode.Code) { $Child.ScriptCode.Code } else { $Parent.ScriptCode.Code } |
| | 0 | 43 | | Language = if ($null -ne $Child.ScriptCode.Language) { $Child.ScriptCode.Language } else { $Parent.ScriptCod |
| | 0 | 44 | | ExtraImports = _KrMerge-Unique $Parent.ScriptCode.ExtraImports $Child.ScriptCode.ExtraImports |
| | 0 | 45 | | ExtraRefs = $extraRefs |
| | 0 | 46 | | Arguments = _KrMerge-Args $Parent.ScriptCode.Arguments $Child.ScriptCode.Arguments |
| | | 47 | | } |
| | | 48 | | } |
| | 0 | 49 | | return New-KrMapRouteOption -Property $merged |
| | | 50 | | } |
| | | 51 | | |