Skip to content

feat: enable variable interpolation in URL field for code generation#6394

Draft
Pragadesh-45 wants to merge 2 commits intousebruno:mainfrom
Pragadesh-45:fix/6365
Draft

feat: enable variable interpolation in URL field for code generation#6394
Pragadesh-45 wants to merge 2 commits intousebruno:mainfrom
Pragadesh-45:fix/6365

Conversation

@Pragadesh-45
Copy link
Copy Markdown
Contributor

@Pragadesh-45 Pragadesh-45 commented Dec 12, 2025

fixes: #6365

Description

This PR introduces support for variable interpolation in the URL field during code generation. This allows dynamic values to be inserted into URLs, enabling more flexible and customizable code generation processes. With this feature, users can now define variables in the URL field that get replaced with actual values at runtime

Contribution Checklist:

  • I've used AI significantly to create this pull request
  • The pull request only addresses one issue or adds one feature.
  • The pull request does not introduce any breaking changes
  • I have added screenshots or gifs to help explain the change if applicable.
  • I have read the contribution guidelines.
  • Create an issue and link to the pull request.

Before:
image
image

After:
image

Summary by CodeRabbit

  • New Features
    • Path parameters in URLs are now interpolated from collection variables and then normalized/encoded, so endpoints reflect substituted values.
  • Bug Fixes
    • Added input validation and early-exit guards for URL interpolation to better handle missing or invalid inputs.
  • Tests
    • Added tests covering path-param interpolation, variable substitution flow, and multiple-parameter scenarios.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Dec 12, 2025

Walkthrough

Adds URL interpolation and normalization to the code-snippet generator and hardens URL utils with input guards; expands tests to cover interpolation of path params that reference collection variables.

Changes

Cohort / File(s) Summary
URL utilities
packages/bruno-app/src/utils/url/index.js, packages/bruno-app/src/utils/url/index.spec.js
Added normalizeAndEncodeUrl(url); added early-return guards in interpolateUrlPathParams for falsy/non-string URLs, empty params, and no enabled path params. Added tests covering path-param replacement and full interpolation flows.
Snippet generator & tests
packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/GenerateCodeItem/utils/snippet-generator.js, packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/GenerateCodeItem/utils/snippet-generator.spec.js
Use defensive copy of request; apply interpolateUrl when shouldInterpolate is true and then normalizeAndEncodeUrl; ensure URL interpolation/normalization precedes header/body interpolation. Updated/added tests to expect interpolated URLs and path-param interpolation via collection variables.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

size/M

Suggested reviewers

  • helloanoop
  • lohit-bruno
  • naman-bruno

Poem

URLs once templated, now refined,
Path params find the vars assigned,
Snippets sing with normalized grace,
Tests confirm the matching place,
🎉 interpolation wins the race

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the primary change: enabling variable interpolation in the URL field during code generation.
Linked Issues check ✅ Passed The PR directly addresses issue #6365 by implementing URL variable interpolation and normalization to fix cURL code generation failures when URLs contain collection variables.
Out of Scope Changes check ✅ Passed All changes are scoped to supporting variable interpolation in URLs for code generation; no unrelated modifications detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e37ab4a and 711829f.

📒 Files selected for processing (2)
  • packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/GenerateCodeItem/utils/snippet-generator.js
  • packages/bruno-app/src/utils/url/index.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/bruno-app/src/utils/url/index.js
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit inference engine (CODING_STANDARDS.md)

