0

Swashbuckle 有一些问题,主要是路由问题。

因此,我正在使用一个 API,该 API 为某些定义了控制器特定的路由,并为所有其他人定义了一个通用的默认路由。两者都包含在路由规范中的默认值。

具体路线示例:

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"
            }
        );

默认路由示例:

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"
            }
        );

我遇到的问题:

  1. 由于通用路由处理程序是“包罗万象”的,因此 Swagger 会选择更具体的路由(在本例中为 Infobutton)和通用路由,这会导致 Swagger UI 中显示两个函数。

  2. 使用出现在默认值中的参数进行 Get 调用会导致 Get 调用根本不显示在 UI 中。

任何想法将不胜感激!

4

0 回答 0