springfox

SpringBoot学习(三)—— springboot快速整合swagger文档

独自空忆成欢 提交于 2019-12-05 03:51:41
目录 Swagger文档 简介 引入swagger组件 代码实战 Swagger文档 @ 简介 优点 后端根据swagger语法,自动生成漂亮规范的接口文档。 做交互测试。 劣势 侵入式的,影响程序运行,尤其是传参的时候。 注意 swagger 分1.2版本和2.0版本,差异较大。swagger1.2 即 swagger-ui ; swagger2.0 即 springfox-swagger 。本文介绍的使用方式是新的版本,即 springfox-swagger 。 发布生产,关闭swagger,以防泄漏项目接口文档,被攻击 引入swagger组件 pom.xml中加入 <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的配置代码要和项目启动文件在同级目录,即如下 但是

How to change the response status code for successful operation in Swagger?

吃可爱长大的小学妹 提交于 2019-12-05 03:01:29
As shown in the image, it says "Response Class (Status 200)" for the add operation. However, the add operation has been implemented in such a way that it will never return 200. It returns 201 on success. My question is how can I change the (Status 200) to (Status 201)? The code for this part is as follows: @RequestMapping(method = RequestMethod.PUT, value = "/add") @ApiOperation(value = "Creates a new person", code = 201) @ApiResponses(value = { @ApiResponse(code = 201, message = "Record created successfully"), @ApiResponse(code = 409, message = "ID already taken") }) public ResponseEntity

Springfox swagger-ui.html unable to infer base URL - Caused by missing cookies

家住魔仙堡 提交于 2019-12-05 01:32:00
We have our Spring Boot services behind an API Gateway. With an earlier version of Springfox - 2.1.2 we had no issues in loading the swagger-ui.html page. This worked with Spring Boot 1.4.3.RELEASE. From then, we have upgraded to Boot 1.5.7 and upgraded Springfox to 2.8.0. Now if we load the page we get an alert box with the following long message. Unable to infer base url. This is common when using dynamic servlet registration or when the API is behind an API Gateway. The base url is the root of where all the swagger resources are served. For e.g. if the api is available at http://example.org

Springfox Swagger generating requests with port 80 for HTTPS URLS

坚强是说给别人听的谎言 提交于 2019-12-05 00:58:03
问题 I am experiencing an issue using springfox-swagger2 v2.2.0 related to the request padding port 80 for a HTTP URL. Is there anyway to disable the generation of the port or set the port to 443 programmatically based on a Spring Profile? Generated CURL: curl -X GET --header "Accept: application/json" "https://test.com:80/api/users/search" 回答1: I had the same issue. It is because Swagger uses a class from Spring Framework which is adding the port 80 to the host property in the /v2/api-docs json

入门Swagger

牧云@^-^@ 提交于 2019-12-04 18:00:26
Swagger:实现前后端分离开发 使用IDEA创建一个web项目 在pom.xml中添加swagger-api依赖 <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.2.1.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.uos</groupId> <artifactId>swagger-demo<

Swagger 2 accept xml instead of json

扶醉桌前 提交于 2019-12-04 11:19:33
I have a project with spring boot and I want to use swagger2 to document my json web services. I have this configuration : @Configuration @EnableSwagger2 public class Swagger2Config { @Bean public Docket welcomeMessageApi() { return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .select() .apis(RequestHandlerSelectors.any()) .paths(PathSelectors.any()) .build(); } private ApiInfo apiInfo() { return new ApiInfoBuilder() .title("My API") .description("Lorem Ipsum is simply dummy text of ...") .termsOfServiceUrl("an url") .contact("contact") .license("") .licenseUrl("") .version("2.0

Customize endpoints of dockets with springfox Swagger

99封情书 提交于 2019-12-04 10:51:27
问题 I've searched on the internet how to customize endpoints of my multiple dockets, but haven't found the answer. My module has several APIs. I want to generate Swagger documentation on different endpoints, each one positioned on the root of its corresponding API. For example : localhost:8080/v1/subscriptions/doc localhost:8080/v1/buckets/doc I've found only one way to have different endpoints for my dockets, but the URL don't correspond to what I want. They are : localhost:8080/doc?group

springboot+swagger接口文档企业实践(上)

£可爱£侵袭症+ 提交于 2019-12-04 10:34:28
tags: springboot swagger doc 一句话概括:对于产品开发,特别是前后端分离的开发模式,接口文档是连接前后端的枢纽,本文对springboot+swagger在企业的实践进行详细描述。 1.引言 在软件开发过程中,接口设计与接口文档编写是重要的一环,特别是在前后端分离的情况下,接口说明文档是开发人员之间的连接点。接口文档的编写有很多方式,可以使用word,也可以使用编写工具如小幺鸡,这些基本属于脱离代码编写的文档,如果接口变化,需要额外修改文档,增加工作量。如何提高写接口文档效率,在springboot开发中,结合swagger来提供接口文档说明是一个很好的实践,通过配置与注解,在编写接口代码过程中,同时也把接口文档写好,接口需要变更时,文档也同时变更,具有工作量少,效率高,接口文档直观简洁,可实时调用验证等好处。本文基本springboot2+swagger2,结合在企业中的实践,对接口文档的编写进行详细说明,具体有如下内容: swagger介绍及文档生成说明 使用springboot2+swagger2构建示例工程及配置描述 使用注解添加文档内容说明 使用全局参数进行接口认证 如需看源码,本文 示例工程地址 : https://github.com/mianshenglee/my-example 2.swagger简介 2.1 swagger 介绍

Swagger建立接口文档示例

余生长醉 提交于 2019-12-04 08:41:38
//Swagger建立接口文档示例package com.xolo.core.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import springfox.documentation.builders.ApiInfoBuilder; import springfox.documentation.builders.ParameterBuilder; import springfox.documentation.builders.PathSelectors; import springfox.documentation.builders.RequestHandlerSelectors; import springfox.documentation.schema.ModelRef; import springfox.documentation.service.*; import springfox.documentation.spi.DocumentationType; import springfox.documentation.spring.web.plugins.Docket;

swagger

白昼怎懂夜的黑 提交于 2019-12-04 07:52:37
1.什么是swagger? Swagger是一个前后端分离下使用的API接口框架,它提供了RESTful 风格的接口生成、描述、调用和可视化。Swagger 的目标是对 REST API 定义一个标准且和语言无关的接口,可以让人和计算机拥有无须访问源码、文档或网络流量监测就可以发现和理解服务的能力。当通过 Swagger 进行正确定义,用户可以理解远程服务并使用最少实现逻辑与远程服务进行交互。与为底层编程所实现的接口类似,Swagger 消除了调用服务时可能会有的猜测。swagger是一款让你更好的书写api文档的框架。 2.swagger的优势 1)支持 API 自动生成同步的在线文档:使用 Swagger 后可以直接通过代码生成文档,不再需要自己手动编写接口文档了,对程序员来说非常方便,可以节约写文档的时间去学习新技术。 2)提供 Web 页面在线测试 API:光有文档还不够,Swagger 生成的文档还支持在线测试。参数和格式都定好了,直接在界面上输入参数对应的值即可在线测试接口。 3.swagger入门案例 1)创建一个springboot项目,引入web依赖 2)在pom文件加入下面这些依赖      <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2<