Streamline management of API collections #1

Merged
administrator merged 43 commits from feature/script-autogenerate-http into main 2026-08-19 14:54:42 +02:00
Showing only changes of commit bdaef511f3 - Show all commits
+31 -3
View File
@@ -12,7 +12,7 @@ function Find-WorkspaceRoot($startDir) {
} }
$parent = Split-Path -Parent $current $parent = Split-Path -Parent $current
if ($parent -eq $current) { if ($parent -eq $current) {
throw "workspace.yml not found" throw "workspace.yml not found from the provided start directory"
} }
$current = $parent $current = $parent
} }
@@ -20,7 +20,8 @@ function Find-WorkspaceRoot($startDir) {
function Parse-YamlFile($path) { function Parse-YamlFile($path) {
try { try {
return ConvertFrom-Yaml (Get-Content -LiteralPath $path -Raw) $parsedYaml = ConvertFrom-Yaml (Get-Content -LiteralPath $path -Raw)
return $parsedYaml ?? @{}
} catch { } catch {
throw "Failed to parse YAML file $path : $_" throw "Failed to parse YAML file $path : $_"
} }
@@ -51,7 +52,7 @@ function Parse-Workspace($workspacePath) {
if (-not $inCollections) { continue } if (-not $inCollections) { continue }
if (-not ($line.StartsWith(' ') -or $line.StartsWith("`t"))) { if (-not ($line.StartsWith(' ') -or $line.StartsWith("`t"))) { # && trimmed?
break break
} }
@@ -70,6 +71,33 @@ function Parse-Workspace($workspacePath) {
return @{ collections = $collections } return @{ collections = $collections }
} }
function Sanitize-VariableName([string]$name) {
$sanitized = $name.Trim()
-replace '[{}]',''
-replace '[^A-Za-z0-9_]','_'
-replace '^([0-9])','_$1'
return $sanitized ?? 'value'
}
function Parse-PlaceholderContent([string]$content) {
$trimmed = $content.Trim();
$dotenvMatch = $trimmed -imatch '^\$dotenv\s+(?<matched>.+)$'
if ($dotenvMatch) {
return @{ name = $Matches.matched.Trim(); isDotEnv = true }
}
return @{ name = $trimmed; isDotEnv = false }
}
function Collect-Placeholders($value) {
# if (typeof value !== 'string') {
# return [];
# }
$placeholders = @()
$placeholders = Select-String "\{\{([^{}]+)\}\}" -InputObject $value -AllMatches | ForEach-Object matches | ForEach-Object (Parse-PlaceholderContent Value)
return $placeholders
}
function Walk-YamlFiles($rootDir) { function Walk-YamlFiles($rootDir) {
Get-ChildItem -LiteralPath $rootDir -Recurse -File -Include *.yml, *.yaml | Get-ChildItem -LiteralPath $rootDir -Recurse -File -Include *.yml, *.yaml |
Where-Object { $_.Name -notmatch '^\.|node_modules' } | Where-Object { $_.Name -notmatch '^\.|node_modules' } |