**/*.{js,jsx,ts,tsx}: Use 2 spaces for indentation. No tabs, just spaces
Stick to single quotes for strings. For JSX/TSX attributes, use double quotes (e.g., )
Always add semicolons at the end of statements
No trailing commas
Always use parentheses around parameters in arrow functions, even for single params
For multiline constructs, put opening braces on the same line, and ensure consistency. Minimum 2 elements for multiline
No newlines inside function parentheses
Space before and after the arrow in arrow functions. () => {} is good
No space between function name and parentheses. func() not func ()
Semicolons go at the end of the line, not on a new line
Names for functions need to be concise and descriptive
Add in JSDoc comments to add more details to the abstractions if needed
Add in meaningful comments instead of obvious ones where complex code flow is explained properly

Files:

  • packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/GenerateCodeItem/utils/snippet-generator.js
🧠 Learnings (1)
📚 Learning: 2025-12-17T21:41:24.730Z
Learnt from: naman-bruno
Repo: usebruno/bruno PR: 6407
File: packages/bruno-app/src/components/Environments/ConfirmCloseEnvironment/index.js:5-41
Timestamp: 2025-12-17T21:41:24.730Z
Learning: Do not suggest PropTypes validation for React components in the Bruno codebase. The project does not use PropTypes, so reviews should avoid proposing PropTypes and rely on the existing typing/validation approach (e.g., TypeScript or alternative runtime checks) if applicable. This guideline applies broadly to all JavaScript/JSX components in the repo.

Applied to files:

  • packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/GenerateCodeItem/utils/snippet-generator.js
🧬 Code graph analysis (1)
packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/GenerateCodeItem/utils/snippet-generator.js (1)
packages/bruno-app/src/utils/url/index.js (4)
  • interpolateUrl (93-99)
  • interpolateUrl (93-99)
  • normalizeAndEncodeUrl (101-129)
  • normalizeAndEncodeUrl (101-129)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: Unit Tests
  • GitHub Check: Playwright E2E Tests
  • GitHub Check: SSL Tests - Linux
  • GitHub Check: CLI Tests
  • GitHub Check: SSL Tests - Windows
  • GitHub Check: SSL Tests - macOS
🔇 Additional comments (2)
packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/GenerateCodeItem/utils/snippet-generator.js (2)

5-5: LGTM: Import statements are correct.

The imports for URL interpolation and normalization utilities are properly added and match their usage in the interpolation block.


15-15: Good defensive practice.

Creating a shallow copy prevents mutation of the original request object, which is appropriate for the top-level property modifications made in this function.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
packages/bruno-app/src/utils/url/index.js (1)

101-164: Add input guards/defaults to prevent crashes when url/params are missing.
Right now interpolateUrlPathParams() will throw if url is undefined (e.g., interpolateUrl() returns undefined) or if params is not an array.

-export const interpolateUrlPathParams = (url, params, variables) => {
+export const interpolateUrlPathParams = (url, params = [], variables) => {
+  if (!url || typeof url !== 'string') {
+    return url;
+  }
+  const originalUrl = url;

   const getInterpolatedBasePath = (pathname, params) => {
     return pathname
       .split('/')
       .map((segment) => {
         // traditional path parameters
         if (segment.startsWith(':')) {
           const name = segment.slice(1);
           const pathParam = params.find((p) => p?.name === name && p?.type === 'path');
           if (pathParam) {
-            const value = variables ? interpolate(pathParam.value, variables) : pathParam.value;
-            return value;
+            const value = variables ? interpolate(pathParam.value, variables) : pathParam.value;
+            return value ?? segment;
           }
           return segment;
         }
@@
   try {
     uri = new URL(url);
   } catch (error) {
     // if the URL is invalid, return the URL as is
-    return url;
+    return originalUrl;
   }
@@
-  return `${uri.origin}${basePath}${uri?.search || ''}`;
+  return `${uri.origin}${basePath}${uri?.search || ''}${uri?.hash || ''}`;
 };
packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/GenerateCodeItem/index.js (1)

90-100: Guard against interpolatedUrl being undefined before path-param interpolation.
interpolateUrl() can return undefined (non-string/empty), so passing it through can break this flow (or show “Invalid URL: undefined”).

-  const interpolatedUrl = interpolateUrl({
+  const interpolatedUrl = interpolateUrl({
     url: requestData.url,
     variables
-  });
+  }) || requestData.url;

   // interpolate the path params
   const finalUrl = interpolateUrlPathParams(
     interpolatedUrl,
     requestData.params,
     variables
   );
🧹 Nitpick comments (2)
packages/bruno-app/src/utils/url/index.js (1)

110-143: Consider honoring enabled for path params (if the data model expects it).
You already check p?.type === 'path, but if disabled params exist, this will still interpolate them.

packages/bruno-app/src/utils/url/index.spec.js (1)

352-385: Optional: add a variables-based test for OData-style (:param) segments.
This would lock in the new interpolation path for the parentheses case too.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2f5537c and deb7f52.

📒 Files selected for processing (4)
  • packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/GenerateCodeItem/index.js (1 hunks)
  • packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/GenerateCodeItem/utils/snippet-generator.spec.js (1 hunks)
  • packages/bruno-app/src/utils/url/index.js (3 hunks)
  • packages/bruno-app/src/utils/url/index.spec.js (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit inference engine (CODING_STANDARDS.md)

**/*.{js,jsx,ts,tsx}: Use 2 spaces for indentation. No tabs, just spaces
Stick to single quotes for strings. For JSX/TSX attributes, use double quotes (e.g., )
Always add semicolons at the end of statements
No trailing commas
Always use parentheses around parameters in arrow functions, even for single params
For multiline constructs, put opening braces on the same line, and ensure consistency. Minimum 2 elements for multiline
No newlines inside function parentheses
Space before and after the arrow in arrow functions. () => {} is good
No space between function name and parentheses. func() not func ()
Semicolons go at the end of the line, not on a new line
Names for functions need to be concise and descriptive
Add in JSDoc comments to add more details to the abstractions if needed
Add in meaningful comments instead of obvious ones where complex code flow is explained properly

