1
安靜的非常直接的問題:我如何在v2.2.6中對swagger-ui中的端點進行排序?我正在使用springfox的Java部分。Swagger UI:如何自定義排序資源
在我的主要頁面上,我收集了按標籤分組的資源。這些標籤是隨機排列的。我想按照自定義順序(如果不可能,按字母順序)。 我SwaggerConfig.java文件:
package cat.meteo.apiinterna.commons.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Tag;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build()
.tags(
new Tag("XEMA Me", "1"),
new Tag("XEMA Ul", "2"),
new Tag("XEMA Ag", "3"),
new Tag("Prono", "4"),
new Tag("Sound", "5")
)
.apiInfo(apiInfo());
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("API REST")
.description("Self-documented API")
.version("v0.1.0")
.build();
}
}
這是招搖的用戶界面以相同的順序使用標籤生成的JSON文件。正如你所看到的順序似乎是隨機的。不是java標籤的順序,而不是按字母順序。 (http://localhost:8080/XXX/v2/api-docs)
"tags": [
{
"name": "XEMA Ul",
"description": "2"
},
{
"name": "XEMA Me",
"description": "1"
},
{
"name": "XEMA Ag",
"description": "3"
},
{
"name": "Sound",
"description": "5"
},
{
"name": "Prono",
"description": "4"
}
]
請參閱https://github.com/springfox/springfox/issues/732 – splintor