springfox

spring boot2集成api文档工具swagger-ui(上)

ⅰ亾dé卋堺 提交于 2020-02-26 09:12:40
说明 第一步:创建项目 浏览器打开: https://start.spring.io/,生成一个spring boot项目 点击Generate这个按钮,下载项目包文件 第二步:导入开发工具 打开下载目录,解压项目文件 启动idea,引入项目文件 第三步:引入swagger-ui包 <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> 第四步:创建一个swagger 配置 @EnableSwagger2 @Configuration public class SwaggerConfig { @Bean public Docket api(){ return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .select() .apis

Swagger not detecting Api built with Spring Data Rest

可紊 提交于 2020-02-24 17:52:30
问题 I'm working on a spring boot application using swagger to generate docs for my API ,I'm using Spring data rest to generate the Api but when I run the app I get the swagger message : No operations defined in spec! This my Api code : @Api(tags = "projets") @RepositoryRestResource(collectionResourceRel = "projets", path = "projets") public interface IProjectRepository extends JpaRepository<Project, Long> { } And this my configuration file : @Configuration @EnableSwagger2 public class

Springboot集成Swagger2

蓝咒 提交于 2020-02-23 15:27:14
目录 Springboot集成Swagger2 一、Swagger2 阐述 二、Swagger2 基础使用 三、相关注解 四、注意事项 Springboot集成Swagger2 一、Swagger2 阐述 Swagger 是一个规范和完整的框架,用于生成、描述、调用和可视化 RESTful 风格的 Web 服务。总体目标是使客户端和文件系统作为服务器以同样的速度来更新。文件的方法,参数和模型紧密集成到服务器端的代码,允许API来始终保持同步。 作用: 1. 接口的文档在线自动生成。 2. 功能测试。 Swagger是一组开源项目,其中主要要项目如下: 1. Swagger-tools :提供各种与Swagger进行集成和交互的工具。例如模式检验、Swagger 1.2文档转换成Swagger 2.0文档等功能。 2. Swagger-core : 用于Java/Scala的的Swagger实现。与JAX-RS(Jersey、Resteasy、CXF...)、Servlets和Play框架进行集成。 3. Swagger-js : 用于JavaScript的Swagger实现。 4. Swagger-node-express : Swagger模块,用于node.js的Express web应用框架。 5. Swagger-ui :一个无依赖的HTML、JS和CSS集合

swagger

妖精的绣舞 提交于 2020-02-17 15:36:12
一. swagger是什么?能干什么? swagger官网: https://swagger.io/tools/ 。 就是把相关的信息存储在它定义的描述文件里面(yml或json格式),再通过维护这个描述文件可以去更新接口文档,以及生成各端代码。而Springfox-swagger,则可以通过扫描代码去生成这个描述文件,连描述文件都不需要再去维护了。所有的信息,都在代码里面了。 代码即接口文档,接口文档即代码。 二. swagger2常用注解: swagger通过注解表明该接口会生成文档,包括接口名、请求方法、参数、返回信息的等等。 @Api:修饰整个类,描述Controller的作用 @ApiOperation:描述一个类的一个方法,或者说一个接口 @ApiParam:单个参数描述 @ApiModel:用对象来接收参数 @ApiProperty:用对象接收参数时,描述对象的一个字段 @ApiResponse:HTTP响应其中1个描述 @ApiResponses:HTTP响应整体描述 @ApiIgnore:使用该注解忽略这个API @ApiError :发生错误返回的信息 @ApiImplicitParam:一个请求参数 @ApiImplicitParams:多个请求参数 @Api:用在请求的类上,表示对类的说明 tags="说明该类的作用,可以在UI界面上看到的注解" value

Swagger2

