Skip to content

Commit

Permalink
interpolate collection vars in Generate Code URL
Browse files Browse the repository at this point in the history
  • Loading branch information
bhaugeea committed Jan 16, 2025
1 parent 3c8cb70 commit a23b38a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,21 @@ const GenerateCodeItem = ({ collection, item, onClose }) => {
return acc;
}, {});
}
let collectionVars = {};
let collectionRequestVars = get(collection, 'root.request.vars.req', []);
collectionRequestVars.forEach((_var) => {
if (_var.enabled) {
collectionVars[_var.name] = _var.value;
}
});

const requestUrl =
get(item, 'draft.request.url') !== undefined ? get(item, 'draft.request.url') : get(item, 'request.url');

// interpolate the url
const interpolatedUrl = interpolateUrl({
url: requestUrl,
collectionVars,
globalEnvironmentVariables,
envVars,
runtimeVariables: collection.runtimeVariables,
Expand Down
3 changes: 2 additions & 1 deletion packages/bruno-app/src/utils/url/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,13 @@ export const isValidUrl = (url) => {
}
};

export const interpolateUrl = ({ url, globalEnvironmentVariables = {}, envVars, runtimeVariables, processEnvVars }) => {
export const interpolateUrl = ({ url, globalEnvironmentVariables = {}, envVars, collectionVars = {}, runtimeVariables, processEnvVars }) => {
if (!url || !url.length || typeof url !== 'string') {
return;
}

return interpolate(url, {
...collectionVars,
...globalEnvironmentVariables,
...envVars,
...runtimeVariables,
Expand Down

0 comments on commit a23b38a

Please sign in to comment.