feat: knife4j v4.3版本网关聚合

This commit is contained in:
郝先瑞 2023-09-27 18:22:31 +08:00
parent de86041995
commit 1e4749bfdb
6 changed files with 165 additions and 103 deletions

View File

@ -4,8 +4,11 @@ import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import io.swagger.v3.oas.models.security.OAuthFlows;
import io.swagger.v3.oas.models.security.Scopes;
import io.swagger.v3.oas.models.security.SecurityScheme;
import org.springdoc.core.models.GroupedOpenApi;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@ -20,6 +23,12 @@ import org.springframework.context.annotation.Configuration;
@Configuration
public class SwaggerConfig {
/**
* 认证服务地址
*/
@Value("${knife4j.oauth2.token-url}")
private String tokenUrl ;
/**
* 接口信息
*/
@ -28,31 +37,33 @@ public class SwaggerConfig {
return new OpenAPI()
.components(new Components()
.addSecuritySchemes("Authorization",
new SecurityScheme().type(SecurityScheme.Type.HTTP)
.scheme("bearer").bearerFormat("JWT")
new SecurityScheme()
.name("Authorization")
.type(SecurityScheme.Type.OAUTH2)
.flows(new OAuthFlows()
.password(
new io.swagger.v3.oas.models.security.OAuthFlow()
.tokenUrl(tokenUrl)
.refreshUrl(tokenUrl)
.scopes(
new Scopes()
.addString("all", "全部权限")
)
)
)
.scheme("bearer")
.in(SecurityScheme.In.HEADER)
.bearerFormat("JWT")
)
)
.info(new Info()
.title("订单服务")
.version("3.0.0")
.description("订单服务接口文档")
.description("订单、购物车等接口")
.license(new License().name("Apache 2.0")
.url("https://www.apache.org/licenses/LICENSE-2.0"))
);
}
/**
* 接口分组
*/
@Bean
public GroupedOpenApi omsApi() {
String[] paths = {"/**"};
String[] packagesToScan = {"com.youlai.mall.oms.controller"};
return GroupedOpenApi.builder()
.group("订单服务")
.packagesToScan(packagesToScan)
.pathsToMatch(paths)
.build();
}
}

View File

@ -4,8 +4,11 @@ import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import io.swagger.v3.oas.models.security.OAuthFlows;
import io.swagger.v3.oas.models.security.Scopes;
import io.swagger.v3.oas.models.security.SecurityScheme;
import org.springdoc.core.models.GroupedOpenApi;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@ -20,6 +23,12 @@ import org.springframework.context.annotation.Configuration;
@Configuration
public class SwaggerConfig {
/**
* 认证服务地址
*/
@Value("${knife4j.oauth2.token-url}")
private String tokenUrl ;
/**
* 接口信息
*/
@ -28,31 +37,34 @@ public class SwaggerConfig {
return new OpenAPI()
.components(new Components()
.addSecuritySchemes("Authorization",
new SecurityScheme().type(SecurityScheme.Type.HTTP)
.scheme("bearer").bearerFormat("JWT")
new SecurityScheme()
.name("Authorization")
.type(SecurityScheme.Type.OAUTH2)
.flows(new OAuthFlows()
.password(
new io.swagger.v3.oas.models.security.OAuthFlow()
.tokenUrl(tokenUrl)
.refreshUrl(tokenUrl)
.scopes(
new Scopes()
.addString("all", "全部权限")
)
)
)
.scheme("bearer")
.in(SecurityScheme.In.HEADER)
.bearerFormat("JWT")
)
)
.info(new Info()
.title("商品服务")
.version("3.0.0")
.description("商品管理、库存、分类、品牌、规格、参数等接口")
.description("库存、分类、品牌、规格、参数等接口")
.license(new License().name("Apache 2.0")
.url("https://www.apache.org/licenses/LICENSE-2.0"))
);
}
/**
* 接口分组
*/
@Bean
public GroupedOpenApi orderApi() {
String[] paths = {"/**"};
String[] packagesToScan = {"com.youlai.mall.pms.controller"};
return GroupedOpenApi.builder()
.group("商品服务")
.packagesToScan(packagesToScan)
.pathsToMatch(paths)
.build();
}
}