人走茶凉 提交于 2020-02-17 14:38:12
1、背景 相信无论是前端还是后端开发,都或多或少地被接口文档折磨过。前端经常抱怨后端给的接口文档与实际情况不一致。后端又觉得编写及维护接口文档会耗费不少精力,经常来不及更新。其实无论是前端调用后端,还是后端调用后端,都期望有一个好的接口文档。但是这个接口文档对于程序员来说,就跟注释一样,经常会抱怨别人写的代码没有写注释,然而自己写起代码起来,最讨厌的,也是写注释。所以仅仅只通过强制来规范大家是不够的,随着时间推移,版本迭代,接口文档往往很容易就跟不上代码了。 2、Swagger是什么?它能干什么? 发现了痛点就要去找解决方案。解决方案用的人多了,就成了标准的规范,这就是Swagger的由来。通过这套规范,你只需要按照它的规范去定义接口及接口相关的信息。再通过Swagger衍生出来的一系列项目和工具,就可以做到生成各种格式的接口文档,生成多种语言的客户端和服务端的代码,以及在线接口调试页面等等。这样,如果按照新的开发模式,在开发新版本或者迭代版本的时候,只需要更新Swagger描述文件,就可以自动生成接口文档和客户端服务端代码,做到调用端代码、服务端代码以及接口文档的一致性。 但即便如此,对于许多开发来说,编写这个yml或json格式的描述文件,本身也是有一定负担的工作,特别是在后面持续迭代开发的时候,往往会忽略更新这个描述文件,直接更改代码。久而久之

springboot 2 整合swagger2

萝らか妹 提交于 2020-02-08 08:14:14
1.首先需要在pom.xml进行增加我们需要 Swagger2 所需要的依赖。 <!--swagger依赖--> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.7.0</version></dependency><dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.7.0</version></dependency> 2.在 Application 中进行声明 @EnableSwagger2 @SpringBootApplication@EnableSwagger2public class JbClaimCaseApplication { public static void main(String[] args) { SpringApplication.run(JbClaimCaseApplication.class, args); }} 3.声明配置内容的配置 @Configuration public class Swagger2 { @Bean public Docket

Swagger2在SpringBoot上的配置

半腔热情 提交于 2020-02-05 12:42:35
简介 Swagger的目标是为REST APIs定义一个标准的,与语言无关的接口,使人与计算机在看不到源码或者看不到文档或者不能通过网络流量检测的情况下能发现和理解各种服务的功能。当服务Swagger定义,消费者可以通过少量的实现逻辑与远程的服务互动,。类似于低级编程接口,Swagger去掉了很多调用服务时候的猜测。 简而言之:Swagger通过读取注解的方式,将REST API的作用,参数限制等一系列信息通过swagger-ui.html曝露给调用者。 原理 反射,扫描所有controller类,以及其中所有标记有mapping的方法(即API的实现方法)。对这些方法,controller的Swagger注解进行扫描,形成API描述信息,呈现在swagger-ui.html,并在界面提供对API的测试(基于curl命令)。 Swagger注解介绍 @Api 标注在controller上,标记这是一组api tags: API分组标签 value: 如果没有定义tags,则value是tags description: deprecated,API的详细描述 @ApiOperation 标注在controller的方法上,标记这是一个api 对一个操作进行描述。 value: 对该api的简单描述,长度为60个汉字,120个字母 notes:对该api的详细描述

使用swagger生成接口文档

陌路散爱 提交于 2020-02-01 01:05:37
前言 在开发过程中,编写接口文档是开发人员必不可少的工作,但在写文档的时候,总会占用不少时间与精力。使用 springfox-swagger2 框架,并在相应地方加上注解,swagger 就可以帮我们自动在线生成标准的接口文档,并支持接口的测试。 具体实现 1、maven依赖 实际上,前两个依赖是自动生成与测试的框架依赖。com.google.guava 这个依赖是为了解决一个报错,貌似是因为在类中有多函数的时候,如果没有这个依赖,就会报 nullClass,具体没有细研究。 <!--swagger--> < 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 > < dependency > < groupId > com.google

Swagger 2 @ApiIgnore properties toggle in config server

ε祈祈猫儿з 提交于 2020-01-25 03:59:25
问题 I am using swagger 2 (2.9.2) in Sprinngboot app. Dependency : <!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 --> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.9.2</version> </dependency> <!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui --> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.9.2</version> </dependency> Code : package com.khan

How to configure Gradle to find local SNAPSHOT resource?

允我心安 提交于 2020-01-24 09:40:07
问题 I'm trying to do some work with the springfox project which has been broken up into two separate projects: the springfox runtime, and a suite of demos. In order to investigate the behavior of certain configurations, I need to change the module in springfox/springfox-petstore , and compile that into springfox-demos/springfox-java-swagger . In springfox , I built and published a new version of springfox-petstore , and validated that it exists correctly in ~/.m2/repository/io/springfox/springfox