update variable values generation to empty string

change autogenerated requests path to autogen/httpyac
This commit is contained in:
2026-06-30 12:24:10 +02:00
parent 42b8f337af
commit 5f7feec2a8
2 changed files with 10 additions and 12 deletions
+1 -1
View File
@@ -10,4 +10,4 @@ node_modules
Thumbs.db
# Automatically generated stuff
autodocs/**/*
autogen/**/*
+9 -11
View File
@@ -7,6 +7,7 @@ import { fileURLToPath } from 'url';
const interpolationVariableRegex = /^{{(.*?)}}$/
const DEFAULT_ENV_VAR_VALUE = 'EDIT_VALUE_HERE'
const VARIABLE_NAME_VALUE_SEPARATOR = '='
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
@@ -181,12 +182,12 @@ function parseHttpBlock(text) {
function formatVariableValue(value, renderContext = {}) {
if (value === null || value === undefined) {
return '';
return "''";
}
if (typeof value === 'string') {
if (value.trim() === '') {
return '';
return "''";
}
const renderedValue = renderContext.renderValue ? renderContext.renderValue(value) : value;
if (/\s/.test(renderedValue)) {
@@ -456,8 +457,7 @@ export function buildRequestContent(request, requestName, requestConfig = {}, do
}
}
if (requestConfig.auth)
{
if (requestConfig.auth) {
if (requestConfig.auth.type === 'bearer') {
addReferencedVariables(requestConfig.auth.token ?? '');
addHeader('Authorization', `Bearer ${renderValue(requestConfig.auth.token ?? '')}`);
@@ -479,17 +479,15 @@ export function buildRequestContent(request, requestName, requestConfig = {}, do
if (commentedVariableDefinitions.length > 0) {
lines.push(`# Other variables for ${requestName}`);
for (const variable of commentedVariableDefinitions) {
lines.push(`# ${sanitizeVarName(variable.name)} = ${formatVariableValue(variable.value, { renderValue })}`);
lines.push(`# ${sanitizeVarName(variable.name)}${VARIABLE_NAME_VALUE_SEPARATOR}${formatVariableValue(variable.value, { renderValue })}`);
}
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, { renderValue })}`);
lines.push(`@${sanitizeVarName(variable.name)}${VARIABLE_NAME_VALUE_SEPARATOR}${formatVariableValue(variable.value, { renderValue })}`);
}
lines.push('');
}
let requestBody = '';
@@ -525,9 +523,8 @@ export function buildRequestContent(request, requestName, requestConfig = {}, do
if (variableDefinitions.length > 0) {
lines.push(`# Variables for ${requestName}`);
for (const variable of variableDefinitions) {
lines.push(`@${sanitizeVarName(variable.name)} = ${formatVariableValue(variable.value, { renderValue })}`);
lines.push(`@${sanitizeVarName(variable.name)}${VARIABLE_NAME_VALUE_SEPARATOR}${formatVariableValue(variable.value, { renderValue })}`);
}
lines.push('');
}
const method = (request.method || 'GET').toUpperCase();
@@ -540,6 +537,7 @@ export function buildRequestContent(request, requestName, requestConfig = {}, do
requestUrl = `${requestUrl}${separator}${param.name}=${param.value}`;
}
lines.push('');
lines.push(`${method} ${requestUrl}`);
for (const header of headers) {
lines.push(`${header.name}: ${header.value}`);
@@ -677,7 +675,7 @@ function main() {
continue;
}
const outputRoot = path.join(workspaceRoot, 'autodocs', 'http', collection.name);
const outputRoot = path.join(workspaceRoot, 'autogen', 'httpyac', collection.name);
ensureDir(outputRoot);
const dotenvVariablesByTarget = writeEnvironmentTemplates(sourceDir, outputRoot);