Swashbuckle.aspnetcore: Swashbuckle shows parameter with custom binding source as query parameter.

Created on 16 Oct 2019  路  6Comments  路  Source: domaindrivendev/Swashbuckle.AspNetCore

Well, I think the subject is self explanatory, but I'll describe my use case.

I created custom model binder which checks several headers sequentially and creates model based on the value.

Task<IActionResult> SendOneTimePassword(
    [FromBody] SendOneTimePasswordRequest request, 
    [FromCustom] Product product)

However, in swagger ui product is shown as product object (query).

Most helpful comment

Swashbuckle can't possibly know the inner workings of your custom model binder and therefore is unable to describe the various headers that it orchestrates. For binders that it doesn't understand, it simply defaults to query.

Your best bet here is an IOperationFiter (see readme) that inspects operation parameters for the presence of the FromCustom attribute. If it finds them, it can then replace the query parameter that was added by default with the various header parameters expected in the request.

All 6 comments

Swashbuckle can't possibly know the inner workings of your custom model binder and therefore is unable to describe the various headers that it orchestrates. For binders that it doesn't understand, it simply defaults to query.

Your best bet here is an IOperationFiter (see readme) that inspects operation parameters for the presence of the FromCustom attribute. If it finds them, it can then replace the query parameter that was added by default with the various header parameters expected in the request.

@domaindrivendev Thanks, Richard, I'll have a look.

For this to work, model binders need a way to expose metadata about its "inner workings" to SwashBuckle/ApiExplorer. This could be accomplished by f.ex. using attributes on the model binder class or property declarations.
SwashBuckle should be able to detect which model binder is registered for a request parameter type.
Is there some way we can get this working, potentially by collaborating with the AspNetCore team?

@voroninp we're facing with the same problem, were you able to solve the problem? Could you maybe show an example?

@lnodaba , honestly, was not busy solving the issue =(

Please refer to my comment above. Closing as I can't provide any further info/capabilities in this area

Was this page helpful?
0 / 5 - 0 ratings