mirror of
https://github.com/chillzhuang/blade-tool
synced 2024-11-14 22:49:33 +08:00
🎉 3.4.1.RELEASE 重构swagger封装
This commit is contained in:
parent
76f0ea534e
commit
1700db64c5
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.springblade</groupId>
|
<groupId>org.springblade</groupId>
|
||||||
<artifactId>blade-tool</artifactId>
|
<artifactId>blade-tool</artifactId>
|
||||||
<version>3.4.0</version>
|
<version>3.4.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
@ -101,7 +101,7 @@ mybatis-plus:
|
|||||||
swagger:
|
swagger:
|
||||||
title: SpringBlade 接口文档系统
|
title: SpringBlade 接口文档系统
|
||||||
description: SpringBlade 接口文档系统
|
description: SpringBlade 接口文档系统
|
||||||
version: 3.4.0
|
version: 3.4.1
|
||||||
license: Powered By SpringBlade
|
license: Powered By SpringBlade
|
||||||
licenseUrl: https://bladex.vip
|
licenseUrl: https://bladex.vip
|
||||||
terms-of-service-url: https://bladex.vip
|
terms-of-service-url: https://bladex.vip
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>blade-tool</artifactId>
|
<artifactId>blade-tool</artifactId>
|
||||||
<groupId>org.springblade</groupId>
|
<groupId>org.springblade</groupId>
|
||||||
<version>3.4.0</version>
|
<version>3.4.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>blade-tool</artifactId>
|
<artifactId>blade-tool</artifactId>
|
||||||
<groupId>org.springblade</groupId>
|
<groupId>org.springblade</groupId>
|
||||||
<version>3.4.0</version>
|
<version>3.4.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>blade-tool</artifactId>
|
<artifactId>blade-tool</artifactId>
|
||||||
<groupId>org.springblade</groupId>
|
<groupId>org.springblade</groupId>
|
||||||
<version>3.4.0</version>
|
<version>3.4.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ import $!{pkg};
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
#end
|
#end
|
||||||
#if($!{swagger2})
|
#if($!{swagger})
|
||||||
import io.swagger.annotations.ApiModel;
|
import io.swagger.annotations.ApiModel;
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
#end
|
#end
|
||||||
@ -42,7 +42,7 @@ import io.swagger.annotations.ApiModelProperty;
|
|||||||
#if($!{superEntityClass})
|
#if($!{superEntityClass})
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
#end
|
#end
|
||||||
#if($!{swagger2})
|
#if($!{swagger})
|
||||||
@ApiModel(value = "$!{entity}对象", description = #if ("$!{table.comment}"=="")"$!{entity}对象"#else"$!{table.comment}"#end)
|
@ApiModel(value = "$!{entity}对象", description = #if ("$!{table.comment}"=="")"$!{entity}对象"#else"$!{table.comment}"#end)
|
||||||
#end
|
#end
|
||||||
#if($!{superEntityClass})
|
#if($!{superEntityClass})
|
||||||
@ -66,7 +66,7 @@ public class $!{entity} implements Serializable {
|
|||||||
/**
|
/**
|
||||||
* $!{field.comment}
|
* $!{field.comment}
|
||||||
*/
|
*/
|
||||||
#if($!{swagger2})
|
#if($!{swagger})
|
||||||
@ApiModelProperty(value = "$!{field.comment}")
|
@ApiModelProperty(value = "$!{field.comment}")
|
||||||
#end
|
#end
|
||||||
#end
|
#end
|
||||||
|
@ -21,7 +21,7 @@ import $!{package.Entity}.$!{entity};
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
#end
|
#end
|
||||||
#if($!{swagger2})
|
#if($!{swagger})
|
||||||
import io.swagger.annotations.ApiModel;
|
import io.swagger.annotations.ApiModel;
|
||||||
#end
|
#end
|
||||||
|
|
||||||
@ -35,7 +35,7 @@ import io.swagger.annotations.ApiModel;
|
|||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
#end
|
#end
|
||||||
#if($!{swagger2})
|
#if($!{swagger})
|
||||||
@ApiModel(value = "$!{entity}VO对象", description = #if ("$!{table.comment}"=="")"$!{entity}VO对象"#else"$!{table.comment}"#end)
|
@ApiModel(value = "$!{entity}VO对象", description = #if ("$!{table.comment}"=="")"$!{entity}VO对象"#else"$!{table.comment}"#end)
|
||||||
#end
|
#end
|
||||||
public class $!{entity}VO extends $!{entity} {
|
public class $!{entity}VO extends $!{entity} {
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>blade-tool</artifactId>
|
<artifactId>blade-tool</artifactId>
|
||||||
<groupId>org.springblade</groupId>
|
<groupId>org.springblade</groupId>
|
||||||
<version>3.4.0</version>
|
<version>3.4.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
@ -25,7 +25,7 @@ public interface AppConstant {
|
|||||||
/**
|
/**
|
||||||
* 应用版本
|
* 应用版本
|
||||||
*/
|
*/
|
||||||
String APPLICATION_VERSION = "3.4.0";
|
String APPLICATION_VERSION = "3.4.1";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 基础包
|
* 基础包
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>blade-tool</artifactId>
|
<artifactId>blade-tool</artifactId>
|
||||||
<groupId>org.springblade</groupId>
|
<groupId>org.springblade</groupId>
|
||||||
<version>3.4.0</version>
|
<version>3.4.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>blade-tool</artifactId>
|
<artifactId>blade-tool</artifactId>
|
||||||
<groupId>org.springblade</groupId>
|
<groupId>org.springblade</groupId>
|
||||||
<version>3.4.0</version>
|
<version>3.4.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>blade-tool</artifactId>
|
<artifactId>blade-tool</artifactId>
|
||||||
<groupId>org.springblade</groupId>
|
<groupId>org.springblade</groupId>
|
||||||
<version>3.4.0</version>
|
<version>3.4.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>blade-tool</artifactId>
|
<artifactId>blade-tool</artifactId>
|
||||||
<groupId>org.springblade</groupId>
|
<groupId>org.springblade</groupId>
|
||||||
<version>3.4.0</version>
|
<version>3.4.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>blade-tool</artifactId>
|
<artifactId>blade-tool</artifactId>
|
||||||
<groupId>org.springblade</groupId>
|
<groupId>org.springblade</groupId>
|
||||||
<version>3.4.0</version>
|
<version>3.4.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>blade-tool</artifactId>
|
<artifactId>blade-tool</artifactId>
|
||||||
<groupId>org.springblade</groupId>
|
<groupId>org.springblade</groupId>
|
||||||
<version>3.4.0</version>
|
<version>3.4.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>blade-tool</artifactId>
|
<artifactId>blade-tool</artifactId>
|
||||||
<groupId>org.springblade</groupId>
|
<groupId>org.springblade</groupId>
|
||||||
<version>3.4.0</version>
|
<version>3.4.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>blade-tool</artifactId>
|
<artifactId>blade-tool</artifactId>
|
||||||
<groupId>org.springblade</groupId>
|
<groupId>org.springblade</groupId>
|
||||||
<version>3.4.0</version>
|
<version>3.4.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright (c) 2018-2028, lengleng (wangiegie@gmail.com).
|
* Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com).
|
||||||
* <p>
|
* <p>
|
||||||
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
|
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -22,7 +22,6 @@ import lombok.AllArgsConstructor;
|
|||||||
import org.springblade.core.launch.props.BladeProperties;
|
import org.springblade.core.launch.props.BladeProperties;
|
||||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Import;
|
import org.springframework.context.annotation.Import;
|
||||||
import springfox.bean.validators.configuration.BeanValidatorPluginsConfiguration;
|
import springfox.bean.validators.configuration.BeanValidatorPluginsConfiguration;
|
||||||
@ -44,11 +43,10 @@ import java.util.List;
|
|||||||
*
|
*
|
||||||
* @author Chill
|
* @author Chill
|
||||||
*/
|
*/
|
||||||
@AutoConfiguration
|
|
||||||
@EnableSwagger
|
@EnableSwagger
|
||||||
@EnableConfigurationProperties(SwaggerProperties.class)
|
@AutoConfiguration
|
||||||
@Import(BeanValidatorPluginsConfiguration.class)
|
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
|
@Import(BeanValidatorPluginsConfiguration.class)
|
||||||
public class SwaggerAutoConfiguration {
|
public class SwaggerAutoConfiguration {
|
||||||
|
|
||||||
private static final String DEFAULT_BASE_PATH = "/**";
|
private static final String DEFAULT_BASE_PATH = "/**";
|
||||||
@ -71,13 +69,11 @@ public class SwaggerAutoConfiguration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
|
@ConditionalOnMissingBean
|
||||||
public Docket api(SwaggerProperties swaggerProperties) {
|
public Docket api(SwaggerProperties swaggerProperties) {
|
||||||
// base-path处理
|
|
||||||
if (swaggerProperties.getBasePath().size() == 0) {
|
if (swaggerProperties.getBasePath().size() == 0) {
|
||||||
swaggerProperties.getBasePath().add(DEFAULT_BASE_PATH);
|
swaggerProperties.getBasePath().add(DEFAULT_BASE_PATH);
|
||||||
}
|
}
|
||||||
|
|
||||||
// exclude-path处理
|
|
||||||
if (swaggerProperties.getExcludePath().size() == 0) {
|
if (swaggerProperties.getExcludePath().size() == 0) {
|
||||||
swaggerProperties.getExcludePath().addAll(DEFAULT_EXCLUDE_PATH);
|
swaggerProperties.getExcludePath().addAll(DEFAULT_EXCLUDE_PATH);
|
||||||
}
|
}
|
||||||
@ -85,54 +81,60 @@ public class SwaggerAutoConfiguration {
|
|||||||
.host(swaggerProperties.getHost())
|
.host(swaggerProperties.getHost())
|
||||||
.apiInfo(apiInfo(swaggerProperties)).select()
|
.apiInfo(apiInfo(swaggerProperties)).select()
|
||||||
.apis(SwaggerUtil.basePackages(swaggerProperties.getBasePackages()));
|
.apis(SwaggerUtil.basePackages(swaggerProperties.getBasePackages()));
|
||||||
|
|
||||||
swaggerProperties.getBasePath().forEach(p -> apis.paths(PathSelectors.ant(p)));
|
swaggerProperties.getBasePath().forEach(p -> apis.paths(PathSelectors.ant(p)));
|
||||||
swaggerProperties.getExcludePath().forEach(p -> apis.paths(PathSelectors.ant(p).negate()));
|
swaggerProperties.getExcludePath().forEach(p -> apis.paths(PathSelectors.ant(p).negate()));
|
||||||
|
return apis.build().securityContexts(securityContexts(swaggerProperties)).securitySchemes(securitySchemas(swaggerProperties))
|
||||||
return apis.build()
|
|
||||||
.securitySchemes(Collections.singletonList(securitySchema(swaggerProperties)))
|
|
||||||
.securityContexts(Collections.singletonList(securityContext(swaggerProperties)))
|
|
||||||
.securityContexts(Lists.newArrayList(securityContext(swaggerProperties)))
|
|
||||||
.securitySchemes(Collections.singletonList(securitySchema(swaggerProperties)))
|
|
||||||
.extensions(openApiExtensionResolver.buildExtensions(bladeProperties.getName()));
|
.extensions(openApiExtensionResolver.buildExtensions(bladeProperties.getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 配置默认的全局鉴权策略的开关,通过正则表达式进行匹配;默认匹配所有URL
|
* 配置默认的全局鉴权策略的开关,通过正则表达式进行匹配;默认匹配所有URL
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
private SecurityContext securityContext(SwaggerProperties swaggerProperties) {
|
private List<SecurityContext> securityContexts(SwaggerProperties swaggerProperties) {
|
||||||
return SecurityContext.builder()
|
return Collections.singletonList(SecurityContext.builder()
|
||||||
.securityReferences(defaultAuth(swaggerProperties))
|
.securityReferences(defaultAuth(swaggerProperties))
|
||||||
.forPaths(PathSelectors.regex(swaggerProperties.getAuthorization().getAuthRegex()))
|
.forPaths(PathSelectors.regex(swaggerProperties.getAuthorization().getAuthRegex()))
|
||||||
.build();
|
.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 默认的全局鉴权策略
|
* 默认的全局鉴权策略
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
private List<SecurityReference> defaultAuth(SwaggerProperties swaggerProperties) {
|
private List<SecurityReference> defaultAuth(SwaggerProperties swaggerProperties) {
|
||||||
ArrayList<AuthorizationScope> authorizationScopeList = new ArrayList<>();
|
List<AuthorizationScope> authorizationScopeList = new ArrayList<>();
|
||||||
swaggerProperties.getAuthorization().getAuthorizationScopeList().forEach(authorizationScope -> authorizationScopeList.add(new AuthorizationScope(authorizationScope.getScope(), authorizationScope.getDescription())));
|
List<SecurityReference> securityReferenceList = new ArrayList<>();
|
||||||
AuthorizationScope[] authorizationScopes = new AuthorizationScope[authorizationScopeList.size()];
|
List<SwaggerProperties.AuthorizationScope> swaggerScopeList = swaggerProperties.getAuthorization().getAuthorizationScopeList();
|
||||||
return Collections.singletonList(SecurityReference.builder()
|
swaggerScopeList.forEach(authorizationScope -> authorizationScopeList.add(new AuthorizationScope(authorizationScope.getScope(), authorizationScope.getDescription())));
|
||||||
.reference(swaggerProperties.getAuthorization().getName())
|
if (authorizationScopeList.size() == 0) {
|
||||||
.scopes(authorizationScopeList.toArray(authorizationScopes))
|
authorizationScopeList.add(new AuthorizationScope("global", "accessEverywhere"));
|
||||||
.build());
|
}
|
||||||
|
AuthorizationScope[] authorizationScopes = authorizationScopeList.toArray(new AuthorizationScope[0]);
|
||||||
|
swaggerScopeList.forEach(authorizationScope -> securityReferenceList.add(new SecurityReference(authorizationScope.getName(), authorizationScopes)));
|
||||||
|
if (securityReferenceList.size() == 0) {
|
||||||
|
securityReferenceList.add(new SecurityReference(SwaggerUtil.clientInfo().getName(), authorizationScopes));
|
||||||
|
securityReferenceList.add(new SecurityReference(SwaggerUtil.bladeAuth().getName(), authorizationScopes));
|
||||||
|
securityReferenceList.add(new SecurityReference(SwaggerUtil.bladeTenant().getName(), authorizationScopes));
|
||||||
|
}
|
||||||
|
return securityReferenceList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
private OAuth securitySchema(SwaggerProperties swaggerProperties) {
|
* 配置安全策略
|
||||||
ArrayList<AuthorizationScope> authorizationScopeList = new ArrayList<>();
|
*/
|
||||||
swaggerProperties.getAuthorization().getAuthorizationScopeList().forEach(authorizationScope -> authorizationScopeList.add(new AuthorizationScope(authorizationScope.getScope(), authorizationScope.getDescription())));
|
private List<SecurityScheme> securitySchemas(SwaggerProperties swaggerProperties) {
|
||||||
ArrayList<GrantType> grantTypes = new ArrayList<>();
|
List<SwaggerProperties.AuthorizationApiKey> swaggerApiKeyList = swaggerProperties.getAuthorization().getAuthorizationApiKeyList();
|
||||||
swaggerProperties.getAuthorization().getTokenUrlList().forEach(tokenUrl -> grantTypes.add(new ResourceOwnerPasswordCredentialsGrant(tokenUrl)));
|
if (swaggerApiKeyList.size() == 0) {
|
||||||
return new OAuth(swaggerProperties.getAuthorization().getName(), authorizationScopeList, grantTypes);
|
return Lists.newArrayList(SwaggerUtil.clientInfo(), SwaggerUtil.bladeAuth(), SwaggerUtil.bladeTenant());
|
||||||
|
} else {
|
||||||
|
List<SecurityScheme> securitySchemeList = new ArrayList<>();
|
||||||
|
swaggerApiKeyList.forEach(authorizationApiKey -> securitySchemeList.add(new ApiKey(authorizationApiKey.getName(), authorizationApiKey.getKeyName(), authorizationApiKey.getPassAs())));
|
||||||
|
return securitySchemeList;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 配置基本信息
|
||||||
|
*/
|
||||||
private ApiInfo apiInfo(SwaggerProperties swaggerProperties) {
|
private ApiInfo apiInfo(SwaggerProperties swaggerProperties) {
|
||||||
return new ApiInfoBuilder()
|
return new ApiInfoBuilder()
|
||||||
.title(swaggerProperties.getTitle())
|
.title(swaggerProperties.getTitle())
|
||||||
|
@ -55,7 +55,7 @@ public class SwaggerProperties {
|
|||||||
/**
|
/**
|
||||||
* 版本
|
* 版本
|
||||||
**/
|
**/
|
||||||
private String version = "3.4.0";
|
private String version = "3.4.1";
|
||||||
/**
|
/**
|
||||||
* 许可证
|
* 许可证
|
||||||
**/
|
**/
|
||||||
@ -120,6 +120,14 @@ public class SwaggerProperties {
|
|||||||
*/
|
*/
|
||||||
private List<AuthorizationScope> authorizationScopeList = new ArrayList<>();
|
private List<AuthorizationScope> authorizationScopeList = new ArrayList<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 鉴权请求头参数列表
|
||||||
|
*/
|
||||||
|
private List<AuthorizationApiKey> authorizationApiKeyList = new ArrayList<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 接口匹配地址
|
||||||
|
*/
|
||||||
private List<String> tokenUrlList = new ArrayList<>();
|
private List<String> tokenUrlList = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,6 +135,10 @@ public class SwaggerProperties {
|
|||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
public static class AuthorizationScope {
|
public static class AuthorizationScope {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 鉴权策略名, 需要和ApiKey的name保持一致
|
||||||
|
*/
|
||||||
|
private String name = "";
|
||||||
/**
|
/**
|
||||||
* 作用域名称
|
* 作用域名称
|
||||||
*/
|
*/
|
||||||
@ -138,4 +150,25 @@ public class SwaggerProperties {
|
|||||||
private String description = "";
|
private String description = "";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
public static class AuthorizationApiKey {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 参数名
|
||||||
|
*/
|
||||||
|
private String name = "";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 参数值
|
||||||
|
*/
|
||||||
|
private String keyName = "";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 参数作用域
|
||||||
|
*/
|
||||||
|
private String passAs = "";
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright (c) 2018-2028, lengleng (wangiegie@gmail.com).
|
* Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com).
|
||||||
* <p>
|
* <p>
|
||||||
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
|
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -17,7 +17,9 @@ package org.springblade.core.swagger;
|
|||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.base.Optional;
|
import com.google.common.base.Optional;
|
||||||
|
import org.springblade.core.launch.constant.TokenConstant;
|
||||||
import springfox.documentation.RequestHandler;
|
import springfox.documentation.RequestHandler;
|
||||||
|
import springfox.documentation.service.ApiKey;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
@ -55,4 +57,17 @@ public class SwaggerUtil {
|
|||||||
return Optional.fromNullable(input.declaringClass());
|
return Optional.fromNullable(input.declaringClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static ApiKey clientInfo() {
|
||||||
|
return new ApiKey("ClientInfo", "Authorization", "header");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ApiKey bladeAuth() {
|
||||||
|
return new ApiKey("BladeAuth", TokenConstant.HEADER, "header");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ApiKey bladeTenant() {
|
||||||
|
return new ApiKey("TenantId", "Tenant-Id", "header");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,39 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com).
|
||||||
|
* <p>
|
||||||
|
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* <p>
|
||||||
|
* http://www.gnu.org/licenses/lgpl.html
|
||||||
|
* <p>
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.springblade.core.swagger;
|
||||||
|
|
||||||
|
|
||||||
|
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||||
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
|
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||||
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* swagger资源配置
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
@AutoConfiguration
|
||||||
|
@EnableConfigurationProperties(SwaggerProperties.class)
|
||||||
|
public class SwaggerWebConfiguration implements WebMvcConfigurer {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||||
|
registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/");
|
||||||
|
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.springblade</groupId>
|
<groupId>org.springblade</groupId>
|
||||||
<artifactId>blade-tool</artifactId>
|
<artifactId>blade-tool</artifactId>
|
||||||
<version>3.4.0</version>
|
<version>3.4.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.springblade</groupId>
|
<groupId>org.springblade</groupId>
|
||||||
<artifactId>blade-tool</artifactId>
|
<artifactId>blade-tool</artifactId>
|
||||||
<version>3.4.0</version>
|
<version>3.4.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>blade-tool</artifactId>
|
<artifactId>blade-tool</artifactId>
|
||||||
<groupId>org.springblade</groupId>
|
<groupId>org.springblade</groupId>
|
||||||
<version>3.4.0</version>
|
<version>3.4.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
6
pom.xml
6
pom.xml
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
<groupId>org.springblade</groupId>
|
<groupId>org.springblade</groupId>
|
||||||
<artifactId>blade-tool</artifactId>
|
<artifactId>blade-tool</artifactId>
|
||||||
<version>3.4.0</version>
|
<version>3.4.1</version>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<name>blade-tool</name>
|
<name>blade-tool</name>
|
||||||
<description>
|
<description>
|
||||||
@ -36,7 +36,7 @@
|
|||||||
</scm>
|
</scm>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<blade.tool.version>3.4.0</blade.tool.version>
|
<blade.tool.version>3.4.1</blade.tool.version>
|
||||||
|
|
||||||
<java.version>1.8</java.version>
|
<java.version>1.8</java.version>
|
||||||
<maven.plugin.version>3.8.1</maven.plugin.version>
|
<maven.plugin.version>3.8.1</maven.plugin.version>
|
||||||
@ -52,7 +52,7 @@
|
|||||||
<mica.auto.version>1.2.5</mica.auto.version>
|
<mica.auto.version>1.2.5</mica.auto.version>
|
||||||
<alibaba.cloud.version>2021.0.1.0</alibaba.cloud.version>
|
<alibaba.cloud.version>2021.0.1.0</alibaba.cloud.version>
|
||||||
<alibaba.nacos.version>2.1.0</alibaba.nacos.version>
|
<alibaba.nacos.version>2.1.0</alibaba.nacos.version>
|
||||||
<alibaba.seata.version>1.5.1.1</alibaba.seata.version>
|
<alibaba.seata.version>1.5.2</alibaba.seata.version>
|
||||||
<spring.plugin.version>2.0.0.RELEASE</spring.plugin.version>
|
<spring.plugin.version>2.0.0.RELEASE</spring.plugin.version>
|
||||||
|
|
||||||
<spring.boot.version>2.7.1</spring.boot.version>
|
<spring.boot.version>2.7.1</spring.boot.version>
|
||||||
|
Loading…
Reference in New Issue
Block a user