Springfox Swagger generating requests with port 80 for HTTPS URLS
Asked Answered
M

3

7

I am experiencing an issue using springfox-swagger2 v2.2.0 related to the request padding port 80 for a HTTP URL.

Is there anyway to disable the generation of the port or set the port to 443 programmatically based on a Spring Profile?

Generated CURL:

curl -X GET --header "Accept: application/json" "https://test.com:80/api/users/search"

Mil answered 14/10, 2015 at 5:46 Comment(5)
I'm also interested in a solution - same problem here.Snapdragon
Are u having the service sit behind load balancers that is causing this to happen by any chance?Alonzo
@DilipKrishnan That's exactly what I have. I have ELB with SSL point to a server.Yablon
@DilipKrishnan - The services are deployed out to a Pivotal Cloud Foundry instance.Mil
Upgrading to springfox 2.6.1 and spring 4.2+ will fix the issue.Alonzo
P
1

I had the same issue. It is because Swagger uses a class from Spring Framework which is adding the port 80 to the host property in the /v2/api-docs json response (Check Swagger2Controller.class). I had this issue with spring framework version 4.1.4.Release. Upgrading to latest version 4.3.2.Release fixed it.

Popp answered 31/8, 2016 at 17:46 Comment(0)
L
4

Hit the same issue, but rather than upgrade the spring framework libraries as per @Akshay answer (thanks for pointing out the Swagger2Controller.class), I added the following property to my application-dev.yml file (replace hostname with your host).

springfox.documentation.swagger.v2.host: hostName:443

Leninist answered 2/11, 2016 at 8:2 Comment(1)
Just recently used this approach. Thanks!Elevator
P
1

I had the same issue. It is because Swagger uses a class from Spring Framework which is adding the port 80 to the host property in the /v2/api-docs json response (Check Swagger2Controller.class). I had this issue with spring framework version 4.1.4.Release. Upgrading to latest version 4.3.2.Release fixed it.

Popp answered 31/8, 2016 at 17:46 Comment(0)
A
0

I had the same issue with spring boot 3.0 and openapi-starter-webmvc-ui 2.0 (My project does sit behind the load balancer)

none of the above answers worked so I tried this:

in my swagger config I added

@OpenAPIDefinition(
        servers = {
                @Server(url = "https://MyProject:443", description = "Default Server URL")
        }
)

after this swagger redirected me to 443 port instead of 80.

hope it helps

Auguste answered 24/3, 2023 at 10:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.