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

DOCS Suggestion, add more extensive docs for delegating handlers as its tricky in F#

jkone27 opened this issue · comments

Without having this, I had bugs in my delegating handlers when adding e.g. authorization to query

https://gist.github.com/panesofglass/a1cfc3c9a3f0d41233ad

the reason is that if just using base.SendAsync inside a task { .. } or async { ... } ce, it will fail to update the parameters and execute it in a different order. I was just assigning it to a binding outside the task and then executing it within the task but that was wrong, it only works if there is no mutation e.g. of request or response.

Shall we add this info to docs website?

Not sure that I fully understand

Here is current auth doc
https://fsprojects.github.io/SwaggerProvider/#/Customization#authentication

and for sure you need to modify request before you call SendAsync (not matter you use task/async ce or not).

your sample should work like if you change it like this

let loggingHandler =
    { new DelegatingHandler() with
        member x.SendAsync(request, cancellationToken) = 
            task {
                 // your code here, if you change Request it will not change! beware !!!!!
                 return! base.SendAsync(request, cancellationToken)
            }
    }

what you propose to improve?

mmm.. if you call base.SendAsync inside the task, the F# compiler will complain dotnet/fsharp#12448

It is slightly surprising, but issue that you mentioned also contains workaround that can be used