Forum Discussion

krenaut's avatar
krenaut
Occasional Contributor
6 years ago

Can't execute API with swagger ui behind NGINX Plus kubernetes ingress

I am unsuccessfully trying to make Swagger UI work inside my kubernetes cluster.   I am running NGINX Plus as my kubernetes ingress controller.   The ingress is re-writing the URL path.   ...
  • krenaut's avatar
    krenaut
    6 years ago

    I was able to get this working using a combination of the stand alone UI and the following code snippet in my SwaggerConfig.

     

            // if running in kubernetes change the pathMapping and force https

            // the KUBERNETES_SERVICE_HOST environment variable is always set by kubernetes.

            // So I am using it to detect that we are running on kubernetes

            // I then set the pathMapping to include the portion of the path that

            // kubernetes prepends (in this case /dev/hell-world/hello )

            // then I also force the protocol to HTTPS

            if (System.getenv("KUBERNETES_SERVICE_HOST") != null) {

                log.debug("Kubernetes detected! Setting pathMapping to: " + kubePath);

                docket.pathMapping(kubePath);

                docket.protocols(newHashSet("https"));

            }