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
2 changed files with 817 additions and 255 deletions
Showing only changes of commit e282ab8576 - Show all commits
+41 -40
View File
@@ -199,6 +199,47 @@ function formatVariableValue(value, renderContext = {}) {
return JSON.stringify(value);
}
export function mergeRequestConfig(base, updates) {
if (!updates || typeof updates !== 'object') {
return base;
}
const merged = { ...(base || {}) };
if (Object.prototype.hasOwnProperty.call(updates, 'auth')) {
if (updates.auth === 'inherit') {
if (merged.auth && typeof merged.auth === 'object') {
merged.auth = merged.auth;
} else {
delete merged.auth;
}
} else if (typeof updates.auth === 'object' && updates.auth !== null) {
merged.auth = updates.auth;
} else {
delete merged.auth;
}
} else {
delete merged.auth;
}
if (Array.isArray(updates.variables)) {
const variables = [...(Array.isArray(base.variables) ? base.variables : [])];
const byName = new Map();
for (const variable of variables) {
if (variable && variable.name) {
byName.set(String(variable.name), variable);
}
}
for (const variable of updates.variables) {
if (variable && variable.name) {
byName.set(String(variable.name), variable);
}
}
merged.variables = [...byName.values()];
}
return merged;
}
export function getRequestConfigForFile(yamlFile, sourceDir) {
const resolved = [];
const seenFiles = new Set();
@@ -267,46 +308,6 @@ export function getRequestConfigForFile(yamlFile, sourceDir) {
return resolved.reduce((result, config) => mergeRequestConfig(result, config), {});
}
export function mergeRequestConfig(base, updates) {
if (!updates || typeof updates !== 'object') {
return base;
}
const merged = { ...(base || {}) };
if (Object.prototype.hasOwnProperty.call(updates, 'auth')) {
if (updates.auth === 'inherit') {
if (merged.auth && typeof merged.auth === 'object') {
merged.auth = merged.auth;
} else {
delete merged.auth;
}
} else if (typeof updates.auth === 'object' && updates.auth !== null) {
merged.auth = updates.auth;
} else {
delete merged.auth;
}
} else {
delete merged.auth;
}
if (Array.isArray(updates.variables)) {
const variables = [...(Array.isArray(base.variables) ? base.variables : [])];
const byName = new Map();
for (const variable of variables) {
if (variable && variable.name) {
byName.set(String(variable.name), variable);
}
}
for (const variable of updates.variables) {
if (variable && variable.name) {
byName.set(String(variable.name), variable);
}
}
merged.variables = [...byName.values()];
}
return merged;
}
export function buildRequestContent(request, requestName, requestConfig = {}, dotenvVariables = new Set()) {
const lines = [];
File diff suppressed because it is too large Load Diff