-
Notifications
You must be signed in to change notification settings - Fork 9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SwaggerUI options url should allow relative path #263
Comments
Assuming this is in the develop-2.0 branch? |
Indeed it is, description has been updated. |
I agree, this needs to be put in. |
This fix stops the host error, but still does not allow for relative urls. If my index.html was at http://localhost:8080/path/to/index.html and it referenced api-docs.json, then the code (as is now) turns this into http://localhost:8080/api-docs.json (rather than http://localhost:8080/path/to/api-docs.json as it should). The current behavior is correct only if the relative url starts with "/" (otherwise, it should take into account the relative path as well). |
is it usually the case that the api listing itself would live in the same structure as the swagger-ui? It's quite easy to change this, just a matter of what would be most intuitive. I'm open to ideas. |
as is, if you put in |
We have our UI config (api-docs and resources) living under host:port/service_version/api-docs as hand written json files and our API under host:port/service_version/api as a resteasy application. So we stick the index file in .../api-docs/index.html and it references relative file api-docs.json. All of our apps use the same war overlay (including the swagger js/css files and index.html) so we don't want to stick the full path name in there if we don't have to. |
My personal preference would be doing as you are when the url starts with '/' and otherwise use: base.substring(0, base.lastIndexOf('/')) + "/" + url When I reference the directory .../api-docs (using the default index page), my browser (firefox/iceweasel) sticks a trailing '/' on the url so the lastIndexOf('/') still works in that edge case as well. |
Here is what I have that seems to work: SwaggerUi.prototype.buildUrl = function(base, url) {
var parts, pound, queryParam, firstUnusableChar;
console.log("base is " + base);
if (url.indexOf("/") === 0) {
parts = base.split("/");
base = parts[0] + "//" + parts[2];
return base + url;
} else {
firstUnusableChar = base.length;
pound = base.indexOf('#');
if( pound > -1 )
firstUnusableChar = Math.min(pound, firstUnusableChar);
queryParam = base.indexOf('?');
if( queryParam > -1 )
firstUnusableChar = Math.min(queryParam, firstUnusableChar);
base = base.substring(0, firstUnusableChar);
base = base.substring(0, base.lastIndexOf('/'));
return base + "/" + url;
}
}; |
in 2.0.19 this should be supported. |
If you specify a relative path ("./api-docs.json" or even just "api-docs.json" for instance) the shred library errors out because of an invalid host name (using either "." or "api-docs.json" as host).
regarding branch: develop-2.0
The text was updated successfully, but these errors were encountered: