swagger2 - swagger-bootstrap-ui

swagger-bootstrap-ui https://doc.xiaominfo.com/guide/

一、引入swagger

二、引入swagger-bootstrap-ui 包

        
            com.github.xiaoymin
            swagger-bootstrap-ui
            1.9.6
        

三、启用
@Configuration
@EnableSwagger2
@EnableSwaggerBootstrapUI

@Configuration
@EnableSwagger2
@EnableSwaggerBootstrapUI
public class Swagger2Config {

    @Bean
    public Docket createRestApi() {
        Docket docket = new Docket(DocumentationType.SWAGGER_2)
//                .enable(false) // 是否启用swagger
                .apiInfo(apiInfo())
                .securitySchemes(createSecuritySchemeList())
//                .pathMapping("/")
                .select()
                // 指定当前包路径,这里就添加了两个包,注意方法变成了basePackage,中间加上成员变量splitor
                // .apis(basePackage("com.XX.api.controller.broad;com.XX.api.controller.village"))
                .apis(RequestHandlerSelectors.basePackage("com.example.lwp.validatordemo.controller"))
                .paths(PathSelectors.any())
                .build();
        return docket;
    }
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("SpringBoot整合Swagger")
                .description("SpringBoot整合Swagger,详细信息......")
                .version("9.0")
                .contact(new Contact("张三", "blog.csdn.net", "[email protected]"))
                .contact(new Contact("李四", "blog.csdn.net", "[email protected]"))
                .termsOfServiceUrl("http://localhost111:8080/")
//                        .license("The Apache License")
//                        .licenseUrl("http://www.baidu.com")
                .build();
    }

    private List createSecuritySchemeList(){
        List list = new ArrayList<>();
        list.add(new ApiKey("access_token", "access_token鉴权值", "header"));
//        list.add(new ApiKey("access_token1", "access_token1鉴权值", "query"));
        return list;
    }
}

你可能感兴趣的:(swagger2)