mirror of
https://github.com/RemainderTime/spring-boot-base-demo.git
synced 2026-02-21 14:30:56 +08:00
swagger api文档功能完善
This commit is contained in:
42
src/main/java/cn/xf/basedemo/config/SwaggerGroupApi.java
Normal file
42
src/main/java/cn/xf/basedemo/config/SwaggerGroupApi.java
Normal file
@@ -0,0 +1,42 @@
|
||||
package cn.xf.basedemo.config;
|
||||
|
||||
import io.swagger.v3.oas.models.ExternalDocumentation;
|
||||
import io.swagger.v3.oas.models.OpenAPI;
|
||||
import io.swagger.v3.oas.models.info.Contact;
|
||||
import io.swagger.v3.oas.models.info.Info;
|
||||
import io.swagger.v3.oas.models.info.License;
|
||||
import org.springdoc.core.models.GroupedOpenApi;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* packageName cn.xf.basedemo.config
|
||||
* @author remaindertime
|
||||
* @className SwaggerGroupApi
|
||||
* @date 2024/12/9
|
||||
* @description swagger分组配置
|
||||
*/
|
||||
@Component
|
||||
public class SwaggerGroupApi {
|
||||
|
||||
@Bean
|
||||
public OpenAPI springShopOpenAPI() {
|
||||
return new OpenAPI()
|
||||
.info(new Info().title("Spring boot脚手架 API")
|
||||
.description("开箱即用的Spring boot脚手架 API")
|
||||
.version("v0.0.1")
|
||||
.contact(new Contact().name("remaindertime").url("https://blog.csdn.net/qq_39818325"))
|
||||
.license(new License().name("Apache 2.0").url("http://springdoc.org")))
|
||||
.externalDocs(new ExternalDocumentation()
|
||||
.description("Spring boot脚手架 Wiki Documentation")
|
||||
.url("https://springshop.wiki.github.org/docs"));
|
||||
}
|
||||
|
||||
@Bean
|
||||
public GroupedOpenApi publicApi() {
|
||||
return GroupedOpenApi.builder()
|
||||
.group("用戶相关分组")
|
||||
.pathsToMatch("/user/**")
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,9 @@ import cn.xf.basedemo.interceptor.SessionContext;
|
||||
import cn.xf.basedemo.model.res.LoginInfoRes;
|
||||
import cn.xf.basedemo.service.UserService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springdoc.core.annotations.RouterOperations;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
@@ -21,6 +24,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
**/
|
||||
@RestController(value = "用户控制器")
|
||||
@RequestMapping("/user")
|
||||
@Tag(name = "用户控制器")
|
||||
public class UserController {
|
||||
|
||||
@Autowired
|
||||
|
||||
@@ -32,13 +32,15 @@ public class TokenInterceptor implements HandlerInterceptor {
|
||||
|
||||
|
||||
//不拦截的请求列表
|
||||
private static final List<String> EXCLUDE_PATH_LIST = Arrays.asList("/user/login", "/web/login");
|
||||
private static final List<String> EXCLUDE_PATH_LIST = Arrays.asList("/user/login", "/web/login","/swagger-ui.html","/v3/api-docs","/swagger-ui/index.html");
|
||||
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||
|
||||
String requestURI = request.getRequestURI();
|
||||
if (EXCLUDE_PATH_LIST.contains(requestURI)) {
|
||||
if (EXCLUDE_PATH_LIST.contains(requestURI) ||
|
||||
requestURI.contains("/swagger-ui") ||
|
||||
requestURI.contains("/v3/api-docs")) {
|
||||
return true;
|
||||
}
|
||||
//登录处理
|
||||
|
||||
Reference in New Issue
Block a user