major refactor

- change autogenerated folder to autodocs/httpyac
- renamed many environment variables
- add config section to env template to manage different apps
- cleanup bruno environments for easier automation of env files
- add pre-request and post-response scripts from bruno
- manage EFTL-specific scripts
- add scripts to setup json template
- add scripts to update environment files
This commit is contained in:
2026-07-14 13:32:59 +02:00
parent 09ff0cacad
commit ca9ba75c21
18 changed files with 368 additions and 88 deletions
+90 -3
View File
@@ -201,12 +201,24 @@ function Parse-HttpBlock ($text) {
$body = $http.body
}
$preRequestScript = $parsed.runtime?.scripts | Where-Object { $_.type -eq 'before-request' } | Select-Object -First 1 -ExpandProperty 'code'
# $preRequestScript = $null
# if ($parsed.runtime -and ($parsed.runtime -is [psobject] -or $parsed.runtime -is [hashtable])) {
# }
$postResponseScript = $parsed.runtime?.scripts | Where-Object { $_.type -eq 'after-response' } | Select-Object -First 1 -ExpandProperty 'code'
# $postResponseScript = $null
# if ($parsed.runtime -and ($parsed.runtime -is [psobject] -or $parsed.runtime -is [hashtable])) {
# }
return @{
method = $http.method ?? 'GET'
url = $http.url ?? ''
params = $params
headers = $headers
body = $body
preRequestScript = $preRequestScript
postResponseScript = $postResponseScript
}
}
@@ -370,7 +382,13 @@ function Get-RequestConfigForFile ($yamlFile, $sourceDir) {
$dirChain = @()
$currentDir = Split-Path -LiteralPath $yamlFile
$result = @{}
while ($true) {
if ($currentDir -match [regex]::Escape("EFTL processing")) {
$result.hasEftlProcessing = $true
}
$dirChain = ,$currentDir + $dirChain
if ($currentDir -eq $sourceDir) {
break
@@ -390,7 +408,6 @@ function Get-RequestConfigForFile ($yamlFile, $sourceDir) {
# Aggiungi il file principale
Add-File $yamlFile
$result = @{}
foreach ($config in $resolved.Value) {
$result = Merge-RequestConfig $result $config
}
@@ -513,6 +530,38 @@ function Build-RequestContent ($request, $requestName, $requestConfig = @{}, [re
})
}
function Replace-PreRequestEftlScript ($inputText) {
# Sostituisce tutto fino al primo [EFTL] con codice specifico
$processedPreRequest = ($inputText -replace '^[\s\S]*?(?=\[EFTL\])', "exports.elixBase64EftlDocument = btoa(String.raw```n")
# Sostituisce tutto fino al primo [EFTL] con codice specifico
$processedPreRequest = ($processedPreRequest -replace '(?s)(.*\[/EFTL\]).*$', "`$1`n``);")
return $processedPreRequest
}
function Add-DefaultPostResponseEftlScript {
return @"
var status = response.statusCode;
if (status !== 200) {
console.log("ERRORE HTTP! Response status code: " + status);
return;
}
var decodedDocument = "";
var response = response.parsedBody;
if (response.value.code === "ERROR") {
decodedDocument = "ERRORE EFTL!\n";
decodedDocument += response.value.description.split("\n").slice(0, 3).join("\n");
}
else {
decodedDocument = atob(response.value.processedDocument);
}
console.log(decodedDocument);
"@
}
# -------------------------
# Variabili da requestConfig
# -------------------------
@@ -679,6 +728,24 @@ function Build-RequestContent ($request, $requestName, $requestConfig = @{}, [re
}
}
# -------------------------
# Super-special treatment for requests belonging to elixForms API v2\EFTL Processing folder
# Here we blindly assume that ALL requests must be treated in the same way!
# Pre-request script is taken from the original request and manipulated so it can be integrated into the generated .http file
# -------------------------
if ($request.preRequestScript) {
$lines += ''
$lines += "{{"
$lines += "// Pre-request script"
if ($requestConfig.hasEftlProcessing) {
$lines += (Replace-PreRequestEftlScript $request.preRequestScript)
}
else {
$lines += $request.preRequestScript
}
$lines += "}}"
}
# -------------------------
# Final request line
# -------------------------
@@ -703,6 +770,26 @@ function Build-RequestContent ($request, $requestName, $requestConfig = @{}, [re
$lines += $requestBody
}
# -------------------------
# Super-special treatment for requests belonging to elixForms API v2\EFTL Processing folder
# Here we blindly assume that ALL requests must be treated in the same way!
# Post-response script is overwritten by default so it should magically work
# -------------------------
if ($requestConfig.hasEftlProcessing) {
$lines += ''
$lines += "{{"
$lines += "// Post-response script (EFTL)"
$lines += Add-DefaultPostResponseEftlScript
$lines += "}}"
}
elseif ($request.postResponseScript) {
$lines += ''
$lines += "{{"
$lines += "// Post-response script"
$lines += $request.postResponseScript
$lines += "}}"
}
return ($lines -join "`n")
}
@@ -729,7 +816,7 @@ function Clean-Folder($dir) {
Remove-Item -LiteralPath $entry.FullName -Force
}
} else {
if (!$entry.PSIsContainer -and $entry.Name -match '\.js$|\.http$|\.env\.template$') {
if (!$entry.PSIsContainer -and $entry.Name -match '\.js$|\.http$|^\.env\..*$') {
Remove-Item -LiteralPath $entry.FullName -Force
}
}
@@ -922,7 +1009,7 @@ function Invoke-Main {
throw "No collections found in workspace.yml"
}
$outputBaseRoot = Join-Path $workspaceRoot 'autogen/httpyac_ps1'
$outputBaseRoot = Join-Path $workspaceRoot 'autodocs/httpyac'
Clean-Folder $outputBaseRoot
foreach ($collection in $collections) {