一、只有openapi3时
依赖
<dependency> <groupId>org.springdoc</groupId> <artifactId>springdoc-openapi-ui</artifactId> </dependency> <dependency> <groupId>org.springdoc</groupId> <artifactId>springdoc-openapi-webflux-ui</artifactId> </dependency> <dependency> <groupId>org.springdoc</groupId> <artifactId>springdoc-openapi-webmvc-core</artifactId> </dependency>
yml文件配置
springdoc: api-docs: path: /v3/api-docs enabled: true swagger-ui: path: /swagger-ui/index.html persistAuthorization: true group-configs: - group: 1.文件上传 packages-to-scan: com.tly.common.minio
二、集成security时
1.SecurityConfig继承了WebSecurityConfigurerAdapter时
重写configure方法
@Override
public void configure(WebSecurity web) {
//配置跳过security验证拦截的路径,配置的放行路径
web.ignoring().antMatchers(
"/swagger-ui/index.html",
"/swagger-ui.html",
"/swagger-ui/**",
"/v3/api-docs/**",
"/v3/api-docs"
);
}
2.SecurityConfig未继承了WebSecurityConfigurerAdapter时
将跳过安全配置的方法作为bean注入
// 放行OpenAPI 3的路径
@Bean
public WebSecurityCustomizer webSecurityCustomizer() {
return (web) -> web.ignoring().antMatchers(
"/swagger-ui/index.html",
"/swagger-ui.html",
"/swagger-ui/**",
"/v3/api-docs/**",
"/v3/api-docs"
);
}