SwaggerProvider icon indicating copy to clipboard operation
SwaggerProvider copied to clipboard

uuid type does not serialize correctly

Open ghost opened this issue 6 years ago • 4 comments

Recent changes introduced by #137 cause optional uuid types to be written to the wire as e.g. 'Some(c5bff7f0-b4df-475e-a331-f737424f013c)'. This is quite a tricky area but I would suggest: defaultArg theGuid Guid.Empty would potentially be more compatible, but this is a bit opinionated.

Workaround: It is possible to use DelegatingHandler (example https://github.com/fsprojects/SwaggerProvider/issues/132#issuecomment-557374506) to replace Some(guid) with guid.

ghost avatar Dec 10 '19 03:12 ghost

Is this parameter in your schema specified as not required? What is the location for parameters? url/header/body?

sergey-tihon avatar Dec 10 '19 10:12 sergey-tihon

It is defined as an optional header (X-Token). I can upload the part of the schema but it will be a few days til I can

On Tue, 10 Dec 2019, 9:05 pm Sergey Tihon, [email protected] wrote:

Is this parameter in your schema specified as not required? What is the location for parameters? url/header/body?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/fsprojects/SwaggerProvider/issues/140?email_source=notifications&email_token=AMAM73GC3HB4WAEDZIBQ5NLQX5SW5A5CNFSM4JYXGN4KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEGOVTOA#issuecomment-563960248, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMAM73G5J6AGMI3KRQZVC53QX5SW5ANCNFSM4JYXGN4A .

ghost avatar Dec 10 '19 10:12 ghost

minimal schema obtained. The schema is generated by swashbuckler:

{
  "openapi": "3.0.1",
  "info": {
    "title": "API",
    "version": "v1"
  },
  "paths": {
    "/api/admin/test": {
      "get": {
        "summary": "Test. Only works in development mode.",
        "parameters": [
          {
            "name": "X-Token",
            "in": "header",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "400": {
            "description": "Bad Request"
          },
          "200": {
            "description": "Success"
          }
        }
      }
    }
  }
}

ghost avatar Dec 11 '19 00:12 ghost

Workaround:

type LoggingHandler(log:ILog, messageHandler) =
    inherit DelegatingHandler(messageHandler)
    // https://wizardsofsmart.wordpress.com/2014/05/13/how-to-use-base-sendasync-in-f-delegatinghandler/
    member private x.SendAsync' (request, cancellationToken) =
        base.SendAsync(request, cancellationToken)
    override this.SendAsync (request, cancellationToken) = task {
        // https://github.com/fsprojects/SwaggerProvider/issues/140
        let name = "X-GUID"
        if request.Headers.Contains name then
            let value = request.Headers.GetValues(name) |> Seq.head
            request.Headers.Remove name |> ignore
            request.Headers.Add(name,[value.Split([|'(';')'|]).[1]])
        return this.SendAsync' (request, cancellationToken)

ghost avatar Apr 21 '20 04:04 ghost