swagger-ui icon indicating copy to clipboard operation
swagger-ui copied to clipboard

Swagger UI is changing the protocol in the request from https to http

Open bretzmo opened this issue 11 years ago • 26 comments

The request url that I enter contains https but when I click the Try It Out button, the request url that Swagger UI generates contains http. This is causing no data to be received. I can mimic this behavior in a browser and when using https I receive a valid response, but when I use http in the direct browser request I receive No Data Received. I need to figure out why Swagger UI is changing the protocol.

screen shot 2015-03-06 at 8 36 14 am

bretzmo avatar Mar 06 '15 16:03 bretzmo

What's the basePath in your spec?

webron avatar Mar 06 '15 16:03 webron

Here is the Swagger config in our code.

screen shot 2015-03-06 at 8 56 32 am

bretzmo avatar Mar 06 '15 16:03 bretzmo

Okay, so you use Swagger 2.0. Do you have a schemes property in your spec? If so, what's in there?

webron avatar Mar 06 '15 16:03 webron

No I don't have a schemes property.

bretzmo avatar Mar 06 '15 17:03 bretzmo

Okay, there may be a bug related to that then as it should use https if the spec is hosted on https. Can you try adding "schemes": ["https"]" to your root document and see if that resolves it for now?

webron avatar Mar 06 '15 17:03 webron

I'm not sure where I'm supposed to add that.

bretzmo avatar Mar 06 '15 17:03 bretzmo

Take a look here - https://github.com/swagger-api/swagger-spec/blob/master/examples/v2.0/json/petstore-minimal.json#L17-L19 - though of course use https instead of http. I'm not sure how to do that with the library you're using (not sure which library it is actually).

webron avatar Mar 06 '15 18:03 webron

I forgot to mention that we are using go-restful/swagger.

bretzmo avatar Mar 06 '15 19:03 bretzmo

I see, in that case, you're using Swagger 1.2.

In the UI, you have a text box with a URL just before the Explore button. Can you open that URL directly in your browser and share the output of it? If you'd rather not share it in public, you can email me directly (email in profile).

webron avatar Mar 06 '15 19:03 webron

screen shot 2015-03-06 at 11 49 25 am

bretzmo avatar Mar 06 '15 19:03 bretzmo

Sorry, that was the url without the swagger.json in it....here it the right screen shot. screen shot 2015-03-06 at 11 51 16 am

bretzmo avatar Mar 06 '15 19:03 bretzmo

Okay, so the problem is that your basePath uses http and not https. I'm not familiar with go nor go-resftul so I'm not sure how to fix that, though I assume setting https://github.com/emicklei/go-restful/blob/89af920d613f1e3f771f6460b2629632e7a36ae9/swagger/swagger.go#L119 would solve that issue.

webron avatar Mar 06 '15 19:03 webron

So our base path is relative. Every time we deploy code the server is torn down a rebuilt, thus a new base path with every deploy.

bretzmo avatar Mar 06 '15 20:03 bretzmo

That's fine, but you still need to build it with https and not http if you want the operations to run against https.

webron avatar Mar 06 '15 20:03 webron

I'm not sure what you are saying.

bretzmo avatar Mar 06 '15 20:03 bretzmo

If you look at the JSON you shared, and look at the basePath property, which is the basis for API calls. As long as it uses http and not https, the requests will end up using http. You need to find a way to make sure it ends up being https.

webron avatar Mar 06 '15 20:03 webron

webron, could you all explore allowing a schemeless protocol to be entered, e.g., "//" instead of "http://"? This would allow people who do not want to specify/force one protocol over another to access our Swagger docs and try them out. This would not prevent people from being specific about the protocol they wish to use at all, if so desired.

For example we have both http and https versions of our web assets using the same doc root, including web services using a schemeless URL approach. See section 4.2 of RFC 3986 that provides for fully qualified URLs that omit protocol (the HTTP or HTTPS) altogether. When a URL’s protocol is omitted, the browser uses the underlying document’s protocol instead.

This would allow both (http and https) versions of my Swagger docs to have a working "Try It out!" feature.

jim-riley-earthscope avatar Apr 15 '15 01:04 jim-riley-earthscope

@Spin45 - no need to explore. Swagger 2.0 supports it already.

webron avatar Apr 15 '15 08:04 webron

@bretzmo - any update on this?

webron avatar May 04 '15 14:05 webron

please reopen if still an issue.

fehguy avatar May 08 '15 21:05 fehguy