I noticed that in some of my REST API endpoints, Swagger UI display unnecessary parameters like accountNonExpired, accountNonLocked and so on
I realized that it is caused by @AuthenticationPrincipal CurrentUser currentUser in those methods' body:
@PutMapping("/change-email")
public ResponseEntity<?> changeEmail(@AuthenticationPrincipal CurrentUser currentUser,
@RequestBody @Valid ChangeEmailRequest changeEmailRequest, BindingResult result){
if (result.hasErrors()) return generateResponseFromBindingResult(result);
try {
userService.changeEmail(currentUser.getUser(), changeEmailRequest);
return generateOkResponse("Changed email");
} catch (ValidationException e) {
return e.generateErrorResponse();
}
}
CurrentUser class:
import org.springframework.security.core.userdetails.User;
public class CurrentUser extends User {
private final pl.makary.entity.User user;
public CurrentUser(String username, String password,
Collection<? extends GrantedAuthority> authorities,
pl.makary.entity.User user) {
super(username, password, authorities);
this.user = user;
}
public com.project.entity.User getUser() {return user;}
}
I was able to deal with couple of those parameters by adding @ApiParam(hidden = true) above every field in user entity, but those form org.springframework.security.core.userdetails.User stayed. I can't add annotation there, so I'm looking for other way i can get rid of those params. I tried adding @ApiParam(hidden = true) before @AuthenticationPrincipal in method body, and everywhere else where i could, but it didnt work.