Skip to content

feat: add support for duplicate request url + type in OpenAPI spec - #8028

Merged
naman-bruno merged 3 commits into
usebruno:mainfrom
prateek-bruno:feat/duplicate-request-url-type-openapi-spec
May 26, 2026
Merged

naman-bruno merged 3 commits into
usebruno:mainfrom
prateek-bruno:feat/duplicate-request-url-type-openapi-spec

Conversation

@prateek-bruno

@prateek-bruno prateek-bruno commented May 18, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Jira

Currently the OpenAPI spec doesn't allow duplicate request url + type and it only keeps one.

After this change it will create a new x-bruno-variants that will be used to keep the duplicates instead of discard it.

Screen.Recording.2026-05-24.at.2.18.37.PM.mov

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

    • Export now preserves duplicate operations as distinct variants (annotated via x-bruno-variants) and respects operation-level server overrides.
    • Import restores variants as separate requests, keeping per-variant servers, parameters, tags, and distinct request-body/security references.
    • Component IDs for request bodies and security schemes are generated consistently and referenced across variants.
    • Export filters out transient and grpc-request items; tag extraction handles both / and \ separators.
  • Bug Fixes

    • JSON/XML parse failures emit warnings and handle component registration safely.
  • Tests

    • Added tests for variant export/import, per-variant examples, component handling, and server overrides.

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 18, 2026 •

Copy link
Copy Markdown
Contributor

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Hidden review stack artifact

Walkthrough

Export assigns unique component IDs per request, aggregates duplicate {url,method} operations into operation.x-bruno-variants, and records per-variant components and security schemes; the importer expands x-bruno-variants into separate Bruno requests, preserving variant servers, tags, parameters, and component/security references.

Changes

OpenAPI duplicate operation variants

Layer / File(s) Summary
Exporter: per-item component IDs & variant accumulation
packages/bruno-app/src/utils/exporters/openapi-spec.js
Filters out grpc-request and transient items, extracts tags by splitting pathname on / or \\, generates unique componentId per item, registers components.schemas/requestBodies/securitySchemes under that id for JSON/XML/multipart/formUrlEncoded bodies and auth schemes, and appends duplicate {url, method} operations into operation.x-bruno-variants while applying operation-level servers when present.
Exporter tests for server metadata and JSON round-trip
packages/bruno-app/src/utils/exporters/openapi-spec.spec.js
Adds a nanoid Jest mock, updates baseUrl test metadata, and adds exportApiSpec - duplicate operation variants tests asserting x-bruno-variants entries preserve per-variant summaries, tags, parameter examples, operation-level servers, distinct requestBody/security component refs (with conflict suffixing), and round-trip preservation without nested variants.
Importer: expand x-bruno-variants into requests
packages/bruno-converters/src/openapi/openapi-to-bruno.js
parseOpenApiCollection expands operations with x-bruno-variants into multiple Bruno requests (base + variants), removes x-bruno-variants, merges path-item and operation parameters (operation-level overrides win), converts {name} placeholders to :name, and emits one request per operation/variant preserving global security and setting per-request servers.
Importer tests: variant import, servers, and tag grouping
packages/bruno-converters/tests/openapi/openapi-to-bruno/openapi-server-variables.spec.js
New tests verify x-bruno-variants imports as distinct request items without preserving the extension, map variant operation.servers into each request's request.vars.req.baseUrl, and group variant requests into folders based on variant tags.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • usebruno/bruno#7622: Both PRs modify packages/bruno-converters/src/openapi/openapi-to-bruno.js, extending request-expansion/dispatch behavior.
  • usebruno/bruno#7170: Prior work on operation-level server overrides in export/import flows; overlaps on server handling paths.
  • usebruno/bruno#7107: Related edits around tag extraction/sanitization and OpenAPI import/export tag handling.

Suggested labels

size/L

Suggested reviewers

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

Poem

