Swagger API Operations Ordering(Swagger API 操作排序)
问题描述
如何按字母顺序对我的操作进行排序,例如DELETE、GET、POST、PUT.
How do I sort my operation by method alphabetically e.g. DELETE, GET, POST, PUT.
我已阅读这篇文章,但它是 HTML 格式的,但就我而言,我已将 Swagger 集成到 Spring Boot 中,因此我需要在创建 Docket 时对其进行排序.
I have read from this post but it is in HTML but in my case, I have integrated Swagger into Spring Boot so I need to sort it when creating a Docket.
在 Swagger UI 中排序 API 方法
然后我在 Docket 中注意到了这个方法 operationOrdering()
,但我仍然无法使其工作.
Then I noticed this method operationOrdering()
in Docket, but I still cannot make it work.
推荐答案
我使用的是 Springfox 2.8.0 版,以下代码片段适用于我记录的 API:
I am using Springfox version 2.8.0 and following code snippet works for my documented API:
@Bean
UiConfiguration uiConfig() {
return UiConfigurationBuilder
.builder()
.operationsSorter(OperationsSorter.METHOD)
...
.build();
}
有 2 个可能的值:
OperationsSorter.ALPHA
- 按路径 的字母顺序对 API 端点进行排序OperationsSorter.METHOD
- 按method 的字母顺序对 API 端点进行排序
OperationsSorter.ALPHA
- sorts API endpoints alphabetically by pathOperationsSorter.METHOD
- sorts API endpoints alphabetically by method
OperationsSorter.METHOD
就是您要查找的内容.
OperationsSorter.METHOD
is what you are looking for.
替代使用operationOrdering()
:
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build()
...
.operationOrdering(new Ordering<Operation>() {
@Override
public int compare(Operation left, Operation right) {
return left.getMethod().name().compareTo(right.getMethod().name());
}
})
}
但是,这不起作用,因为 Springfox 中的一个错误似乎仍然处于活动状态(Operation订购无效).
However, this does not work because of a bug in Springfox which seems to be still active (Operation ordering is not working).
这篇关于Swagger API 操作排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Swagger API 操作排序


- GC_FOR_ALLOC 是否更“严重"?在调查内存使用情况时? 2022-01-01
- Eclipse 的最佳 XML 编辑器 2022-01-01
- 如何使 JFrame 背景和 JPanel 透明且仅显示图像 2022-01-01
- 获取数字的最后一位 2022-01-01
- 未找到/usr/local/lib 中的库 2022-01-01
- 转换 ldap 日期 2022-01-01
- 将 Java Swing 桌面应用程序国际化的最佳实践是什么? 2022-01-01
- 在 Java 中,如何将 String 转换为 char 或将 char 转换 2022-01-01
- java.lang.IllegalStateException:Bean 名称“类别"的 BindingResult 和普通目标对象都不能用作请求属性 2022-01-01
- 如何指定 CORS 的响应标头? 2022-01-01