spring boot 配置swagger UI
Posted pkyou
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了spring boot 配置swagger UI相关的知识,希望对你有一定的参考价值。
有这样的需求
1.在每个接口上都增加一个字段;
2.接口文档只展示满足一定条件URL的接口
配置文件
详细看代码
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import springfox.documentation.builders.ApiInfoBuilder; import springfox.documentation.builders.ParameterBuilder; import springfox.documentation.service.ApiInfo; import springfox.documentation.spring.web.plugins.Docket; import springfox.documentation.swagger2.annotations.EnableSwagger2; import java.util.ArrayList; import java.util.List; import springfox.documentation.builders.PathSelectors; import springfox.documentation.builders.RequestHandlerSelectors; import springfox.documentation.schema.ModelRef; import springfox.documentation.spi.DocumentationType; import springfox.documentation.service.Parameter; @Configuration @EnableSwagger2 public class SwaggerConfig { ApiInfo apiInfo(){ return new ApiInfoBuilder().title("显示的标题").description("标题描述").build(); } @Bean public Docket api(){ ParameterBuilder tokenPar = new ParameterBuilder(); List<Parameter> pars = new ArrayList<Parameter>(); tokenPar.name("Authorization").description("token").modelRef(new ModelRef("string")).defaultValue("").parameterType("header").required(false).build(); pars.add(tokenPar.build()); return new Docket(DocumentationType.SWAGGER_2) .select() .apis(RequestHandlerSelectors.any()) .paths(PathSelectors.regex("/go(d|to)/.*")) .build() .globalOperationParameters(pars) .apiInfo(apiInfo()); } }
以上是关于spring boot 配置swagger UI的主要内容,如果未能解决你的问题,请参考以下文章
spring boot整合swagger时,打开swagger-ui中文出现乱码
Spring Boot 集成 Swagger,再也不写接口文档了!
在 swagger UI 中生成示例示例(在 Spring boot 项目中)