fsprojects / SwaggerProvider

F# generative Type Provider for Swagger

Home Page:https://fsprojects.github.io/SwaggerProvider/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`Guid []` not serialized correctly as query parameter

Eliemer opened this issue · comments

Description

The swagger schema im targeting specifies two arrays as query parameters: a uuid array and an int array. Heres the relevant bit

"/api/UserTitle/filter-users-by-user-title-type": {
  "get": {
    "tags": [
      "UserTitle"
    ],
    "operationId": "getUserTitleFilterUsersByUserTitleTypeId",
    "parameters": [
      {
        "name": "usersIds",
        "in": "query",
        "schema": {
          "type": "array",
          "items": {
            "type": "string",
            "format": "uuid"
          }
        }
      },
      {
        "name": "userTitleTypeIds",
        "in": "query",
        "schema": {
          "type": "array",
          "items": {
            "type": "integer",
            "format": "int32"
          }
        }
      }
    ],
    "responses": { ... }
  }
}

image
The issue is that when i provide both arrays, only the int array is encoded in the url correctly.

Repro steps

Theres obviously some steps you can't reproduce with respect to the actual API im targeting, but this bug about the request itself

#r "nuget: SwaggerProvider"

open System
open SwaggerProvider

[<Literal>]
let Schema = "https://localhost:60023/swagger/v1/swagger.json"

type Organization = OpenApiClientProvider<Schema, PreferAsync=true, PreferNullable=true>
let orgClient = Organization.Client()

let usersIds =
    [| "d01bb230-55f7-46ae-b90e-64c6ae459041"
       "ca7fdcdf-3803-423d-90d5-4477b9d2ea1e"
       "34447d35-e1ec-48c8-9781-e7ad1fb05d86"
       "a32d2356-82f9-497a-aee6-83e1f34e3031"
       "5dba5a9f-a4f2-4d2f-8911-0d115b17d495"
       "96119219-7eee-4d4b-af7e-b604923f72c8"
       "b3f56dec-5c3a-4cc4-ba6d-3db766233dce"
       "ba1d1799-9780-421e-b9e4-22a6bea75846" |]
    |> Array.map Guid.Parse

let userTitleTypeIds = [| 11; 12; 13; 14; 15; 5; 6 |]
async {
    let! res = orgClient.GetUserTitleFilterUsersByUserTitleTypeId(usersIds, userTitleTypeIds)
    printfn "%A" res
}
|> Async.RunSynchronously
// Causes server to return BadRequest

Expected behavior

The URL should look like

api/UserTitle/filter-users-by-user-title-type?usersIds=d01bb230-55f7-46ae-b90e-64c6ae459041&usersIds=ca7fdcdf-3803-423d-90d5-4477b9d2ea1e&usersIds=34447d35-e1ec-48c8-9781-e7ad1fb05d86&userTitleTypeIds=11&userTitleTypeIds=12&userTitleTypeIds=13

Actual behavior

The URL produced looks like this

api/UserTitle/filter-users-by-user-title-type?usersIds=System.Guid%5b%5d&userTitleTypeIds=11&userTitleTypeIds=12&userTitleTypeIds=13

the Guid [] is encoded as "System.Guid[]" as if it just called .ToString() on the whole thing. The int [] in the same request is being encoded correctly.

Known workarounds

I guess there would be a way to make a custom serializer for this...

Related information

  • Windows 10
  • Latest Nuget package version
  • Net 6.0