Exporter carves each name to id, no shadows left to hide,
Variants gather, tagged and stored, each server kept inside.
Importer fans the bundled rows and spans them back to one,
Components, auth, and bodies stay where every variant's spun. 🚀

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main feature: adding support for duplicate request URL + type in OpenAPI spec through the x-bruno-variants mechanism.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@prateek-bruno
prateek-bruno marked this pull request as ready for review May 18, 2026 12:42

@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.

🧹 Nitpick comments (1)
packages/bruno-converters/tests/openapi/openapi-to-bruno/openapi-server-variables.spec.js (1)

383-383: ⚡ Quick win

Assert extension removal on the request item object.

On Line 383, the check targets request.request['x-bruno-variants'], but extension leakage would occur on the request item object itself. This can hide regressions.

Proposed test fix
-    expect(requests.every((request) => !request.request['x-bruno-variants'])).toBe(true);
+    expect(requests.every((request) => request['x-bruno-variants'] === undefined)).toBe(true);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@packages/bruno-converters/tests/openapi/openapi-to-bruno/openapi-server-variables.spec.js`
at line 383, The test currently checks for the extension on request.request
(expect(requests.every((request) => !request.request['x-bruno-variants']))) but
the extension would be attached to the request item itself; update the predicate
to assert the extension is removed from the request item by checking
request['x-bruno-variants'] (i.e., expect(requests.every((request) =>
!request['x-bruno-variants'])).toBe(true)). Ensure you update the assertion that
iterates over the requests array in openapi-server-variables.spec.js
accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In
`@packages/bruno-converters/tests/openapi/openapi-to-bruno/openapi-server-variables.spec.js`:
- Line 383: The test currently checks for the extension on request.request
(expect(requests.every((request) => !request.request['x-bruno-variants']))) but
the extension would be attached to the request item itself; update the predicate
to assert the extension is removed from the request item by checking
request['x-bruno-variants'] (i.e., expect(requests.every((request) =>
!request['x-bruno-variants'])).toBe(true)). Ensure you update the assertion that
iterates over the requests array in openapi-server-variables.spec.js
accordingly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: a497594c-ef7b-4ea0-9211-8ac8fd27218c

📥 Commits

Reviewing files that changed from the base of the PR and between e8468ac and 6541f98.

📒 Files selected for processing (4)
  • packages/bruno-app/src/utils/exporters/openapi-spec.js
  • packages/bruno-app/src/utils/exporters/openapi-spec.spec.js
  • packages/bruno-converters/src/openapi/openapi-to-bruno.js
  • packages/bruno-converters/tests/openapi/openapi-to-bruno/openapi-server-variables.spec.js

@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: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/bruno-app/src/utils/exporters/openapi-spec.js (1)

342-445: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Fix OpenAPI security and auth scheme serialization

  • pathBody['security'] is still emitted as an object ({ [componentId]: [] }), but OpenAPI requires security to be an array of security requirement objects (e.g., [{ [componentId]: [] }]) across all these auth variants.
  • OAuth2 client_credentials is mapped to flows.password; it should use flows.clientCredentials.
  • Digest auth is emitted as type: 'digest'; it should be type: 'http' with scheme: 'digest'.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/bruno-app/src/utils/exporters/openapi-spec.js` around lines 342 -
445, The code emits invalid OpenAPI security and flow types: update all places
where pathBody['security'] is assigned so it becomes an array of requirement
objects (e.g., wrap the existing { [componentId]: [] } inside [ ... ]), change
the oauth2 client_credentials branch in the switch under auth?.oauth2.grantType
(the case 'client_credentials' in the oauth2 handling) to use
flows.clientCredentials instead of flows.password, and adjust the digest branch
(the case 'digest' that currently sets components.securitySchemes[componentId] =
{ type: 'digest', scheme: 'digest', ... }) to use { type: 'http', scheme:
'digest', description: 'Digest Authentication' } while keeping
components.securitySchemes and pathBody updates consistent with the other cases.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/bruno-app/src/utils/exporters/openapi-spec.js`:
- Around line 283-287: In components.requestBodies[componentId] you are using
invalid media-type keys with trailing colons ('multipart/form-data:' and
'application/x-www-form-urlencoded:'); remove the trailing ':' so the keys are
exactly 'multipart/form-data' and 'application/x-www-form-urlencoded' (update
the object literals where these strings are used around the requestBodies
creation to use the corrected media-type keys).
- Around line 360-361: The switch case for 'oauth2' declares const {
authorizationUrl, accessTokenUrl, callbackUrl, scope } = auth?.oauth2; directly
under the case label which violates noSwitchDeclarations; fix it by wrapping the
entire case 'oauth2' branch in braces (i.e. case 'oauth2': { ... break; }) so
the const destructuring and any local variables are in a block scope and Biome
will stop flagging it; ensure you keep the existing guard if
(!auth?.oauth2?.grantType) break; and existing logic inside the new { } block.

---

Outside diff comments:
In `@packages/bruno-app/src/utils/exporters/openapi-spec.js`:
- Around line 342-445: The code emits invalid OpenAPI security and flow types:
update all places where pathBody['security'] is assigned so it becomes an array
of requirement objects (e.g., wrap the existing { [componentId]: [] } inside [
... ]), change the oauth2 client_credentials branch in the switch under
auth?.oauth2.grantType (the case 'client_credentials' in the oauth2 handling) to
use flows.clientCredentials instead of flows.password, and adjust the digest
branch (the case 'digest' that currently sets
components.securitySchemes[componentId] = { type: 'digest', scheme: 'digest',
... }) to use { type: 'http', scheme: 'digest', description: 'Digest
Authentication' } while keeping components.securitySchemes and pathBody updates
consistent with the other cases.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: c856212d-88e8-43b2-9718-d9199aecb44e

📥 Commits

Reviewing files that changed from the base of the PR and between 6541f98 and 68872d2.

📒 Files selected for processing (2)
  • packages/bruno-app/src/utils/exporters/openapi-spec.js
  • packages/bruno-app/src/utils/exporters/openapi-spec.spec.js

@prateek-bruno
prateek-bruno force-pushed the feat/duplicate-request-url-type-openapi-spec branch from 6f14181 to 64c9a3e Compare May 21, 2026 20:11

@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: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/bruno-app/src/utils/exporters/openapi-spec.js`:
- Around line 304-349: The switch cases for 'multipartForm' and 'formUrlEncoded'
declare const/let bindings directly under the case labels which violates
noSwitchDeclarations; fix by wrapping each case body in its own block (i.e., add
{ ... } around the code for the 'multipartForm' and 'formUrlEncoded' branches)
so getItemComponentId, multipartFormToKeyValue, formUrlEncodedToKeyValue,
components.schemas/ requestBodies assignments, generateProperyShape calls, and
the pathBody['requestBody'] = ... lines are block-scoped; keep the existing
break statements inside those new blocks.

In `@packages/bruno-app/src/utils/exporters/openapi-spec.spec.js`:
- Around line 220-230: The helper flattenItemsForExport currently hardcodes
Windows backslashes in pathname and depth computation; update
flattenItemsForExport to build pathnames using Node's path.join (import path)
and compute depth using path.sep (or splitting on path.sep), e.g., join
parentPath and item.name plus '.bru' for pathname and derive depth from
parentPath.split(path.sep). Also update the exporter parsing/normalization code
that consumes pathname to use path.normalize or split on path.sep so tests are
OS-agnostic (refer to flattenItemsForExport and the exporter parse/normalize
function names in the diff when making the changes).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 29137dfc-bcb9-43d2-90ee-1433715fb290

📥 Commits

Reviewing files that changed from the base of the PR and between 68872d2 and 6f14181.

📒 Files selected for processing (2)
  • packages/bruno-app/src/utils/exporters/openapi-spec.js
  • packages/bruno-app/src/utils/exporters/openapi-spec.spec.js

@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

♻️ Duplicate comments (3)
packages/bruno-app/src/utils/exporters/openapi-spec.spec.js (1)

220-232: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

flattenItemsForExport helper (and the surrounding fixtures) still hardcode Windows-style \\ separators.

