Skip to content

[repo-assist] Fix toParam to encode byte[] as base64 instead of calling ToString()#465

Open
github-actions[bot] wants to merge 2 commits into
masterfrom
repo-assist/improve-toparam-bytes-20260704-31b56c9dfa57521b
Open

[repo-assist] Fix toParam to encode byte[] as base64 instead of calling ToString()#465
github-actions[bot] wants to merge 2 commits into
masterfrom
repo-assist/improve-toparam-bytes-20260704-31b56c9dfa57521b

Conversation

@github-actions

@github-actions github-actions Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

🤖 This PR was created by Repo Assist, an automated AI assistant.

Summary

Fixes a bug where passing a byte[] value to toParam (used for path, header, and cookie parameters, and toFormUrlEncodedContent) would produce the string "System.Byte[]" instead of a valid base64-encoded value.

Root Cause

toParam uses a chain of type-test patterns. There was no explicit arm for byte[], so it fell through to the final | _ -> obj.ToString() arm, which for arrays produces the type name rather than any useful value.

For comparison, toQueryParams already handled byte[] correctly via client.Serialize(xs).Trim('"') (JSON serialization of a byte array yields a base64 string wrapped in quotes). The fix in toParam uses Convert.ToBase64String directly, which produces an identical result.

Changes

  • src/SwaggerProvider.Runtime/RuntimeHelpers.fs: Added | :? array<byte> as xs -> Convert.ToBase64String xs arm in toParam, placed before the obj.ToString() fallthrough.
  • tests/SwaggerProvider.Tests/RuntimeHelpersTests.fs: Added 5 new tests:
    • 4 in ToParamTests covering byte[], empty byte[], Some(byte[]), and None (typed as byte[] option)
    • 1 in ToFormUrlEncodedContentTests verifying end-to-end encoding via toFormUrlEncodedContent

Test Status

dotnet tests/SwaggerProvider.Tests/bin/Release/net10.0/SwaggerProvider.Tests.dll
Total: 527, Errors: 0, Failed: 0, Skipped: 1, Time: 0.994s

Format check (dotnet fsi build.fsx → CheckFormat target) passed. Unit tests passed (527/527). Integration tests require a running server and were not run in this environment, consistent with prior Repo Assist PRs.

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • petstore.swagger.io

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "petstore.swagger.io"

See Network Configuration for more information.

Generated by 🌈 Repo Assist, see workflow run. Learn more.

Add this agentic workflows to your repo

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@e15e57b40918dbca11b350c55d02ab61934afa75

Previously, passing a byte[] to toParam fell through to the obj.ToString()
fallback, producing the string "System.Byte[]" instead of a valid base64
representation. This fix adds an explicit arm before the fallthrough that
calls Convert.ToBase64String, consistent with how toQueryParams already
handles byte[] values.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@sergey-tihon sergey-tihon marked this pull request as ready for review July 4, 2026 05:25
Copilot AI review requested due to automatic review settings July 4, 2026 05:25

Copilot AI 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.

Pull request overview

Fixes runtime parameter serialization for byte[] values by encoding them as OpenAPI format: byte base64 rather than falling back to obj.ToString() (which yields "System.Byte[]" for arrays). This aligns toParam behavior with existing toQueryParams handling and ensures correct serialization for path/header/cookie/form-url-encoded parameters.

Changes:

  • Add an explicit byte[] (array<byte>) match arm in toParam that uses Convert.ToBase64String.
  • Add unit tests covering byte[], empty byte[], Some byte[], and None : byte[] option for toParam.
  • Add an end-to-end test validating toFormUrlEncodedContent correctly emits base64 for byte[].

Reviewed changes

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

File Description
src/SwaggerProvider.Runtime/RuntimeHelpers.fs Adds base64 encoding support for byte[] in toParam to prevent "System.Byte[]" serialization.
tests/SwaggerProvider.Tests/RuntimeHelpersTests.fs Adds focused tests validating byte[] serialization via toParam and toFormUrlEncodedContent.

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

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant