Skip to content

fix: avoid round trip loss of annotation data#7730

Open
sid-bruno wants to merge 1 commit intousebruno:mainfrom
sid-bruno:fix/schema-updates
Open

fix: avoid round trip loss of annotation data#7730
sid-bruno wants to merge 1 commit intousebruno:mainfrom
sid-bruno:fix/schema-updates

Conversation

@sid-bruno
Copy link
Copy Markdown
Collaborator

@sid-bruno sid-bruno commented Apr 10, 2026

Description

Reopening #7711

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.

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

  • New Features

    • Added support for annotations on query parameters, request headers, environment variables, and multipart form entries to help users document and track important details.
  • Tests

    • Added test coverage to verify annotation data is properly preserved during transformations and exports.

Copilot AI review requested due to automatic review settings April 10, 2026 11:29
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 10, 2026

Walkthrough

This PR adds first-class support for annotations across the Bruno application and Electron packages. Changes include Redux store mappings for query parameters and headers, serialization utilities for filesystem persistence, TypeScript schema type definitions for annotations on variables and key-value pairs, and Yup validation schemas to enforce annotation structure.

Changes

Cohort / File(s) Summary
Redux Store Mappings
packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js
Extended four setter functions (setQueryParams, setRequestHeaders, setCollectionHeaders, setFolderHeaders) to map annotations: null into Redux state for params and headers.
Collection Serialization (bruno-app)
packages/bruno-app/src/utils/collections/index.js, packages/bruno-app/src/utils/collections/index.spec.js
Added annotations field to serialized output of headers, params, and request objects during save/export transformations. New test suite verifies annotation preservation through serialization round-trip.
Collection Serialization (bruno-electron)
packages/bruno-electron/src/utils/collection.js, packages/bruno-electron/src/utils/tests/collection-utils.spec.js
Extended transformRequestToSaveToFilesystem to include annotations from params and headers; updated test fixtures to verify annotations are preserved in transformed output.
Schema Type Definitions
packages/bruno-schema-types/src/common/annotation.ts, packages/bruno-schema-types/src/common/index.ts, packages/bruno-schema-types/src/common/key-value.ts, packages/bruno-schema-types/src/common/variables.ts, packages/bruno-schema-types/src/collection/environment.ts
Introduced new Annotation interface (name: string, value?: string | null) and added optional annotations?: Annotation[] | null field to KeyValue, Variable, and EnvironmentVariable types.
Schema Validation (bruno-schema)
packages/bruno-schema/src/collections/index.js, packages/bruno-schema/src/collections/annotationsSchema.spec.js
Added annotationSchema Yup validation and extended validation models (environmentVariablesSchema, keyValueSchema, varsSchema, multipartFormSchema, requestParamsSchema, fileSchema) to accept optional annotations arrays; new test suite validates annotation acceptance across item, environment, and collection schemas.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested labels

size/XL

Suggested reviewers

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

Poem

📝 Annotations flow through every wire,
From Redux state to files they aspire,
Headers and params now tell their tale,
With notes and values that will not fail,
Schema-blessed, validated with care. ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main fix: preventing loss of annotation data during round-trip operations (save/load cycles).
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

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

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ast-grep (0.42.1)
packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR reintroduces/extends support for preserving annotation metadata across schema validation and save/export transformations, aiming to prevent annotation loss during read → write round trips.

Changes:

  • Extend @usebruno/schema Yup validators to accept annotations on multiple pair-like structures (headers, params, vars, env vars, multipart entries, file entries).
  • Propagate annotations through request/collection transformation utilities in bruno-app and bruno-electron.
  • Add schema and transformation tests, and introduce Annotation typings in bruno-schema-types.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
packages/bruno-schema/src/collections/index.js Adds annotationSchema and allows annotations on multiple collection/request structures.
packages/bruno-schema/src/collections/annotationsSchema.spec.js New Jest spec verifying schemas accept annotations in several locations.
packages/bruno-schema-types/src/common/variables.ts Adds annotations to Variable.
packages/bruno-schema-types/src/common/key-value.ts Adds annotations to KeyValue (covers headers/params via inheritance).
packages/bruno-schema-types/src/common/index.ts Re-exports Annotation type.
packages/bruno-schema-types/src/common/annotation.ts New Annotation interface.
packages/bruno-schema-types/src/collection/environment.ts Adds annotations to EnvironmentVariable.
packages/bruno-electron/src/utils/collection.js Preserves annotations when projecting request params/headers to filesystem shape.
packages/bruno-electron/src/utils/tests/collection-utils.spec.js Updates transformation expectations to include annotations.
packages/bruno-app/src/utils/collections/index.js Preserves annotations in multiple save/export projections (headers/params and request transforms).
packages/bruno-app/src/utils/collections/index.spec.js Adds test asserting request transform preserves header/param annotations.
packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js Ensures headers/query params reducers carry annotations through set operations.
Comments suppressed due to low confidence (1)

packages/bruno-app/src/utils/collections/index.js:201

  • transformCollectionToSaveToExportAsFile now preserves annotations for request headers/params, but the other body pair projections (copyFormUrlEncodedParams, copyMultipartFormParams, copyFileParams) still omit annotations. Since the schema now accepts annotations on formUrlEncoded/multipart/file entries, exporting will still drop annotation data for those sections; these copy helpers should also pass through annotations to fully avoid round-trip loss.