Same concern as the previous round of review — the pathname/depth plumbing here pins variant coverage to Windows. Build paths with path.join() and derive depth via path.sep (or path.split(path.sep)) so the suite runs identically on macOS/Linux. Note that the source-side extractTagFromDepth in openapi-spec.js also splits on '\\', so the fix likely needs a coordinated touch on the exporter too.

Sketch of an OS-agnostic helper
+const path = require('path');
+
 describe('exportApiSpec - duplicate operation variants', () => {
-  const flattenItemsForExport = (items, parentPath = 'collection') => {
-    return items.flatMap((item) => {
-      if (item.type === 'folder') {
-        return flattenItemsForExport(item.items || [], `${parentPath}\\${item.name}`);
-      }
-
-      return [{
-        ...item,
-        pathname: `${parentPath}\\${item.name}.bru`,
-        depth: parentPath.split('\\').length
-      }];
-    });
-  };
+  const flattenItemsForExport = (items, parentPath = 'collection') => {
+    return items.flatMap((item) => {
+      if (item.type === 'folder') {
+        return flattenItemsForExport(item.items || [], path.join(parentPath, item.name));
+      }
+
+      return [{
+        ...item,
+        pathname: path.join(parentPath, `${item.name}.bru`),
+        depth: parentPath.split(path.sep).length
+      }];
+    });
+  };

As per coding guidelines: "File paths must use path.join() or path.resolve() instead of hardcoded / or \\ separators".

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/bruno-app/src/utils/exporters/openapi-spec.spec.js` around lines 220
- 232, The flattenItemsForExport helper currently hardcodes Windows backslashes;
update flattenItemsForExport to build pathname using path.join(parentPath,
`${item.name}.bru`) (importing Node's path) and compute depth by splitting
parentPath on path.sep (e.g., parentPath.split(path.sep).length) instead of
'\\'; also update the recursive call to use path.join(parentPath, item.name) for
folders. Make a coordinated change to the corresponding source helper
extractTagFromDepth in openapi-spec.js so it derives depth/tags by splitting on
path.sep rather than '\\', and adjust any test fixtures that hardcode
backslashes to use path.join or platform-agnostic values.
packages/bruno-app/src/utils/exporters/openapi-spec.js (2)

304-348: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Block-scope the multipartForm and formUrlEncoded cases, and also fix the stray : in the media-type keys.

Two issues survive in this hunk that prior reviews already called out:

  1. Biome noSwitchDeclarations still trips on the const multipartFormComponentId / const formUrlEncodedComponentId (and let …KeyValue) declared directly under the case labels (lines 306, 307–310, 329, 330–333).
  2. The media-type keys are still 'multipart/form-data:' and 'application/x-www-form-urlencoded:' — that trailing : makes consumers miss the body entirely.

Both can be fixed in one go:

Proposed fix
-          case 'multipartForm':
+          case 'multipartForm': {
             if (!body?.multipartForm) break;
             const multipartFormComponentId = getItemComponentId();
             let multipartFormToKeyValue = body?.multipartForm.reduce((acc, f) => {
               acc[f?.name] = f.value;
               return acc;
             }, {});
             components.schemas[multipartFormComponentId] = generateProperyShape(multipartFormToKeyValue);
             components.requestBodies[multipartFormComponentId] = {
               content: {
-                'multipart/form-data:': {
+                'multipart/form-data': {
                   schema: {
                     $ref: `#/components/schemas/${multipartFormComponentId}`
                   }
                 }
               },
               description: '',
               required: true
             };
             pathBody['requestBody'] = {
               $ref: `#/components/requestBodies/${multipartFormComponentId}`
             };
             break;
