Protocol is not selectable
When schemes is set to ["http","https"], Swagger UI does not show UI for a protocol selector and instead uses http.
Repro steps
- Open Swagger-ui with a spec containing multiple schemes.
- Expand the operations
- Click "Try it out"
- Observe that the scheme is always http.
Here's a spec for reproducing the issue:
{
"swagger": "2.0",
"info": {
"version": "0.0.0",
"title": "Simple API"
},
"schemes": [
"http",
"https"
],
"paths": {
"/": {
"get": {
"responses": {
"200": {
"description": "OK"
}
}
}
}
}
}
I have also created a gist of the above spec.
Side note: Swagger editor handles it correctly
Any idea when is this planned?
@FoxxMD @webron @rgogulakrishnan was this issue resolved in v2.1.3? I want to know if I should go ahead and download it.... my site is hosted on both https and http, and my schemes are [http,https] but swagger-ui uses http even when the host scheme is https, ofcourse the browser prevents the call to be made, so no output....
It's not intended to be selectable by the end user. It will prefer the https protocol, and select it automatically if your site is being hosted by https.
Given the milestone has been modified continuously above, I'm struggling to see when this issue was actually fixed, if it has been at all? I am using Swagger 2.0 and want to know what minimum version I need to go to to get this fix?
@GavBurke the comment is pretty clear. It was not implemented and closed as won't fix.
We do have a new version coming soon where this will change though.
@webron Not sure what comment you're referring to because on this issue, #1247, you haven't even replied....
Anyhoos, I got around the issue by setting the schemes to an empty array so the location.scheme is used instead of this.schemes[0] and I can now have HTTP on one site and HTTPS on the other without your tool breaking.
I was referring to @fehguy's last comment before he actually closed the ticket.
Ah okay, so that behaviour was introduced in v2.1.3?
I am trying to use Swagger UI for the first time today, and I can't seem to dissuade it from using https on a development system, even though none of Swagger UI, the JSON definition, or the Swagger server itself are being served over https.
As suggested in the documentation, I just opened dist/index.html in a browser. I served up my local swagger JSON file using http-server --cors so that it provides http://localhost:8080/swagger.json which I entered in the box and clicked 'explore'. So far so good. However all the generated server calls are to https://localhost:10010/, so they don't work, because swagger project start runs the server using http, not https.
I have tried removing https from scheme. I have tried removing scheme entirely from the definition. It still uses https for requests.. Did I miss anything obvious, or do I need to customise the Swagger UI installation to make this work? It seems like this would be a common enough use case that it should work out of the box.
Edited to add: I got it working in the end. It seems the fundamental problem is opening dist/index.html as a file, which is neither http nor https. Just by serving the whole dist folder (http-server --cors) and opening it in a browser, it does use http for the server calls. I can't help thinking this might be made easier. A selectable protocol would have solved the problem.
This work.
findReact() method
var findReact = function(dom) {
for (var key in dom) {
if (key.startsWith("__reactInternalInstance$")) {
var compInternals = dom[key]._currentElement;
var compWrapper = compInternals._owner;
var comp = compWrapper._instance;
return comp;
}
}
return null;
};
Set https scheme:
var ui = SwaggerUIBundle({
// ....
onComplete: function() {
var schemeSelect = document.querySelector('.scheme-container select');
FindReact(schemeSelect).setScheme('https');
}
});