flexguse
flexguse

Reputation: 479

Micronaut with remote Swagger-UI / CORS error

At the moment I'm struggling with Micronaut 1.2.5 and a remote Swagger-UI. My idea is to collect several APIs in one Swagger-UI instance.

In my Micronaut project I'm able to create a valid Swagger YAML file and with this solution Swagger for Micronaut with maven (serve static Swagger-UI page in my project) everything works fine.

To let Micronaut work with a remote Swagger-UI which resides in another domain than my service I did the following settings in application.yml:

micronaut:
  server:
    cors:
      endabled: true
      configurations:
        web:
          exposedHeaders:
            - Access-Control-Allow-Origin
            - Access-Control-Allow-Headers
            - Access-Control-Allow-Methods

Unfortunately, this does not help, Swagger-UI fails with

Fetch error
NetworkError when attempting to fetch resource. https://....yml

Fetch error
Possible cross-origin (CORS) issue? The URL origin (https://aa) does not match the page (https://bb). Check the server returns the correct 'Access-Control-Allow-*' headers.

In the Micronaut response, no Access-Control-Allow headers are contained. While debugging CorsFilter seems not to be called, the breakpoint in the doFilter method has no effect.

Any ideas?

Thank you in advance, Christoph

Upvotes: 1

Views: 1503

Answers (1)

flexguse
flexguse

Reputation: 479

After some investigation I was able to solve the problems.

My application.yaml looks now like this:

micronaut:
  server:
    cors:
      enabled: true
      configurations:
        web:
          exposedHeaders:
            - Content-Type
            - Authorization
            - '*'

The issues regarding Chrome and Edge were caused by self signed SSL certificates, which were not accepted.

To solve that it helps to open the swagger.yml file in your browser and add the self signed SSL certificate to your browser. After that you are able to use your Micronaut API in Swagger.

Upvotes: 3

Related Questions