export const transformCollectionToSaveToExportAsFile = (collection, options = {}) => {
  const copyHeaders = (headers) => {
    return map(headers, (header) => {
      return {
        uid: header.uid,
        name: header.name,
        value: header.value,
        description: header.description,
        annotations: header.annotations,
        enabled: header.enabled
      };
    });
  };

  const copyParams = (params) => {
    return map(params, (param) => {
      return {
        uid: param.uid,
        name: param.name,
        value: param.value,
        description: param.description,
        annotations: param.annotations,
        type: param.type,
        enabled: param.enabled
      };
    });

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +137 to +142
Yup.object({
name: Yup.string().min(1).required('annotation name is required'),
value: Yup.string().nullable()
})
.noUnknown(true)
.strict()
Comment on lines 1 to 6
export type { UID } from './uid';
export type { KeyValue } from './key-value';
export type { Variable, Variables } from './variables';
export type { Annotation } from './annotation';
export type { MultipartFormEntry, MultipartForm } from './multipart-form';
export type { FileEntry, FileList } from './file';
Comment on lines +1 to +4
const { itemSchema, environmentSchema, collectionSchema } = require('./index');

describe('annotation acceptance', () => {
test('itemSchema accepts annotations on headers and params', async () => {
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
packages/bruno-schema/src/collections/index.js (1)

134-144: DRY violation: duplicate annotation schema definition.

This inline object schema duplicates annotationSchema exactly. All other usages (environmentVariablesSchema, keyValueSchema, varsSchema, fileSchemaWithAnnotations, requestParamsSchema) reference annotationSchema directly, but multipartFormSchema defines it inline.

♻️ Use annotationSchema reference
   // Optional annotations on multipart entries
   annotations: Yup.array()
     .of(
-      Yup.object({
-        name: Yup.string().min(1).required('annotation name is required'),
-        value: Yup.string().nullable()
-      })
-        .noUnknown(true)
-        .strict()
+      annotationSchema
     )
     .nullable(),
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/bruno-schema/src/collections/index.js` around lines 134 - 144, The
multipartFormSchema currently inlines the same object as annotationSchema,
violating DRY; update multipartFormSchema to reference the existing
annotationSchema (used by environmentVariablesSchema, keyValueSchema,
varsSchema, fileSchemaWithAnnotations, requestParamsSchema) instead of
redefining the Yup.object(...) inline so all annotation validations come from
the single annotationSchema symbol.
packages/bruno-app/src/utils/collections/index.spec.js (1)

42-66: UID lengths are inconsistent with schema requirements.

The schema expects 21-character alphanumeric UIDs, but requestuid123456789012 and headeruid123456789012 are 22 characters. While this test exercises the transform function directly and may not invoke schema validation, it's good practice to use valid fixtures.

🔧 Suggested fix
   const item = {
-     uid: 'requestuid123456789012',
+     uid: 'requestuid12345678901',
      type: 'http-request',
      ...
          {
-           uid: 'headeruid123456789012',
+           uid: 'headeruid12345678901',
            name: 'X-Test',
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/bruno-app/src/utils/collections/index.spec.js` around lines 42 - 66,
Fixture UIDs in the test object are 22 (or otherwise non-21) characters and must
be adjusted to match the 21-character alphanumeric schema; update the uid fields
used in this spec (specifically the values 'requestuid123456789012',
'headeruid123456789012', and 'paramuid1234567890123') to be 21 characters (e.g.,
remove one trailing character or otherwise trim to 21 chars) and verify any
other fixture uid strings in the same test also conform to the 21-character
requirement so the test data matches the schema.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/bruno-app/src/utils/collections/index.spec.js`:
- Around line 42-66: Fixture UIDs in the test object are 22 (or otherwise
non-21) characters and must be adjusted to match the 21-character alphanumeric
schema; update the uid fields used in this spec (specifically the values
'requestuid123456789012', 'headeruid123456789012', and 'paramuid1234567890123')
to be 21 characters (e.g., remove one trailing character or otherwise trim to 21
chars) and verify any other fixture uid strings in the same test also conform to
the 21-character requirement so the test data matches the schema.

In `@packages/bruno-schema/src/collections/index.js`:
- Around line 134-144: The multipartFormSchema currently inlines the same object
as annotationSchema, violating DRY; update multipartFormSchema to reference the
existing annotationSchema (used by environmentVariablesSchema, keyValueSchema,
varsSchema, fileSchemaWithAnnotations, requestParamsSchema) instead of
redefining the Yup.object(...) inline so all annotation validations come from
the single annotationSchema symbol.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 66e5177e-dc6d-4ad0-b744-49988cce39f1

📥 Commits

Reviewing files that changed from the base of the PR and between cd06f28 and 60aa386.

📒 Files selected for processing (12)
  • packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js
  • packages/bruno-app/src/utils/collections/index.js
  • packages/bruno-app/src/utils/collections/index.spec.js
  • packages/bruno-electron/src/utils/collection.js
  • packages/bruno-electron/src/utils/tests/collection-utils.spec.js
  • packages/bruno-schema-types/src/collection/environment.ts
  • packages/bruno-schema-types/src/common/annotation.ts
  • packages/bruno-schema-types/src/common/index.ts
  • packages/bruno-schema-types/src/common/key-value.ts
  • packages/bruno-schema-types/src/common/variables.ts
  • packages/bruno-schema/src/collections/annotationsSchema.spec.js
  • packages/bruno-schema/src/collections/index.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants