springboot集成restdocs输出接口文档
1、pom文件新增restdocs
<dependency>
<groupId>org.springframework.restdocs</groupId>
<artifactId>spring-restdocs-mockmvc</artifactId>
<scope>test</scope>
</dependency>
<plugin>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctor-maven-plugin</artifactId>
<version>1.5.8</version>
<executions>
<execution>
<id>generate-docs</id>
<phase>prepare-package</phase>
<goals>
<goal>process-asciidoc</goal>
</goals>
<configuration>
<backend>html</backend>
<doctype>book</doctype>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.springframework.restdocs</groupId>
<artifactId>spring-restdocs-asciidoctor</artifactId>
<version>${spring-restdocs.version}</version>
</dependency>
</dependencies>
</plugin>
2、在test包下新建controller
@RunWith(SpringRunner.class)
@SpringBootTestpublic class ApiBaseController {
@Rule
public JUnitRestDocumentation restDocumentation = new JUnitRestDocumentation();
public MockMvc mockMvc;
@Autowired
private WebApplicationContext context;
@Before
public void setUp() {
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
.apply(documentationConfiguration(this.restDocumentation))
.build();
}
}
3、新建单元测试
public class TestController extends ApiBaseController {
@Test
public void test() throws Exception {
super.mockMvc.perform(post("/test").param("aaa", "bbb")
.contentType(MediaType.APPLICATION_JSON))
.andDo(document("{ClassName}/{methodName}",
preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint()),
requestParameters(parameterWithName("aaa").description("查询名字"))));
}
}
4、运行后会在target\generated-snippets生成adoc文件
5、在main下新建asciidoc包,新建index.adoc 拼接已经生成的adoc
= API:toc:
left:toclevels: 4
[[order-it]]
== 1. 订单接口
[[order-query]]
=== 订单查询
operation::TestController/test[snippets='curl-request,http-request']
springboot集成restdocs输出接口文档的更多相关文章
- SpringBoot集成Swagger2在线文档
目录 SpringBoot集成Swagger2在线文档 前言 集成SpringBoot 登录接口文档示例 代码 效果 注解说明 总结 SpringBoot集成Swagger2在线文档 前言 不得不说, ...
- SpringBoot 如何生成接口文档,老鸟们都这么玩的!
大家好,我是飘渺. SpringBoot老鸟系列的文章已经写了两篇,每篇的阅读反响都还不错,果然大家还是对SpringBoot比较感兴趣.那今天我们就带来老鸟系列的第三篇:集成Swagger接口文档以 ...
- springboot使用swagger2创建文档
一.导入swagger2依赖 <dependency> <groupId>io.springfox</groupId> <artifactId>spri ...
- Springboot+swagger2的接口文档开发
一.创建一个SpringBoot项目 1. 2. 3. 4. 把web里的web选中,SQL里选择自己需要的,点击next 二.创建各项所需的controller,configure等 1. 项目布局 ...
- SpringCloud微服务实战——搭建企业级开发框架(六):使用knife4j集成Swagger2接口文档
knife4j是为集成Swagger生成api文档的增强解决方案,前后端Java代码以及前端Ui模块进行分离,在微服务架构下使用更加灵活, 提供专注于Swagger的增强解决方案,不同于只是改善增强前 ...
- Springboot swagger2 导出api文档
具体导出的代码,参考了:http://www.spring4all.com/article/699 导出前,首先需要配置好swagger2,参见 https://www.cnblogs.com/yan ...
- springboot + swagger2 生成api文档
直接贴代码: <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-sw ...
- SpringBoot+FreeMarker开发word文档下载,预览
背景: 开发一个根据模版,自动填充用户数据并下载word文档的功能 使用freemarker进行定义模版,然后把数据进行填充. maven依赖: <parent> <groupId& ...
- spring-boot+swagger实现WebApi文档
1.引用依赖包 <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-s ...
随机推荐
- 如何读取redis中的key值中的结果
redis的值有5种类型,不同的类型有不同的命令来获取: 字符直接 get key 队列 左端弹出一个元素 LPOP key 哈希 HGET key field 集合 SMEMBERS key 返回 ...
- linux一些重要数据结构
如同你想象的, 注册设备编号仅仅是驱动代码必须进行的诸多任务中的第一个. 我们将很 快看到其他重要的驱动组件, 但首先需要涉及一个别的. 大部分的基础性的驱动操作包括 3 个重要的内核数据结构, 称为 ...
- 2018-10-22-win10-uwp-自定义控件入门
title author date CreateTime categories win10 uwp 自定义控件入门 lindexi 2018-10-22 09:47:54 +0800 2018-10- ...
- 一道非常棘手的 Java 面试题:i++ 是线程安全的吗
转载自 一道非常棘手的 Java 面试题:i++ 是线程安全的吗 i++ 是线程安全的吗? 相信很多中高级的 Java 面试者都遇到过这个问题,很多对这个不是很清楚的肯定是一脸蒙逼.内心肯定还在质疑 ...
- opacity兼容性以及存在问题处理
opacity兼容性以及存在问题处理 opacity兼容性 opacity属性是CSS3的属性,用于设置元素的不透明级别.语法: opacity: value | inherit; ①值value表示 ...
- CodeForce - 1189 D1. Add on a Tree (思维题)
Note that this is the first problem of the two similar problems. You can hack this problem only if y ...
- IdentityServer4 Resources
原文地址 Resources 的定义 通常在系统中是顶一个需要保护的资源.这些资源可是用户的信息,比如身份信息或者邮箱地址,也可以是某些API的访问权限. Note: 可以通过C#的对象模型或者通过数 ...
- js解决跨域下载文件
之前用的是a标签的方式,同源是没有问题的,但一跨域就不行了,试了其它方法,不是报跨域错误,就是在当前页面打开文件,体验相当不好. data = data.replace(/\\/g, '/'); va ...
- Channel 9视频整理【3】
Will 保哥 微软mvp https://channel9.msdn.com/Niners/Will_Huang 繁体中文视频 Visual Studio 2017 新功能探索 https://ch ...
- Qt和c/c++connect函数冲突解决方法
在使用c/c++的connect函数时在前面写::connect()这样就可以解决了