Skip to content
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

Closed
rage-shadowman opened this issue Jul 17, 2013 · 10 comments
Closed

SwaggerUI options url should allow relative path #263

rage-shadowman opened this issue Jul 17, 2013 · 10 comments

Comments

@rage-shadowman
Copy link

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

@fehguy
Copy link
Contributor

fehguy commented Jul 17, 2013

Assuming this is in the develop-2.0 branch?

@rage-shadowman
Copy link
Author

Indeed it is, description has been updated.

@fehguy
Copy link
Contributor

fehguy commented Jul 17, 2013

I agree, this needs to be put in.

fehguy added a commit that referenced this issue Jul 17, 2013
@fehguy fehguy closed this as completed Jul 17, 2013
@rage-shadowman
Copy link
Author

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).

@fehguy
Copy link
Contributor

fehguy commented Jul 17, 2013

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.

@fehguy fehguy reopened this Jul 17, 2013
@fehguy
Copy link
Contributor

fehguy commented Jul 17, 2013

as is, if you put in /path/to/api-docs.json in the explorer, it should take you there with the host:port of where it's served from.

@rage-shadowman
Copy link
Author

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.

@rage-shadowman
Copy link
Author

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.

@rage-shadowman
Copy link
Author

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;
      }
    };

@fehguy
Copy link
Contributor

fehguy commented Aug 2, 2014

in 2.0.19 this should be supported.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants