title: Swagger UI - getting the CORS issue when bearer authorization token is wrong (server responds with 403), works fine in case of correct token
body: <p>I am documenting APIs using swagger openApi 3.0.0. And I am using bearer authentication provided by the swagger itself. Now when the authorization token is correct, server sends the response and it is getting displayed over the swagger UI, but when token is incorrect, server sends the 403 forbidden error and swagger just displays "TypeError: Failed to fetch". I have attached the screenshots of browser's network tab stuff.</p>
  
  <p><a href="https://i.stack.imgur.com/NUfU9.png" rel="nofollow noreferrer">OPTIONS with sending 200 response</a></p>
  
  <p><a href="https://i.stack.imgur.com/On0og.png" rel="nofollow noreferrer">getting the Access-control-allow-origin: * from the OPTIONS response</a></p>
  
  <p><a href="https://i.stack.imgur.com/IG6L2.png" rel="nofollow noreferrer">getting the server response 403 as the authorization token is wrong</a></p>
  
  <p><a href="https://i.stack.imgur.com/rzPGb.png" rel="nofollow noreferrer">but not getting Access control allow origin response in the actual response.. so getting the CORS issue</a></p>
  
  <p>This is my swaggerConfig.java code</p>
  
  <pre><code>@Bean
  public Docket swagger() {
      return new Docket(DocumentationType.SWAGGER_12)
      .select()
     .apis(RequestHandlerSelectors.any())
     .paths(PathSelectors.any())
     .build();
  }
  /**
   * @param defaultResourcesProvider
   * @return swaggerResource for documenting the APIs
   */
  @Primary
  @Bean
  public SwaggerResourcesProvider swaggerResourcesProvider(
      InMemorySwaggerResourcesProvider defaultResourcesProvider) {
      return () -&gt; {
          List&lt;SwaggerResource&gt; resources = new ArrayList&lt;&gt;();
          Arrays.asList(&lt;list of APIs&gt;)
          .forEach(resourceName -&gt; resources.add(loadResource(resourceName)));
          return resources;
     };
  }
  
  private SwaggerResource loadResource(String resource) {
      String file_name = "swagger.yaml";
      SwaggerResource swaggerResource = new SwaggerResource();
      swaggerResource.setName(resource);
      swaggerResource.setLocation("/swagger-apis/" + resource + "/" + file_name);
      return swaggerResource;
  }
  </code></pre>
  
  <p>and in the swagger.yaml file for one of the APIs, I have used securityschema as follows:</p>
  
  <p>security:
     - bearerAuth: []</p>
  
  <p>securitySchemes:
      bearerAuth:
        type: http
        scheme: bearer</p>