spring boot利用swagger和spring doc生成在線和離線文檔


參考博客地址:

在線文檔:http://blog.didispace.com/springbootswagger2/

離線文檔:http://www.jianshu.com/p/af7a6f29bf4f

用到的技術spring boot + maven + swagger2 + spring doc,swagger2生成整個文檔,spring doc是測試一個個實例接口,首先是利用將swagger2在線文檔的json數據得到

,然后將json數據和spring doc得到的數據一起轉化為asciidoc格式的數據,然后將asciidoc格式的數據轉化為html和pdf格式等等

spring boot利用swagger2生成在線文檔:

1.在pom.xml中加入swagger2的jar包,這里用的2.6.1的版本,2.7版本試了下有版本兼容的問題

<dependency>
  <groupId>io.springfox</groupId>
  <artifactId>springfox-swagger2</artifactId>
  <version>2.6.1</version>
</dependency>

<dependency>
  <groupId>io.springfox</groupId>
  <artifactId>springfox-swagger-ui</artifactId>
  <version>2.6.1</version>
</dependency>

2.配置swagger2的配置文件

新建一個類叫什么都行:

@Configuration
@EnableSwagger2
public class Swagger2 {

@Bean
public Docket createTestApi() throws Exception{
  return new Docket(DocumentationType.SWAGGER_2)
  .apiInfo(apiInfo())
  .select()
  .apis(RequestHandlerSelectors.basePackage("com.ssm.MyServer.web"))
  .paths(PathSelectors.any())
  .build();
}

public ApiInfo apiInfo() throws Exception{
  return new ApiInfoBuilder()
  .title("Spring Boot中使用Swagger2構建restful APIs")
  .description("這是我的項目")
  .termsOfServiceUrl("http://www.wust.edu.cn/default.html")
  .version("1.0")
  .build();
  }

}

3.在具體的restful接口上面配置文檔

涉及到項目技術不寫了看上面兩個地址就可以配置了

遺留問題:

1.spring doc的測試所有接口是怎么寫的,不會是一個一個的寫吧?有待實驗

**************************************************************

5個月后再來看找不到我寫的代碼了,還是把原來的代碼上傳一份吧https://github.com/waterlufei/spring-boot,下面的QA-server


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM