title: Modifying swagger annotations at runtime
body: <p>I have a Swagger API documentation. Some of the methods I want to hide dynamically, depending on user permissions for reading/ accessing the API.</p>
  <p>Since I couldn't come up with a Swagger functionality on this, I have implemented a ContainerRequestFilter on my service, which is executed when getting the openapi.json document for the Swagger UI. This filter is scanning all methods containing the <code>@Operation</code> annotation and changing the field <code>hidden</code> from true to false for users with the correct permission.</p>
  <pre><code>import io.swagger.v3.oas.annotations.Operation;
  
  @Provider
  @Priority(Priorities.USER)
  public class MyFilter implements ContainerRequestFilter{
  
      public void filter(ContainerRequestContext crc) throws IOException{
  
          Reflections reflections = new Reflections(new ConfigurationBuilder()
               .setUrls(ClasspathHelper.forPackage(&quot;my.package&quot;))
               .setScanners(new MethodAnnotationsScanner()));
          
          // get all Operation methods
          Set&lt;Method&gt; resources = reflections.getMethodsAnnotatedWith(Operation.class);
          
          for(Method method : resources) {
              method.setAccessible(true);
      
              Operation operation = method.getAnnotation(Operation.class);
              InvocationHandler h = Proxy.getInvocationHandler(operation);
                  
              Field hField = h.getClass().getDeclaredField(&quot;memberValues&quot;);
              hField.setAccessible(true);
              Map memberValues = (Map) hField.get(h);
                  
              for(Object key : memberValues.keySet()) {
                  System.out.println(&quot;memberValue: &quot;+key+&quot;, &quot;+memberValues.get(key));
              }
  
              memberValues.put(&quot;hidden&quot;, false);    
              System.out.println(&quot;operation is hidden?: &quot; +operation.hidden());
          }
      }
  }
  </code></pre>
  <p>The code seems to work insofar as the hidden field value is changed from true to false inside this filter class. However, the openapi.json document returned from the same service request does not reflect those changes.</p>
  <p>Why are the changes on the modified annotations not consistent within the executed request?</p>