swagger

Swagger2的使用及注意事项

三世轮回 提交于 2020-12-05 22:13:29
一、Swagger的主要作用有两方面: 1、生成在线文档,通过注解方式生成在线文档,方便在定义修正接口时直接修改接口文档; 2、对接口文档在线测试,不用在输入接口地址以及里面的参数对象,可以很方便的对在线接口测试。 二、 Swagger的使用方法如下: 1、引入springfox-swagger2的jar包依赖 < dependency > < groupId > io.springfox </ groupId > < artifactId > springfox-swagger2 </ artifactId > < version > 2.9.2 </ version > </ dependency > < dependency > < groupId > io.springfox </ groupId > < artifactId > springfox-swagger-ui </ artifactId > < version > 2.9.2 </ version > </ dependency > 2、增加swagger配置文件 @Configuration @EnableSwagger 2 public class SwaggerConfig { /** * 根据配置读取是否开启swagger文档,针对测试与生产环境采用不同的配置 */ @Value ( "$

SpringBoot整合Swagger

纵饮孤独 提交于 2020-12-04 17:51:01
@Author:SimpleWu 什么是Swagger? Swagger是什么:THE WORLD’S MOST POPULAR API TOOLING 根据官网的介绍: Swagger Inspector:测试API和生成OpenAPI的开发工具。Swagger Inspector的建立是为了解决开发者的三个主要目标。 执行简单的API测试 生成OpenAPI文档 探索新的API功能 我的理解Swagger是一个规范和完整的框架,用于生成、描述、调用和可视化RESTful风格的Web服务。简单来说,Swagger是一个功能强大的接口管理工具,并且提供了多种编程语言的前后端分离解决方案。根据我的使用,当然我只是最简单的使用,我感觉Swagger有以下几个优点: Swagger可以整合到代码中,在开发时通过注解,编写注释,自动生成API文档。 将前端后台分开,不会有过分的依赖。 界面清晰,无论是editor的实时展示还是ui的展示都十分人性化,如果自己仅仅用markdown来编写,又要纠结该如何展现,十分痛苦。 构建项目 step1.导入依赖 <!--swagger服务api构建个性包--> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version

课程分类列表后端实现

梦想与她 提交于 2020-12-03 11:13:04
一 创建vo @Data public class SubjectVo implements Serializable { private static final long serialVersionUID = 1L; /** * 课程分类id */ private String id; /** * 标题 */ private String title; /** * 排序 */ private Integer sort; /** * 课程孩子节点 */ private List<SubjectVo> children = new ArrayList<>(); } 二 控制器 /** * @className: SubjectController * @description: 课程分类列表 * @date: 2020/12/2 * @author: cakin */ @ApiOperation("嵌套数据列表") @GetMapping("nested-list") public R nestedList() { List<SubjectVo> subjectVoList = subjectService.nestedList(); return R.ok().data("items", subjectVoList); } 三 服务 1 接口 /** * 功能描述:树形展示 *

Idea正则表达式一键替换注释,生成@ApiModelProperty("")

时光总嘲笑我的痴心妄想 提交于 2020-12-02 23:17:41
平常日常开发中,返回给前端的vo对象在字段上需要加注释@ApiModelProperty("xxx"),方便在前端同事在swagger文档看注释,一般我是domain对象生成之后,复制代码到vo对象里,然后再修改Java块注释为前端的注释@ApiModelProperty("xxx"),那怎么从以下的代码注释转为@ApiModelProperty("xxx")注释呢?如果字段很多的话,一个一个写会比较耗时也枯燥,可以用正则表达式一键替。 /** * xxx */ (1)domain对象 @Data @Table @Entity public class FactoryOrder { /** * id */ @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; /** * 订单号 */ private String orderNum; /** * 订单创建时间 */ private Long createTime; /** * 员工工号 */ private String staffId; /** * 员工名称 */ private String staffName; /** * 订单总金额 */ private Integer orderPrice; /** * 订单类型 */

BUG赏金 | 无效的API授权导致的越权

不打扰是莪最后的温柔 提交于 2020-11-30 20:56:42
图片来源于网络 大家好,我想分享一下我是如何在某邀请项目中发现一个简单的API授权错误的,该错误影响了数千个子域,并允许我在无需用户干预的情况下使用大量不受保护的功能,从帐户删除到接管甚至于泄漏部分信息(姓名,电子邮件和雇主)。 要点: 服务器没有检查(发起请求的)授权token是属于普通用户还是超级用户。 这是一个邀请项目,因此将删除一些敏感信息,我将其称为 target.com 。 我在使用dirsearch对网站进行扫描的同时,通过浏览 academy.target.com 对网站的功能做了大致了解,我注意到一个有趣的端点,如: academy.target.com/api/docs 此类端点就像是个金矿,因为它列出了API文档并指定了请求和响应的结构。 在浏览到端点时,我发现页面与Swagger UI非常相似(尽管此站点未使用swagger)。 它还有一个名为“ Authenticate (验证)”的按钮,单击该按钮可导航到登录页面,但是如果我尝试登录,则会提示“ Account not authorized (账户未授权)”。 有一些有趣的端点,例如: / poweruser / add / poweruser / delete / user / delete / user / create / user / user_logged_in / user / profile

How to define swagger annotation for json payload

血红的双手。 提交于 2020-11-30 00:10:41
问题 how to define swagger annotation for this example post API.TenantConfiguration is getting as a json payload. @Consumes({ "application/json", "application/xml" }) @POST public Message configureSettings(TenantConfiguration configuration) throws AndroidAgentException { ..................... } 回答1: I found a solution to annotate json consuming Jax-rs Apis.It's working properly. @POST @ApiOperation( consumes = MediaType.APPLICATION_JSON, httpMethod = "POST", value = "Configuring Android Platform

How to define swagger annotation for json payload

雨燕双飞 提交于 2020-11-30 00:10:41
问题 how to define swagger annotation for this example post API.TenantConfiguration is getting as a json payload. @Consumes({ "application/json", "application/xml" }) @POST public Message configureSettings(TenantConfiguration configuration) throws AndroidAgentException { ..................... } 回答1: I found a solution to annotate json consuming Jax-rs Apis.It's working properly. @POST @ApiOperation( consumes = MediaType.APPLICATION_JSON, httpMethod = "POST", value = "Configuring Android Platform

How to define swagger annotation for json payload

喜夏-厌秋 提交于 2020-11-30 00:10:35
问题 how to define swagger annotation for this example post API.TenantConfiguration is getting as a json payload. @Consumes({ "application/json", "application/xml" }) @POST public Message configureSettings(TenantConfiguration configuration) throws AndroidAgentException { ..................... } 回答1: I found a solution to annotate json consuming Jax-rs Apis.It's working properly. @POST @ApiOperation( consumes = MediaType.APPLICATION_JSON, httpMethod = "POST", value = "Configuring Android Platform

How to define swagger annotation for json payload

隐身守侯 提交于 2020-11-30 00:10:28
问题 how to define swagger annotation for this example post API.TenantConfiguration is getting as a json payload. @Consumes({ "application/json", "application/xml" }) @POST public Message configureSettings(TenantConfiguration configuration) throws AndroidAgentException { ..................... } 回答1: I found a solution to annotate json consuming Jax-rs Apis.It's working properly. @POST @ApiOperation( consumes = MediaType.APPLICATION_JSON, httpMethod = "POST", value = "Configuring Android Platform

How to define swagger annotation for json payload

落爺英雄遲暮 提交于 2020-11-30 00:10:10
问题 how to define swagger annotation for this example post API.TenantConfiguration is getting as a json payload. @Consumes({ "application/json", "application/xml" }) @POST public Message configureSettings(TenantConfiguration configuration) throws AndroidAgentException { ..................... } 回答1: I found a solution to annotate json consuming Jax-rs Apis.It's working properly. @POST @ApiOperation( consumes = MediaType.APPLICATION_JSON, httpMethod = "POST", value = "Configuring Android Platform