diff --git a/scripts/generate-http-docs.ps1 b/scripts/generate-http-docs.ps1 index 185f95f..c831801 100644 --- a/scripts/generate-http-docs.ps1 +++ b/scripts/generate-http-docs.ps1 @@ -12,7 +12,7 @@ function Find-WorkspaceRoot($startDir) { } $parent = Split-Path -Parent $current if ($parent -eq $current) { - throw "workspace.yml not found" + throw "workspace.yml not found from the provided start directory" } $current = $parent } @@ -20,7 +20,8 @@ function Find-WorkspaceRoot($startDir) { function Parse-YamlFile($path) { try { - return ConvertFrom-Yaml (Get-Content -LiteralPath $path -Raw) + $parsedYaml = ConvertFrom-Yaml (Get-Content -LiteralPath $path -Raw) + return $parsedYaml ?? @{} } catch { throw "Failed to parse YAML file $path : $_" } @@ -51,7 +52,7 @@ function Parse-Workspace($workspacePath) { if (-not $inCollections) { continue } - if (-not ($line.StartsWith(' ') -or $line.StartsWith("`t"))) { + if (-not ($line.StartsWith(' ') -or $line.StartsWith("`t"))) { # && trimmed? break } @@ -70,6 +71,33 @@ function Parse-Workspace($workspacePath) { 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+(?.+)$' + 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) { Get-ChildItem -LiteralPath $rootDir -Recurse -File -Include *.yml, *.yaml | Where-Object { $_.Name -notmatch '^\.|node_modules' } |