Files:

  • packages/bruno-app/src/utils/url/index.spec.js
  • packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/GenerateCodeItem/index.js
  • packages/bruno-app/src/utils/url/index.js
  • packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/GenerateCodeItem/utils/snippet-generator.spec.js
🧠 Learnings (1)
📚 Learning: 2025-12-05T20:31:33.005Z
Learnt from: CR
Repo: usebruno/bruno PR: 0
File: CODING_STANDARDS.md:0-0
Timestamp: 2025-12-05T20:31:33.005Z
Learning: Applies to **/*.test.{js,jsx,ts,tsx} : Add tests for any new functionality or meaningful changes. If code is added, removed, or significantly modified, corresponding tests should be updated or created

Applied to files:

  • packages/bruno-app/src/utils/url/index.spec.js
  • packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/GenerateCodeItem/utils/snippet-generator.spec.js
🧬 Code graph analysis (2)
packages/bruno-app/src/utils/url/index.spec.js (1)
packages/bruno-app/src/utils/url/index.js (2)
  • interpolateUrlPathParams (101-164)
  • interpolateUrlPathParams (101-164)
packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/GenerateCodeItem/utils/snippet-generator.spec.js (1)
packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/GenerateCodeItem/utils/snippet-generator.js (2)
  • result (43-43)
  • generateSnippet (7-50)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: SSL Tests - macOS
  • GitHub Check: SSL Tests - Linux
  • GitHub Check: Unit Tests
  • GitHub Check: CLI Tests
  • GitHub Check: Playwright E2E Tests
  • GitHub Check: SSL Tests - Windows
🔇 Additional comments (1)
packages/bruno-app/src/utils/url/index.spec.js (1)

352-385: Nice coverage for the new variables behavior (with and without variables).
These tests directly validate the new signature + interpolation semantics.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between deb7f52 and 713d945.

📒 Files selected for processing (1)
  • packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/GenerateCodeItem/utils/snippet-generator.spec.js (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit inference engine (CODING_STANDARDS.md)

**/*.{js,jsx,ts,tsx}: Use 2 spaces for indentation. No tabs, just spaces
Stick to single quotes for strings. For JSX/TSX attributes, use double quotes (e.g., )
Always add semicolons at the end of statements
No trailing commas
Always use parentheses around parameters in arrow functions, even for single params
For multiline constructs, put opening braces on the same line, and ensure consistency. Minimum 2 elements for multiline
No newlines inside function parentheses
Space before and after the arrow in arrow functions. () => {} is good
No space between function name and parentheses. func() not func ()
Semicolons go at the end of the line, not on a new line
Names for functions need to be concise and descriptive
Add in JSDoc comments to add more details to the abstractions if needed
Add in meaningful comments instead of obvious ones where complex code flow is explained properly

Files:

  • packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/GenerateCodeItem/utils/snippet-generator.spec.js
