swagger 接口参数顺序,在Swagger-UI中对API方法进行排序

I cannot find any working example, how to achieve the following:

I want my API methods in the Swagger-UI sorted either by methods (GET-POST-PUT-DELETE) OR/AND alphabetically.

So far, all methods are displayed in a random order, even not in the order given my source code.

I use Jax-RS + Jersey 1.

Sorting using the position attribute of @ApiOperation is not an option for me, as there are too many methods and the API is still extending, so I would need to update all if there is a new one.

Any hints?

解决方案

Update for Swagger UI 2.1.0+: The sorter parameter has been split into two parameters, as noted in Fix 1040, Fix 1280:

apisSorter

Apply a sort to the API/tags list. It can be 'alpha'

(sort by name) or a function (see Array.prototype.sort() to know how

sort function works). Default is the order returned by the server

unchanged.

operationsSorter

Apply a sort to the operation list of each API. It can be 'alpha' (sort by paths alphanumerically), 'method' (sort by

HTTP method) or a function (see Array.prototype.sort() to know how

sort function works). Default is the order returned by the server

unchanged.

So you'll want to update sorter to apisSorter to sort the API list alphabetically, and/or operationsSorter to sort the operations list of each API. The pet shop demo has updated to apisSorter, as shown below:

Example: (working demo, sorted alphabetically)

window.swaggerUi = new SwaggerUi({

...

apisSorter : "alpha"

});

For Swagger UI versions older than 2.1.0:

The sorter parameter is still relevant for older versions of Swagger UI:

You can use the sorter parameter when instantiating SwaggerUi. This happens in the javascript on the Swagger-Ui index.html. From the documentation:

sorter apply a sort to the API list. It can be 'alpha' (sort paths

alphanumerically) or 'method' (sort operations by HTTP method).

Default is the order returned by the server unchanged.

window.swaggerUi = new SwaggerUi({

...

sorter : "alpha"

});

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值