Skip to content

fix: openapi cli import#7028

Merged
sid-bruno merged 6 commits intousebruno:mainfrom
pooja-bruno:fix/cli-import-openapi-yml-format
Feb 23, 2026
Merged

fix: openapi cli import#7028
sid-bruno merged 6 commits intousebruno:mainfrom
pooja-bruno:fix/cli-import-openapi-yml-format

Conversation

@pooja-bruno
Copy link
Collaborator

@pooja-bruno pooja-bruno commented Feb 3, 2026

Description

Fix openapi import in cli

JIRA

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.

Summary by CodeRabbit

  • New Features

    • Add selectable collection export formats (BRU or OpenCollection YAML) and a CLI option to choose output format.
    • Output now produces format-appropriate root, environment, folder and item files with correct filenames and content.
  • Refactor

    • Serialization and export flow made format-aware to ensure consistent handling across nested collection content.
  • Tests

    • Updated tests to exercise the new format option and export behavior.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 3, 2026

Walkthrough

Adds a format option to the collection import flow and CLI, enabling output as BRU (.bru) or OpenCollection YAML (.yml). The collection utility and tests now accept an options object with a format field and propagate it through serialization and file writing.

Changes

Cohort / File(s) Summary
Collection utils
packages/bruno-cli/src/utils/collection.js
Add options = { format } to createCollectionFromBrunoObject and processCollectionItems; choose root/folder/env/item filenames and serialized content based on format (bru.bru + BRU behavior, ymlopencollection.yml/.yml + OpenCollection behavior); only write bruno.json in BRU mode; propagate options in recursive calls.
CLI import command
packages/bruno-cli/src/commands/import.js
Add --collection-format CLI flag (bru
Tests
packages/bruno-cli/tests/utils/collection/create-collection-from-bruno-object.spec.js
Update tests to pass { format: 'bru' } as third arg to createCollectionFromBrunoObject, aligning with new signature.

Sequence Diagram(s)

sequenceDiagram
    participant CLI as "CLI"
    participant ImportCmd as "import.js"
    participant CollUtil as "collection.js"
    participant Serializer as "stringify*"
    participant FS as "FileSystem"

    CLI->>ImportCmd: run import --collection-format <bru|opencollection>
    ImportCmd->>CollUtil: createCollectionFromBrunoObject(collection, dir, {format})
    CollUtil->>Serializer: stringify root collection (format-aware)
    Serializer-->>CollUtil: serialized root
    CollUtil->>Serializer: stringify folders/envs/items (format-aware)
    Serializer-->>CollUtil: serialized pieces
    CollUtil->>FS: write collection root + per-item files (.bru or .yml)
    FS-->>CollUtil: write results
    CollUtil-->>ImportCmd: return dirPath
    ImportCmd-->>CLI: finish
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

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

Poem

✨ A flag decides the format today,
BRU or YAML finds its way.
Files split tidy, names aligned,
Options threaded through each find.
Small change, clear display.

🚥 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 'fix: openapi cli import' directly addresses the main change—enabling OpenAPI CLI import with YML/opencollection format support by adding format-aware collection generation.
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 (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
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: 3

🤖 Fix all issues with AI agents
In `@packages/bruno-cli/src/utils/collection.js`:
- Around line 463-464: The environment YAML file is being written without
explicitly telling stringifyEnvironment to produce YAML; update the call to
stringifyEnvironment(env) so it passes the format option (e.g.,
stringifyEnvironment(env, { format: 'yml' })) before writing the sanitized
filename from sanitizeName(`${env.name}.yml`) so the output matches the .yml
extension.
- Around line 532-534: The call to stringifyRequest is missing the format option
so the request JSON may not be serialized as YAML even though it's written to a
.yml file; update the call to stringifyRequest(itemJson) to pass the YAML option
(e.g., stringifyRequest(itemJson, { format: 'yml' })) before calling
safeWriteFileSync to write sanitizedFilename in currentPath so the file content
matches the .yml extension.
- Around line 489-496: The call to stringifyFolder when generating folder.yml
omits the format option, causing incorrect serialization; update the invocation
of stringifyFolder (used before safeWriteFileSync for folderYmlFilePath) to pass
the format: 'yml' option (e.g., stringifyFolder(item.root, { format: 'yml' }))
so folderContent is serialized as YAML; keep the existing logic that sets
item.root.meta.seq when item.seq exists and write the resulting folderContent to
folder.yml as before.
🧹 Nitpick comments (1)
packages/bruno-cli/src/utils/collection.js (1)

445-451: Consider adding opencollection: true to brunoConfig.

Based on learnings, the Redux reducer determines collection format by checking for the opencollection property in brunoConfig. Adding this property ensures consistent format detection across the codebase.

♻️ Proposed improvement
   // Create brunoConfig for yml format
   const brunoConfig = {
     version: '1',
     name: collection.name,
     type: 'collection',
-    ignore: ['node_modules', '.git']
+    ignore: ['node_modules', '.git'],
+    opencollection: true
   };

Based on learnings: "the Redux reducer determines collection format by checking for the opencollection property in brunoConfig."

Copy link
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 (1)
packages/bruno-cli/src/utils/collection.js (1)

518-519: ⚠️ Potential issue | 🔴 Critical

Bug: Recursive call drops options, so nested items lose format awareness.

processCollectionItems(item.items, folderPath) on line 519 omits the third argument. All nested folders and requests will get format: undefined, which will break stringifyFolder, stringifyRequest, etc. for the 'yml' path (they'll hit "Unsupported format: undefined").

🐛 Proposed fix
       if (item.items && item.items.length) {
-        await processCollectionItems(item.items, folderPath);
+        await processCollectionItems(item.items, folderPath, options);
       }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/bruno-cli/src/utils/collection.js` around lines 518 - 519, The
recursive call to processCollectionItems is missing the options argument,
causing nested items (item.items) to lose format context and break functions
like stringifyFolder/stringifyRequest; update the recursive invocation
processCollectionItems(item.items, folderPath) to pass the same options object
(e.g., processCollectionItems(item.items, folderPath, options)) so nested
folders/requests retain format awareness and avoid "Unsupported format:
undefined".
🧹 Nitpick comments (3)
packages/bruno-cli/src/utils/collection.js (3)

458-458: Use strict equality (===) instead of loose (==).

Lines 458 and 524 use ==. Both operands are strings, so it works, but === is the project convention and avoids subtle coercion surprises.

♻️ Proposed fix
-  const collectionRootFilePath = format == 'bru' ? path.join(dirPath, 'collection.bru') : path.join(dirPath, 'opencollection.yml');
+  const collectionRootFilePath = format === 'bru' ? path.join(dirPath, 'collection.bru') : path.join(dirPath, 'opencollection.yml');
-      if (format == 'yml') {
+      if (format === 'yml') {

Also applies to: 524-524

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/bruno-cli/src/utils/collection.js` at line 458, Replace loose
equality checks with strict equality: change comparisons that use format ==
'bru' (and the similar comparison at the other occurrence) to use format ===
'bru'. Update the relevant expressions in the collectionRootFilePath assignment
and the other spot (both referencing the format variable) so they use === to
follow project convention and avoid coercion.

536-537: Stale comment: "Convert to YML format" is inaccurate when format is 'bru'.

The comment on line 536 says "Convert to YML format" but the block handles both formats. Same applies to line 558.

📝 Proposed fix
-      // Convert to YML format
+      // Build the request item JSON
       const itemJson = {
-      // Convert to YML format and write to file
+      // Stringify and write to file
       const content = stringifyRequest(itemJson, { format });
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/bruno-cli/src/utils/collection.js` around lines 536 - 537, The
inline comment "Convert to YML format" is stale because the block that builds
itemJson and the subsequent serialization handles both 'yml' and 'bru' output
formats; update that comment(s) to accurately reflect the behavior (e.g.,
"Convert to output format (YML or BRU)" or "Prepare item object for
serialization based on output format") so readers see that itemJson and the
serialization logic support both formats; update both occurrences near the
itemJson construction and the later serialization block that references format
=== 'bru'.

494-495: JSDoc @param descriptions are copy-pasted.

Both options and options.format have the description "Current directory path".

📝 Proposed fix
- * `@param` {object} [options] - Current directory path
- * `@param` {"bru"|"yml"} options.format - Current directory path
+ * `@param` {object} [options] - Processing options
+ * `@param` {"bru"|"yml"} options.format - Output format for the collection files
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/bruno-cli/src/utils/collection.js` around lines 494 - 495, The JSDoc
for the function in packages/bruno-cli/src/utils/collection.js has copy-pasted
descriptions: both `@param` {object} [options] and `@param` {"bru"|"yml"}
options.format read "Current directory path"; update these to accurate
descriptions by replacing the generic text with a brief, correct description for
options (e.g., "options object for collection operations") and for
options.format (e.g., "output format: 'bru' or 'yml'"), ensuring the param names
match the JSDoc tokens exactly (options and options.format) so tools like VSCode
and TypeScript can pick up the correct docs.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/bruno-cli/src/utils/collection.js`:
- Around line 455-457: The collection writer is not propagating format and
options correctly: change the stringifyCollection call to select format based on
format === 'yml' (i.e. use format === 'yml' ? 'yml' : 'bru' instead of checking
'opencollection'), pass the options through when recursing (call
processCollectionItems(item.items, folderPath, options)), replace all loose
equality checks (==) in this module with strict ===, and fix the JSDoc for
processCollectionItems to give correct descriptions for each parameter (path,
items, and options) so nested items retain format awareness and equality checks
are strict; the key symbols to update are stringifyCollection,
processCollectionItems, the recursive call using item.items, and any ==
comparisons in this file.

---

Outside diff comments:
In `@packages/bruno-cli/src/utils/collection.js`:
- Around line 518-519: The recursive call to processCollectionItems is missing
the options argument, causing nested items (item.items) to lose format context
and break functions like stringifyFolder/stringifyRequest; update the recursive
invocation processCollectionItems(item.items, folderPath) to pass the same
options object (e.g., processCollectionItems(item.items, folderPath, options))
so nested folders/requests retain format awareness and avoid "Unsupported
format: undefined".

---

Nitpick comments:
In `@packages/bruno-cli/src/utils/collection.js`:
- Line 458: Replace loose equality checks with strict equality: change
comparisons that use format == 'bru' (and the similar comparison at the other
occurrence) to use format === 'bru'. Update the relevant expressions in the
collectionRootFilePath assignment and the other spot (both referencing the
format variable) so they use === to follow project convention and avoid
coercion.
- Around line 536-537: The inline comment "Convert to YML format" is stale
because the block that builds itemJson and the subsequent serialization handles
both 'yml' and 'bru' output formats; update that comment(s) to accurately
reflect the behavior (e.g., "Convert to output format (YML or BRU)" or "Prepare
item object for serialization based on output format") so readers see that
itemJson and the serialization logic support both formats; update both
occurrences near the itemJson construction and the later serialization block
that references format === 'bru'.
- Around line 494-495: The JSDoc for the function in
packages/bruno-cli/src/utils/collection.js has copy-pasted descriptions: both
`@param` {object} [options] and `@param` {"bru"|"yml"} options.format read "Current
directory path"; update these to accurate descriptions by replacing the generic
text with a brief, correct description for options (e.g., "options object for
collection operations") and for options.format (e.g., "output format: 'bru' or
'yml'"), ensuring the param names match the JSDoc tokens exactly (options and
options.format) so tools like VSCode and TypeScript can pick up the correct
docs.

Comment on lines +455 to +457
const collectionContent = await stringifyCollection(collection.root || {}, brunoConfig, {
format: format === 'opencollection' ? 'yml' : 'bru'
});
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

# First, let's get the file size to see if we can read it entirely
wc -l packages/bruno-cli/src/utils/collection.js

Repository: usebruno/bruno

Length of output: 104


🏁 Script executed:

# Read the specific lines mentioned in the review
sed -n '440,470p' packages/bruno-cli/src/utils/collection.js

Repository: usebruno/bruno

Length of output: 1085


🏁 Script executed:

# Check the recursive call at line 519
sed -n '515,530p' packages/bruno-cli/src/utils/collection.js

Repository: usebruno/bruno

Length of output: 642


🏁 Script executed:

# Check the equality operators at lines 458 and 524
sed -n '455,460p' packages/bruno-cli/src/utils/collection.js
sed -n '520,530p' packages/bruno-cli/src/utils/collection.js

Repository: usebruno/bruno

Length of output: 797


🏁 Script executed:

# Check the JSDoc at lines 494-495
sed -n '490,500p' packages/bruno-cli/src/utils/collection.js

Repository: usebruno/bruno

Length of output: 527


🏁 Script executed:

# Verify how createCollectionFromBrunoObject is called throughout the codebase
rg -n "createCollectionFromBrunoObject" --type=js -B 3 -A 3

Repository: usebruno/bruno

Length of output: 6161


Two critical bugs prevent format from being properly propagated.

  1. Line 455–457: The condition format === 'opencollection' will never be true because the caller in import.js already maps 'opencollection''yml', so format is always 'bru' or 'yml'. When format === 'yml', the ternary returns 'bru', causing the collection root to always be written in the wrong format.

  2. Line 519: The recursive call to processCollectionItems(item.items, folderPath) does not pass the options parameter, so nested items lose format awareness and default to undefined.

Additionally, lines 458 and 524 use loose equality (==) instead of strict equality (===), and the JSDoc for processCollectionItems (lines 496–498) incorrectly repeats "Current directory path" for all parameter descriptions.

Proposed fix for line 455–457
-  const collectionContent = await stringifyCollection(collection.root || {}, brunoConfig, {
-    format: format === 'opencollection' ? 'yml' : 'bru'
-  });
+  const collectionContent = await stringifyCollection(collection.root || {}, brunoConfig, {
+    format
+  });
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/bruno-cli/src/utils/collection.js` around lines 455 - 457, The
collection writer is not propagating format and options correctly: change the
stringifyCollection call to select format based on format === 'yml' (i.e. use
format === 'yml' ? 'yml' : 'bru' instead of checking 'opencollection'), pass the
options through when recursing (call processCollectionItems(item.items,
folderPath, options)), replace all loose equality checks (==) in this module
with strict ===, and fix the JSDoc for processCollectionItems to give correct
descriptions for each parameter (path, items, and options) so nested items
retain format awareness and equality checks are strict; the key symbols to
update are stringifyCollection, processCollectionItems, the recursive call using
item.items, and any == comparisons in this file.

Copy link
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 (1)
packages/bruno-cli/tests/utils/collection/create-collection-from-bruno-object.spec.js (1)

59-143: ⚠️ Potential issue | 🟠 Major

No test coverage for { format: 'yml' } — the core scenario this PR introduces.

All three tests pass { format: 'bru' }. The yml path — which is the fix this PR ships (OpenAPI → OpenCollection YAML output) — is completely untested. Missing coverage includes:

  • opencollection.yml root file creation
  • folder.yml generation
  • Request files with .yml extension
  • Environment files with .yml extension

As per coding guidelines: "Add tests for any new functionality or meaningful changes."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@packages/bruno-cli/tests/utils/collection/create-collection-from-bruno-object.spec.js`
around lines 59 - 143, Add tests that exercise the new YAML output path by
duplicating the existing bru-format specs but using { format: 'yml' } and
YAML-specific parsers; specifically, add cases calling
createCollectionFromBrunoObject with format: 'yml' to verify opencollection.yml
(root) is written, folder.yml is created for folder items, request files have
.yml extensions and environment files are emitted with .yml; use analogous
helpers to parse and assert contents (mirroring parseBruRequestFromPath and
parseBruFolderFromPath — e.g., parseYmlRequestFromPath / parseYmlFolderFromPath)
and assert expected properties (type, request.method, meta.name, meta.seq) and
file existence for each scenario.
🧹 Nitpick comments (2)
packages/bruno-cli/src/utils/collection.js (2)

458-458: FORMAT_CONFIG is defined but not used in the write path — duplicate format logic.

FORMAT_CONFIG centralizes format-to-filename mappings (already used in createCollectionJsonFromPathname), but createCollectionFromBrunoObject and processCollectionItems reconstruct the same logic via manual ternaries. Destructure from FORMAT_CONFIG[format] for consistency.

♻️ Proposed refactor
// createCollectionFromBrunoObject
-  const collectionRootFilePath = format == 'bru' ? path.join(dirPath, 'collection.bru') : path.join(dirPath, 'opencollection.yml');
+  const { ext, collectionFile, folderFile } = FORMAT_CONFIG[format];
+  const collectionRootFilePath = path.join(dirPath, collectionFile);

// environments loop
-      const filename = format === 'bru' ? sanitizeName(`${env.name}.bru`) : sanitizeName(`${env.name}.yml`);
+      const filename = sanitizeName(`${env.name}${ext}`);

// processCollectionItems — folder section
-        const folderFileName = format === 'bru' ? 'folder.bru' : 'folder.yml';
+        const folderFileName = FORMAT_CONFIG[format].folderFile;

// processCollectionItems — request section
-      if (format == 'yml') {
-        sanitizedFilename = sanitizeName(item?.filename || `${item.name}.yml`);
-        if (!sanitizedFilename.endsWith('.yml')) { sanitizedFilename += '.yml'; }
-      } else {
-        sanitizedFilename = sanitizeName(item?.filename || `${item.name}.bru`);
-        if (!sanitizedFilename.endsWith('.bru')) { sanitizedFilename += '.bru'; }
-      }
+      sanitizedFilename = sanitizeName(item?.filename || `${item.name}${FORMAT_CONFIG[format].ext}`);
+      if (!sanitizedFilename.endsWith(FORMAT_CONFIG[format].ext)) {
+        sanitizedFilename += FORMAT_CONFIG[format].ext;
+      }

Also applies to: 478-478, 508-508, 524-534

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/bruno-cli/src/utils/collection.js` at line 458, The code duplicates
format-to-filename logic instead of using the existing FORMAT_CONFIG; update
createCollectionFromBrunoObject and processCollectionItems to read the filename
(and any other mapping) from FORMAT_CONFIG[format] (destructure the value) and
replace the inline ternary expressions (e.g., where collectionRootFilePath is
computed) with that destructured filename; apply the same replacement at the
other occurrences you noted (around the similar ternaries at the other lines) so
all write paths consistently use FORMAT_CONFIG.

536-558: Stale comments reference "YML format" — misleading now that logic handles both formats.

Lines 536 (// Convert to YML format) and 558 (// Convert to YML format and write to file) should reflect the format-agnostic behaviour, e.g. // Serialize and write request file.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/bruno-cli/src/utils/collection.js` around lines 536 - 558, Update
the misleading inline comments that say "Convert to YML format" to reflect
format-agnostic behavior: change the comment above the itemJson construction and
the later comment before writing to file to something like "Serialize request
data" or "Serialize and write request file". Locate the comments near the
itemJson variable inside the function handling collection serialization
(references: itemJson, request fields like request.method/request.url) and
update both occurrences so they no longer mention YML specifically.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/bruno-cli/src/utils/collection.js`:
- Around line 447-453: The brunoConfig object is currently created identically
for both formats and the comment incorrectly says it's only for yml; modify the
code that builds brunoConfig (symbol: brunoConfig) to be format-aware: keep the
common fields (version, name, type, ignore) but when collection.format === 'yml'
add opencollection: '1.0.0' so CLI yml exports match the electron app behavior;
also update the preceding comment to reflect that brunoConfig is used for both
formats and note the conditional opencollection addition.

---

Outside diff comments:
In
`@packages/bruno-cli/tests/utils/collection/create-collection-from-bruno-object.spec.js`:
- Around line 59-143: Add tests that exercise the new YAML output path by
duplicating the existing bru-format specs but using { format: 'yml' } and
YAML-specific parsers; specifically, add cases calling
createCollectionFromBrunoObject with format: 'yml' to verify opencollection.yml
(root) is written, folder.yml is created for folder items, request files have
.yml extensions and environment files are emitted with .yml; use analogous
helpers to parse and assert contents (mirroring parseBruRequestFromPath and
parseBruFolderFromPath — e.g., parseYmlRequestFromPath / parseYmlFolderFromPath)
and assert expected properties (type, request.method, meta.name, meta.seq) and
file existence for each scenario.

---

Duplicate comments:
In `@packages/bruno-cli/src/utils/collection.js`:
- Line 458: Replace the loose equality used when building collectionRootFilePath
so it uses strict comparison: change the conditional that checks format (the
expression used in the ternary that assigns collectionRootFilePath) from using
== to ===; update the expression where format is compared to 'bru' (in the
collectionRootFilePath assignment) to use strict equality (format === 'bru') to
follow coding guidelines.
- Around line 489-495: The JSDoc for the recursive collection processor has
placeholder texts for the options parameters; update the `@param` descriptions for
the options object and options.format in the JSDoc above the recursive function
(the block starting "Recursively processes collection items to create files and
folders") to accurately describe that options is an optional configuration
object (e.g., contains format and other flags) and options.format is a string
enum ("bru"|"yml") indicating the output file format; keep descriptions concise
and consistent with other JSDoc in collection.js and reference the same option
names (options, options.format) so readers can locate the params easily.
- Line 524: The conditional uses loose equality: replace the `if (format ==
'yml')` check with a strict equality comparison so it reads `if (format ===
'yml')`; locate the `format` variable usage in the same block in collection.js
and update this operator (and any other accidental `==` occurrences in the same
function) to `===` to enforce strict comparison.

---

Nitpick comments:
In `@packages/bruno-cli/src/utils/collection.js`:
- Line 458: The code duplicates format-to-filename logic instead of using the
existing FORMAT_CONFIG; update createCollectionFromBrunoObject and
processCollectionItems to read the filename (and any other mapping) from
FORMAT_CONFIG[format] (destructure the value) and replace the inline ternary
expressions (e.g., where collectionRootFilePath is computed) with that
destructured filename; apply the same replacement at the other occurrences you
noted (around the similar ternaries at the other lines) so all write paths
consistently use FORMAT_CONFIG.
- Around line 536-558: Update the misleading inline comments that say "Convert
to YML format" to reflect format-agnostic behavior: change the comment above the
itemJson construction and the later comment before writing to file to something
like "Serialize request data" or "Serialize and write request file". Locate the
comments near the itemJson variable inside the function handling collection
serialization (references: itemJson, request fields like
request.method/request.url) and update both occurrences so they no longer
mention YML specifically.

Set opencollection version for YAML format.
Copy link
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

♻️ Duplicate comments (2)
packages/bruno-cli/src/utils/collection.js (2)

493-499: JSDoc parameter descriptions for processCollectionItems still incorrect.

Lines 498–499 still repeat "Current directory path" for both options and options.format. Was flagged in the previous review and not addressed.

📝 Proposed fix
 /**
  * Recursively processes collection items to create files and folders
  *
  * `@param` {Array} items - Collection items
  * `@param` {string} currentPath - Current directory path
- * `@param` {object} [options] - Current directory path
- * `@param` {"bru"|"yml"} options.format - Current directory path
+ * `@param` {object} [options] - Options for processing
+ * `@param` {"bru"|"yml"} options.format - Output format for collection files
  */
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/bruno-cli/src/utils/collection.js` around lines 493 - 499, The JSDoc
for processCollectionItems incorrectly repeats "Current directory path" for both
the options object and options.format; update the `@param` lines so `@param`
{object} [options] describes the optional settings object (e.g., "Options for
processing, such as format and recursion flags") and `@param` {"bru"|"yml"}
options.format describes the output file format (e.g., "Output file format:
'bru' or 'yml'"). Ensure the parameter names match the function signature
processCollectionItems and keep types and optional notation intact.

462-462: Loose equality (==) still not fixed on Lines 462 and 528.

Both comparisons (format == 'bru' and format == 'yml') should use strict equality (===). This was flagged previously and remains unresolved.

🐛 Proposed fix
-  const collectionRootFilePath = format == 'bru' ? path.join(dirPath, 'collection.bru') : path.join(dirPath, 'opencollection.yml');
+  const collectionRootFilePath = format === 'bru' ? path.join(dirPath, 'collection.bru') : path.join(dirPath, 'opencollection.yml');
-      if (format == 'yml') {
+      if (format === 'yml') {

Also applies to: 528-528

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/bruno-cli/src/utils/collection.js` at line 462, Replace the loose
equality checks using == with strict equality === for the format comparisons to
avoid type-coercion bugs; specifically update the conditional that sets
collectionRootFilePath (currently using format == 'bru') to use format ===
'bru', and likewise update the other comparison that checks format == 'yml'
(around the other branch at the other occurrence) to format === 'yml' so both
branches reliably evaluate the intended string values.
🧹 Nitpick comments (1)
packages/bruno-cli/src/utils/collection.js (1)

10-13: FORMAT_CONFIG is defined but unused in the write path.

FORMAT_CONFIG centralizes file naming for both formats and is correctly used in createCollectionJsonFromPathname, but createCollectionFromBrunoObject and processCollectionItems scatter the same literals inline (lines 462, 482, 512, 527–538). Prefer FORMAT_CONFIG[format].* to eliminate the duplication.

♻️ Proposed refactor (representative examples)
-  const collectionRootFilePath = format === 'bru' ? path.join(dirPath, 'collection.bru') : path.join(dirPath, 'opencollection.yml');
+  const collectionRootFilePath = path.join(dirPath, FORMAT_CONFIG[format].collectionFile);
-      const filename = format === 'bru' ? sanitizeName(`${env.name}.bru`) : sanitizeName(`${env.name}.yml`);
+      const filename = sanitizeName(`${env.name}${FORMAT_CONFIG[format].ext}`);
-        const folderFileName = format === 'bru' ? 'folder.bru' : 'folder.yml';
+        const folderFileName = FORMAT_CONFIG[format].folderFile;
-      if (format === 'yml') {
-        sanitizedFilename = sanitizeName(item?.filename || `${item.name}.yml`);
-        if (!sanitizedFilename.endsWith('.yml')) {
-          sanitizedFilename += '.yml';
-        }
-      } else {
-        sanitizedFilename = sanitizeName(item?.filename || `${item.name}.bru`);
-        if (!sanitizedFilename.endsWith('.bru')) {
-          sanitizedFilename += '.bru';
-        }
-      }
+      const ext = FORMAT_CONFIG[format].ext;
+      sanitizedFilename = sanitizeName(item?.filename || `${item.name}${ext}`);
+      if (!sanitizedFilename.endsWith(ext)) {
+        sanitizedFilename += ext;
+      }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/bruno-cli/src/utils/collection.js` around lines 10 - 13, The write
path uses hardcoded file names/exts instead of the central FORMAT_CONFIG, so
update createCollectionFromBrunoObject and processCollectionItems to use
FORMAT_CONFIG[format].collectionFile, FORMAT_CONFIG[format].folderFile and
FORMAT_CONFIG[format].ext (and any other format-specific literals) wherever
'collection.bru', 'opencollection.yml', 'folder.bru', 'folder.yml', or
extensions are currently inlined; ensure the functions receive/derive the same
format variable used elsewhere (as in createCollectionJsonFromPathname) and
replace the duplicated literals with the FORMAT_CONFIG lookups for consistency.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/bruno-cli/src/utils/collection.js`:
- Line 447: Update the four stale inline comments to correctly describe
format-aware behavior: change the comment near the brunoConfig construction
(referencing brunoConfig) to indicate it is built for both .bru and .yml formats
(format-agnostic), update the comment above the folder file creation (the logic
that chooses between folder.bru and folder.yml) to say it creates the folder
file using the selected format, replace the "Convert to YML format" comment next
to itemJson preparation to indicate it is preparing format-agnostic item data,
and update the final comment before writing the file to state the write uses the
dynamic/selected format rather than always YML; locate these by the symbols
brunoConfig, itemJson and the folder file creation/write block and adjust the
comment text accordingly.

---

Duplicate comments:
In `@packages/bruno-cli/src/utils/collection.js`:
- Around line 493-499: The JSDoc for processCollectionItems incorrectly repeats
"Current directory path" for both the options object and options.format; update
the `@param` lines so `@param` {object} [options] describes the optional settings
object (e.g., "Options for processing, such as format and recursion flags") and
`@param` {"bru"|"yml"} options.format describes the output file format (e.g.,
"Output file format: 'bru' or 'yml'"). Ensure the parameter names match the
function signature processCollectionItems and keep types and optional notation
intact.
- Line 462: Replace the loose equality checks using == with strict equality ===
for the format comparisons to avoid type-coercion bugs; specifically update the
conditional that sets collectionRootFilePath (currently using format == 'bru')
to use format === 'bru', and likewise update the other comparison that checks
format == 'yml' (around the other branch at the other occurrence) to format ===
'yml' so both branches reliably evaluate the intended string values.

---

Nitpick comments:
In `@packages/bruno-cli/src/utils/collection.js`:
- Around line 10-13: The write path uses hardcoded file names/exts instead of
the central FORMAT_CONFIG, so update createCollectionFromBrunoObject and
processCollectionItems to use FORMAT_CONFIG[format].collectionFile,
FORMAT_CONFIG[format].folderFile and FORMAT_CONFIG[format].ext (and any other
format-specific literals) wherever 'collection.bru', 'opencollection.yml',
'folder.bru', 'folder.yml', or extensions are currently inlined; ensure the
functions receive/derive the same format variable used elsewhere (as in
createCollectionJsonFromPathname) and replace the duplicated literals with the
FORMAT_CONFIG lookups for consistency.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 349e28e and 45d7898.

📒 Files selected for processing (1)
  • packages/bruno-cli/src/utils/collection.js

// Create bruno.json
const createCollectionFromBrunoObject = async (collection, dirPath, options = {}) => {
const { format = 'bru' } = options;
// Create brunoConfig for yml format
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Stale comments don't reflect format-aware behavior.

Four comments need updating:

  • Line 447: "Create brunoConfig for yml format"brunoConfig is built for both formats.
  • Line 510: "Create folder.yml file if root exists" — now creates folder.bru or folder.yml.
  • Line 540: "Convert to YML format"itemJson is format-agnostic data prep.
  • Line 562: "Convert to YML format and write to file" — format is dynamic.
📝 Proposed fix
-  // Create brunoConfig for yml format
+  // Build brunoConfig; add opencollection property for yml format
   const brunoConfig = {
-      // Create folder.yml file if root exists
+      // Create folder metadata file (folder.bru or folder.yml) if root exists
       if (item?.root?.meta?.name) {
-      // Convert to YML format
+      // Build request item data structure
       const itemJson = {
-      // Convert to YML format and write to file
+      // Serialize and write request item file
       const content = stringifyRequest(itemJson, { format });

Also applies to: 510-510, 540-541, 562-562

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/bruno-cli/src/utils/collection.js` at line 447, Update the four
stale inline comments to correctly describe format-aware behavior: change the
comment near the brunoConfig construction (referencing brunoConfig) to indicate
it is built for both .bru and .yml formats (format-agnostic), update the comment
above the folder file creation (the logic that chooses between folder.bru and
folder.yml) to say it creates the folder file using the selected format, replace
the "Convert to YML format" comment next to itemJson preparation to indicate it
is preparing format-agnostic item data, and update the final comment before
writing the file to state the write uses the dynamic/selected format rather than
always YML; locate these by the symbols brunoConfig, itemJson and the folder
file creation/write block and adjust the comment text accordingly.

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