51 lines
1.8 KiB
PowerShell
51 lines
1.8 KiB
PowerShell
param(
|
|
[string]$RouterPath = (Join-Path $PSScriptRoot "..\backend\internal\api\router.go"),
|
|
[string]$ContractPath = (Join-Path $PSScriptRoot "..\contracts\app-api.openapi.yaml")
|
|
)
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
$router = Get-Content -Raw -LiteralPath (Resolve-Path -LiteralPath $RouterPath)
|
|
$contract = Get-Content -Raw -LiteralPath (Resolve-Path -LiteralPath $ContractPath)
|
|
|
|
function Normalize-Path {
|
|
param([string]$Path)
|
|
|
|
return ($Path -replace ":id", "{executionId}")
|
|
}
|
|
|
|
$routePattern = 'router\.(GET|POST|PUT|PATCH|DELETE)\("([^"]+)"'
|
|
$routes = [regex]::Matches($router, $routePattern) | ForEach-Object {
|
|
$method = $_.Groups[1].Value.ToLowerInvariant()
|
|
$path = Normalize-Path $_.Groups[2].Value
|
|
"$method $path"
|
|
} | Sort-Object -Unique
|
|
|
|
$pathMatches = [regex]::Matches($contract, '(?m)^ (/api/[^:]+):\s*$')
|
|
$operations = New-Object System.Collections.Generic.List[string]
|
|
for ($index = 0; $index -lt $pathMatches.Count; $index++) {
|
|
$path = $pathMatches[$index].Groups[1].Value
|
|
$start = $pathMatches[$index].Index + $pathMatches[$index].Length
|
|
$end = if ($index + 1 -lt $pathMatches.Count) { $pathMatches[$index + 1].Index } else { $contract.Length }
|
|
$block = $contract.Substring($start, $end - $start)
|
|
|
|
[regex]::Matches($block, '(?m)^ (get|post|put|patch|delete):\s*$') | ForEach-Object {
|
|
$operations.Add("$($_.Groups[1].Value) $path")
|
|
}
|
|
}
|
|
|
|
$contractOperations = $operations | Sort-Object -Unique
|
|
$missing = Compare-Object -ReferenceObject $routes -DifferenceObject $contractOperations |
|
|
Where-Object { $_.SideIndicator -eq "<=" } |
|
|
Select-Object -ExpandProperty InputObject
|
|
|
|
if ($missing) {
|
|
Write-Host "OpenAPI contract is missing backend route(s):"
|
|
foreach ($route in $missing) {
|
|
Write-Host " - $route"
|
|
}
|
|
exit 1
|
|
}
|
|
|
|
Write-Host "OpenAPI contract covers all backend routes."
|