使用Swagger生成简单接口文档
使用swagger通过简单的配置可以生成简单的接口文档;
依赖包:
// Swagger2
compile 'io.springfox:springfox-swagger2:2.8.0'
compile 'io.springfox:springfox-swagger-ui:2.8.0'
启动类添加配置:
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication
@EnableAutoConfiguration
public class ShowCaseApplication { public static void main(String[] args) {
SpringApplication.run(ShowCaseApplication.class, args);
}
}
配置类:
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration; import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2; @Configuration
@ComponentScan(basePackages = { //"com.a.controller", //
})
@EnableSwagger2
public class AutoConfiguration { @Bean
public Docket docketCommon() {
return new Docket(DocumentationType.SWAGGER_2)
.groupName("test").select()
.apis(RequestHandlerSelectors.basePackage("com.a.controller"))
.paths(PathSelectors.any())
.build()
.apiInfo(new ApiInfoBuilder().
title("test Restful API").
description("接口API").
contact(new Contact("", "", "")).
version("1.0").
build());
}
}
接口注释:在controller里的接口上面添加标识
@ApiOperation(nickname = "getList", value = "获取列表。")
@Override
public List<String> getList(
@RequestBody @ApiParam(name = "请求对象", value = "传入json格式", required = true) TestRequest request) {
return null
}
使用Swagger生成简单接口文档的更多相关文章
- spring boot使用swagger生成api接口文档
前言 在之前的文章中,使用mybatis-plus生成了对应的包,在此基础上,我们针对项目的api接口,添加swagger配置和注解,生成swagger接口文档 具体可以查看本站spring boot ...
- .NET Core WEB API使用Swagger生成在线接口文档
1项目引用Swashbuckle.AspNetCore程序集和Microsoft.Extensions.PlatformAbstractions程序集 右击项目打开"管理NuGet程序包.. ...
- swagger 生成的接口文档,隐藏接口的某个参数
[问题描述] controller 中的处理请求的方法,有时候会添加一些额外的参数.比如下面代码中 UserVo: @PostMapping(value = "/add-office-par ...
- .netcore Swagger 生成 api接口文档
1, 引用第三方包, Swashbuckle.AspNetCore Swashbuckle.AspNetCore.Swagger Swashbuckle.AspNetCore.SwaggerUI 最简 ...
- Swagger+Spring mvc生成Restful接口文档
简介 Swagger 是一个规范和完整的框架,用于生成.描述.调用和可视化 RESTful 风格的 Web 服务.总体目标是使客户端和文件系统作为服务器以同样的速度来更新.文件的方法,参数和模型紧密集 ...
- Spring Boot 集成 Swagger 生成 RESTful API 文档
原文链接: Spring Boot 集成 Swagger 生成 RESTful API 文档 简介 Swagger 官网是这么描述它的:The Best APIs are Built with Swa ...
- Spring MVC学习总结(9)——Spring MVC整合swagger自动生成api接口文档
Swagger 号称:世界最流行的API框架,官网:http://swagger.io/,Swagger 是一个规范和完整的框架,用于生成.描述.调用和可视化 RESTful 风格的 Web 服务.总 ...
- Swagger: 一个restful接口文档在线生成+功能测试软件
一.什么是 Swagger? Swagger 是一款RESTFUL接口的文档在线自动生成+功能测试功能软件.Swagger 是一个规范和完整的框架,用于生成.描述.调用和可视化 RESTful 风格的 ...
- springboot项目利用Swagger2生成在线接口文档
Swagger简介. Swagger2是一款restful接口文档在线生成和在线调试工具.很多项目团队利用Swagger自动生成接口文档,保证接口文档和代码同步更新.在线调试.简单地说,你可以利用这个 ...
随机推荐
- (一)maven的安装
Maven下载 下载地址:http://maven.apache.org/download.cgi 下载完成后,得到一个压缩包
- 堡垒机(paramiko)
实现思路 堡垒机执行流程: 管理员为用户在服务器上创建账号(将公钥放置服务器,或者使用用户名密码) 用户登陆堡垒机,输入堡垒机用户名密码,现实当前用户管理的服务器列表 用户选择服务器,并自动登陆 执行 ...
- 专题2-通过按键玩中断\2440按键中断编程lesson2
1.程序优化 修改Makefile 把main.c里面的mmu代码复制到mmu.c并修改如下 main.c的修改 由于在bootloader当中一般不会使用MMU,所以 main.c 加入led.c文 ...
- mysql 全文搜索 FULLTEXT
到 3.23.23 时,MySQL 开始支持全文索引和搜索.全文索引在 MySQL 中是一个 FULLTEXT 类型索引.FULLTEXT 索引用于 MyISAM 表,可以在 CREATE TABLE ...
- LibreOJ 6004 圆桌聚餐 (最大流)
题解:天啊,这道最大流真是水的一批……只需要每张桌子向每个单位建一条容量为1的边,源点向桌子建边,容量为桌子能坐的人数;单位向汇点建边,容量为单位人数即可,然后根据单位与桌子的连边值是否为一来了解每个 ...
- jenkins slave Windows 2008 R2
布置jenkins,添加节点(win2008R2) 配置节点参考: http://www.cnblogs.com/juddhu/archive/2013/07/18/3198191.html 生效la ...
- 阿里 vs. 腾讯,谁的收购更有眼光?
近年来我们国内企业高速发展,各大集团纷纷收购其他公司发展自己,在这么多的集团收购里面尤其以阿里巴巴和腾讯的收购引人注目.在2014年里阿里巴巴先后投资了中信,美国奢侈品电子商务lstdibs,高德,优 ...
- C# 操作 MongoDB
今项目使用Mongodb,C#操作MongoDB使用MongoDB.Driver.dll库(Nuget),写了个小Demo,如下: using System; using System.Collect ...
- PTA数据结构之 List Leaves
Given a tree, you are supposed to list all the leaves in the order of top down, and left to right. I ...
- 关联关系的接口+unittest实现关联接口
关联关系的接口: import requests def login(): url = 'http://ip/api/user/login' data = {'username':'niuhang', ...