增加鉴权

master
zhang chengzhi 2024-08-08 09:44:58 +08:00
parent 8ea2902ec5
commit cd89e21aed
1 changed files with 19 additions and 19 deletions

View File

@ -39,25 +39,25 @@ public class SpringDocConfig {
// @Bean
// public GlobalOpenApiCustomizer globalOpenApiCustomizer() {
// return openApi -> {
// // 全局添加鉴权参数
// if (openApi.getPaths() != null) {
// openApi.getPaths().forEach((s, pathItem) -> {
// // 登录接口/验证码不需要添加鉴权参数
// if (s.equals("/login") || s.equals("/code") ||s.equals("/register")) {
// return;
// }
// // 接口添加鉴权参数
// pathItem.readOperations()
// .forEach(operation ->
// operation.addSecurityItem(new SecurityRequirement().addList(HttpHeaders.AUTHORIZATION))
// );
// });
// }
// };
// }
@Bean
public GlobalOpenApiCustomizer globalOpenApiCustomizer() {
return openApi -> {
// 全局添加鉴权参数
if (openApi.getPaths() != null) {
openApi.getPaths().forEach((s, pathItem) -> {
// 登录接口/验证码不需要添加鉴权参数
if (s.equals("/login") || s.equals("/code") ||s.equals("/register")) {
return;
}
// 接口添加鉴权参数
pathItem.readOperations()
.forEach(operation ->
operation.addSecurityItem(new SecurityRequirement().addList(HttpHeaders.AUTHORIZATION))
);
});
}
};
}
// @Bean