fix: resolve variables in HTML documentation export#7768
fix: resolve variables in HTML documentation export#7768eeshm wants to merge 1 commit intousebruno:mainfrom
Conversation
WalkthroughThe PR enhances HTML documentation generation by integrating global environment variables into the export process. The GenerateDocumentation component retrieves global environment variables from Redux state and injects them into the collection before export. A new utility function resolves all template placeholders throughout collection requests using computed interpolation variables from global, environment, and request-scoped sources. Changes
Sequence DiagramsequenceDiagram
participant UI as GenerateDocumentation<br/>Component
participant Redux as Redux<br/>State
participant Resolver as resolveCollection<br/>ForHtmlDocumentation
participant Interpolator as Interpolation<br/>Engine
participant Exporter as HTML<br/>Exporter
UI->>Redux: Query globalEnvironments<br/>& activeGlobalEnvironmentUid
Redux-->>UI: Return globalEnvironmentVariables
UI->>UI: Deep clone collection
UI->>Resolver: resolveCollection(collectionCopy,<br/>globalEnvironmentVariables)
loop For each request item
Resolver->>Interpolator: getAllVariables(item)
Interpolator-->>Resolver: Computed variables<br/>(global + env + request)
Resolver->>Resolver: Interpolate URL,<br/>headers, params, auth, body
Resolver->>Resolver: Interpolate examples<br/>(if present)
end
Resolver-->>UI: Return resolved collection
UI->>Exporter: Export resolved<br/>collection to HTML
Exporter-->>UI: HTML documentation
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
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.
Pull request overview
Fixes HTML documentation generation so exported docs render resolved request fields (e.g., URLs) instead of raw {{var}} placeholders, addressing #7636 in the Bruno app documentation exporter flow.
Changes:
- Added a collection/request resolver for HTML docs export that interpolates variables across requests and examples.
- Wired the resolver into the “Generate Documentation” flow before converting to OpenCollection/YAML.
- Added regression tests ensuring exported request fields no longer contain unresolved
{{...}}placeholders.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| packages/bruno-app/src/utils/exporters/html-documentation.js | New resolver to interpolate request fields (url/headers/params/body/auth/docs) for HTML docs export. |
| packages/bruno-app/src/components/Sidebar/Collections/Collection/GenerateDocumentation/index.js | Applies resolver during documentation generation and injects global env variables from Redux state. |
| packages/bruno-app/src/utils/exporters/html-documentation.spec.js | Adds tests verifying placeholder resolution for URLs and payload fields. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| body.xml = interpolateString(body.xml, variables); | ||
| break; | ||
| case 'graphql': | ||
| body.graphql = interpolateString(body.graphql, variables, { escapeJSONStrings: true }); |
| const collectionCopy = cloneDeep(collection); | ||
| collectionCopy.globalEnvironmentVariables = globalEnvironmentVariables; | ||
| resolveCollectionForHtmlDocumentation(collectionCopy); | ||
|
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
packages/bruno-app/src/utils/exporters/html-documentation.spec.js (1)
54-134: Add one edge-path test for example requests (and multipart file parts).Current coverage is strong for primary request payloads, but this resolver also processes
item.examples[].requestand multipart entries. A focused test there would reduce regression risk on changed paths.As per coding guidelines, "Cover both the 'happy path' and the realistically problematic paths."
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/bruno-app/src/utils/exporters/html-documentation.spec.js` around lines 54 - 134, Add a new unit test exercising resolveCollectionForHtmlDocumentation that includes an item with non-empty items[].examples (populate examples[].request with template variables) and a multipart formdata body containing file-type parts so the resolver's example-request and multipart file-part paths are covered; assert that variables in examples[].request (url, headers, body) are resolved (no '{{' remaining) and that file parts retain expected metadata (e.g., filename/type) after resolution to prevent regressions in the example-request and multipart handling code paths.
🤖 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-app/src/utils/exporters/html-documentation.js`:
- Around line 94-102: The current early return for non-text multipart entries
prevents name interpolation; instead, always set name:
interpolateString(entry.name, variables) for every entry and only skip value
interpolation when entry.type !== 'text' (i.e., preserve the existing behavior
of not interpolating file/binary values). Update the block that references entry
and interpolateString so it returns { ...entry, name:
interpolateString(entry.name, variables), value: (entry.type === 'text' ?
interpolateString(entry.value, variables) : entry.value) } rather than returning
early for non-text entries.
---
Nitpick comments:
In `@packages/bruno-app/src/utils/exporters/html-documentation.spec.js`:
- Around line 54-134: Add a new unit test exercising
resolveCollectionForHtmlDocumentation that includes an item with non-empty
items[].examples (populate examples[].request with template variables) and a
multipart formdata body containing file-type parts so the resolver's
example-request and multipart file-part paths are covered; assert that variables
in examples[].request (url, headers, body) are resolved (no '{{' remaining) and
that file parts retain expected metadata (e.g., filename/type) after resolution
to prevent regressions in the example-request and multipart handling code paths.
🪄 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: 5a0a866c-7c2d-43a3-9097-a431f8994025
📒 Files selected for processing (3)
packages/bruno-app/src/components/Sidebar/Collections/Collection/GenerateDocumentation/index.jspackages/bruno-app/src/utils/exporters/html-documentation.jspackages/bruno-app/src/utils/exporters/html-documentation.spec.js
| if (entry.type && entry.type !== 'text') { | ||
| return entry; | ||
| } | ||
|
|
||
| return { | ||
| ...entry, | ||
| name: interpolateString(entry.name, variables), | ||
| value: interpolateString(entry.value, variables) | ||
| }; |
There was a problem hiding this comment.
Interpolate multipart field names for non-text entries too.
Line 94 currently returns early for non-text multipart entries, so name placeholders can remain unresolved in exported docs. Keep skipping value interpolation for file/binary parts, but still resolve name.
💡 Proposed fix
- if (entry.type && entry.type !== 'text') {
- return entry;
- }
-
- return {
- ...entry,
- name: interpolateString(entry.name, variables),
- value: interpolateString(entry.value, variables)
- };
+ const interpolatedEntry = {
+ ...entry,
+ name: interpolateString(entry.name, variables)
+ };
+
+ if (entry.type && entry.type !== 'text') {
+ return interpolatedEntry;
+ }
+
+ return {
+ ...interpolatedEntry,
+ value: interpolateString(entry.value, variables)
+ };📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if (entry.type && entry.type !== 'text') { | |
| return entry; | |
| } | |
| return { | |
| ...entry, | |
| name: interpolateString(entry.name, variables), | |
| value: interpolateString(entry.value, variables) | |
| }; | |
| const interpolatedEntry = { | |
| ...entry, | |
| name: interpolateString(entry.name, variables) | |
| }; | |
| if (entry.type && entry.type !== 'text') { | |
| return interpolatedEntry; | |
| } | |
| return { | |
| ...interpolatedEntry, | |
| value: interpolateString(entry.value, variables) | |
| }; |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@packages/bruno-app/src/utils/exporters/html-documentation.js` around lines 94
- 102, The current early return for non-text multipart entries prevents name
interpolation; instead, always set name: interpolateString(entry.name,
variables) for every entry and only skip value interpolation when entry.type !==
'text' (i.e., preserve the existing behavior of not interpolating file/binary
values). Update the block that references entry and interpolateString so it
returns { ...entry, name: interpolateString(entry.name, variables), value:
(entry.type === 'text' ? interpolateString(entry.value, variables) :
entry.value) } rather than returning early for non-text entries.
Description
fixes : #7636
Fixes HTML documentation export to resolve variable placeholders before rendering docs.
Problem - Generated HTML docs were showing raw placeholders like
{{url}}/getinstead of resolved values.Changes
resolveCollectionForHtmlDocumentationinutils/exporters/html-documentation.GenerateDocumentationbefore converting to OpenCollection/YAML.Tests
html-documentation.spec.jsregression tests to verify: no unresolved{{...}}placeholders remain in resolved request fields.Note : Request execution behavior is unchanged; this only affects docs export output
Contribution Checklist:
Publishing to New Package Managers
Please see here for more information.
Summary by CodeRabbit
New Features
Tests