Merge pull request #4995 from pooja-bruno/fix/include-unsaved-changes-in-generate-code

fix: include unsaved changes in generate code
This commit is contained in:
lohit
2025-06-27 19:11:28 +05:30
committed by GitHub
2 changed files with 11 additions and 9 deletions

View File

@@ -16,12 +16,16 @@ export const getTreePathFromCollectionToItem = (collection, _itemUid) => {
// Resolve inherited auth by traversing up the folder hierarchy
export const resolveInheritedAuth = (item, collection) => {
const request = item.draft?.request || item.request;
const authMode = request?.auth?.mode;
const mergedRequest = {
...(item.request || {}),
...(item.draft?.request || {})
};
// If auth is not inherit or no auth defined, return the request as is
const authMode = mergedRequest.auth.mode;
// If auth is not inherit or no auth defined, return the merged request as is
if (!authMode || authMode !== 'inherit') {
return request;
return mergedRequest;
}
// Get the tree path from collection to item
@@ -43,7 +47,7 @@ export const resolveInheritedAuth = (item, collection) => {
}
return {
...request,
...mergedRequest,
auth: effectiveAuth
};
};

View File

@@ -2,7 +2,6 @@ import { buildHarRequest } from 'utils/codegenerator/har';
import { getAuthHeaders } from 'utils/codegenerator/auth';
import { getAllVariables } from 'utils/collections/index';
import { interpolateHeaders, interpolateBody, createVariablesObject } from './interpolation';
import { resolveInheritedAuth } from './auth-utils';
const generateSnippet = ({ language, item, collection, shouldInterpolate = false }) => {
try {
@@ -21,15 +20,14 @@ const generateSnippet = ({ language, item, collection, shouldInterpolate = false
processEnvVars: collection.processEnvVariables || {}
});
// Get the request with resolved auth
const request = resolveInheritedAuth(item, collection);
const request = item.request;
// Prepare headers
let headers = [...(request.headers || [])];
// Add auth headers if needed
if (request.auth && request.auth.mode !== 'none') {
const authHeaders = getAuthHeaders(request.auth, variables);
const authHeaders = getAuthHeaders(collection.root.request.auth, request.auth);
headers = [...headers, ...authHeaders];
}