Skip to content

Commit

Permalink
feat: upgrade swagger
Browse files Browse the repository at this point in the history
  • Loading branch information
ekoz committed Dec 18, 2024
1 parent 085ff19 commit 45e57a4
Show file tree
Hide file tree
Showing 13 changed files with 68 additions and 153 deletions.
20 changes: 3 additions & 17 deletions kbase-stack-base/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,9 @@
</dependency>

<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<exclusions>
<exclusion>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>${springdoc.version}</version>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,50 +1,31 @@

package com.ibothub.heap.base.config;

import io.swagger.annotations.Api;
import org.apache.tomcat.util.net.openssl.ciphers.Authentication;
import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import java.util.Collections;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

/**
* @author <a href="mailto:[email protected]">eko.zhan</a>
* @version v1.0
* @date 2020/10/15 20:25
*/
@Configuration
@EnableSwagger2WebMvc
@OpenAPIDefinition
public class SwaggerConfig {

@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.produces(Collections.singleton(MediaType.APPLICATION_JSON_UTF8_VALUE))
.consumes(Collections.singleton(MediaType.APPLICATION_JSON_UTF8_VALUE))
.ignoredParameterTypes(Authentication.class)
.useDefaultResponseMessages(false)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.withClassAnnotation(Api.class))
.paths(PathSelectors.any())
.build();
}


