1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
| package com.foxconn.mcebg.portal.config;
import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j; import com.google.common.collect.Lists; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import springfox.bean.validators.configuration.BeanValidatorPluginsConfiguration; import springfox.documentation.builders.ApiInfoBuilder; import springfox.documentation.builders.PathSelectors; import springfox.documentation.builders.RequestHandlerSelectors; import springfox.documentation.service.*; import springfox.documentation.spi.DocumentationType; import springfox.documentation.spi.service.contexts.SecurityContext; import springfox.documentation.spring.web.plugins.Docket; import springfox.documentation.swagger2.annotations.EnableSwagger2;
import java.util.ArrayList; import java.util.List;
@Configuration @EnableSwagger2 @EnableKnife4j @Import(BeanValidatorPluginsConfiguration.class) public class SwaggerConfiguration {
@Bean(value = "defaultApi2") public Docket defaultApi2() { Docket docket=new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .groupName("2.X版本") .select() .apis(RequestHandlerSelectors.basePackage("com.foxconn.mcebg.portal.controller")) .paths(PathSelectors.any()) .build().securityContexts(Lists.newArrayList(securityContext())).securitySchemes(Lists.<SecurityScheme>newArrayList(apiKey())); return docket; }
private ApiInfo apiInfo() { return new ApiInfoBuilder() .title("SystemPortal系统门户 RESTful APIs") .description("# SystemPortal系统门户 RESTful APIs") .termsOfServiceUrl("http://10.244.186.86:8081/") .contact(new Contact("向波任(C3005579)", "http://10.244.186.86:8081/doc.html", "[email protected]")) .version("1.0") .build(); }
private ApiKey apiKey() { return new ApiKey("BearerToken", "Authorization", "header"); }
private SecurityContext securityContext() { return SecurityContext.builder() .securityReferences(defaultAuth()) .forPaths(PathSelectors.regex("/.*")) .build(); }
private List<SecurityReference> defaultAuth() { List<SecurityReference> list = new ArrayList<>(); AuthorizationScope[] scopes = new AuthorizationScope[1]; scopes[0] = new AuthorizationScope("", ""); SecurityReference sr = new SecurityReference("", scopes); list.add(sr);
return list; } }
|