Streamline management of API collections #1
@@ -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 = [];
|
||||
|
||||
+796
-235
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user