| | 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 | | ) |
| 1 | 21 | | $pattern = if ($Child.Pattern) { |
| 4 | 22 | | if ($Parent.Pattern) { "$($Parent.Pattern)/$($Child.Pattern)" } else { $Child.Pattern } |
| 0 | 23 | | } else { $Parent.Pattern } |
| | 24 | |
|
| 1 | 25 | | $extraRefs = if ($null -ne $Child.ExtraRefs) { |
| 0 | 26 | | if ($Parent.ExtraRefs) { |
| 0 | 27 | | $Parent.ExtraRefs + $Child.ExtraRefs |
| | 28 | | } else { |
| 0 | 29 | | $Child.ExtraRefs |
| | 30 | | } |
| 1 | 31 | | } else { $Parent.ExtraRefs } |
| | 32 | |
|
| 1 | 33 | | $merged = @{ |
| 1 | 34 | | Pattern = $pattern.Replace('//', '/') |
| 4 | 35 | | HttpVerbs = if ($null -ne $Child.HttpVerbs -and ($Child.HttpVerbs.Count -gt 0)) { $Child.HttpVerbs } else { $Par |
| 3 | 36 | | Code = if ($Child.Code) { $Child.Code } else { $Parent.Code } |
| 2 | 37 | | Language = if ($null -ne $Child.Language) { $Child.Language } else { $Parent.Language } |
| 1 | 38 | | ExtraImports = _KrMerge-Unique $Parent.ExtraImports $Child.ExtraImports |
| 1 | 39 | | ExtraRefs = $extraRefs |
| 1 | 40 | | RequireSchemes = _KrMerge-Unique $Parent.RequireSchemes $Child.RequireSchemes |
| 1 | 41 | | RequirePolicies = _KrMerge-Unique $Parent.RequirePolicies $Child.RequirePolicies |
| 2 | 42 | | CorsPolicyName = if ($Child.CorsPolicyName) { $Child.CorsPolicyName } else { $Parent.CorsPolicyName } |
| 1 | 43 | | Arguments = _KrMerge-Args $Parent.Arguments $Child.Arguments |
| 2 | 44 | | OpenAPI = if ($Child.OpenAPI) { $Child.OpenAPI } else { $Parent.OpenAPI } |
| 1 | 45 | | ThrowOnDuplicate = $Child.ThrowOnDuplicate -or $Parent.ThrowOnDuplicate |
| | 46 | | } |
| 1 | 47 | | return New-KrMapRouteOption -Property $merged |
| | 48 | | } |
| | 49 | |
|