View File

@ -4,8 +4,11 @@ import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import io.swagger.v3.oas.models.security.OAuthFlows;
import io.swagger.v3.oas.models.security.Scopes;
import io.swagger.v3.oas.models.security.SecurityScheme;
import org.springdoc.core.models.GroupedOpenApi;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@ -20,6 +23,12 @@ import org.springframework.context.annotation.Configuration;
@Configuration
public class SwaggerConfig {
/**
* 认证服务地址
*/
@Value("${knife4j.oauth2.token-url}")
private String tokenUrl ;
/**
* 接口信息
*/
@ -28,31 +37,32 @@ public class SwaggerConfig {
return new OpenAPI()
.components(new Components()
.addSecuritySchemes("Authorization",
new SecurityScheme().type(SecurityScheme.Type.HTTP)
.scheme("bearer").bearerFormat("JWT")
new SecurityScheme()
.name("Authorization")
.type(SecurityScheme.Type.OAUTH2)
.flows(new OAuthFlows()
.password(
new io.swagger.v3.oas.models.security.OAuthFlow()
.tokenUrl(tokenUrl)
.refreshUrl(tokenUrl)
.scopes(
new Scopes()
.addString("all", "全部权限")
)
)
)
.scheme("bearer")
.in(SecurityScheme.In.HEADER)
.bearerFormat("JWT")
)
)
.info(new Info()
.title("营销服务")
.version("3.0.0")
.description("首页广告等接口")
.description("广告、优惠券等接口")
.license(new License().name("Apache 2.0")
.url("https://www.apache.org/licenses/LICENSE-2.0"))
);
}
/**
* 接口分组
*/
@Bean
public GroupedOpenApi smsApi() {
String[] paths = {"/**"};
String[] packagesToScan = {"com.youlai.mall.sms.controller"};
return GroupedOpenApi.builder()
.group("营销服务")
.packagesToScan(packagesToScan)
.pathsToMatch(paths)
.build();
}
}

View File

@ -4,8 +4,11 @@ import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import io.swagger.v3.oas.models.security.OAuthFlows;
import io.swagger.v3.oas.models.security.Scopes;
import io.swagger.v3.oas.models.security.SecurityScheme;
import org.springdoc.core.models.GroupedOpenApi;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@ -20,6 +23,13 @@ import org.springframework.context.annotation.Configuration;
@Configuration
public class SwaggerConfig {
/**
* 认证服务地址
*/
@Value("${knife4j.oauth2.token-url}")
private String tokenUrl ;
/**
* 接口信息
*/
@ -28,31 +38,32 @@ public class SwaggerConfig {
return new OpenAPI()
.components(new Components()
.addSecuritySchemes("Authorization",
new SecurityScheme().type(SecurityScheme.Type.HTTP)
.scheme("bearer").bearerFormat("JWT")
new SecurityScheme()
.name("Authorization")
.type(SecurityScheme.Type.OAUTH2)
.flows(new OAuthFlows()
.password(
new io.swagger.v3.oas.models.security.OAuthFlow()
.tokenUrl(tokenUrl)
.refreshUrl(tokenUrl)
.scopes(
new Scopes()
.addString("all", "全部权限")
)
)
)
.scheme("bearer")
.in(SecurityScheme.In.HEADER)
.bearerFormat("JWT")
)
)
.info(new Info()
.title("会员服务")
.version("3.0.0")
.description("会员管理、地址接口")
.description("会员、地址接口")
.license(new License().name("Apache 2.0")
.url("https://www.apache.org/licenses/LICENSE-2.0"))
);
}
/**
* 接口分组
*/
@Bean
public GroupedOpenApi orderApi() {
String[] paths = {"/**"};
String[] packagesToScan = {"com.youlai.mall.ums.controller"};
return GroupedOpenApi.builder()
.group("会员服务")
.packagesToScan(packagesToScan)
.pathsToMatch(paths)
.build();
}
}

View File

