swagger

How to DRY when using Swagger UI and the ApiResponses annotations with Java Spring endpoints?

别等时光非礼了梦想. 提交于 2019-12-09 15:03:04
问题 I like Swagger because it makes your apis very user friendly. I use Swagger annotations like @ApiParam @ApiResponse | @ApiResponses @ApiOperation Others On endpoints, query params, request params, request body and so on. I like to keep my POJO classes clean and in general I try my best to follow DRY rule however, when it comes to swagger I noticed that I keep repeating myself over and over as shown below @ApiOperation(value = "Retrieve object by id") @ApiResponses(value = { @ApiResponse(code

Swagger: is it possible to make an operation parameter constant / readonly?

旧巷老猫 提交于 2019-12-09 14:54:31
问题 This is the description of a certain parameter I have: { "name": "myParam", "description": "My param description", "required": true, "paramType": "query", "type": "string", "defaultValue":"myValue" } The defaultValue is the only value the parameter can have, so is there a way to declare this? Seen in the context of the swagger-ui, I need the parameter's textbox to be read-only. I'm using swagger 1.2. Thanks 回答1: The proper way to declare this would be: { "name": "myParam", "description": "My

SrpingCloud 九、Springboot 整合 Swagger2 及 SrpingCloud Zuul 网关整合 Swagger2 (API 接口文档管理)

夙愿已清 提交于 2019-12-09 14:34:54
一、Swagger 是什么,有什么用? 1、Swagger 是什么? Swagger 是生成文档的工具,随着微服务架构体系的发展和应用, 为了前后端能够更好的集成与对接,同时为了项目的方便交付,每个项目都需要提供相应的API文档。 2、传统的API文档编写存在以下几个痛点 1、对API文档进行更新的时候,需要通知前端开发人员,导致文档更新交流不及时; 2、API接口返回信息不明确,大公司中肯定会有专门文档服务器对接口文档进行更新。 3、缺乏在线接口测试,通常需要使用相应的API测试工具,比如postman、SoapUI等 4、接口文档太多,不便于管理 5、为了解决传统API接口文档维护的问题,为了方便进行测试后台Restful接口并实现动态的更新,因而引入Swagger接口工具。 3、Swagger 优点 1.功能丰富:支持多种注解,自动生成接口文档界面,支持在界面测试API接口功能; 2.及时更新:开发过程中花一点写注释的时间,就可以及时的更新API文档,省心省力; 3.整合简单:通过添加pom依赖和简单配置,内嵌于应用中就可同时发布API接口文档界面,不需要部署独立服务。 二、Springboot 整合 Swagger2 1、maven 依赖 < ! -- SpringBoot整合 swagger -- > < dependency > < groupId > io .

Spring Boot + Springbox swagger error

一个人想着一个人 提交于 2019-12-09 14:27:29
问题 I have a spring boot project want to integrate with swagger via springbox. I have my spring boot app up and running all good. However after I added springbox, it can not pass unit test. Here are the details I added in project. For pom.xml , added <!--Swagger io for API doc--> <dependency> <groupId>io.swagger</groupId> <artifactId>swagger-core</artifactId> <version>1.5.3</version> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2

Spring Boot集成Swagger应对前后端联调

蓝咒 提交于 2019-12-09 13:52:49
现在的项目大部分都是前后端分离的,联调的时候沟通成本是个问题,而Swagger能很好地减少沟通成本,下面讲解Spring Boot如何集成Swagger。 Maven: <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.7.0</version> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.7.0</version> </dependency> 新建 Swagger2 文件(跟启动类在同一个目录): @Configuration @EnableSwagger2 public class Swagger2 { @Bean public Docket createdRestApi() { return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .select() .apis(RequestHandlerSelectors.basePackage("controller"))

SpringFox not finding jax-rs endpoints

空扰寡人 提交于 2019-12-09 12:48:29
问题 After solving Using Springfox to document jax-rs services in a Spring app, I now find that SpringFox's JSON reply doesn't show any APIs: { "swagger": "2.0", "info": { "description": "Some description", "version": "1.0", "title": "My awesome API", "contact": { "name": "my-email@domain.org" }, "license": {} }, "host": "localhost:9090", "basePath": "/myapp" } Here's springfox-servlet.xml: <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema

How do I combine multiple OpenAPI 3 specification files together?

我的梦境 提交于 2019-12-09 12:14:45
问题 I want to combine an API specification written using the OpenAPI 3 spec, that is currently divided into multiple files that reference each other using $ref . How can I do that? 回答1: One way to do this is to use the open-source project speccy. Open the terminal and install speccy by running (requires Node.js): npm install speccy -g Then run: speccy resolve path/to/spec.yaml -o spec-output.yaml 回答2: Most OpenAPI tools can work with multi-file OpenAPI definitions and resolve $ref s dynamically.

How to run swagger-codegen for OpenAPI 3.0.0

牧云@^-^@ 提交于 2019-12-09 03:00:59
问题 looks like official swagger for openapi specification V3 support is near release https://blog.readme.io/an-example-filled-guide-to-swagger-3-2/, and the swagger-codegen has 3.0.0 support developed and passing some level of testing https://github.com/swagger-api/swagger-codegen on the 3.0.0 branch I have a swagger spec (generated from my existing 2.0 spec via https://github.com/mermade/swagger2openapi, output looks good) Is there an easy way to run the swagger-codegen without having to package

Best practice to send response in spring boot

强颜欢笑 提交于 2019-12-09 01:33:17
问题 I'm coding REST Api-s in spring boot. I want to make sure that my code is readable to front-end developers using swagger API development tool (Swagger). For example @GetMapping("/getOne") public ResponseEntity<?> getOne(@RequestParam String id) { try { return new ResponseEntity<Branch>(branchService.getOne(id), HttpStatus.OK); } catch (Exception e) { return new ResponseEntity<FindError>(new FindError(e.getMessage()), HttpStatus.BAD_REQUEST); } } If the request is successful, response is a

How to calculate AWS signature V4 in Swagger before request

假如想象 提交于 2019-12-08 23:54:37
问题 For our AWS API Endpoints we use AWS_IAM authorization and want to make a call from Swagger UI. To make a successful call there must be 2 headers 'Authorization' and 'x-amz-date'. To form 'Authorization' we use following steps from aws doc. We must to change 'x-amz-date' with every call to go through authorization. The question is: How to write script in Swagger to sign request, which run every time before request send to aws? (We know how to specify both headers one time before loading