将文档框架从Springfox更换为了SpringDoc

master
ArgonarioD 2022-07-07 11:10:25 +08:00
parent 9ac3eb04ec
commit 9690fff08e
11 changed files with 56 additions and 90 deletions

View File

@ -103,9 +103,9 @@
<version>1.2.9</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.6.9</version>
</dependency>
<dependency>
<groupId>com.auth0</groupId>

View File

@ -1,6 +1,6 @@
package cn.edu.hfut.rmdjzz.projectmanagement;
import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
@ -11,7 +11,7 @@ import org.springframework.web.bind.annotation.RestController;
* @author
* @since 2022/6/27 11:24
*/
@Api(tags = "hello")
@Tag(name = "hello")
@SpringBootApplication(exclude = {SecurityAutoConfiguration.class})
@RestController
public class ProjectManagement {

View File

@ -0,0 +1,26 @@
package cn.edu.hfut.rmdjzz.projectmanagement.config;
import io.swagger.v3.oas.models.ExternalDocumentation;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* @author
* @since 2022/6/27 11:24
*/
@Configuration
public class SpringDocConfig {
@Bean
public OpenAPI openAPI() {
return new OpenAPI()
.info(new Info()
.title("项目管理系统")
.description("前后端接口文档")
.version("1.0"))
.externalDocs(new ExternalDocumentation()
.description("项目管理系统前后端接口文档")
.url("http://101.34.228.45:8080"));
}
}

View File

@ -1,50 +0,0 @@
package cn.edu.hfut.rmdjzz.projectmanagement.config;
import com.fasterxml.classmate.TypeResolver;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import java.util.ArrayList;
/**
* @author
* @since 2022/6/27 11:24
*/
@Configuration
//@EnableSwagger2 //开启Swagger2
@EnableOpenApi
public class SwaggerConfig {
//配置 Swagger的Docket的Bean实例
@Bean
public Docket docket(TypeResolver typeResolver){
return new Docket(DocumentationType.OAS_30)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("cn.edu.hfut.rmdjzz.projectmanagement"))
.paths(PathSelectors.any())
.build()
.additionalModels(typeResolver.resolve(Integer.class));
}
//配置Swagger 信息apiInfo
private ApiInfo apiInfo(){
//作者信息
Contact DEFAULT_CONTACT = new Contact("项目管理系统", "http://101.34.228.45:8080/", "");
return new ApiInfo("前后端接口文档",
"",
"1.0",
"http://wuyize.ml/",
DEFAULT_CONTACT,
"",
"",
new ArrayList());
}
}

View File

@ -30,6 +30,7 @@ public class WebConfig implements WebMvcConfigurer {
.addPathPatterns("/**")
.excludePathPatterns("/hello", "/error") //测试
.excludePathPatterns("/staff/login") //登录
.excludePathPatterns("/swagger-resources/**", "/swagger-ui/**", "/v2/**", "/v3/**", "/webjars/**", "/doc.html"); //swagger
.excludePathPatterns("/swagger-ui.html", "/swagger-resources/**", "/swagger-ui/**",
"/v2/**", "/v3/**", "/webjars/**", "/doc.html"); //swagger
}
}

View File

@ -9,15 +9,11 @@ import cn.edu.hfut.rmdjzz.projectmanagement.utils.http.RequestPage;
import cn.edu.hfut.rmdjzz.projectmanagement.utils.http.ResponseList;
import cn.edu.hfut.rmdjzz.projectmanagement.utils.http.ResponseMap;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import javax.validation.Valid;
import java.util.Map;
@ -35,17 +31,14 @@ public class ProjectController {
@Autowired
private IProjectGroupService projectGroupService;
@ApiOperation("根据Token获取该员工的ProjectList")
@ApiImplicitParams({
@ApiImplicitParam(name = "paramMap", value = "参数列表见Project实体类时间可以用xxxxStart与xxxxEnd来确定区间"
, required = true)
})
@Operation(summary = "根据Token获取该员工的ProjectList")
@SneakyThrows
@GetMapping
public ResponseList<ProjectDto> getProjectListOfStaff(
@RequestHeader("Token") String token,
@Valid RequestPage page,
@RequestParam("paramMap") Map<String, Object> paramMap
@Parameter(description = "参数列表见Project实体类时间可以用xxxxStart与xxxxEnd来确定区间"
, required = true) @RequestParam("paramMap") Map<String, Object> paramMap
) {
Page<ProjectDto> result = projectService.getOnePageProject(token, page, paramMap);
return ResponseList.ofSuccess("成功返回列表", result);
@ -63,7 +56,7 @@ public class ProjectController {
return ResponseMap.ofSuccess("查询成功", projectService.getById(projectId));
}
@ApiOperation("根据Token获取该员工的Project数")
@Operation(description = "根据Token获取该员工的Project数")
@SneakyThrows
@GetMapping("/count")
public ResponseMap getProjectNumOfStaff(@RequestHeader("Token") String token) {

View File

@ -7,9 +7,10 @@ import cn.edu.hfut.rmdjzz.projectmanagement.service.IProjectGroupService;
import cn.edu.hfut.rmdjzz.projectmanagement.utils.http.ResponseList;
import cn.edu.hfut.rmdjzz.projectmanagement.utils.http.ResponseMap;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiParam;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.media.SchemaProperty;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@ -64,16 +65,13 @@ public class ProjectGroupController {
}
//TODO: test
@ApiImplicitParams(
@ApiImplicitParam(paramType = "body", name = "positions", dataTypeClass = String.class, required = true)
)
@SneakyThrows
@PutMapping("/{staffId}")
public ResponseMap modifyDesignatedStaffPosition(
@RequestHeader("Token") String token,
@PathVariable Integer projectId,
@PathVariable Integer staffId,
@ApiParam(hidden = true) @RequestBody GroupPositionVo groupPosition
@Parameter(description = "不需要在body中传递staffId用path传递") @RequestBody GroupPositionVo groupPosition
) {
projectGroupService.updateStaffPositions(token, staffId, projectId, groupPosition.getPositions());
return ResponseMap.ofSuccess("更新成功");

View File

@ -4,8 +4,7 @@ import cn.edu.hfut.rmdjzz.projectmanagement.entity.Staff;
import cn.edu.hfut.rmdjzz.projectmanagement.exception.TokenException;
import cn.edu.hfut.rmdjzz.projectmanagement.service.IStaffService;
import cn.edu.hfut.rmdjzz.projectmanagement.utils.http.ResponseMap;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@ -20,12 +19,12 @@ public class StaffController {
@Autowired
private IStaffService staffService;
@ApiImplicitParams({
@ApiImplicitParam(name = "staff", value = "只需要传入staffUsername和staffPassword两个属性即可staffPassword需要md5加密后传输")
})
@SneakyThrows
@PostMapping("/login")
public ResponseMap login(@RequestBody Staff staff) {
public ResponseMap login(
@Parameter(description = "只需要传入staffUsername和staffPassword两个属性即可staffPassword需要md5加密后传输")
@RequestBody Staff staff
) {
return staffService.login(staff.getStaffUsername(), staff.getStaffPassword());
}

View File

@ -6,7 +6,7 @@ import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.time.LocalDateTime;
@ -39,7 +39,7 @@ public class Task {
private LocalDateTime taskClosedTime;
private Integer taskPriority;
private String taskDescription;
@ApiModelProperty(
@Schema(description =
"demandSource:需求来源 (String), estimatedManHours:预估工时 (Integer), severity:严重程度 (String), recurrenceProbability:复现概率 (String)")
@TableField(typeHandler = JacksonTypeHandler.class)
private Map<String, Object> attachedInfo;

View File

@ -4,7 +4,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.NoArgsConstructor;
@ -24,9 +24,9 @@ public class RequestPage {
@NotNull
@Min(1)
Integer pageSize;
@ApiModelProperty("不传或传空时不排序,否则按照此字段排序")
@Schema(description = "不传或传空时不排序,否则按照此字段排序")
String sortBy;
@ApiModelProperty("传true或空时为顺序排序否则倒序排序")
@Schema(description = "传true或空时为顺序排序否则倒序排序")
Boolean asc;
public <T> IPage<T> getPage() {

View File

@ -16,9 +16,6 @@ spring:
max-idle: 8
min-idle: 0
password: weakPassword
mvc:
pathmatch:
matching-strategy: ant_path_matcher
mybatis-plus:
mapper-locations: classpath:mapper/*.xml
configuration:
@ -32,3 +29,5 @@ server:
charset: UTF-8
force: true
enabled: true
springdoc:
packages-to-scan: cn.edu.hfut.rmdjzz.projectmanagement