将文档框架从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> <version>1.2.9</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>io.springfox</groupId> <groupId>org.springdoc</groupId>
<artifactId>springfox-boot-starter</artifactId> <artifactId>springdoc-openapi-ui</artifactId>
<version>3.0.0</version> <version>1.6.9</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.auth0</groupId> <groupId>com.auth0</groupId>

View File

@ -1,6 +1,6 @@
package cn.edu.hfut.rmdjzz.projectmanagement; 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.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration; import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
@ -11,7 +11,7 @@ import org.springframework.web.bind.annotation.RestController;
* @author * @author
* @since 2022/6/27 11:24 * @since 2022/6/27 11:24
*/ */
@Api(tags = "hello") @Tag(name = "hello")
@SpringBootApplication(exclude = {SecurityAutoConfiguration.class}) @SpringBootApplication(exclude = {SecurityAutoConfiguration.class})
@RestController @RestController
public class ProjectManagement { 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("/**") .addPathPatterns("/**")
.excludePathPatterns("/hello", "/error") //测试 .excludePathPatterns("/hello", "/error") //测试
.excludePathPatterns("/staff/login") //登录 .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.ResponseList;
import cn.edu.hfut.rmdjzz.projectmanagement.utils.http.ResponseMap; import cn.edu.hfut.rmdjzz.projectmanagement.utils.http.ResponseMap;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.annotations.ApiImplicitParams; import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.SneakyThrows; import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import javax.validation.Valid; import javax.validation.Valid;
import java.util.Map; import java.util.Map;
@ -35,17 +31,14 @@ public class ProjectController {
@Autowired @Autowired
private IProjectGroupService projectGroupService; private IProjectGroupService projectGroupService;
@ApiOperation("根据Token获取该员工的ProjectList") @Operation(summary = "根据Token获取该员工的ProjectList")
@ApiImplicitParams({
@ApiImplicitParam(name = "paramMap", value = "参数列表见Project实体类时间可以用xxxxStart与xxxxEnd来确定区间"
, required = true)
})
@SneakyThrows @SneakyThrows
@GetMapping @GetMapping
public ResponseList<ProjectDto> getProjectListOfStaff( public ResponseList<ProjectDto> getProjectListOfStaff(
@RequestHeader("Token") String token, @RequestHeader("Token") String token,
@Valid RequestPage page, @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); Page<ProjectDto> result = projectService.getOnePageProject(token, page, paramMap);
return ResponseList.ofSuccess("成功返回列表", result); return ResponseList.ofSuccess("成功返回列表", result);
@ -63,7 +56,7 @@ public class ProjectController {
return ResponseMap.ofSuccess("查询成功", projectService.getById(projectId)); return ResponseMap.ofSuccess("查询成功", projectService.getById(projectId));
} }
@ApiOperation("根据Token获取该员工的Project数") @Operation(description = "根据Token获取该员工的Project数")
@SneakyThrows @SneakyThrows
@GetMapping("/count") @GetMapping("/count")
public ResponseMap getProjectNumOfStaff(@RequestHeader("Token") String token) { 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.ResponseList;
import cn.edu.hfut.rmdjzz.projectmanagement.utils.http.ResponseMap; import cn.edu.hfut.rmdjzz.projectmanagement.utils.http.ResponseMap;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.annotations.ApiImplicitParams; import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.annotations.ApiParam; import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.media.SchemaProperty;
import lombok.SneakyThrows; import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -64,16 +65,13 @@ public class ProjectGroupController {
} }
//TODO: test //TODO: test
@ApiImplicitParams(
@ApiImplicitParam(paramType = "body", name = "positions", dataTypeClass = String.class, required = true)
)
@SneakyThrows @SneakyThrows
@PutMapping("/{staffId}") @PutMapping("/{staffId}")
public ResponseMap modifyDesignatedStaffPosition( public ResponseMap modifyDesignatedStaffPosition(
@RequestHeader("Token") String token, @RequestHeader("Token") String token,
@PathVariable Integer projectId, @PathVariable Integer projectId,
@PathVariable Integer staffId, @PathVariable Integer staffId,
@ApiParam(hidden = true) @RequestBody GroupPositionVo groupPosition @Parameter(description = "不需要在body中传递staffId用path传递") @RequestBody GroupPositionVo groupPosition
) { ) {
projectGroupService.updateStaffPositions(token, staffId, projectId, groupPosition.getPositions()); projectGroupService.updateStaffPositions(token, staffId, projectId, groupPosition.getPositions());
return ResponseMap.ofSuccess("更新成功"); 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.exception.TokenException;
import cn.edu.hfut.rmdjzz.projectmanagement.service.IStaffService; import cn.edu.hfut.rmdjzz.projectmanagement.service.IStaffService;
import cn.edu.hfut.rmdjzz.projectmanagement.utils.http.ResponseMap; import cn.edu.hfut.rmdjzz.projectmanagement.utils.http.ResponseMap;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.annotations.ApiImplicitParams;
import lombok.SneakyThrows; import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -20,12 +19,12 @@ public class StaffController {
@Autowired @Autowired
private IStaffService staffService; private IStaffService staffService;
@ApiImplicitParams({
@ApiImplicitParam(name = "staff", value = "只需要传入staffUsername和staffPassword两个属性即可staffPassword需要md5加密后传输")
})
@SneakyThrows @SneakyThrows
@PostMapping("/login") @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()); 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.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic; import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler; import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import io.swagger.annotations.ApiModelProperty; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data; import lombok.Data;
import java.time.LocalDateTime; import java.time.LocalDateTime;
@ -39,7 +39,7 @@ public class Task {
private LocalDateTime taskClosedTime; private LocalDateTime taskClosedTime;
private Integer taskPriority; private Integer taskPriority;
private String taskDescription; private String taskDescription;
@ApiModelProperty( @Schema(description =
"demandSource:需求来源 (String), estimatedManHours:预估工时 (Integer), severity:严重程度 (String), recurrenceProbability:复现概率 (String)") "demandSource:需求来源 (String), estimatedManHours:预估工时 (Integer), severity:严重程度 (String), recurrenceProbability:复现概率 (String)")
@TableField(typeHandler = JacksonTypeHandler.class) @TableField(typeHandler = JacksonTypeHandler.class)
private Map<String, Object> attachedInfo; 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.metadata.OrderItem;
import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 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.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
@ -24,9 +24,9 @@ public class RequestPage {
@NotNull @NotNull
@Min(1) @Min(1)
Integer pageSize; Integer pageSize;
@ApiModelProperty("不传或传空时不排序,否则按照此字段排序") @Schema(description = "不传或传空时不排序,否则按照此字段排序")
String sortBy; String sortBy;
@ApiModelProperty("传true或空时为顺序排序否则倒序排序") @Schema(description = "传true或空时为顺序排序否则倒序排序")
Boolean asc; Boolean asc;
public <T> IPage<T> getPage() { public <T> IPage<T> getPage() {

View File

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