0
点赞
收藏
分享

微信扫一扫

Swagger:分组(4)

芭芭蘑菇 2022-02-27 阅读 78

Swagger分组

默认没配置分组,swagger是default分组
如图将人作为分组,选择分组,表示各自下面所属的接口
在这里插入图片描述

代码实现

package com.it2.swagger.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

@Configuration
@EnableSwagger2
public class SwaggerConfig {

    @Bean
    public Docket docket(Environment environment) {
        Contact contact=new Contact("熊大","http://www.feichai.cc/","lcz0710@163.com");
        ApiInfo apiInfo= new ApiInfo("项目的API",
                "API的描述信息",
                "1.0",
                "http://www.feichai.cc/", contact, "Apache 2.0", "http://www.apache.org/licenses/LICENSE-2.0", new ArrayList());

        /**
         * 这里取的是spring.profiles.active的值,通常dev/test表示测试,prod或者pro表示正式
         */
        Profiles profiles= Profiles.of("dev","test");
        boolean flag=environment.acceptsProfiles(profiles);

        return new Docket(DocumentationType.SWAGGER_2).enable(flag)
                .apiInfo(apiInfo).groupName("王某")
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.it2.swagger.thirdcontroller"))
                //.paths(PathSelectors.any())  //过滤掉什么
                .build();
    }

    @Bean
    public Docket docket2(Environment environment) {
        Contact contact=new Contact("熊大","http://www.feichai.cc/","lcz0710@163.com");
        ApiInfo apiInfo= new ApiInfo("项目的API",
                "API的描述信息",
                "1.0",
                "http://www.feichai.cc/", contact, "Apache 2.0", "http://www.apache.org/licenses/LICENSE-2.0", new ArrayList());

        /**
         * 这里取的是spring.profiles.active的值,通常dev/test表示测试,prod或者pro表示正式
         */
        Profiles profiles= Profiles.of("dev","test");
        boolean flag=environment.acceptsProfiles(profiles);

        return new Docket(DocumentationType.SWAGGER_2).enable(flag)
                .apiInfo(apiInfo).groupName("李某")
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.it2.swagger.controller"))
                //.paths(PathSelectors.any())  //过滤掉什么
                .build();
    }


}


举报

相关推荐

0 条评论