排序Swagger标签

问题描述 投票:1回答:1

嗨,我正在使用闪光灯/招摇,但我想知道是否有功能,我可以按字母顺序对所有标签进行排序?对,我不明白我的标签的顺序。它既不是Alpha也不是数字。样品订单是这样的

User
   - API GET
   - API POST
   - API PUT
   - API DELETE
Company
   - API GET
   - API POST
   - API PUT
   - API DELETE
Room
   - API GET
   - API POST
   - API PUT
   - API DELETE

所以基本上用户,公司和房间都是Swagger标签。我想安排在公司应该先到达的地方,然后是Room then User。有没有办法在swagger 2.0中实现这一点

更新:我希望它在Web浏览器显示中排序。简而言之,我们如何按排序顺序查看所有这些标签的显示

python swagger flasgger
1个回答
0
投票

对于标记顺序有问题的每个人,您可以使用javascript(样本按字母顺序升序排序,但您可以根据需要更改排序功能):

$(document).ready(function () {
    sort();
});

function sort() {
    ascending = true;
    var tbody = document.getElementById("resources");//ul
    var rows = tbody.childNodes;//li
    var unsorted = true;

    while (unsorted) {
        unsorted = false

        for (var r = 0; r < rows.length - 1; r++) {
            debugger;
            var row = rows[r];
            var nextRow = rows[r + 1];

            var value = row.getAttribute("id");
            var nextValue = nextRow.getAttribute("id");

            if (ascending ? value > nextValue : value < nextValue) {
                tbody.insertBefore(nextRow, row);
                unsorted = true;
            }
        }
    }
}

这个JS你应该注册,如下面的示例所示(Web api / c#/ .net)

config.EnableSwagger(c =>
            {
                ***
            })
            .EnableSwaggerUi(u =>  
                {                   
                    u.InjectJavaScript(typeof(Startup).Assembly, "yourNamespace.SwaggerExt.js");
                }
            );

JS文件应该是嵌入式资源。

© www.soinside.com 2019 - 2024. All rights reserved.