🧠 Learnings (1)
📚 Learning: 2025-12-05T20:31:33.005Z
Learnt from: CR
Repo: usebruno/bruno PR: 0
File: CODING_STANDARDS.md:0-0
Timestamp: 2025-12-05T20:31:33.005Z
Learning: Applies to **/*.test.{js,jsx,ts,tsx} : Add tests for any new functionality or meaningful changes. If code is added, removed, or significantly modified, corresponding tests should be updated or created

Applied to files:

  • packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/GenerateCodeItem/utils/snippet-generator.spec.js
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: SSL Tests - Windows
  • GitHub Check: SSL Tests - Linux
  • GitHub Check: SSL Tests - macOS
  • GitHub Check: Unit Tests
  • GitHub Check: Playwright E2E Tests
  • GitHub Check: CLI Tests

bijin-bruno
bijin-bruno previously approved these changes Dec 22, 2025
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 05e131d and 26c5fe1.

📒 Files selected for processing (5)
  • packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/GenerateCodeItem/index.js
  • packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/GenerateCodeItem/utils/snippet-generator.js
  • packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/GenerateCodeItem/utils/snippet-generator.spec.js
  • packages/bruno-app/src/utils/url/index.js
  • packages/bruno-app/src/utils/url/index.spec.js
🚧 Files skipped from review as they are similar to previous changes (3)
  • packages/bruno-app/src/utils/url/index.spec.js
  • packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/GenerateCodeItem/utils/snippet-generator.spec.js
  • packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/GenerateCodeItem/index.js
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit inference engine (CODING_STANDARDS.md)

**/*.{js,jsx,ts,tsx}: Use 2 spaces for indentation. No tabs, just spaces
Stick to single quotes for strings. For JSX/TSX attributes, use double quotes (e.g., )
Always add semicolons at the end of statements
No trailing commas
Always use parentheses around parameters in arrow functions, even for single params
For multiline constructs, put opening braces on the same line, and ensure consistency. Minimum 2 elements for multiline
No newlines inside function parentheses
Space before and after the arrow in arrow functions. () => {} is good
No space between function name and parentheses. func() not func ()
Semicolons go at the end of the line, not on a new line
Names for functions need to be concise and descriptive
Add in JSDoc comments to add more details to the abstractions if needed
Add in meaningful comments instead of obvious ones where complex code flow is explained properly

Files:

  • packages/bruno-app/src/utils/url/index.js
  • packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/GenerateCodeItem/utils/snippet-generator.js
🧠 Learnings (1)
📚 Learning: 2025-12-17T21:41:24.730Z
Learnt from: naman-bruno
Repo: usebruno/bruno PR: 6407
File: packages/bruno-app/src/components/Environments/ConfirmCloseEnvironment/index.js:5-41
Timestamp: 2025-12-17T21:41:24.730Z
Learning: Do not suggest PropTypes validation for React components in the Bruno codebase. The project does not use PropTypes, so reviews should avoid proposing PropTypes and rely on the existing typing/validation approach (e.g., TypeScript or alternative runtime checks) if applicable. This guideline applies broadly to all JavaScript/JSX components in the repo.

Applied to files:

  • packages/bruno-app/src/utils/url/index.js
  • packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/GenerateCodeItem/utils/snippet-generator.js
🧬 Code graph analysis (1)
packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/GenerateCodeItem/utils/snippet-generator.js (1)
packages/bruno-app/src/utils/url/index.js (2)
  • interpolateUrlPathParams (101-174)
  • interpolateUrlPathParams (101-174)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: SSL Tests - macOS
  • GitHub Check: SSL Tests - Windows
  • GitHub Check: SSL Tests - Linux
  • GitHub Check: Unit Tests
  • GitHub Check: Playwright E2E Tests
  • GitHub Check: CLI Tests
🔇 Additional comments (8)
packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/GenerateCodeItem/utils/snippet-generator.js (3)

5-5: LGTM!

Import added correctly to support path parameter interpolation.


15-15: Good defensive programming!

Creating a shallow copy prevents mutation of the original item.request object, which is the correct approach here.


