<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          Swagger-UI-layer基于 Swagger 的前端 UI 實現(xiàn)

          聯(lián)合創(chuàng)作 · 2023-09-28 01:36

          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包地址:

          http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.github.caspar-chen%22%20AND%20a%3A%22swagger-ui-layer%22

          
              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

          瀏覽 36
          點贊
          評論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報
          評論
          圖片
          表情
          推薦
          點贊
          評論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  国产多毛| 中文有码人妻熟女久久 | 国产精品美女毛片真酒店 | www欧美区| 色婷婷粉嫩Av |