zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    Redux
    React-Router常见API
    webpack的plugin原理
    Kubernetes核心原理笔记
    阿里云证书过期时间监测
    DRF
    一个TCP可以发送多少个请求
    jenkins exporter(收集jenkins构建结果)
    Kubernetes SDN
    Django REST framework API认证(包括JWT认证)
  • 原文地址:https://www.cnblogs.com/waterlufei/p/6941679.html
Copyright © 2011-2022 走看看