28-35: LGTM!

Path parameter interpolation is correctly integrated into the interpolation flow. The ordering (path params → headers → body) is logical and the implementation properly passes variables through the interpolation chain.

packages/bruno-app/src/utils/url/index.js (5)

101-104: Good input validation!

Adding defensive checks for falsy or non-string URLs prevents potential errors downstream.


107-109: Good optimization!

Early return when no path params are enabled avoids unnecessary URL parsing and processing.


120-124: LGTM!

The interpolation logic correctly handles both variable-based and direct value substitution, with proper fallback to the original segment when values are missing.


148-150: LGTM!

OData-style parameter interpolation correctly mirrors the traditional path param logic with proper variable support.


173-173: Good fix!

Including the hash fragment ensures the complete URL is preserved during interpolation, addressing the requirement from the commit message.

Comment on lines +106 to +110
// If there are no enabled path params, return the URL as-is to avoid URL encoding side
const hasPathParams = params.some((p) => p?.type === 'path' && p?.enabled);
if (!hasPathParams) {
return url;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Fix the incomplete comment.

The comment "to avoid URL encoding side" appears incomplete. Consider: "to avoid URL encoding side effects" or "to avoid unnecessary URL encoding".

🔎 Suggested fix
-  // If there are no enabled path params, return the URL as-is to avoid URL encoding side
+  // If there are no enabled path params, return the URL as-is to avoid unnecessary URL encoding
🤖 Prompt for AI Agents
In packages/bruno-app/src/utils/url/index.js around lines 106 to 110, the inline
comment "to avoid URL encoding side" is incomplete; update it to a clear,
complete phrase such as "to avoid URL encoding side effects" or "to avoid
unnecessary URL encoding" so the intent is unambiguous (replace the current
comment text only; no code changes).

