|
|
|
@ -4,13 +4,11 @@ import io.swagger.annotations.Api; |
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
import org.springframework.context.annotation.Bean; |
|
|
|
import org.springframework.context.annotation.Configuration; |
|
|
|
import springfox.documentation.service.SecurityReference; |
|
|
|
import springfox.documentation.builders.ParameterBuilder; |
|
|
|
import springfox.documentation.schema.ModelRef; |
|
|
|
import springfox.documentation.service.*; |
|
|
|
import springfox.documentation.builders.ApiInfoBuilder; |
|
|
|
import springfox.documentation.builders.RequestHandlerSelectors; |
|
|
|
import springfox.documentation.service.ApiInfo; |
|
|
|
import springfox.documentation.service.ApiKey; |
|
|
|
import springfox.documentation.service.Contact; |
|
|
|
import springfox.documentation.service.AuthorizationScope; |
|
|
|
import springfox.documentation.spi.DocumentationType; |
|
|
|
import springfox.documentation.spi.service.contexts.SecurityContext; |
|
|
|
import springfox.documentation.spring.web.plugins.Docket; |
|
|
|
@ -48,9 +46,15 @@ public class SwaggerConfig { |
|
|
|
|
|
|
|
@Bean |
|
|
|
public Docket customDocket() { |
|
|
|
ParameterBuilder tokenPar= new ParameterBuilder(); |
|
|
|
List<Parameter> pars=new ArrayList<>(); |
|
|
|
tokenPar.name("Authorization").description("令牌 格式:【bearer 令牌值】,注意bearer后根一个空格。").modelRef(new ModelRef("string")).parameterType("header").required(false).build(); |
|
|
|
pars.add(tokenPar.build()); |
|
|
|
tokenPar.name("accessToken").description("令牌,直接填写令牌值").modelRef(new ModelRef("string")).parameterType("query").required(false).build(); |
|
|
|
pars.add(tokenPar.build()); |
|
|
|
Docket docket= new Docket(DocumentationType.SWAGGER_2).select(). |
|
|
|
apis(RequestHandlerSelectors.any()) |
|
|
|
.build() |
|
|
|
.build().globalOperationParameters(pars) |
|
|
|
.apiInfo(apiInfo()).enable(true); |
|
|
|
|
|
|
|
/* |
|
|
|
@ -60,7 +64,7 @@ public class SwaggerConfig { |
|
|
|
//存储用户必须提交的参数 |
|
|
|
List<ApiKey> apikey = new ArrayList(); |
|
|
|
//规定用户需要输入什么参数 |
|
|
|
apikey.add(new ApiKey("token", "token", "token")); |
|
|
|
apikey.add(new ApiKey("accesToken", "accesToken", "accesToken")); |
|
|
|
docket.securitySchemes(apikey); |
|
|
|
|
|
|
|
//以下定义如果用户JWT认证通过,则在Swagger中全局有效 |
|
|
|
|