Swagger openapi redirect http to https

Viewed 58

In my application we are using openapi to bootstrap swagger with default configurations.

Dependency we are using : org.springdoc:springdoc-openapi-ui:1.6.9

We are not using any json / yaml to specify open api specs.

The application is running on https, but swagger uses default protocol as http.

I've gone thru community answers like this which suggest to edit json specs to configure the protocol.

But was wondering if there is any other way (may be any annotation) with which I can achive the same?

Please suggest.

1 Answers

Define @OpenAPIDefinition in main SpringBootApplication using openapi @ServerVariable as below:

@OpenAPIDefinition(servers = {@Server(url = "https://{host}",
variables = @ServerVariable(name = "host",
defaultValue = "hostname_sit",
allowableValues = {"hostname_sit","hostname_uat"}),
description = "Host name by environment")})
    
Related