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
2 changes: 0 additions & 2 deletions .github/workflows/dotnetcore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ on:
branches:
- master
pull_request:
branches:
- master

jobs:
build:
Expand Down
4 changes: 2 additions & 2 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "10.0.103",
"rollForward": "minor"
"version": "10.0.100",
"rollForward": "latestPatch"
}
}
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
| :? 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, 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)))

Expand Down
Loading
Loading