SwaggerConfig配置类

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.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class SwaggerConfig {

    @Bean
    public Docket createApi(){

        //        全局添加接口被调用是的需要只能加参数
//        ParameterBuilder parameterBuilder = new ParameterBuilder();
//        List<Parameter> parameters = new ArrayList<>();
//        parameterBuilder.name("token").description("令牌").modelRef(new ModelRef("string")).parameterType("header").required(false).build();
//        ParameterBuilder parameterBuilder1 = new ParameterBuilder();
//        parameterBuilder1.name("test").description("test").modelRef(new ModelRef("string")).parameterType("header").required(false).build();
//        parameters.add(parameterBuilder.build());
//        parameters.add(parameterBuilder1.build());

        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.any()).build();
//                .globalOperationParameters(parameters);       //        全局添加接口被调用是的需要只能加参数
    }

    //基本信息的配置,信息会在api文档上显示
    private ApiInfo apiInfo(){
        return new ApiInfoBuilder()
                .title("****的接口文档")
                .description("****相关接口的文档")
                .termsOfServiceUrl("http://localhost:8080/*")
                .version("1.0")
                .build();
    }
}
  • 4
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
SwaggerConfig是一个配置,用于集成和配置Swagger框架。Swagger是一个用于构建、文档化和测试API的开源工具集,它可以帮助开发人员快速生成API文档,并提供可交互的界面供用户测试API。 在SwaggerConfig中,通常会进行一些配置,例如指定要扫描的API包路径、设置API文档的标题、描述等信息,以及配置Swagger UI的访问路径等。通过配置SwaggerConfig,开发人员可以自定义Swagger的行为,以满足项目的需求。 以下是一个示例的SwaggerConfig: ```java @Configuration @EnableSwagger2 public class SwaggerConfig { @Bean public Docket api() { return new Docket(DocumentationType.SWAGGER_2) .select() .apis(RequestHandlerSelectors.basePackage("com.example.api")) .paths(PathSelectors.any()) .build() .apiInfo(apiInfo()); } private ApiInfo apiInfo() { return new ApiInfoBuilder() .title("Example API") .description("API documentation for Example project") .version("1.0") .build(); } } ``` 在上述示例中,`@EnableSwagger2`注解用于启用Swagger支持,`@Configuration`注解表示这是一个配置。`api()`方法用于创建一个Docket实例,其中指定了要扫描的API包路径和API文档信息。`apiInfo()`方法用于设置API文档的标题、描述和版本信息。 通过以上配置,访问`http://localhost:8080/swagger-ui.html`即可查看生成的API文档和Swagger UI界面。开发人员可以在Swagger UI界面上测试API,并查看API的详细信息和参数说明。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值