Skip to content

feat: enhance request and response translation capabilities - #6981

Merged
bijin-bruno merged 1 commit into
usebruno:mainfrom
sanish-bruno:feat/add-more-translations
Jan 30, 2026
Merged

bijin-bruno merged 1 commit into
usebruno:mainfrom
sanish-bruno:feat/add-more-translations

Conversation

@sanish-bruno

@sanish-bruno sanish-bruno commented Jan 30, 2026 •

Copy link
Copy Markdown
Collaborator
  • Added translations for req.method, req.headers, and req.body to their Postman equivalents.
  • Implemented handling for req.setUrl, req.setMethod, req.setBody, and req.setHeaders, converting them to appropriate Postman assignments and method calls.
  • Introduced support for translating res.responseTime and res.headers properties.
  • Updated tests to cover new translations and ensure accuracy in request and response handling.

Description

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.

Note: Keeping the PR small and focused helps make it easier to review and merge. If you have multiple changes you want to make, please consider submitting them as separate pull requests.

Publishing to New Package Managers

Please see here for more information.

Summary by CodeRabbit

  • New Features

    • Extended Bruno to Postman conversion support for request properties (method, headers, body) and response properties (response time, headers).
    • Added translation support for additional request setter functions and response property access patterns.
  • Documentation

    • Clarified which Bruno APIs are not supported in conversions.
  • Tests

    • Significantly expanded test coverage for request and response property translations and setter functions.

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

- Added translations for req.method, req.headers, and req.body to their Postman equivalents.
- Implemented handling for req.setUrl, req.setMethod, req.setBody, and req.setHeaders, converting them to appropriate Postman assignments and method calls.
- Introduced support for translating res.responseTime and res.headers properties.
- Updated tests to cover new translations and ensure accuracy in request and response handling.
@coderabbitai

coderabbitai Bot commented Jan 30, 2026 •

Copy link
Copy Markdown
Contributor

Walkthrough

Extended the Bruno-to-Postman translator with direct property mappings for request and response objects (req.method, req.headers, req.body, res.responseTime, res.headers) and implemented complex transformations for request setter methods. Comprehensive test coverage validates all new translation patterns.

Changes

Cohort / File(s) Summary
Translator Implementation
packages/bruno-converters/src/utils/bruno-to-postman-translator.js
Added simple translations for request/response properties and complex transformations for request setter methods (setUrl, setMethod, setBody, setHeaders), with updated precedence logic to apply complex transforms before simple ones.
Request Tests
packages/bruno-converters/tests/bruno/bruno-to-postman-translations/request.test.js
Expanded test coverage for property assignments and setter methods, including req.getAuthMode(), req.setUrl(), req.setMethod(), req.setBody(), and req.setHeaders() with variable handling scenarios.
Response Tests
packages/bruno-converters/tests/bruno/bruno-to-postman-translations/response.test.js
Added tests for res.responseTime and res.headers translation patterns, enforced exact output matching with trimmed comparisons, and covered multiple access patterns and conditionals.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • bruno#6956: Adds request/response property mappings to the same Bruno-to-Postman translator file.
  • bruno#6761: Directly extends bruno-to-postman translator implementation and test suites with new mappings.
  • bruno#6792: Modifies the complex transformation pipeline in the same translator component for AST transformations.

Suggested labels

size/XXL

Suggested reviewers

  • lohit-bruno
  • naman-bruno
  • bijin-bruno
  • helloanoop

Poem

🔄 From Bruno's realm to Postman's land,
Properties dance at your command,
Setters translate with care and grace,
Each mapping finds its rightful place! 📍✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main changes: adding and enhancing translation capabilities for request and response properties/methods between Bruno and Postman formats.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

🧪 Unit Test Generation v2 is now available!

We have significantly improved our unit test generation capabilities.

To enable: Add this to your .coderabbit.yaml configuration:

reviews:
  finishing_touches:
    unit_tests:
      enabled: true

Try it out by using the @coderabbitai generate unit tests command on your code files or under ✨ Finishing Touches on the walkthrough!

