0

Technical Stack, Springboot 2.6.7, java 8 or 11 Springopenapi 1.6.9

Swagger properties

springdoc:
  api-docs:
    enabled: true
    path: /api-docs
  swagger-ui:
    enabled: true
    display-Request-duration: true
    path: /swagger-ui-myname.html
    use-root-path: true
    filter: true
    supportedSubmitMethods: nomethod**



  @Bean
  public OpenAPI myOpenApi()
  {
    return new OpenAPI().info( new Info().title( "XXXXX" )
                                         .description( "XXXXX" ) );
  }

  @Bean
  public GroupedOpenApi myExternalOpenApi()
  {
    String[] paths = { "XXXX" };
    return GroupedOpenApi.builder()
                         .group( "XXXXXX" )
                         .displayName( "XXXXXXX" )
                         .pathsToMatch( paths )
                         .build();
  }

is my swagger configuration.

this works perfectly in my local machine, I can access http://localhost:8091/api-docs or http://localhost:8091/swagger-ui-myname.html(this redirects to http://localhost:8091/swagger-ui/index.html), and I can see my group api completely all is well till here.

But when I deploy this on a pod in kubernetes as a service, and try to see swagger ui on https://server:port/service-name/swagger-ui-myname.html or http://server:port/service-name/swagger-ui/index.html, these two requests landed in 404 not found.

Note: I am able to access http://server:port/service-name/api-docs, I can see the complete json of my group api documentation.

Can you please give me clue what went wrong in Kubernetes deployment. I have tried all the options from github ofspring openapi bug logs/comments or from stackoverflow.

One more adding to this, on a springboot app start , can we log the swagger ui html absolute pathe, where it reside to access or, add the url in /api-docs or related url.

1 Answers1

0

I think the issue you are facing is described and answered here: https://github.com/springdoc/springdoc-openapi/issues/153

Solution should be setting the forward-headers-strategy in your application.yml to framework:

server:
  forward-headers-strategy: framework

And also in your kubernetes ingress configurations be sure the X-Forwarded-Prefix header is set to /service-name

For example, if you are using an nginx ingress it should contain:

metadata:
  annotations:
    nginx.ingress.kubernetes.io/x-forwarded-prefix: "/service-name"
Rowan
  • 86
  • 4