Skip to content

Conversation

@akrem-chabchoub
Copy link
Contributor

@akrem-chabchoub akrem-chabchoub commented Jan 2, 2026

Checklist

  • I have read the coding guide.
  • My change requires a documentation update, and I have done it.
  • I have added tests to cover my changes.
  • I have filled out the description and linked the related issues.

Description

Adds validation for the Swarm-Redundancy-Level header in bytes and BZZ upload/download handlers to ensure values are within the valid range (NONE to PARANOID).

Changes

  • Uses custom rLevel validation tag instead of lte=4 to reuse existing Level.Validate() method and provide clearer error messages referencing enum constants
  • Added unit tests for all affected handlers
  • Fix OpenAPI spec parameter definitions

Files Changed

  • openapi/Swarm.yaml
  • pkg/api/api.go
  • pkg/api/bytes.go
  • pkg/api/bytes_test.go
  • pkg/api/bzz.go
  • pkg/api/bzz_test.go
  • pkg/api/validation.go
  • pkg/file/redundancy/level.go

Open API Spec Version Changes (if applicable)

Motivation and Context (Optional)

Related Issue (Optional)

Screenshots (if appropriate):

@akrem-chabchoub akrem-chabchoub force-pushed the fix/redundancy-level-validation branch from 3c3c515 to b7d9bcc Compare January 5, 2026 08:40
@akrem-chabchoub akrem-chabchoub force-pushed the fix/redundancy-level-validation branch from 038716d to d5857af Compare January 5, 2026 19:38
@akrem-chabchoub akrem-chabchoub marked this pull request as ready for review January 5, 2026 19:47
Copilot AI review requested due to automatic review settings January 5, 2026 19:47
@akrem-chabchoub akrem-chabchoub changed the title fix: add validation for redundancy level in bytes and bzz upload handlers fix: add validation for redundancy level in bytes and bzz handlers Jan 5, 2026
Copy link
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 adds validation for the redundancy level parameter in both bytes and bzz upload/download handlers. It introduces a new Validate() method for the redundancy.Level type to ensure values fall within the valid range (NONE to PARANOID), and integrates this validation with a custom validator registration in the API service.

  • Adds Validate() method to redundancy.Level for range checking
  • Creates custom validation infrastructure with setupValidation() function and custom error messages
  • Applies validation tags to RLevel fields across bytes and bzz handlers (both upload and download)

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
pkg/file/redundancy/level.go Adds Validate() method to check if redundancy level is within valid range (NONE to PARANOID)
pkg/api/validation.go New file containing custom validation setup, registering the "rLevel" validator and custom error messages
pkg/api/api.go Updates Service struct to include customValidationMessages map, calls setupValidation() during initialization, and enhances error handling to use custom validation messages
pkg/api/bytes.go Adds "rLevel" validation tag to RLevel field in bytesUploadHandler
pkg/api/bzz.go Adds "rLevel" validation tag to RLevel fields in bzzUploadHandler, serveReference, and downloadHandler (using "omitempty,rLevel" for pointer types)
pkg/api/bytes_test.go Adds comprehensive tests for redundancy level validation including boundary cases (minimum, maximum, below minimum, above maximum)
pkg/api/bzz_test.go Adds tests for redundancy level validation in both upload and download scenarios
openapi/Swarm.yaml Refactors parameter definitions to use references instead of inline definitions (formatting improvement)

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

@bcsorvasi bcsorvasi added this to the v2.7.0 milestone Jan 6, 2026
@akrem-chabchoub akrem-chabchoub merged commit 37ab9c7 into master Jan 8, 2026
26 of 27 checks passed
@akrem-chabchoub akrem-chabchoub deleted the fix/redundancy-level-validation branch January 8, 2026 14:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants