title: How to trim Swagger docs based on current User Role in Java Spring?
body: <p>I'm developing application using Spring Boot, and I'm using Swagger to auto-generate API docs and also I use <code>swagger-ui.html</code> to interact with those APIs.</p>
  
  <p>I have Spring Security enabled too, and I have Users with different roles. Different REST APIs are available to different roles. </p>
  
  <p>Question: how do I configure Swagger to respect Spring's <code>@Secured</code> annotation and trim operations displayed by <code>swagger-ui.html</code> so that only operations available to current user are available?</p>
  
  <p>I.e. imagine following controller</p>
  
  <pre><code>@RestController
  @Secured(ROLE_USER)
  public void SomeRestController {
    @GetMapping
    @Secured(ROLE_USER_TOP_MANAGER)
    public String getInfoForTopManager() { /*...*/ }
  
    @GetMapping
    @Secured(ROLE_USER_MIDDLE_MANAGER)
    public String getInfoForMiddleManager() { /*...*/ }
  
    @GetMapping
    public String getInfoForAnyUser() { /*...*/ }
  }
  </code></pre>
  
  <p>Swagger will show both operations <code>getInfoForTopManager</code> and <code>getInfoForMiddleManager</code> regardless of current user role. In case currently authenticated user role is <code>ROLE_USER_MIDDLE_MANAGER</code>, I want only <code>getInfoForMiddleManager</code> and <code>getInfoForAnyUser</code> operations to be available in the Swagger.</p>