Private/ConvertTo-GraphNormalizedPath.ps1
|
function ConvertTo-GraphNormalizedPath { <# .SYNOPSIS Normalizes a Microsoft Graph REST path so it can be compared across sources. .DESCRIPTION The GraphShell command catalog (from MgCommandMetadata.json) and the official OpenAPI info files spell the same operation differently. Comparing them by exact string would report thousands of false "missing cmdlet" results. This function applies the same normalization rules used by GraphShell everywhere it needs to relate a REST path across sources (Get-GraphParity, scripts/sync-graph-openapi-parity.ps1): 1. trims leading/trailing "/" and lowercases the path; 2. collapses every path parameter segment ("{application-id}", "{id}", ...) to a single "{id}" token, since parameter names differ between sources; 3. strips the "microsoft.graph." namespace prefix OpenAPI adds to OData actions and functions (the SDK uses the unqualified name, e.g. "addKey" not "microsoft.graph.addKey"); 4. removes OData function-call parentheses (e.g. "delta()" -> "delta"); 5. removes trailing "$ref", "$count" and "$value" segments, which the two sources model inconsistently for the same underlying operation. .PARAMETER Path The REST path to normalize, with or without a leading "/". .OUTPUTS System.String #> [CmdletBinding()] [OutputType([string])] param( [Parameter(Mandatory, ValueFromPipeline)] [AllowEmptyString()] [string]$Path ) process { $normalized = $Path.Trim('/').ToLowerInvariant() $normalized = $normalized -replace '\{[^}]+\}', '{id}' $normalized = $normalized -replace 'microsoft\.graph\.', '' $normalized = $normalized -replace '\(\)', '' $normalized = $normalized -replace '/\$ref$', '' $normalized = $normalized -replace '/\$count$', '' $normalized = $normalized -replace '/\$value$', '' return $normalized } } |