private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("接口文档")
.termsOfServiceUrl("http://ibothub.com/")
.version("1.0")
.build();
public OpenAPI openAPI() {
return new OpenAPI()
.info(new Info()
.title("swagger api")
.contact(new Contact().name("eko.zhan").url("https://ekozhan.com"))
.description("swagger api")
.version("2.0.0")
);
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.ibothub.heap.base.exception;

import io.swagger.annotations.ApiModel;

import io.swagger.v3.oas.annotations.media.Schema;

/**
* <pre>
Expand All @@ -14,7 +15,7 @@
* @version v1.0 , 2019-03-02 16:03
* @see org.springframework.web.client.HttpClientErrorException.BadRequest
*/
@ApiModel
@Schema
public enum ResultCode {
/**
* request handle success
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

import com.fasterxml.jackson.databind.ObjectMapper;
import com.ibothub.heap.base.exception.ResultCode;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import java.io.IOException;
import java.io.Serializable;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand All @@ -12,9 +13,6 @@
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import java.io.IOException;
import java.io.Serializable;

/**
* wrapper for response entity
*
Expand All @@ -26,31 +24,31 @@
@Accessors(chain = true)
@NoArgsConstructor
@AllArgsConstructor
@ApiModel(description = "响应数据")
@Schema(description = "响应数据")
public class ResponseEntity<T> implements Serializable {

/**
* response result code, not http response code
*/
@ApiModelProperty("响应码")
@Schema(description = "响应码")
private String code = "";

/**
* response result code meaning
*/
@ApiModelProperty("响应码含义")
@Schema(description = "响应码含义")
private String message = "";

/**
* response result explanation, usually used to describe exception detail
*/
@ApiModelProperty("响应码解释,通常用于描述异常细节")
@Schema(description = "响应码解释,通常用于描述异常细节")
private String description = "";

/**
* response result data
*/
@ApiModelProperty("响应主体")
@Schema(description = "响应主体")
private T data;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
import com.ibothub.heap.flowable.model.vo.TaskVO;
import com.ibothub.heap.flowable.service.BeanConverterContext;
import com.ibothub.heap.flowable.util.FlowableUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import org.flowable.engine.*;
//import org.flowable.engine.common.impl.identity.Authentication;
Expand All @@ -36,7 +36,7 @@
* @version v1.0
* @date 2022/2/21 21:50
*/
@Api(tags = "费用报销")
@Tag(name = "费用报销")
@RestController
@RequestMapping("/api/expense")
@Slf4j
Expand Down Expand Up @@ -65,7 +65,7 @@ public class ExpenseController {
@Resource
BeanConverterContext beanConverterContext;

@ApiOperation("test")
@Operation(summary = "test")
@PostMapping("test")
public ResponseEntity<String> test() {

Expand All @@ -76,7 +76,7 @@ public ResponseEntity<String> test() {
return ResponseEntity.ok();
}

@ApiOperation("发起流程")
@Operation(summary = "发起流程")
@PostMapping("start")
public ResponseEntity<String> start(String userId, Double money, String summary) {

Expand Down Expand Up @@ -113,7 +113,7 @@ public ResponseEntity<String> start(String userId, Double money, String summary)
return ResponseEntity.ok(String.format("提交成功.流程实例Id为:%s", processInstance.getId()));
}

@ApiOperation("查询所有流程实例")
@Operation(summary = "查询所有流程实例")
@GetMapping(value = "/historyList")
public ResponseEntity<List<ProcessInstanceVO>> historyList(String userId){

Expand All @@ -132,7 +132,7 @@ public ResponseEntity<List<ProcessInstanceVO>> historyList(String userId){
return ResponseEntity.ok(beanConverter.forwardProcessInstance(list));
}

@ApiOperation("查询指定用户的待办事项")
@Operation(summary = "查询指定用户的待办事项")
@GetMapping(value = "/taskList")
public ResponseEntity<List<TaskVO>> taskList(String userId){

Expand Down Expand Up @@ -165,7 +165,7 @@ public ResponseEntity<List<TaskVO>> taskList(String userId){
*
* @param taskId 任务ID
*/
@ApiOperation("通过")
@Operation(summary = "通过")
@PostMapping(value = "apply")
public ResponseEntity apply(String taskId) {
Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
Expand All @@ -182,7 +182,7 @@ public ResponseEntity apply(String taskId) {
/**
* 拒绝
*/
@ApiOperation("拒绝")
@Operation(summary = "拒绝")
@PostMapping(value = "reject")
public ResponseEntity reject(String taskId) {
HashMap<String, Object> map = Maps.newHashMap();
Expand All @@ -195,7 +195,7 @@ public ResponseEntity reject(String taskId) {
* 删除所有流程实例
* @return
*/
@ApiOperation("删除所有流程实例")
@Operation(summary = "删除所有流程实例")
@DeleteMapping(value="deleteAll")
public ResponseEntity deleteAll(){

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import com.ibothub.heap.flowable.model.vo.TaskVO;
import com.ibothub.heap.flowable.service.BeanConverterContext;
import com.ibothub.heap.flowable.util.FlowableUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import org.flowable.common.engine.impl.identity.Authentication;
import org.flowable.engine.*;
Expand All @@ -34,7 +34,7 @@
* @version v1.0
* @date 2022/3/10 20:41
*/
@Api(tags = "工作流流转接口")
@Tag(name = "工作流流转接口")
@RestController
@RequestMapping("/api/flowable")
@Slf4j
Expand Down Expand Up @@ -64,7 +64,7 @@ public class FlowableController {
BeanConverterContext beanConverterContext;


@ApiOperation("发起流程")
@Operation(summary = "发起流程")
@PostMapping("start")
public ResponseEntity<String> start(String userId, String deptLeader) {
// 设置流程发起人,流程发起人默认是从 security 框架中获取的,可以在这里设置下
Expand Down Expand Up @@ -94,7 +94,7 @@ public ResponseEntity<String> start(String userId, String deptLeader) {
*
* @param taskId 任务ID
*/
@ApiOperation("继续流转,通过或拒绝")
@Operation(summary = "继续流转,通过或拒绝")
@PostMapping(value = "apply")
public ResponseEntity apply(String taskId, Integer acceptType, String deptMgr) {
Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
Expand All @@ -111,7 +111,7 @@ public ResponseEntity apply(String taskId, Integer acceptType, String deptMgr) {
}


@ApiOperation("查询指定用户的待办事项")
@Operation(summary = "查询指定用户的待办事项")
@GetMapping(value = "/listTodo")
public ResponseEntity<List<TaskVO>> listTodo(String userId){

Expand All @@ -127,7 +127,7 @@ public ResponseEntity<List<TaskVO>> listTodo(String userId){
return ResponseEntity.ok(voList);
}

@ApiOperation("查询指定用户的已办事项")
@Operation(summary = "查询指定用户的已办事项")
@GetMapping(value = "/listDone")
public ResponseEntity<List<TaskInstanceVO>> listDone(String userId){

Expand Down Expand Up @@ -157,7 +157,7 @@ public ResponseEntity<List<TaskInstanceVO>> listDone(String userId){
return ResponseEntity.ok(taskInstanceList);
}

@ApiOperation("查询指定用户的发起事项")
@Operation(summary = "查询指定用户的发起事项")
@GetMapping(value = "/listCreated")
public ResponseEntity<List<ProcessInstanceVO>> listCreated(String userId){

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import com.ibothub.heap.base.model.vo.ResponseEntity;
import com.ibothub.heap.minio.service.MinioService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import software.amazon.awssdk.services.s3.model.Bucket;
Expand All @@ -17,36 +17,36 @@
* @version v1.0
* @date 2022/6/11 14:28
*/
@Api(tags = "Minio Restful Api")
@Tag(name = "Minio Restful Api")
@RestController
@RequestMapping("api")
public class MinioController {

@Resource
MinioService minioService;

@ApiOperation("创建bucket")
@Operation(summary = "创建bucket")
@PostMapping("bucket")
public ResponseEntity createBucket(String bucketName){
minioService.createBucket(bucketName);
return ResponseEntity.ok();
}

@ApiOperation("删除bucket")
@Operation(summary = "删除bucket")
@DeleteMapping("bucket")
public ResponseEntity deleteBucket(String bucketName){
minioService.deleteBucket(bucketName);
return ResponseEntity.ok();
}

@ApiOperation("上传文件")
@Operation(summary = "上传文件")
@PostMapping("upload")
public ResponseEntity<List<Bucket>> upload(String bucketName, MultipartFile file) throws IOException {
minioService.upload(bucketName, file);
return ResponseEntity.ok();
}

@ApiOperation("下载文件")
@Operation(summary = "下载文件")
@GetMapping("download")
public org.springframework.http.ResponseEntity<byte[]> upload(String bucketName, String key) throws IOException {
return minioService.download(bucketName, key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.ibothub.heap.base.model.vo.ResponseEntity;
import com.ibothub.heap.screw.model.vo.req.DriverReq;
import com.ibothub.heap.screw.service.ScrewService;
import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
import org.springframework.http.HttpHeaders;
Expand All @@ -22,7 +22,7 @@
* @version v1.0
* @date 2022/8/3 20:55
*/
@Api
@Tag(name = "Screw")
@RestController
@RequestMapping("/screw")
@Slf4j
Expand Down
Loading

0 comments on commit 45e57a4

Please sign in to comment.