<p>We have a Java Spring Boot project with Swagger and docker. We deploy it on kubernetes behind an ingress controller.</p>

<p>It works properly in localhost (using postman and swagger-ui try button).
Problem comes when we deploy it.</p>

<p>Rest Controller:</p>

<pre><code>@ApiOperation(value = "Operation", 
          notes = "it does something&lt;br /&gt;")
@RequestMapping(value="/operation", method=RequestMethod.POST)
@ApiResponses({
    @ApiResponse(code = 200, message = "OK")
})
@ResponseBody public ResponseEntity&lt;String&gt; operation(@RequestBody BodyThing thing) {

    return new ResponseEntity&lt;&gt;("OK", HttpStatus.OK);
} //operation
</code></pre>

<p>Now the ingress:</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Ingress

metadata:
  name: myapp-ingress
  namespace: __NAMESPACE__
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/rewrite-target: /

spec:
  tls:
  - hosts:
    - test.host.com
    secretName: key-pair
  rules:
  - host: test.host.com


http:
  paths:
  - path: /myapp
    backend:
      serviceName: myapp-service
      servicePort: 8080
</code></pre>

<p>Then, with the app online deployed on K8S, usign an app like postman we must call:
<a href="https://test.host.com/myapp/operation" rel="noreferrer">https://test.host.com/myapp/operation</a> in order to call the API. It works OK.</p>

<p>The problem comes if we enter in Swagger UI portal: <a href="https://test.host.com/myapp/swagger-ui.html" rel="noreferrer">https://test.host.com/myapp/swagger-ui.html</a></p>

<p>If we try the API call inside the swagger UI, it tries to call to <a href="https://test.host.com/operation" rel="noreferrer">https://test.host.com/operation</a> and it fails with 404 code.</p>

<p>Swagger-UI makes the Endpoint URL with: host + basepath + operation_path and that is: test.host.com + / + operation</p>

<p>It doesnt aggregate ingress path.</p>

<p>How can we deal with it?
Of course is something that only happends if we deploy it with the ingress controller because, we add the /myapp path.</p>

<p>Thanks!</p>

<p>The problem is how to get swagger's base path to match to the one that is being used behind the proxy. There is more than one solution as per <a href="https://github.com/springfox/springfox/issues/1443" rel="nofollow noreferrer">https://github.com/springfox/springfox/issues/1443</a> </p>

<p>Since you have a specific host, I'd suggest going with the one to change the base path that swagger knows about based upon the host the request goes to. This way you can set it differently for localhost vs in the remote host. You'd need to set a RelativePathProvider for your host in your custom docket section of your Swagger @Configuration class like in <a href="https://github.com/springfox/springfox/issues/1443#issuecomment-274540681" rel="nofollow noreferrer">https://github.com/springfox/springfox/issues/1443#issuecomment-274540681</a></p>
