-
Notifications
You must be signed in to change notification settings - Fork 2k
fix#6247: Interpolate dynamic variables in path param #6251
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
base: main
Are you sure you want to change the base?
Conversation
|
Hey @NikHillAgar Could you add a test for this please ? |
WalkthroughUpdated URL interpolation so path-parameter replacement is performed and then variable interpolation is applied using a provided Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Poem
Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this 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/utils/url/index.js (1)
101-142: Minor robustness: defaultparamsinside helper to avoid potential.findon undefinedTo make
interpolateUrlPathParamssafer against unexpectedparamsbeingundefined(e.g. when a caller passes nothing ornull), you can default the helper argument:-export const interpolateUrlPathParams = (url, params, variables) => { - const getInterpolatedBasePath = (pathname, params) => { +export const interpolateUrlPathParams = (url, params, variables) => { + const getInterpolatedBasePath = (pathname, params = []) => {This keeps behavior the same for normal callers but avoids a
TypeErrorfromparams.find(...)if something upstream forgets to supply a params array.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/GenerateCodeItem/index.js(1 hunks)packages/bruno-app/src/utils/url/index.js(2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/GenerateCodeItem/index.js (4)
packages/bruno-electron/src/utils/collection.js (1)
variables(535-535)packages/bruno-app/src/utils/collections/index.js (3)
variables(1072-1072)variables(1098-1098)variables(1313-1313)packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/GenerateCodeItem/utils/snippet-generator.js (1)
variables(12-12)packages/bruno-cli/src/utils/bru.js (1)
variables(131-131)
⏰ 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: SSL Tests - macOS
- GitHub Check: Unit Tests
- GitHub Check: SSL Tests - Windows
- GitHub Check: SSL Tests - Linux
- GitHub Check: CLI Tests
🔇 Additional comments (2)
packages/bruno-app/src/utils/url/index.js (1)
101-142: Path-param interpolation fix looks correct and is backward compatibleUsing
variablesto runinterpolateon thereplacedPathnameafter substituting:param/OData segments is exactly what’s needed to resolve{{var}}in path param values (e.g.{{varXXX}}→1000000). Existing callers that don’t passvariableswill still work, sinceinterpolateis already used elsewhere with possibly undefined variables.Please ensure there’s at least one test that covers:
- URL like
https://www.url.com/:path-param/something- Path param
path-paramwith value{{varXXX}}variables = { varXXX: '1000000' }
and verifies the final interpolated path is/1000000/something.If you don’t already have tests around
interpolateUrlPathParams, consider adding one in the existing URL utils test suite.packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/GenerateCodeItem/index.js (1)
86-100: Correct wiring ofvariablesinto path-param interpolationPassing
variablesintointerpolateUrlPathParamsafter buildinginterpolatedUrlensures:
- Base URL (scheme/host/query) is interpolated once via
interpolateUrl.- Path params are substituted using
requestData.params.- Any
{{var}}that came from path param values is then resolved using the samevariablesmap.This matches the issue’s scenario and shouldn’t introduce double-interpolation for already-resolved parts of the URL.
Once tests are in place for the utils, consider also adding a higher-level test (or e2e) that exercises
GenerateCodeItemend-to-end for a request with:
url = "https://www.url.com/:path-param/something"path-param = {{varXXX}}variables.varXXX = "1000000"
to confirmfinalUrland the code snippet both usehttps://www.url.com/1000000/something.
There was a problem hiding this 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/utils/url/index.spec.js (1)
329-329: Good backward compatibility updates.Existing tests properly updated to pass the new
variablesparameter. Consider adding edge-case tests for robustness:
- When
variablesparameter isnullorundefined- When a path param references a variable that doesn't exist in the variables object
- When path param values contain multiple variable references (e.g.,
{{var1}}-{{var2}})Also applies to: 339-339, 349-349
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/bruno-app/src/utils/url/index.spec.js(4 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
packages/bruno-app/src/utils/url/index.spec.js (1)
packages/bruno-app/src/utils/url/index.js (4)
interpolateUrlPathParams(101-160)interpolateUrlPathParams(101-160)interpolateUrl(93-99)interpolateUrl(93-99)
⏰ 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 - Linux
- GitHub Check: SSL Tests - macOS
- GitHub Check: SSL Tests - Windows
- GitHub Check: Unit Tests
- GitHub Check: Playwright E2E Tests
- GitHub Check: CLI Tests
🔇 Additional comments (2)
packages/bruno-app/src/utils/url/index.spec.js (2)
301-310: LGTM! Test properly verifies the fix.This test case directly addresses the reported issue where path parameter values containing dynamic variable references (e.g.,
{{user}}) are now correctly interpolated to their actual values.
312-322: Integration test correctly validates the full interpolation flow.The test properly exercises the two-step process (URL variable interpolation → path parameter interpolation) and confirms that variable references in path parameter values are resolved in the final URL.
|
@helloanoop I have added the tests considering dynamic variable in path params |
|
Thank you @NikHillAgar |
Description
This PR fix #6247. When path param are replaced in the url during code snippet generation it does not take into account that value could refer to a dynamic variable.
Contribution Checklist:
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.