15

When I publish, I will use HTTPS requests instead of HTTP, but swagger original URL is still HTTP, I have no idea how to set it up, and there is no documentation for servers in the original springdoc-openapi-ui configuration

https://springdoc.org/index.html#properties enter image description here

Tablo_Jhin
  • 301
  • 1
  • 3
  • 10

5 Answers5

18

you can try this :

...
import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.servers.Server;
...
@OpenAPIDefinition(servers = {@Server(url = "/", description = "Default Server URL")})

@SpringBootApplication
public class MyApplication {
...
}

more info here https://github.com/springdoc/springdoc-openapi/issues/726

David KELLER
  • 464
  • 4
  • 8
  • 1
    The only approach that worked for me. Just setting "url = /" makes REST call relative to where you are (no need to rewrite host or anything). – Fernando Miguélez Apr 27 '22 at 21:06
  • spring: server.forward-headers-strategy=framework nginx: proxy_set_header X-Forwarded-Proto $scheme; – Tablo_Jhin Jun 23 '22 at 03:44
  • 1
    Another Note, if you have a default context path you would add that to the url. For example, `@OpenAPIDefinition(servers = {@Server(url = "/v1", description = "Default Server URL")})` – Ryan Burch Feb 23 '23 at 19:24
7

I solved the problem by modifying the Nginx configuration and the Spring-boot configuration(application.properties)

nginx-conf:

proxy_set_header        X-Forwarded-Proto $scheme;

spring-boot (application.properties):

server.forward-headers-strategy=framework

https://github.com/springdoc/springdoc-openapi/issues/171

remykarem
  • 2,251
  • 22
  • 28
Tablo_Jhin
  • 301
  • 1
  • 3
  • 10
0

For who is using CXF. I submitted an issue here:

https://issues.apache.org/jira/browse/CXF-8685

Thang Le
  • 1,419
  • 1
  • 17
  • 25
0

For Spring Boot application in Azure Services only needed this line in the application.properties as in the accepted answer:

server.forward-headers-strategy = framework
Tyler2P
  • 2,324
  • 26
  • 22
  • 31
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/33423047) – user12256545 Dec 21 '22 at 19:51
0

A slightly improvement from the existing answers. In my situation, I have defined a context-path that is also used by my traefik reverse proxy. If I apply the above answers at explained, a https://my.domain.com/my-context-path/api/action is converted to https://my.domain.com/api/action that is wrong. Then on the @OpenAPIDefinition set your context path rather than /.

The complete configuration is:

On the application.properties:

server.servlet.context-path=/my-context-path
server.forward-headers-strategy=framework

And in the @SpringBootApplication class:

@OpenAPIDefinition(servers = {@Server(url = "${server.servlet.context-path}", description = "Default Server URL")})

Also I need to set the server.forward-headers-strategy=framework as shown to make it work.

King Midas
  • 1,442
  • 4
  • 29
  • 50