Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

interpolate collection variables in Generate Code URL #3825

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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