|
|
@@ -1,63 +0,0 @@
|
|
|
-package com.ctsi.config;
|
|
|
-
|
|
|
-import org.springframework.context.annotation.Bean;
|
|
|
-import org.springframework.context.annotation.Configuration;
|
|
|
-import springfox.documentation.builders.ApiInfoBuilder;
|
|
|
-import springfox.documentation.builders.PathSelectors;
|
|
|
-import springfox.documentation.oas.annotations.EnableOpenApi;
|
|
|
-import springfox.documentation.service.*;
|
|
|
-import springfox.documentation.spi.DocumentationType;
|
|
|
-import springfox.documentation.spi.service.contexts.SecurityContext;
|
|
|
-import springfox.documentation.spring.web.plugins.Docket;
|
|
|
-
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Collections;
|
|
|
-import java.util.List;
|
|
|
-
|
|
|
-@Configuration
|
|
|
-@EnableOpenApi
|
|
|
-public class SwaggerConfig {
|
|
|
-
|
|
|
- @Bean
|
|
|
- public Docket api() {
|
|
|
- return new Docket(DocumentationType.OAS_30)
|
|
|
- .select()
|
|
|
- .paths(PathSelectors.any())
|
|
|
- .build()
|
|
|
- .securitySchemes(securitySchemes())
|
|
|
- .securityContexts(Collections.singletonList(securityContext()))
|
|
|
- .apiInfo(apiInfo());
|
|
|
- }
|
|
|
-
|
|
|
- private ApiInfo apiInfo() {
|
|
|
- return new ApiInfoBuilder()
|
|
|
- .title("GeneralFrame Documentation")
|
|
|
- .description("API documentation for GeneralFrame")
|
|
|
- .version("1.0.0")
|
|
|
- .build();
|
|
|
- }
|
|
|
-
|
|
|
- private List<SecurityScheme> securitySchemes() {
|
|
|
- List<SecurityScheme> apiKeyList= new ArrayList<>();
|
|
|
- //注意,这里应对应登录token鉴权对应的k-v
|
|
|
- apiKeyList.add(new ApiKey("token", "token", "header"));
|
|
|
- return apiKeyList;
|
|
|
- }
|
|
|
- /**
|
|
|
- * 这里设置 swagger2 认证的安全上下文
|
|
|
- */
|
|
|
- private SecurityContext securityContext() {
|
|
|
- return SecurityContext.builder()
|
|
|
- .securityReferences(Collections.singletonList(new SecurityReference("token", scopes())))
|
|
|
- .build();
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 这里是写允许认证的scope
|
|
|
- */
|
|
|
- private AuthorizationScope[] scopes() {
|
|
|
- return new AuthorizationScope[]{
|
|
|
- new AuthorizationScope("web", "All scope is trusted!")
|
|
|
- };
|
|
|
- }
|
|
|
-}
|