Conversation
WalkthroughAdds 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 Changes
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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 addingopencollection: trueto brunoConfig.Based on learnings, the Redux reducer determines collection format by checking for the
opencollectionproperty inbrunoConfig. 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
opencollectionproperty in brunoConfig."
There was a problem hiding this comment.
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 | 🔴 CriticalBug: 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 getformat: undefined, which will breakstringifyFolder,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@paramdescriptions are copy-pasted.Both
optionsandoptions.formathave 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.
| const collectionContent = await stringifyCollection(collection.root || {}, brunoConfig, { | ||
| format: format === 'opencollection' ? 'yml' : 'bru' | ||
| }); |
There was a problem hiding this comment.
🧩 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.jsRepository: 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.jsRepository: 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.jsRepository: 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.jsRepository: 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.jsRepository: usebruno/bruno
Length of output: 527
🏁 Script executed:
# Verify how createCollectionFromBrunoObject is called throughout the codebase
rg -n "createCollectionFromBrunoObject" --type=js -B 3 -A 3Repository: usebruno/bruno
Length of output: 6161
Two critical bugs prevent format from being properly propagated.
-
Line 455–457: The condition
format === 'opencollection'will never be true because the caller inimport.jsalready maps'opencollection'→'yml', soformatis always'bru'or'yml'. Whenformat === 'yml', the ternary returns'bru', causing the collection root to always be written in the wrong format. -
Line 519: The recursive call to
processCollectionItems(item.items, folderPath)does not pass theoptionsparameter, so nested items lose format awareness and default toundefined.
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.
There was a problem hiding this comment.
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 | 🟠 MajorNo test coverage for
{ format: 'yml' }— the core scenario this PR introduces.All three tests pass
{ format: 'bru' }. Theymlpath — which is the fix this PR ships (OpenAPI → OpenCollection YAML output) — is completely untested. Missing coverage includes:
opencollection.ymlroot file creationfolder.ymlgeneration- Request files with
.ymlextension- Environment files with
.ymlextensionAs 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_CONFIGis defined but not used in the write path — duplicate format logic.
FORMAT_CONFIGcentralizes format-to-filename mappings (already used increateCollectionJsonFromPathname), butcreateCollectionFromBrunoObjectandprocessCollectionItemsreconstruct the same logic via manual ternaries. Destructure fromFORMAT_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.
There was a problem hiding this comment.
Actionable comments posted: 1
♻️ Duplicate comments (2)
packages/bruno-cli/src/utils/collection.js (2)
493-499: JSDoc parameter descriptions forprocessCollectionItemsstill incorrect.Lines 498–499 still repeat
"Current directory path"for bothoptionsandoptions.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'andformat == '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_CONFIGis defined but unused in the write path.
FORMAT_CONFIGcentralizes file naming for both formats and is correctly used increateCollectionJsonFromPathname, butcreateCollectionFromBrunoObjectandprocessCollectionItemsscatter the same literals inline (lines 462, 482, 512, 527–538). PreferFORMAT_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.
| // Create bruno.json | ||
| const createCollectionFromBrunoObject = async (collection, dirPath, options = {}) => { | ||
| const { format = 'bru' } = options; | ||
| // Create brunoConfig for yml format |
There was a problem hiding this comment.
Stale comments don't reflect format-aware behavior.
Four comments need updating:
- Line 447:
"Create brunoConfig for yml format"—brunoConfigis built for both formats. - Line 510:
"Create folder.yml file if root exists"— now createsfolder.bruorfolder.yml. - Line 540:
"Convert to YML format"—itemJsonis 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.
Description
Fix openapi import in cli
JIRA
Contribution Checklist:
Summary by CodeRabbit
New Features
Refactor
Tests