-
Notifications
You must be signed in to change notification settings - Fork 2k
export & import in opencollection format #6329
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
WalkthroughThis PR adds comprehensive OpenCollection format support to Bruno, enabling users to both import OpenCollection payloads and export Bruno collections in OpenCollection format. Changes span UI components, Redux actions, and new transformer utilities for bidirectional data conversion between Bruno and OpenCollection schemas. Changes
Sequence Diagram(s)sequenceDiagram
actor User
participant UI as ImportCollection UI
participant Redux as Redux<br/>(workspaces/actions)
participant Importer as processOpenCollection
participant Validator as Schema<br/>Validator
participant Store as Collection<br/>Store
User->>UI: Upload/Select OpenCollection file
UI->>UI: Detect format (isOpenCollection)
UI->>Redux: Dispatch transformCollection action
rect rgb(220, 240, 250)
Note over Redux,Store: Import Flow
Redux->>Importer: Call processOpenCollection(jsonData)
Importer->>Importer: openCollectionToBruno conversion
Importer->>Importer: Hydrate & UID augmentation
Importer->>Validator: Validate against schema
Validator-->>Importer: Validation result
end
alt Valid
Importer-->>Redux: Return Bruno collection
Redux->>Store: Persist collection
Store-->>User: Collection imported ✓
else Invalid
Importer-->>Redux: Throw BrunoError
Redux-->>User: Error notification
end
sequenceDiagram
actor User
participant UI as ShareCollection UI
participant Handler as handleExportOpenCollection
participant Exporter as brunoToOpenCollection
participant Transformer as Schema<br/>Transformers
participant FileSaver as YAML<br/>Export
User->>UI: Click "Export OpenCollection"
UI->>Handler: handleExportOpenCollection()
Handler->>Handler: Clone collection
Handler->>Exporter: brunoToOpenCollection(collection)
rect rgb(240, 250, 220)
Note over Exporter,Transformer: Transform Flow
Exporter->>Transformer: Map auth, headers, items
Exporter->>Transformer: Transform HTTP/GraphQL/gRPC/WS
Exporter->>Transformer: Map variables, scripts, assertions
Exporter->>Transformer: Aggregate environments & metadata
Transformer-->>Exporter: Transformed OpenCollection object
end
Exporter-->>Handler: Return OpenCollection
Handler->>FileSaver: exportCollection (YAML)
FileSaver->>FileSaver: Serialize to YAML
FileSaver-->>User: Download {collectionName}.yaml ✓
Handler->>UI: Close modal
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Areas requiring extra attention:
Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 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 (5)
packages/bruno-app/src/utils/exporters/opencollection.js (2)
750-757: Dead code:config.environmentsdeletion is unreachable.
transformConfignever creates anenvironmentsproperty, so this check and deletion will never execute.const config = transformConfig(collection.brunoConfig); if (config) { openCollection.config = config; - - if (config.environments) { - delete config.environments; - } }
797-811: Sanitize filename to prevent issues with special characters.
collection.namecould contain characters invalid for filenames (e.g.,/,\,:). Consider sanitizing before use.+const sanitizeFilename = (name) => { + return (name || 'collection').replace(/[/\\:*?"<>|]/g, '_'); +}; + export const exportCollection = (collection) => { const openCollection = brunoToOpenCollection(collection); const yamlContent = jsyaml.dump(openCollection, { indent: 2, lineWidth: -1, noRefs: true, sortKeys: false }); - const fileName = `${collection.name}.yml`; + const fileName = `${sanitizeFilename(collection.name)}.yml`; const fileBlob = new Blob([yamlContent], { type: 'application/x-yaml' }); FileSaver.saveAs(fileBlob, fileName); };packages/bruno-app/src/utils/importers/opencollection.js (3)
280-292: Minor edge case: array values.Line 286 uses
typeof v.value === 'object'which is also true for arrays. Ifv.valuewere an array, accessing.datawould returnundefined, falling back to''. This works but relies on implicit behavior.If arrays are never expected here, consider adding explicit handling for clarity:
- value: typeof v.value === 'object' ? v.value.data || '' : v.value || '', + value: typeof v.value === 'object' && v.value !== null && !Array.isArray(v.value) ? v.value.data || '' : v.value || '',
605-628: Redundant condition.Line 605: The
&& config.proxy !== falsecheck is redundant sinceconfig.proxybeingfalsewould already fail the first condition.- if (config.proxy && config.proxy !== false) { + if (config.proxy) {That said, if the explicit intent is to document that
falseis a valid sentinel value in OpenCollection, keeping it is acceptable for readability.
740-752: Original error context lost in BrunoError.The catch block logs the original error but throws a generic
BrunoErrorwithout the original message or cause. This can make debugging import failures difficult.Consider including the original error message:
} catch (err) { console.error('Error processing OpenCollection:', err); - throw new BrunoError('Import OpenCollection failed'); + throw new BrunoError(`Import OpenCollection failed: ${err.message}`); }
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
packages/bruno-app/src/components/ShareCollection/index.js(3 hunks)packages/bruno-app/src/components/Sidebar/ImportCollection/index.js(3 hunks)packages/bruno-app/src/components/Sidebar/ImportCollectionLocation/index.js(3 hunks)packages/bruno-app/src/providers/ReduxStore/slices/workspaces/actions.js(1 hunks)packages/bruno-app/src/utils/exporters/opencollection.js(1 hunks)packages/bruno-app/src/utils/importers/opencollection.js(1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{js,jsx,ts,tsx}
📄 CodeRabbit inference engine (CODING_STANDARDS.md)
**/*.{js,jsx,ts,tsx}: Use 2 spaces for indentation. No tabs, just spaces
Stick to single quotes for strings. For JSX/TSX attributes, use double quotes (e.g., )
Always add semicolons at the end of statements
No trailing commas
Always use parentheses around parameters in arrow functions, even for single params
For multiline constructs, put opening braces on the same line, and ensure consistency. Minimum 2 elements for multiline
No newlines inside function parentheses
Space before and after the arrow in arrow functions.() => {}is good
No space between function name and parentheses.func()notfunc ()
Semicolons go at the end of the line, not on a new line
Names for functions need to be concise and descriptive
Add in JSDoc comments to add more details to the abstractions if needed
Add in meaningful comments instead of obvious ones where complex code flow is explained properly
Files:
packages/bruno-app/src/utils/exporters/opencollection.jspackages/bruno-app/src/components/Sidebar/ImportCollectionLocation/index.jspackages/bruno-app/src/utils/importers/opencollection.jspackages/bruno-app/src/components/ShareCollection/index.jspackages/bruno-app/src/providers/ReduxStore/slices/workspaces/actions.jspackages/bruno-app/src/components/Sidebar/ImportCollection/index.js
🧬 Code graph analysis (5)
packages/bruno-app/src/utils/exporters/opencollection.js (1)
packages/bruno-app/src/utils/importers/opencollection.js (8)
transformItem(532-554)transformFolder(491-530)transformItems(556-560)transformEnvironments(562-575)root(658-658)brunoConfig(578-583)config(585-585)collection(742-742)
packages/bruno-app/src/components/Sidebar/ImportCollectionLocation/index.js (1)
packages/bruno-app/src/utils/importers/opencollection.js (3)
collection(742-742)processOpenCollection(740-752)processOpenCollection(740-752)
packages/bruno-app/src/utils/importers/opencollection.js (2)
packages/bruno-app/src/utils/exporters/opencollection.js (20)
auth(324-324)auth(423-423)auth(481-481)auth(536-536)auth(592-592)auth(657-657)headers(315-315)headers(410-410)headers(514-514)headers(591-591)headers(654-654)params(318-318)params(413-413)body(321-321)variables(330-330)variables(429-429)variables(487-487)variables(542-542)variables(594-594)variables(660-660)packages/bruno-app/src/utils/common/error.js (1)
BrunoError(4-10)
packages/bruno-app/src/providers/ReduxStore/slices/workspaces/actions.js (1)
packages/bruno-app/src/utils/importers/opencollection.js (3)
processOpenCollection(740-752)processOpenCollection(740-752)collection(742-742)
packages/bruno-app/src/components/Sidebar/ImportCollection/index.js (1)
packages/bruno-app/src/utils/importers/opencollection.js (2)
isOpenCollection(754-768)isOpenCollection(754-768)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
- GitHub Check: SSL Tests - Windows
- GitHub Check: SSL Tests - macOS
- GitHub Check: SSL Tests - Linux
- GitHub Check: Playwright E2E Tests
- GitHub Check: Unit Tests
- GitHub Check: CLI Tests
🔇 Additional comments (24)
packages/bruno-app/src/utils/exporters/opencollection.js (5)
4-66: LGTM on auth transformation.Comprehensive handling of all auth modes including basic, bearer, digest, NTLM, AWS v4, API key, WSSE, and OAuth2. The early returns for
noneandinheritmodes are clean.
68-176: OAuth2 transformation covers all standard grant types.Good coverage of client_credentials, password, authorization_code, and implicit flows with proper token configuration mapping.
178-251: Clean header, param, and body transformers.Appropriate use of spread for optional properties. The body transformer handles all Bruno body modes including GraphQL bodies correctly.
304-397: HTTP request transformation is thorough.Includes examples transformation with proper request/response mapping. All optional fields are conditionally added.
556-576: Verify item type mapping consistency with importer.The switch cases use Bruno's internal types (
http-request,graphql-request, etc.) while the transformation functions output OpenCollection types. Confirm the importer'stransformItemcorrectly reverses this mapping (e.g.,http→http-request).packages/bruno-app/src/components/Sidebar/ImportCollection/index.js (3)
11-11: LGTM on import addition.Correct import path for the new OpenCollection validator.
76-77: Detection order is appropriate.OpenCollection is checked after more specific formats (OpenAPI, WSDL, Postman, Insomnia) but before Bruno's native format. Since
isOpenCollectionchecks for theopencollectionversion string property, this ordering prevents false positives.
165-165: Help text updated correctly.Users are now informed that OpenCollection format is supported alongside other formats.
packages/bruno-app/src/components/Sidebar/ImportCollectionLocation/index.js (3)
11-11: LGTM on import.
40-41: Collection name extraction follows existing patterns.Correctly accesses
info.namewith fallback to 'OpenCollection', consistent with other formats.
70-72: Conversion case correctly uses async processor.
processOpenCollectionhandles schema validation, UID hydration, and sequence numbering per the relevant snippet.packages/bruno-app/src/providers/ReduxStore/slices/workspaces/actions.js (1)
37-40: LGTM on Redux action handler.Follows established dynamic import pattern for code splitting, consistent with other collection types.
packages/bruno-app/src/components/ShareCollection/index.js (3)
3-3: LGTM on new imports.
IconFileExportis appropriate for a generic export action, differentiating from Bruno's logo and Postman's download icon.Also applies to: 8-8
52-56: Export handler follows established pattern.Uses
transformCollectionToSaveToExportAsFilelike Bruno export, ensuring consistent data preparation.
86-105: OpenCollection export UI is well-integrated.No warning banner needed here since OpenCollection format supports gRPC and WebSocket requests (unlike Postman). Loading states and click handlers mirror existing export options.
packages/bruno-app/src/utils/importers/opencollection.js (9)
1-4: LGTM!Imports are clean and all are utilized throughout the file.
6-196: LGTM!Auth transformation covers all expected types including comprehensive OAuth2 flow handling. The nested helper functions for token/credentials placement are cleanly encapsulated.
318-394: LGTM!HTTP and GraphQL item transformers are thorough. Examples handling correctly maps both request and response data. Default method for GraphQL being 'POST' is appropriate.
396-489: LGTM!gRPC and WebSocket transformers handle both single-message and multi-message formats gracefully. Using
metadatafor gRPC headers is the correct OpenCollection convention.
532-560: LGTM!The
transformItemswitch handles all expected types and gracefully returnsnullfor unknown types, whichtransformItemsfilters out. Clean recursive pattern for nested structures.
562-575: LGTM!Environment transformation correctly maps OpenCollection's
transientproperty to Bruno'ssecretfield.
681-692: LGTM!
openCollectionToBrunocleanly orchestrates the conversion by delegating to specialized transform functions. Good separation of concerns.
694-738: LGTM!Recursive UID assignment for root and nested folder roots is correct. The mutation pattern is consistent with the related
updateUidsInCollectionutility.
754-768: LGTM!
isOpenCollectionprovides robust structural validation for format detection. The checks for requiredopencollectionstring andinfoobject are appropriate guards.
Description
Contribution Checklist:
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
Release Notes
✏️ Tip: You can customize this high-level summary in your review settings.