Swagger-UI-layer基于 Swagger 的前端 UI 實現(xiàn)
Swagger-UI-layer 是一個基于 Swagger 的前端 UI 實現(xiàn),是為了替換了默認(rèn)的 SwaggerUI,讓生成的文檔更加友好和美觀。
Swagger-UI-layer 要依賴 Swagger 的注解功能,因為 Swagger-UI-layer 僅僅只是一個前端 UI 界面的實現(xiàn),解析的數(shù)據(jù)來源于 /v2/api-docs
效果
最終生成文檔的展示例子:http://suldemo.tianox.com/docs.html
接口文檔信息界面
接口文檔調(diào)試界面
如何使用
1、引入jar包
首先需要在你的 pom.xml 中引入swagger 和 swagger-ui-layer 的包
swagger-ui-layer 最新版jar包地址:
io.springfox
springfox-swagger2
2.2.2
com.github.caspar-chen
swagger-ui-layer
${last-version}
2、添加swagger功能和注解
啟用swagger ,創(chuàng)建SwaggerConfig文件,內(nèi)容如下,
需要注意的一點是 swagger api 的默認(rèn)地址是
/v2/api-docs所以swagger-ui-layer也讀取的是默認(rèn)地址, 所以在new Docket()的時候不能指定group參數(shù),否則 swagger api 的地址會在后面加入group的參數(shù)導(dǎo)致swagger-ui-layer不能正確請求到數(shù)據(jù)
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket ProductApi() {
return new Docket(DocumentationType.SWAGGER_2)
.genericModelSubstitutes(DeferredResult.class)
.useDefaultResponseMessages(false)
.forCodeGeneration(false)
.pathMapping("/")
.select()
.build()
.apiInfo(productApiInfo());
}
private ApiInfo productApiInfo() {
ApiInfo apiInfo = new ApiInfo("XXX系統(tǒng)數(shù)據(jù)接口文檔",
"文檔描述。。。",
"1.0.0",
"API TERMS URL",
"聯(lián)系人郵箱",
"license",
"license url");
return apiInfo;
}
}
常用的swagger注解 Api ApiModel ApiModelProperty ApiOperation ApiParam ApiResponse ApiResponses ResponseHeader 具體的注解用法可參閱互聯(lián)網(wǎng)
3、查看結(jié)果
swagger-ui-layer 的默認(rèn)訪問地址是 http://${host}:${port}/docs.html
License
Apache License 2.0
