Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uuid type does not serialize correctly #140

Open
ghost opened this issue Dec 10, 2019 · 4 comments
Open

uuid type does not serialize correctly #140

ghost opened this issue Dec 10, 2019 · 4 comments

Comments

@ghost
Copy link

ghost commented Dec 10, 2019

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 #132 (comment)) to replace Some(guid) with guid.

@sergey-tihon
Copy link
Member

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

@ghost
Copy link
Author

ghost commented Dec 10, 2019 via email

@ghost
Copy link
Author

ghost commented Dec 11, 2019

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
Copy link
Author

ghost commented Apr 21, 2020

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant