springfox

SpringMVC使用Swagger

微笑、不失礼 提交于 2019-12-26 08:02:21
Swagger 是一个规范和完整的框架,用于生成、描述、调用和可视化 RESTful 风格的 Web 服务。总体目标是使客户端和文件系统作为服务器以同样的速度来更新。文件的方法,参数和模型紧密集成到服务器端的代码,允许API来始终保持同步。 我们这里使用SpringBoot来快速搭建一个MVC,同时使用Swagger插件。 pom.xml,主要是引用swagger2 <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.6.RELEASE</version> <relativePath /> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org

how to replace Model schema Body parameter with actual example

十年热恋 提交于 2019-12-24 14:01:46
问题 I have spring-boot/spring-mvc and springfox swagger2 integration. I have attached sample screen shot. In parameter type of 'body' I have a Model schema which describe elements data types. string, 0 etc! How can I replace it with actual example so that I can 'Try it out' . That would be more useful for my API consumer. 回答1: Not sure if you found the answer to this one, but I am going to answer this anyways. The @ApiModelProperty has a property called example . You can make use of that.

Change model schema for java.sql.Time in swagger-ui

筅森魡賤 提交于 2019-12-24 12:58:31
问题 In my spring-boot application, I use swagger2 to document the web-services. I use some classes that have java.sql.Time and java.util.Date attributes. In swagger-ui, they appears like this : Date : Time : I want to modify this to display : "change_date": "YYYY-MM-DD" "change_time": "mm:ss" Here is my class : @lombok.Data @JsonRootName("translation_value") @ApiModel(value="TranslationValue", description="Traduction de valeur") public class TranslationValue implements Serializable {

How Do I Test That My Swagger Documentation Is Valid?

别说谁变了你拦得住时间么 提交于 2019-12-24 11:00:35
问题 It is very easy for Swagger annotations to drift away from the actual code. E.g. I could change the return from Response.ok to Response.created and easily forget to update the annotations from 200 to 201. Or I could change what is valid as null or not null and the end user will get confusing rejection messages even though their payload matches exactly what the documentation says. How do I test that my swagger documentation matches what my code is doing? A test that uses selenium and phantomjs

How to ignore swagger resource property for specific http verb(GET,POST,PUT)

一世执手 提交于 2019-12-23 13:26:32
问题 We are implemented spring fox swagger 2 of version 2.6.1, i wanted to display a specific property of a resource for HTTP GET METHOD and not for POST METHOD, i haven't find any approach using swagger 2. Please help thanks. For example: Class Employee{ Integer id; String name; } Request URI: GET /api/employee/{id} i should see the swagger request document as { id:"", name:"" } Request URI: POST /api/employee i should see the swagger request sample as { name:"" } 回答1: I upgraded to version 2.8.0

Swagger Springfox Configuration Issue

孤街浪徒 提交于 2019-12-23 11:35:11
问题 I have an application that uses Spring MVC to handle REST calls, the Controllers are REST Controllers and annotated with @RestController , and the controller and its methods are annotated with @RequestMapping . I'm trying to add Swagger to generate documentation for the existing REST services. I'm trying to add it for one as a test to see what it looks like. I've added the springfox and ui libraries, added swagger config classes and bean definitions to the spring context xml file. I can hit

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

↘锁芯ラ 提交于 2019-12-22 04:28:20
问题 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

swagger consolidation for multiple microservices

雨燕双飞 提交于 2019-12-21 12:36:52
问题 I have multiple microservices, for which swagger has already been implemented. I would like to bring all the api's under single swagger UI. I've followed the following link for doing this. but tried it in maven approach in STS. Swagger Consilidation Github example Here are my different files in the project, @SpringBootApplication @ComponentScan @EnableAutoConfiguration @EnableSwagger2 public class SgtestApplication { public static void main(String[] args) { SpringApplication.run

Cannot send Authorization Bearer Token using Springfox

对着背影说爱祢 提交于 2019-12-21 01:17:20
问题 I'm having trouble understanding why "Authorization: Bearer __" is not being sent in my api using Springfox 2.5.0. I have the following configuration: private ApiKey apiKey() { return new ApiKey( "Authorization", // name: My key - Authorization "api_key", // keyname: api_key "header"); } @Bean SecurityConfiguration security() { return new SecurityConfiguration( null, null, null, "Docserver2_fwk", // app name "BEARER", // api key value ApiKeyVehicle.HEADER, "Authorization", ","); } And the

Is there a way I can stop springfox swagger from scanning the model classes?

狂风中的少年 提交于 2019-12-19 03:14:55
问题 I'm currently using Springfox Swagger to document my spring boot application with a Java config. My API starts in about 75 seconds, (it was originally 20 secs without Springfox) with the whole scanning process. I currently just need the controller information without any model info. Is there a way I can exclude model scanning from the startup process in order to make my API start faster? And are there any other ways to make it faster? I'm using swagger 1.2 回答1: There is a way to prevent