[repo-assist] Fix toParam to encode byte[] as base64 instead of calling ToString()#465
Open
github-actions[bot] wants to merge 2 commits into
Open
Conversation
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>
3 tasks
Contributor
There was a problem hiding this comment.
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 intoParamthat usesConvert.ToBase64String. - Add unit tests covering
byte[], emptybyte[],Some byte[], andNone : byte[] optionfortoParam. - Add an end-to-end test validating
toFormUrlEncodedContentcorrectly emits base64 forbyte[].
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 This PR was created by Repo Assist, an automated AI assistant.
Summary
Fixes a bug where passing a
byte[]value totoParam(used for path, header, and cookie parameters, andtoFormUrlEncodedContent) would produce the string"System.Byte[]"instead of a valid base64-encoded value.Root Cause
toParamuses a chain of type-test patterns. There was no explicit arm forbyte[], so it fell through to the final| _ -> obj.ToString()arm, which for arrays produces the type name rather than any useful value.For comparison,
toQueryParamsalready handledbyte[]correctly viaclient.Serialize(xs).Trim('"')(JSON serialization of a byte array yields a base64 string wrapped in quotes). The fix intoParamusesConvert.ToBase64Stringdirectly, which produces an identical result.Changes
src/SwaggerProvider.Runtime/RuntimeHelpers.fs: Added| :? array<byte> as xs -> Convert.ToBase64String xsarm intoParam, placed before theobj.ToString()fallthrough.tests/SwaggerProvider.Tests/RuntimeHelpersTests.fs: Added 5 new tests:ToParamTestscoveringbyte[], emptybyte[],Some(byte[]), andNone(typed asbyte[] option)ToFormUrlEncodedContentTestsverifying end-to-end encoding viatoFormUrlEncodedContentTest Status
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.ioSee Network Configuration for more information.
Add this agentic workflows to your repo
To install this agentic workflow, run