0

Having a few issues with Swashbuckle and mostly routing.

So I am working with an API that has controller specific routes defined for some and a generic default route for all others. Both have defaults included in the route specification.

Specific route example:

config.Routes.MapHttpRoute(
            name: "Infobutton",
            routeTemplate: "api/Infobutton/{clientId}",
            defaults: new
            {
                controller = "Infobutton",
                maxresults = 0,
                firstresult = 0,
                format = "xhtml",
                urlType = "x",
                alphaSort = "",
                showAll = "false",
                spellcheck = "true",
                showCategories = "false",
                showSnippet = "false",
                showGroups = "false",
                disableAltSearch = "false",
                requireCode = "false",
                forceRelevance = "true",
                searchtype="",
                showSearchedTerms = "true",
                searchId = "",
                omitBlanks = "false"
            }
        );

Default route example:

config.Routes.MapHttpRoute(
            name: "DefaultApi",
            routeTemplate: "api/{controller}/{id}",
            defaults: new
            {
                id = RouteParameter.Optional,
                query = "",
                category = "",
                cpt = "",
                diagnosis = "",
                group = "",
                icd10 = "",
                icd9 = "",
                keyword = "",
                title = "",
                language = "en",
                maxresults = 0,
                firstresult = 0,
                fields = "",
                format = "xml",
                encoding = "",
                printsize = "",
                images = "",
                snomed = "",
                age = 0,
                gender = "",
                loinc = "",
                ndc = "",
                rxnorm = "",
                browse = "",
                urlType = "",
                alphaSort = "",
                showAll = "false",
                spellcheck = "true",
                resultLanguage = "en",
                showGroups = "false",
                disableAltSearch = "false",
                requireCode = "false",
                forceRelevance = "false",
                showSearchedTerms = "false",
                omitBlanks = "false"
            }
        );

Issues I am running across:

  1. Since the generic route handler is a "catch-all" swagger picks up the more specific route (Infobutton in this case) and the generic one, which results in two functions showing up in the Swagger UI.

  2. Having a Get call with parameters that appear in defaults results in the Get call not showing at all in the UI.

Any ideas would be greatly appreciated!

Reosoul
  • 197
  • 9
  • Please create a new question for your third question. It is not related to the other two. – venerik Mar 23 '16 at 21:11
  • Could you add the generic route to your question? – venerik Mar 23 '16 at 21:11
  • Added to the post above! – Reosoul Mar 24 '16 at 18:51
  • 1
    I'm not sure what the problem is. I don't think your analysis of the first bullet is correct. I created a similar route config and did not experience what you describe. The second problem might be caused by swashbuckle giving the same operation Id to both Gets. Have you tried to check the your spec in editor.swagger.io? It's a very convenient tool to check whether something is wrong with your spec. – venerik Mar 24 '16 at 19:14
  • Definitely paste your swagger json into editor.swagger.io - it will validate the format. If it turns out to be operationId issue you can fix that with an operation filter :) – VisualBean Mar 29 '16 at 19:49
  • Thanks for linking that tool. I tested it out as is, and I get an error saying: "Cannot have multiple operations with the same operationId: Infobutton_Post," which is the first issue I mentioned (two posts showing for one call). I am not seeing what could be generating this though? I also tried commenting out the default route, while keeping Infobutton route and vice versa, in both cases the resulting json said it was valid swagger but I still do not see the Get call. – Reosoul Apr 01 '16 at 17:55

0 Answers0