2016-11-15 8 views
1

静かで静かな質問:v2.2.6のswagger-uiでエンドポイントを並べ替えるにはどうしたらいいですか?私はJava部分にspringfoxを使用しています。スワッガー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(); 
    } 
} 

をそして、これは威張っ-UIが同じ順序で使用して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" 
} 
] 

答えて

2

問題を掘り下げるの後、私が闊歩-UIの新しいバージョンがオプションとしてカスタム順序付けをサポートしていないことがわかります。 Springfoxは生成されたjsonを並べ替える機会も与えないので、唯一の方法はswagger-uiで "回避策"を実装することです。このコードUIで

// Workaround: alphabetically ordered tags 
this.api.apisArray.sort(function (a, b) { 
if (a.tag < b.tag) 
    return -1; 
if (a.tag > b.tag) 
    return 1; 
return 0; 
}) 

タグが注文を示しています。

では威張っ-ui.jsファイル(v2.2.6)のライン21766は、機能をレンダリングします。

+0

https://github.com/springfox/springfox/issues/732を参照してください。 – splintor

関連する問題