You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Swagger中按HTTP Method排序接口(无需标签)

问题:按HTTP Method排序Swagger接口并禁用路径分组

我正尝试按HTTP Method(GET/POST/PUT/DELETE)对控制器接口进行排序,期望无需使用标签实现该效果。同时注意到Swagger会先对路径进行分组再排序,想了解是否可以禁用路径分组,让所有GET接口能放在一起。

我已尝试以下代码,但均未生效:

尝试代码1

options.OrderActionsBy((apiDesc) => $"{apiDesc.ActionDescriptor.RouteValues["controller"]}_{apiDesc.HttpMethod}"); 

尝试代码2

options.OrderActionsBy((apiDesc) => apiDesc.HttpMethod);

尝试代码3

Func<ApiDescription, string> sortKeySelector = (x =>
{
    return
        x.HttpMethod.Equals("GET", StringComparison.InvariantCultureIgnoreCase)
            ? "0"
            : x.HttpMethod.Equals("POST", StringComparison.InvariantCultureIgnoreCase)
                ? "1"
                : x.HttpMethod.Equals("PUT", StringComparison.InvariantCultureIgnoreCase)
                    ? "2"
                    : x.HttpMethod.Equals("DELETE", StringComparison.InvariantCultureIgnoreCase)
                        ? "3"
                        : "4";
});
options.OrderActionsBy(sortKeySelector);

内容的提问来源于stack exchange,提问作者Master

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.30 19:45:30