Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/workflows/dotnetcore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ on:
branches:
- master
pull_request:
branches:
- master

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
Expand Down
85 changes: 53 additions & 32 deletions src/SwaggerProvider.Runtime/RuntimeHelpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -85,38 +85,42 @@ module RuntimeHelpers =
| _ -> obj.ToString()

let toQueryParams (name: string) (obj: obj) (client: Swagger.ProvidedApiClientBase) =
match obj with
| :? array<byte> as xs -> [ name, (client.Serialize xs).Trim('\"') ] // TODO: Need to verify how servers parse byte[] from query string
| :? array<bool> as xs -> xs |> toStrArray name
| :? array<int32> as xs -> xs |> toStrArray name
| :? array<int64> as xs -> xs |> toStrArray name
| :? array<float32> as xs -> xs |> toStrArray name
| :? array<double> as xs -> xs |> toStrArray name
| :? array<string> as xs -> xs |> toStrArray name
| :? array<DateTime> as xs -> xs |> toStrArrayDateTime name
| :? array<DateTimeOffset> as xs -> xs |> toStrArrayDateTimeOffset name
| :? array<Guid> as xs -> xs |> toStrArray name
| :? array<Option<bool>> as xs -> xs |> toStrArrayOpt name
| :? array<Option<int32>> as xs -> xs |> toStrArrayOpt name
| :? array<Option<int64>> as xs -> xs |> toStrArrayOpt name
| :? array<Option<float32>> as xs -> xs |> toStrArrayOpt name
| :? array<Option<double>> as xs -> xs |> toStrArrayOpt name
| :? array<Option<string>> as xs -> xs |> toStrArrayOpt name
| :? array<Option<DateTime>> as xs -> xs |> toStrArrayDateTimeOpt name
| :? array<Option<DateTimeOffset>> as xs -> xs |> toStrArrayDateTimeOffsetOpt name
| :? array<Option<Guid>> as xs -> xs |> toStrArray name
| :? Option<bool> as x -> x |> toStrOpt name
| :? Option<int32> as x -> x |> toStrOpt name
| :? Option<int64> as x -> x |> toStrOpt name
| :? Option<float32> as x -> x |> toStrOpt name
| :? Option<double> as x -> x |> toStrOpt name
| :? Option<string> as x -> x |> toStrOpt name
| :? Option<DateTime> as x -> x |> toStrDateTimeOpt name
| :? Option<DateTimeOffset> as x -> x |> toStrDateTimeOffsetOpt name
| :? DateTime as x -> [ name, x.ToString("O") ]
| :? DateTimeOffset as x -> [ name, x.ToString("O") ]
| :? Option<Guid> as x -> x |> toStrOpt name
| _ -> [ name, (if isNull obj then null else obj.ToString()) ]
if isNull obj then
[]
else

match obj with
| :? array<byte> as xs -> [ name, (client.Serialize xs).Trim('\"') ] // TODO: Need to verify how servers parse byte[] from query string
| :? array<bool> as xs -> xs |> toStrArray name
| :? array<int32> as xs -> xs |> toStrArray name
| :? array<int64> as xs -> xs |> toStrArray name
| :? array<float32> as xs -> xs |> toStrArray name
| :? array<double> as xs -> xs |> toStrArray name
| :? array<string> as xs -> xs |> toStrArray name
Comment on lines +97 to +99

Copilot AI Mar 10, 2026

Copy link

Choose a reason for hiding this comment

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

Query param serialization for float32/double uses ToString() (via toStrArray), which is culture-sensitive. On machines with a comma decimal separator this will produce values like "1,5" in URLs; consider formatting numeric types with InvariantCulture (and aligning/adding tests accordingly) to make query strings stable across locales.

Copilot uses AI. Check for mistakes.
| :? array<DateTime> as xs -> xs |> toStrArrayDateTime name
| :? array<DateTimeOffset> as xs -> xs |> toStrArrayDateTimeOffset name
| :? array<Guid> as xs -> xs |> toStrArray name
| :? array<Option<bool>> as xs -> xs |> toStrArrayOpt name
| :? array<Option<int32>> as xs -> xs |> toStrArrayOpt name
| :? array<Option<int64>> as xs -> xs |> toStrArrayOpt name
| :? array<Option<float32>> as xs -> xs |> toStrArrayOpt name
| :? array<Option<double>> as xs -> xs |> toStrArrayOpt name
| :? array<Option<string>> as xs -> xs |> toStrArrayOpt name
| :? array<Option<DateTime>> as xs -> xs |> toStrArrayDateTimeOpt name
| :? array<Option<DateTimeOffset>> as xs -> xs |> toStrArrayDateTimeOffsetOpt name
| :? array<Option<Guid>> as xs -> xs |> toStrArray name

Copilot AI Mar 10, 2026

Copy link

Choose a reason for hiding this comment

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

array<Option<Guid>> is currently routed to toStrArray, which will serialize values as Some(...) and will throw a NullReferenceException when the array contains None (compiled as null). It should be handled the same way as the other option arrays (e.g. via toStrArrayOpt / Array.choose id) so None items are skipped and Some g becomes g.ToString().

Suggested change
| :? array<Option<Guid>> as xs -> xs |> toStrArray name
| :? array<Option<Guid>> as xs -> xs |> toStrArrayOpt name

Copilot uses AI. Check for mistakes.
| :? Option<bool> as x -> x |> toStrOpt name
| :? Option<int32> as x -> x |> toStrOpt name
| :? Option<int64> as x -> x |> toStrOpt name
| :? Option<float32> as x -> x |> toStrOpt name
| :? Option<double> as x -> x |> toStrOpt name
| :? Option<string> as x -> x |> toStrOpt name
| :? Option<DateTime> as x -> x |> toStrDateTimeOpt name
| :? Option<DateTimeOffset> as x -> x |> toStrDateTimeOffsetOpt name
| :? DateTime as x -> [ name, x.ToString("O") ]
| :? DateTimeOffset as x -> [ name, x.ToString("O") ]
| :? Option<Guid> as x -> x |> toStrOpt name
| _ -> [ name, obj.ToString() ]

let getPropertyNameAttribute name =
{ new Reflection.CustomAttributeData() with
Expand Down Expand Up @@ -145,6 +149,22 @@ module RuntimeHelpers =
content
| _ -> failwith $"Unexpected parameter type {boxedStream.GetType().Name} instead of IO.Stream"

// Unwraps F# option values: returns the inner value for Some, null for None.
// This prevents `Some(value)` from being sent as-is in form data.
let private unwrapFSharpOption(value: obj) : obj =
if isNull value then
null
else
let ty = value.GetType()

if
ty.IsGenericType
&& ty.GetGenericTypeDefinition() = typedefof<option<_>>
then
ty.GetProperty("Value").GetValue(value)
else
value

let getPropertyValues(object: obj) =
if isNull object then
Seq.empty
Expand All @@ -162,6 +182,7 @@ module RuntimeHelpers =
| _ -> prop.Name

prop.GetValue(object)
|> unwrapFSharpOption
|> Option.ofObj
|> Option.map(fun value -> (name, value)))
Comment on lines 184 to 187

Copilot AI Mar 10, 2026

Copy link

Choose a reason for hiding this comment

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

getPropertyValues now unwraps F# options before building form/urlencoded content, but there are no assertions covering this behavior in the new RuntimeHelpers unit tests. Please add a regression test that verifies Some(value) becomes the inner value and None/null is omitted when producing key/value sequences.

Copilot uses AI. Check for mistakes.

Expand Down
Loading
Loading