@ -4,15 +4,15 @@ import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import io.swagger.v3.oas.models.security.OAuthFlows;
import io.swagger.v3.oas.models.security.Scopes;
import io.swagger.v3.oas.models.security.SecurityScheme;
import org.springdoc.core.models.GroupedOpenApi;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* Swagger 配置
* <p>
* Spring Doc FAQ: https://springdoc.org/#faq
*
* @author haoxr
* @since 2023/2/17
@ -20,6 +20,12 @@ import org.springframework.context.annotation.Configuration;
@Configuration
public class SwaggerConfig {
/**
* 认证服务地址
*/
@Value("${knife4j.oauth2.token-url}")
private String tokenUrl ;
/**
* 接口信息
*/
@ -28,31 +34,32 @@ public class SwaggerConfig {
return new OpenAPI()
.components(new Components()
.addSecuritySchemes("Authorization",
new SecurityScheme().type(SecurityScheme.Type.HTTP)
.scheme("bearer").bearerFormat("JWT")
new SecurityScheme()
.name("Authorization")
.type(SecurityScheme.Type.OAUTH2)
.flows(new OAuthFlows()
.password(
new io.swagger.v3.oas.models.security.OAuthFlow()
.tokenUrl(tokenUrl)
.refreshUrl(tokenUrl)
.scopes(
new Scopes()
.addString("all", "全部权限")
)
)
)
.scheme("bearer")
.in(SecurityScheme.In.HEADER)
.bearerFormat("JWT")
)
)
.info(new Info()
.title("认证中心")
.version("3.0.0")
.description("认证、注销、获取验签公钥接口")
.description("认证接口")
.license(new License().name("Apache 2.0")
.url("https://www.apache.org/licenses/LICENSE-2.0"))
);
}
/**
* 认证中心接口
*/
@Bean
public GroupedOpenApi authApi() {
String[] paths = {"/**"};
String[] packagesToScan = {"com.youlai.auth.controller"};
return GroupedOpenApi.builder()
.group("认证中心")
.packagesToScan(packagesToScan)
.pathsToMatch(paths)
.build();
}
}

View File

@ -4,8 +4,11 @@ import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import io.swagger.v3.oas.models.security.OAuthFlows;
import io.swagger.v3.oas.models.security.Scopes;
import io.swagger.v3.oas.models.security.SecurityScheme;
import org.springdoc.core.models.GroupedOpenApi;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@ -20,6 +23,12 @@ import org.springframework.context.annotation.Configuration;
@Configuration
public class SwaggerConfig {
/**
* 认证服务地址
*/
@Value("${knife4j.oauth2.token-url}")
private String tokenUrl ;
/**
* 接口信息
*/
@ -28,31 +37,33 @@ public class SwaggerConfig {
return new OpenAPI()
.components(new Components()
.addSecuritySchemes("Authorization",
new SecurityScheme().type(SecurityScheme.Type.HTTP)
.scheme("bearer").bearerFormat("JWT")
new SecurityScheme()
.name("Authorization")
.type(SecurityScheme.Type.OAUTH2)
.flows(new OAuthFlows()
.password(
new io.swagger.v3.oas.models.security.OAuthFlow()
.tokenUrl(tokenUrl)
.refreshUrl(tokenUrl)
.scopes(
new Scopes()
.addString("all", "全部权限")
)
)
)
.scheme("bearer")
.in(SecurityScheme.In.HEADER)
.bearerFormat("JWT")
)
)
.info(new Info()
.title("系统服务")
.version("2.0.0")
.description("系统服务接口文档")
.version("3.0.0")
.description("用户、角色、菜单、部门、字典等接口")
.license(new License().name("Apache 2.0")
.url("https://www.apache.org/licenses/LICENSE-2.0"))
);
}
/**
* 接口分组-系统接口
*/
@Bean
public GroupedOpenApi systemApi() {
String[] paths = {"/**"};
String[] packagesToScan = {"com.youlai.system.controller"};
return GroupedOpenApi.builder()
.group("系统服务")
.packagesToScan(packagesToScan)
.pathsToMatch(paths)
.build();
}
}