-          case 'formUrlEncoded':
+          }
+          case 'formUrlEncoded': {
             if (!body?.formUrlEncoded) break;
             const formUrlEncodedComponentId = getItemComponentId();
             let formUrlEncodedToKeyValue = body?.formUrlEncoded.reduce((acc, f) => {
               acc[f?.name] = f.value;
               return acc;
             }, {});
             components.schemas[formUrlEncodedComponentId] = generateProperyShape(formUrlEncodedToKeyValue);
             components.requestBodies[formUrlEncodedComponentId] = {
               content: {
-                'application/x-www-form-urlencoded:': {
+                'application/x-www-form-urlencoded': {
                   schema: {
                     $ref: `#/components/schemas/${formUrlEncodedComponentId}`
                   }
                 }
               },
               description: '',
               required: true
             };
             pathBody['requestBody'] = {
               $ref: `#/components/requestBodies/${formUrlEncodedComponentId}`
             };
             break;
+          }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/bruno-app/src/utils/exporters/openapi-spec.js` around lines 304 -
348, The switch cases for multipartForm and formUrlEncoded declare block-scoped
variables (multipartFormComponentId, formUrlEncodedComponentId,
multipartFormToKeyValue, formUrlEncodedToKeyValue) directly under the case
labels which trips noSwitchDeclarations; wrap each case body in braces to create
a proper block so those const/let declarations are scoped correctly, and while
editing fix the media-type keys in components.requestBodies to remove the stray
trailing colons (use 'multipart/form-data' and
'application/x-www-form-urlencoded' as the content keys) so consumers can find
the requestBody referenced by pathBody['requestBody'] (keep using
getItemComponentId and generateProperyShape as before).

391-457: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Wrap the oauth2 case in a block.

const { authorizationUrl, accessTokenUrl, callbackUrl, scope } = auth?.oauth2; is still declared directly under case 'oauth2':, so Biome keeps flagging it (noSwitchDeclarations at line 394). Quick fix:

Proposed fix
-          case 'oauth2':
+          case 'oauth2': {
             if (!auth?.oauth2?.grantType) break;
             componentId = getItemComponentId();
             const { authorizationUrl, accessTokenUrl, callbackUrl, scope } = auth?.oauth2;
             switch (auth?.oauth2?.grantType) {
@@
             }
             break;
+          }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/bruno-app/src/utils/exporters/openapi-spec.js` around lines 391 -
457, The switch case for 'oauth2' declares variables directly under the case
which triggers noSwitchDeclarations; fix it by wrapping the case 'oauth2' body
in a block (add { ... } after case 'oauth2':) and move the destructuring line
const { authorizationUrl, accessTokenUrl, callbackUrl, scope } = auth?.oauth2;
(and any other local declarations like componentId) inside that block so all
declarations are scoped properly; keep the existing logic that sets
components.securitySchemes[componentId] and pathBody['security'] for the
authorization_code, password, and client_credentials branches unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/bruno-converters/src/openapi/openapi-to-bruno.js`:
- Around line 859-877: Variants are currently using only operationObjectCleaned,
causing sparse variants to drop base operation fields (like parameters and
servers); update the loop to first merge each variant with the base operation
(e.g., build a mergedOperation by spreading base operationObject and then
spreading the variant to let per-variant values override), then delete
'x-bruno-variants' from that mergedOperation and compute mergedParams =
mergeParams(pathItemParams, mergedOperation.parameters || []), and use
mergedOperation.servers || pathItemObject.servers || null when constructing the
request pushed into requests so variants inherit base fields before overrides.

---

Duplicate comments:
In `@packages/bruno-app/src/utils/exporters/openapi-spec.js`:
- Around line 304-348: The switch cases for multipartForm and formUrlEncoded
declare block-scoped variables (multipartFormComponentId,
formUrlEncodedComponentId, multipartFormToKeyValue, formUrlEncodedToKeyValue)
directly under the case labels which trips noSwitchDeclarations; wrap each case
body in braces to create a proper block so those const/let declarations are
scoped correctly, and while editing fix the media-type keys in
components.requestBodies to remove the stray trailing colons (use
'multipart/form-data' and 'application/x-www-form-urlencoded' as the content
keys) so consumers can find the requestBody referenced by
pathBody['requestBody'] (keep using getItemComponentId and generateProperyShape
as before).
- Around line 391-457: The switch case for 'oauth2' declares variables directly
under the case which triggers noSwitchDeclarations; fix it by wrapping the case
'oauth2' body in a block (add { ... } after case 'oauth2':) and move the
destructuring line const { authorizationUrl, accessTokenUrl, callbackUrl, scope
} = auth?.oauth2; (and any other local declarations like componentId) inside
that block so all declarations are scoped properly; keep the existing logic that
sets components.securitySchemes[componentId] and pathBody['security'] for the
authorization_code, password, and client_credentials branches unchanged.

In `@packages/bruno-app/src/utils/exporters/openapi-spec.spec.js`:
- Around line 220-232: The flattenItemsForExport helper currently hardcodes
Windows backslashes; update flattenItemsForExport to build pathname using
path.join(parentPath, `${item.name}.bru`) (importing Node's path) and compute
depth by splitting parentPath on path.sep (e.g.,
parentPath.split(path.sep).length) instead of '\\'; also update the recursive
call to use path.join(parentPath, item.name) for folders. Make a coordinated
change to the corresponding source helper extractTagFromDepth in openapi-spec.js
so it derives depth/tags by splitting on path.sep rather than '\\', and adjust
any test fixtures that hardcode backslashes to use path.join or
platform-agnostic values.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 97bc1602-58d0-496c-a1b0-c9257f74716d

📥 Commits

Reviewing files that changed from the base of the PR and between 6f14181 and 64c9a3e.

📒 Files selected for processing (4)
  • packages/bruno-app/src/utils/exporters/openapi-spec.js
  • packages/bruno-app/src/utils/exporters/openapi-spec.spec.js
  • packages/bruno-converters/src/openapi/openapi-to-bruno.js
  • packages/bruno-converters/tests/openapi/openapi-to-bruno/openapi-server-variables.spec.js

@prateek-bruno
prateek-bruno force-pushed the feat/duplicate-request-url-type-openapi-spec branch from 64c9a3e to eae6523 Compare May 21, 2026 20:27

@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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/bruno-app/src/utils/exporters/openapi-spec.js (1)

439-458: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Fix OAuth2 client_credentials OpenAPI flow mapping

client_credentials currently maps to flows.password; OpenAPI 3.0 requires flows.clientCredentials.

  • Also, when scope.length === 0, the current code omits scopes, but OpenAPI requires scopes (an empty object {} is acceptable).
🐛 Proposed fix
               case 'client_credentials':
                 components.securitySchemes[componentId] = {
                   type: 'oauth2',
                   flows: {
-                    password: {
+                    clientCredentials: {
                       tokenUrl: accessTokenUrl,
                       ...(scope.length > 0
                         ? {
                             scopes: {
                               [scope]: ''
                             }
                           }
                         : {})
                     }
                   }
                 };
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/bruno-app/src/utils/exporters/openapi-spec.js` around lines 439 -
458, The OAuth2 mapping for the 'client_credentials' case is wrong: change the
flows key from password to clientCredentials and ensure scopes is always present
(use an empty object {} when scope.length === 0). Specifically, update the
switch case handling 'client_credentials' that sets
components.securitySchemes[componentId] so flows uses clientCredentials with
tokenUrl set to accessTokenUrl, and adjust the scopes construction so it yields
either { [scope]: '' } or {} (never omitted); leave the pathBody['security']
assignment as-is.
♻️ Duplicate comments (3)
packages/bruno-converters/src/openapi/openapi-to-bruno.js (1)

858-877: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Variants should inherit base operation fields before override.

Line 865 and Line 876 currently resolve from the variant object only. Sparse variants will drop base fields (e.g., parameters, servers, security, requestBody) instead of inheriting and overriding selectively.

Proposed minimal fix
-            operations.forEach((operation) => {
-              const operationObjectCleaned = { ...operation };
-              delete operationObjectCleaned['x-bruno-variants'];
-              const mergedParams = mergeParams(pathItemParams, operationObjectCleaned.parameters || []);
+            operations.forEach((operation) => {
+              const operationObjectCleaned = { ...operation };
+              delete operationObjectCleaned['x-bruno-variants'];
+
+              const effectiveOperation = operation === operationObject
+                ? operationObjectCleaned
+                : { ...operationObject, ...operationObjectCleaned };
+              delete effectiveOperation['x-bruno-variants'];
+
+              const mergedParams = mergeParams(pathItemParams, effectiveOperation.parameters || []);

               requests.push({
                 method: method,
                 path: path.replace(/{([^}]+)}/g, ':$1'), // Replace placeholders enclosed in curly braces with colons
                 originalPath: path, // Keep original path for grouping
-                operationObject: { ...operationObjectCleaned, parameters: mergedParams },
+                operationObject: { ...effectiveOperation, parameters: mergedParams },
                 global: {
                   server: '{{baseUrl}}',
                   security: securityConfig
                 },
-                servers: operationObjectCleaned.servers || pathItemObject.servers || null
+                servers: effectiveOperation.servers || pathItemObject.servers || null
               });
             });
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/bruno-converters/src/openapi/openapi-to-bruno.js` around lines 858 -
877, The variant handling in the reduce callback currently uses the variant
object alone, so sparse variants drop base operation fields; change the logic to
merge each variant with its base operationObject before cleaning and processing
(i.e., produce a mergedOperation = { ...operationObject, ...variant } or
equivalent deep merge for arrays/objects), then delete x-bruno-variants from
mergedOperation, compute mergedParams from pathItemParams and
mergedOperation.parameters, and use mergedOperation.servers,
mergedOperation.security, mergedOperation.requestBody when building the requests
entry so variants inherit base fields and only override specified keys; update
references operationObjectCleaned and mergedParams accordingly.
packages/bruno-app/src/utils/exporters/openapi-spec.js (2)

314-320: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Invalid media type key: trailing colon breaks OpenAPI consumers.

'multipart/form-data:' is not a valid MIME type. Remove the trailing colon so consumers can correctly parse the request body.

🐛 Proposed fix
             components.requestBodies[multipartFormComponentId] = {
               content: {
-                'multipart/form-data:': {
+                'multipart/form-data': {
                   schema: {
                     $ref: `#/components/schemas/${multipartFormComponentId}`
                   }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/bruno-app/src/utils/exporters/openapi-spec.js` around lines 314 -
320, The requestBodies entry uses an invalid media type key
'multipart/form-data:' (trailing colon) which breaks OpenAPI consumers; update
the components.requestBodies creation to use the correct MIME type
'multipart/form-data' for the content key where multipartFormComponentId is used
(and search for any other occurrences of 'multipart/form-data:' in this module
to replace them as well) so the schema $ref remains under a valid media type.

337-343: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Invalid media type key: trailing colon breaks OpenAPI consumers.

'application/x-www-form-urlencoded:' has the same trailing colon issue. Remove it.

🐛 Proposed fix
             components.requestBodies[formUrlEncodedComponentId] = {
               content: {
-                'application/x-www-form-urlencoded:': {
+                'application/x-www-form-urlencoded': {
                   schema: {
                     $ref: `#/components/schemas/${formUrlEncodedComponentId}`
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/bruno-app/src/utils/exporters/openapi-spec.js` around lines 337 -
343, The media type key for the form urlencoded request body is incorrect: in
components.requestBodies the key is written as
'application/x-www-form-urlencoded:' (with a trailing colon) which breaks
OpenAPI consumers; update the object under
components.requestBodies[formUrlEncodedComponentId].content to use the correct
media type 'application/x-www-form-urlencoded' (no trailing colon) wherever
formUrlEncodedComponentId is used so the schema $ref remains under the valid
media type key.
🧹 Nitpick comments (1)
packages/bruno-converters/tests/openapi/openapi-to-bruno/openapi-server-variables.spec.js (1)

345-456: ⚡ Quick win

Add a sparse-variant inheritance regression test.

Current coverage is good, but it doesn’t assert that a variant with only partial fields inherits base operation fields (especially parameters and servers). Adding that test will lock down the intended contract.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@packages/bruno-converters/tests/openapi/openapi-to-bruno/openapi-server-variables.spec.js`
around lines 345 - 456, Add a new test in the same spec file that calls
openApiToBruno with an operation that defines servers and parameters on the base
operation and a sparse x-bruno-variants entry that only supplies a summary (or
one overridden parameter); assert the variant's generated request inherits the
base operation's parameters (inspect request.request.params values) and baseUrl
server (inspect request.request.vars.req[0].value or .name === 'baseUrl') so
that partial variants merge fields rather than dropping them.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@packages/bruno-app/src/utils/exporters/openapi-spec.js`:
- Around line 439-458: The OAuth2 mapping for the 'client_credentials' case is
wrong: change the flows key from password to clientCredentials and ensure scopes
is always present (use an empty object {} when scope.length === 0).
Specifically, update the switch case handling 'client_credentials' that sets
components.securitySchemes[componentId] so flows uses clientCredentials with
tokenUrl set to accessTokenUrl, and adjust the scopes construction so it yields
either { [scope]: '' } or {} (never omitted); leave the pathBody['security']
assignment as-is.

---

Duplicate comments:
In `@packages/bruno-app/src/utils/exporters/openapi-spec.js`:
- Around line 314-320: The requestBodies entry uses an invalid media type key
'multipart/form-data:' (trailing colon) which breaks OpenAPI consumers; update
the components.requestBodies creation to use the correct MIME type
'multipart/form-data' for the content key where multipartFormComponentId is used
(and search for any other occurrences of 'multipart/form-data:' in this module
to replace them as well) so the schema $ref remains under a valid media type.
- Around line 337-343: The media type key for the form urlencoded request body
is incorrect: in components.requestBodies the key is written as
'application/x-www-form-urlencoded:' (with a trailing colon) which breaks
OpenAPI consumers; update the object under
components.requestBodies[formUrlEncodedComponentId].content to use the correct
media type 'application/x-www-form-urlencoded' (no trailing colon) wherever
formUrlEncodedComponentId is used so the schema $ref remains under the valid
media type key.

In `@packages/bruno-converters/src/openapi/openapi-to-bruno.js`:
- Around line 858-877: The variant handling in the reduce callback currently
uses the variant object alone, so sparse variants drop base operation fields;
change the logic to merge each variant with its base operationObject before
cleaning and processing (i.e., produce a mergedOperation = { ...operationObject,
...variant } or equivalent deep merge for arrays/objects), then delete
x-bruno-variants from mergedOperation, compute mergedParams from pathItemParams
and mergedOperation.parameters, and use mergedOperation.servers,
mergedOperation.security, mergedOperation.requestBody when building the requests
entry so variants inherit base fields and only override specified keys; update
references operationObjectCleaned and mergedParams accordingly.

---

Nitpick comments:
In
`@packages/bruno-converters/tests/openapi/openapi-to-bruno/openapi-server-variables.spec.js`:
- Around line 345-456: Add a new test in the same spec file that calls
openApiToBruno with an operation that defines servers and parameters on the base
operation and a sparse x-bruno-variants entry that only supplies a summary (or
one overridden parameter); assert the variant's generated request inherits the
base operation's parameters (inspect request.request.params values) and baseUrl
server (inspect request.request.vars.req[0].value or .name === 'baseUrl') so
that partial variants merge fields rather than dropping them.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: ee6bf87d-e06d-44e3-9c39-5592f0757ec4

📥 Commits

Reviewing files that changed from the base of the PR and between 64c9a3e and eae6523.

📒 Files selected for processing (4)
  • packages/bruno-app/src/utils/exporters/openapi-spec.js
  • packages/bruno-app/src/utils/exporters/openapi-spec.spec.js
  • packages/bruno-converters/src/openapi/openapi-to-bruno.js
  • packages/bruno-converters/tests/openapi/openapi-to-bruno/openapi-server-variables.spec.js

@naman-bruno
naman-bruno merged commit d9c13e7 into usebruno:main May 26, 2026
15 of 19 checks passed
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.

3 participants