0

I have ASP.NET WebApi configured with Swashbuckle to show swagger ui. I run it from within VS in IIS Express. The solution was in VS 2013 and it worked fine. After migration to VS 2015 the swagger shows no methods. There's no error, just empty list. The response returned is:

{"swagger":"2.0","info":{"version":"v4","title":"Swashbuckle Dummy API V4"},"host":"localhost:35622","schemes":["http"],"paths":{},"definitions":{}}

I checked the troubleshooting chapter in documentation but based on it the configuration is ok. What can I try next?

eXavier
  • 4,821
  • 4
  • 35
  • 57

1 Answers1

1

I have found the problem. I briefly describe the situation: We have versioned API and use custom ControllerSelector (derived from DefaultHttpControllerSelector) to select the right version of the controller. (The API version is taken from Http header.) There are subfolders in Controllers folder (like V1, V2, ..) and the controller classes are placed in those subfolders.

Generally, for documentation generation it is used ApiExplorer class fed by DefaultHttpControllerSelector, which internally manages list of HttpControllerDescriptors keyed by controller name (the short name without 'Controller' suffix). When it builds this list it checks if the controller name has already been added to the list and if yes, it not only does not add the other one but also removes the one already added. In our case it means there are no descriptors for controllers that have multiple versions.

I was able to fix it by overriding IHttpControllerSelector.GetControllerMapping() in our custom controller selector and passing in the controller name prefixed with version, which is also a valid route. Our custom ControllerSelector accepts also version passed in URL.

eXavier
  • 4,821
  • 4
  • 35
  • 57