2
votes

I have an endpoint that takes a custom type (in this particular case a NodaTime.LocalDate). The type has a custom model binder and is mapped in Swagger using MapType<>.

When the type is used in the route as a path parameter, the endpoint doesn't show up in Swagger/Swashbuckle. However, if I remove it (so that it's included as a URL parameter instead), it shows just fine.

A simple version of the endpoint:

public class MyController : System.Web.Http.ApiController
{
    [Route( "my/route/{date}" )] // Doesn't show up
    [Route( "my/route" )]        // Does show up
    [HttpPut]
    public Task<IHttpActionResult> MyEndpoint( LocalDate date, InputModel inputModel ) {
        // Do stuff...
    }
}

Note that both endpoints actually work, one just doesn't show up. I can also get the both endpoints to show up, if I change the type to DateTime- but I don't want that, since that would change the valid input set.

1
That does not look like a valid path, LocalDate is an object it can not be represented in the URL route... - Helder Sepulveda
So the type has a model binder that allows the struct (it is not an object) to be parsed from a string - in our case in the ISO8601 format. The endpoint works just fine, i.e. you can call it with my/route/2017-10-17 without any problems. It just doesn't show up in Swagger/Swashbuckle. - Mikkel R. Lund
To troubleshoot you can add a controller/action showing all the endpoint from the GetApiExplorer: github.com/heldersepu/SwashbuckleTest/blob/master/Swagger_Test/… - Helder Sepulveda
That looks great! I'll try that when I get to work tomorrow. - Mikkel R. Lund
@razon swashbuckle uses GetApiExplorer, if when you use GetApiExplorer directly it does not show the endpoint, there is nothing that swashbuckle can do, you might want to report your issue directly to Microsoft. - Helder Sepulveda

1 Answers

0
votes

I solved this problem by adding custom binding and custom converter from string. These actions are needed so that ApiExplorer resolve the route. After that Swagger resolves the route too.

See my example here: https://stackoverflow.com/a/47123965/908936