From ba01e76c750896a352cb661b718c3a978a426a79 Mon Sep 17 00:00:00 2001 From: Pier-Paolo Mammi Date: Fri, 26 Jun 2026 16:31:52 +0200 Subject: [PATCH] add disabled variables as commented and enabled as parametrized --- scripts/generate-http-docs.js | 56 +++++++++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 2 deletions(-) diff --git a/scripts/generate-http-docs.js b/scripts/generate-http-docs.js index 70271ec..5fbf1f7 100644 --- a/scripts/generate-http-docs.js +++ b/scripts/generate-http-docs.js @@ -297,6 +297,8 @@ function getRequestConfigForFile(yamlFile, sourceDir) { function buildRequestContent(request, requestName, requestConfig = {}, dotenvVariables = new Set()) { const lines = []; const variableDefinitions = []; + const commentedVariableDefinitions = []; + const parameterVariableDefinitions = []; const seenVariables = new Set(); const addVariable = (name, value) => { @@ -311,12 +313,44 @@ function buildRequestContent(request, requestName, requestConfig = {}, dotenvVar variableDefinitions.push({ name: normalized, value }); }; + const addParameterVariable = (name, value) => { + if (!name) { + return; + } + const normalized = String(name).trim(); + if (!normalized || seenVariables.has(normalized) || dotenvVariables.has(normalized)) { + return; + } + seenVariables.add(normalized); + parameterVariableDefinitions.push({ name: normalized, value }); + }; + + const addCommentedVariable = (name, value) => { + if (!name) { + return; + } + const normalized = String(name).trim(); + if (!normalized) { // || seenVariables.has(normalized) || dotenvVariables.has(normalized)) { + return; + } + // seenVariables.add(normalized); + commentedVariableDefinitions.push({ name: normalized, value }); + }; + const addReferencedVariables = (value, fallbackValue = 'YOUR_VALUE_HERE') => { for (const placeholder of collectPlaceholders(String(value))) { addVariable(placeholder, fallbackValue); } }; + const addParameterVariables = (name, value) => { + addParameterVariable(name, value); + }; + + const addCommentedVariables = (name, value) => { + addCommentedVariable(name, value); + }; + const renderValue = (value) => { if (typeof value !== 'string') { return value; @@ -364,6 +398,7 @@ function buildRequestContent(request, requestName, requestConfig = {}, dotenvVar const disabled = String(param.disabled).toLowerCase() === 'true'; if (disabled) { + addCommentedVariables(name, value); continue; } @@ -372,7 +407,8 @@ function buildRequestContent(request, requestName, requestConfig = {}, dotenvVar if (type === 'header') { headers.push({ name, value: renderValue(value) }); } else { - queryParams.push({ name, value: renderValue(value) }); + queryParams.push({ name, value: `{{${name}}}` }); + addParameterVariables(name, value); } } @@ -402,6 +438,22 @@ function buildRequestContent(request, requestName, requestConfig = {}, dotenvVar } } + if (commentedVariableDefinitions.length > 0) { + lines.push(`# Other variables for ${requestName}`); + for (const variable of commentedVariableDefinitions) { + lines.push(`# ${sanitizeVarName(variable.name)} = ${formatVariableValue(variable.value)}`); + } + lines.push(''); + } + + if (parameterVariableDefinitions.length > 0) { + lines.push(`# Parameter variables for ${requestName}`); + for (const variable of parameterVariableDefinitions) { + lines.push(`@${sanitizeVarName(variable.name)} = ${formatVariableValue(variable.value)}`); + } + lines.push(''); + } + if (variableDefinitions.length > 0) { lines.push(`# Variables for ${requestName}`); for (const variable of variableDefinitions) { @@ -524,7 +576,7 @@ function writeEnvironmentTemplates(sourceDir, outputRoot) { } } - const templateContent = variableNames.length > 0 ? `${variableNames.map(v => `${v}={{${v}}}`).join('\n')}\n` : ''; + const templateContent = variableNames.length > 0 ? `${variableNames.map(v => `${v}=EDIT_VALUE_HERE`).join('\n')}\n` : ''; fs.writeFileSync(path.join(targetDir, '.env.template'), templateContent, 'utf8'); dotenvVariablesByTarget.set(targetDir, new Set(variableNames)); }