Have feedback? Share your thoughts on our Discord thread!


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.

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@packages/bruno-converters/src/utils/bruno-to-postman-translator.js`:
- Around line 300-357: The for...in generated for the req.setHeaders transform
currently iterates inherited enumerable properties; update the transformation
that builds the forInStatement (variables headersVar `_headers` and keyVar
`key`) to guard the loop body with an own-property check (e.g., if
(Object.prototype.hasOwnProperty.call(_headers, key)) { ... }) before calling
pm.request.headers.upsert, or alternatively replace the for-in with an iteration
over Object.keys(_headers) so only own keys are processed; adjust the
j.blockStatement used as the loop body in the j.forInStatement (or replace the
loop node) to include this guard so inherited properties are not upserted.

Comment on lines +300 to +357
// req.setHeaders(headers) -> loop calling pm.request.headers.upsert() for each header
{
pattern: 'req.setHeaders',
transform: (path) => {
const callExpr = path.value;
const args = callExpr.arguments;
if (!args || args.length === 0) {
// No arguments, return the property access
return buildMemberExpressionFromString('pm.request.headers');
}
const headersArg = args[0];

// Transform req.setHeaders(obj) to a for...in loop that calls upsert for each property
// Generate: for (const key in headersObj) { pm.request.headers.upsert({key: key, value: headersObj[key]}); }
const headersVar = j.identifier('_headers');
const keyVar = j.identifier('key');

// Create: for (const key in _headers) { pm.request.headers.upsert({key: key, value: _headers[key]}); }
const forLoop = j.forInStatement(
j.variableDeclaration('const', [j.variableDeclarator(keyVar)]),
headersVar,
j.blockStatement([
j.expressionStatement(
j.callExpression(
j.memberExpression(
buildMemberExpressionFromString('pm.request.headers'),
j.identifier('upsert')
),
[
j.objectExpression([
j.property('init', j.identifier('key'), keyVar),
j.property('init', j.identifier('value'), j.memberExpression(headersVar, keyVar, true))
])
]
)
)
])
);

// We need to replace the call expression with a block that includes the variable declaration and loop
// But the current architecture only replaces the call expression itself
// So we'll create an IIFE (Immediately Invoked Function Expression) that contains both
const iife = j.callExpression(
j.functionExpression(
null,
[],
j.blockStatement([
j.variableDeclaration('const', [
j.variableDeclarator(headersVar, headersArg)
]),
forLoop
])
),
[]
);

return iife;
}

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

Guard against inherited header keys in the for...in loop.

for...in can enumerate inherited enumerable props; adding a hasOwnProperty check avoids unexpected headers.

Proposed fix
-      // Create: for (const key in _headers) { pm.request.headers.upsert({key: key, value: _headers[key]}); }
+      // Create: for (const key in _headers) { if (!Object.prototype.hasOwnProperty.call(_headers, key)) continue; ... }
+      const hasOwnPropCall = j.callExpression(
+        j.memberExpression(
+          j.memberExpression(j.identifier('Object'), j.identifier('prototype')),
+          j.identifier('hasOwnProperty')
+        ),
+        [headersVar, keyVar]
+      );
+
       const forLoop = j.forInStatement(
         j.variableDeclaration('const', [j.variableDeclarator(keyVar)]),
         headersVar,
         j.blockStatement([
+          j.ifStatement(
+            j.unaryExpression('!', hasOwnPropCall),
+            j.continueStatement()
+          ),
           j.expressionStatement(
             j.callExpression(
               j.memberExpression(
                 buildMemberExpressionFromString('pm.request.headers'),
                 j.identifier('upsert')
🤖 Prompt for AI Agents
In `@packages/bruno-converters/src/utils/bruno-to-postman-translator.js` around
lines 300 - 357, The for...in generated for the req.setHeaders transform
currently iterates inherited enumerable properties; update the transformation
that builds the forInStatement (variables headersVar `_headers` and keyVar
`key`) to guard the loop body with an own-property check (e.g., if
(Object.prototype.hasOwnProperty.call(_headers, key)) { ... }) before calling
pm.request.headers.upsert, or alternatively replace the for-in with an iteration
over Object.keys(_headers) so only own keys are processed; adjust the
j.blockStatement used as the loop body in the j.forInStatement (or replace the
loop node) to include this guard so inherited properties are not upserted.

@sanish-bruno
sanish-bruno marked this pull request as draft January 30, 2026 07:32
@sanish-bruno
sanish-bruno marked this pull request as ready for review January 30, 2026 08:42
@bijin-bruno
bijin-bruno merged commit 8fface4 into usebruno:main Jan 30, 2026
@coderabbitai coderabbitai Bot mentioned this pull request Mar 3, 2026
6 tasks
maxenceleblanc pushed a commit to maxenceleblanc/curly_cats2 that referenced this pull request Jul 20, 2026
…#6981)

- Added translations for req.method, req.headers, and req.body to their Postman equivalents.
- Implemented handling for req.setUrl, req.setMethod, req.setBody, and req.setHeaders, converting them to appropriate Postman assignments and method calls.
- Introduced support for translating res.responseTime and res.headers properties.
- Updated tests to cover new translations and ensure accuracy in request and response handling.
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.

2 participants