• 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

  • 相关阅读:
    pydbg系列[1]
    内核参与方式
    Debugging with GDB阅读[6]
    宏技巧解读
    右键-发送到-邮件接收者没有了的解决方法
    获得文件版本信息
    解决动态生成的SQL中特殊字符的问题 QuotedStr function
    CreateFileMapping的MSDN翻译和使用心得
    关闭Windows自动播放功能
    清凉明目茶
  • 原文地址:https://www.cnblogs.com/waterlufei/p/6941679.html
Copyright © 2020-2023  润新知