// Interpolate headers, body and path params if needed
if (shouldInterpolate) {
// Interpolate path parameters
request.url = interpolateUrlPathParams(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per current implementation,

  1. I think the interpolateUrlPathParams shouldn't be done here since it is expected to be resolved already from the parent component GenerateCodeItem.
  2. Considering the above fact, variable interpolation shouldn't happen inside interpolateUrlPathParams since it should respect the setting called shouldInterpolate. interpolateUrlPathParams should only interpolate the path params.
  3. I think we should revert other changes in this PR and just do interpolateUrl here.
request.url = interpolateUrl(request.url, variables);

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/GenerateCodeItem/utils/snippet-generator.spec.js (1)

430-477: Well-structured test for issue #6365.

The test properly validates that the snippet generator interpolates collection variables in URLs. The explanatory comment (lines 431-433) clearly documents the design decision to test the snippet generator's responsibility in isolation.

Optional: Consider more precise assertion

The current assertions using toContain are sufficient, but you could make them more precise by checking the exact output:

-    // The URL should have the interpolated variable value
-    expect(result).toContain('https://api.example.com/en');
-    // And not contain the variable placeholder
-    expect(result).not.toContain('{{current_language}}');
+    expect(result).toBe('curl -X GET https://api.example.com/en');

This matches the pattern used in other tests and validates the complete output structure.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 26c5fe1 and e37ab4a.

📒 Files selected for processing (4)
  • packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/GenerateCodeItem/utils/snippet-generator.js
  • packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/GenerateCodeItem/utils/snippet-generator.spec.js
  • packages/bruno-app/src/utils/url/index.js
  • packages/bruno-app/src/utils/url/index.spec.js
🚧 Files skipped from review as they are similar to previous changes (3)
  • packages/bruno-app/src/utils/url/index.spec.js
  • packages/bruno-app/src/utils/url/index.js
  • packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/GenerateCodeItem/utils/snippet-generator.js
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit inference engine (CODING_STANDARDS.md)

**/*.{js,jsx,ts,tsx}: Use 2 spaces for indentation. No tabs, just spaces
Stick to single quotes for strings. For JSX/TSX attributes, use double quotes (e.g., )
Always add semicolons at the end of statements
No trailing commas
Always use parentheses around parameters in arrow functions, even for single params
For multiline constructs, put opening braces on the same line, and ensure consistency. Minimum 2 elements for multiline
No newlines inside function parentheses
Space before and after the arrow in arrow functions. () => {} is good
No space between function name and parentheses. func() not func ()
Semicolons go at the end of the line, not on a new line
Names for functions need to be concise and descriptive
Add in JSDoc comments to add more details to the abstractions if needed
Add in meaningful comments instead of obvious ones where complex code flow is explained properly

Files:

  • packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/GenerateCodeItem/utils/snippet-generator.spec.js
🧠 Learnings (3)
📚 Learning: 2025-12-16T07:16:23.647Z
Learnt from: sanish-bruno
Repo: usebruno/bruno PR: 6090
File: tests/scripting/hooks/init-user-data/ui-state-snapshot.json:1-8
Timestamp: 2025-12-16T07:16:23.647Z
Learning: For e2e tests in the bruno repository: Collections that are shared between CLI and UI tests (comprehensive test suites testing core functionality) should be placed in `packages/bruno-tests/` to avoid duplication. The `tests/**/fixtures/collection` pattern should be used for test-specific collections that test particular UI behaviors or are specific to a single test file.

Applied to files:

  • packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/GenerateCodeItem/utils/snippet-generator.spec.js
📚 Learning: 2025-12-05T20:31:33.005Z
Learnt from: CR
Repo: usebruno/bruno PR: 0
File: CODING_STANDARDS.md:0-0
Timestamp: 2025-12-05T20:31:33.005Z
Learning: Applies to **/*.test.{js,jsx,ts,tsx} : Add tests for any new functionality or meaningful changes. If code is added, removed, or significantly modified, corresponding tests should be updated or created

Applied to files:

  • packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/GenerateCodeItem/utils/snippet-generator.spec.js
📚 Learning: 2025-12-17T21:41:24.730Z
Learnt from: naman-bruno
Repo: usebruno/bruno PR: 6407
File: packages/bruno-app/src/components/Environments/ConfirmCloseEnvironment/index.js:5-41
Timestamp: 2025-12-17T21:41:24.730Z
Learning: Do not suggest PropTypes validation for React components in the Bruno codebase. The project does not use PropTypes, so reviews should avoid proposing PropTypes and rely on the existing typing/validation approach (e.g., TypeScript or alternative runtime checks) if applicable. This guideline applies broadly to all JavaScript/JSX components in the repo.

Applied to files:

  • packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/GenerateCodeItem/utils/snippet-generator.spec.js
🧬 Code graph analysis (1)
packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/GenerateCodeItem/utils/snippet-generator.spec.js (1)
packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/GenerateCodeItem/utils/snippet-generator.js (2)
  • result (46-46)
  • generateSnippet (8-53)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: Playwright E2E Tests
  • GitHub Check: CLI Tests
  • GitHub Check: Unit Tests
  • GitHub Check: SSL Tests - Windows
  • GitHub Check: SSL Tests - Linux
  • GitHub Check: SSL Tests - macOS
🔇 Additional comments (1)
packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/GenerateCodeItem/utils/snippet-generator.spec.js (1)

153-153: LGTM! Test expectations correctly updated for URL interpolation.

The updated assertions properly reflect that generateSnippet now interpolates variables in URLs when shouldInterpolate is true. The changes are consistent across all affected tests and align with the new functionality.

Also applies to: 210-210, 272-272, 378-378

}

// If there are no params or no enabled path params, return the URL as-is
if (!params || !params.length) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though this is not the right place to do the url encoding, it seems like this method interpolateUrlPathParams is also doing the encoding job at the code block 156 to 171 as below.

  let uri;

  if (!url.startsWith('http://') && !url.startsWith('https://')) {
    url = `http://${url}`;
  }

  try {
    uri = new URL(url);
  } catch (error) {
    // if the URL is invalid, return the URL as is
    return url;
  }

  const basePath = getInterpolatedBasePath(uri.pathname, params);

  return `${uri.origin}${basePath}${uri?.search || ''}`;

So without moving the encoding task out of this method, we cannot place these safety checks here since the encoding will break when there is no params included.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/GenerateCodeItem/utils/snippet-generator.js (1)

28-40: Past review feedback addressed; guard against undefined URL.

The implementation now correctly uses interpolateUrl and respects the shouldInterpolate setting as suggested by bijin-bruno's earlier review. The order of operations (interpolate → normalize → headers/body) is logical.

However, interpolateUrl can return undefined if the URL is falsy, empty, or not a string (see utils/url/index.js:92-98). If this occurs, request.url would be set to undefined, potentially breaking buildHarRequest downstream.

🔎 Proposed guard for undefined return
 // Interpolate URL, headers, and body if needed
 if (shouldInterpolate) {
-  request.url = interpolateUrl({ url: request.url, variables });
+  const interpolatedUrl = interpolateUrl({ url: request.url, variables });
+  if (interpolatedUrl !== undefined) {
+    request.url = interpolatedUrl;
+  }

   // Normalize and encode URL to ensure consistent encoding
   // This must happen after variable interpolation but before buildHarRequest
   request.url = normalizeAndEncodeUrl(request.url);

   headers = interpolateHeaders(headers, variables);
   if (request.body) {
     request.body = interpolateBody(request.body, variables);
   }
 }
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e37ab4a and 711829f.

📒 Files selected for processing (2)
  • packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/GenerateCodeItem/utils/snippet-generator.js
  • packages/bruno-app/src/utils/url/index.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/bruno-app/src/utils/url/index.js
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit inference engine (CODING_STANDARDS.md)

**/*.{js,jsx,ts,tsx}: Use 2 spaces for indentation. No tabs, just spaces
Stick to single quotes for strings. For JSX/TSX attributes, use double quotes (e.g., )
Always add semicolons at the end of statements
No trailing commas
Always use parentheses around parameters in arrow functions, even for single params
For multiline constructs, put opening braces on the same line, and ensure consistency. Minimum 2 elements for multiline
No newlines inside function parentheses
Space before and after the arrow in arrow functions. () => {} is good
No space between function name and parentheses. func() not func ()
Semicolons go at the end of the line, not on a new line
Names for functions need to be concise and descriptive
Add in JSDoc comments to add more details to the abstractions if needed
Add in meaningful comments instead of obvious ones where complex code flow is explained properly

Files:

  • packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/GenerateCodeItem/utils/snippet-generator.js
🧠 Learnings (1)
📚 Learning: 2025-12-17T21:41:24.730Z
Learnt from: naman-bruno
Repo: usebruno/bruno PR: 6407
File: packages/bruno-app/src/components/Environments/ConfirmCloseEnvironment/index.js:5-41
Timestamp: 2025-12-17T21:41:24.730Z
Learning: Do not suggest PropTypes validation for React components in the Bruno codebase. The project does not use PropTypes, so reviews should avoid proposing PropTypes and rely on the existing typing/validation approach (e.g., TypeScript or alternative runtime checks) if applicable. This guideline applies broadly to all JavaScript/JSX components in the repo.

Applied to files:

  • packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/GenerateCodeItem/utils/snippet-generator.js
🧬 Code graph analysis (1)
packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/GenerateCodeItem/utils/snippet-generator.js (1)
packages/bruno-app/src/utils/url/index.js (4)
  • interpolateUrl (93-99)
  • interpolateUrl (93-99)
  • normalizeAndEncodeUrl (101-129)
  • normalizeAndEncodeUrl (101-129)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: Unit Tests
  • GitHub Check: Playwright E2E Tests
  • GitHub Check: SSL Tests - Linux
  • GitHub Check: CLI Tests
  • GitHub Check: SSL Tests - Windows
  • GitHub Check: SSL Tests - macOS
🔇 Additional comments (2)
packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/GenerateCodeItem/utils/snippet-generator.js (2)

5-5: LGTM: Import statements are correct.

The imports for URL interpolation and normalization utilities are properly added and match their usage in the interpolation block.


15-15: Good defensive practice.

Creating a shallow copy prevents mutation of the original request object, which is appropriate for the top-level property modifications made in this function.

@Pragadesh-45 Pragadesh-45 marked this pull request as draft December 30, 2025 11:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bruno does generate code if URL contains a parameter referring a collection variable

2 participants