Swagger-ui: Port number gets lost leading to incorrect URLs for each api listing

Created on 1 Jun 2015  路  13Comments  路  Source: swagger-api/swagger-ui

Hi, I'm working on upgrading from an older version of swagger-ui to facilitate an upgrade from swagger 1.2 to 2.0. I downloaded a copy of the 2.1.8-M1 release and put it on my local development server. It loads the pet store example perfectly, but when I switch to my api listing json file at http://localhost:3000/apis/listings/api-docs.json it chokes and tells me that it's unable to load each of the listings (E.g. "Unable to read api 'speech-to-text' from path /apis/listings/speech-to-text (server returned undefined)")

Here's what my api-docs.json file looks like:

{
  "swaggerVersion": "1.2",
  "basePath": "/apis/listings",
  "apis": [
    {
      "path": "/speech-to-text",
      "description": "REST methods for IBM Speech to Text"
    },
    //...
  ]
}

I saw a bunch of CORS errors in my console, which makes no sense at all since everything is loading from the same domain.. then I realized it wasn't. Somewhere along the way, swagger is loosing the port number, so instead of loading the correct URL of http://localhost:3000/apis/listings/speech-to-text, it's loading http://localhost/apis/listings/speech-to-text and choking.

It may be something as simple as using location.hostname instead of location.host, I'll see if I can track it down and send a PR.

(This may be a regression of https://github.com/swagger-api/swagger-ui/issues/355)

P2 bug

Most helpful comment

For anyone else hitting this issue, I found a simple workaround - add useJQuery: true, to your initial new SwaggerUI() options - it swaps in jQuery instead of Shred and bypasses this bug entirely.

All 13 comments

Digging in a bit more, it looks like the underlying bug is in the Shred library, and has already been fixed in master, but it just hasn't made it into a release yet: https://github.com/pandastrike/shred/issues/60

For anyone else hitting this issue, I found a simple workaround - add useJQuery: true, to your initial new SwaggerUI() options - it swaps in jQuery instead of Shred and bypasses this bug entirely.

+1

I do not want to mess around with swagger at all, only using it. Unfortunately the Try button is still not working for me as the port specified in the url is not considered.

Workaround I found is to set basePath to :8080/api/

@fdlk please explain what you have for host and what version you're using.

@fehguy I have urls http://localhost:8080/api/v2/method1 http://localhost:8080/api/v1/method2 etc . The only way I could get the Try button to work was

host: localhost
schemes:
    - http
basePath: :8080/api/
/v2/method1:
/v1/method2:

the port should live on host, like this:

host: localhost:8080

If you do that, does it behave incorrectly?

@fehguy It behaves great, thanks for the help! (Though I could have sworn that I tried that first and it complained about an invalid hostname at the time..)

@nfriedly - almost afraid to ask, but is this still an issue?

@webron - I was affected by the issue as well and for me this is solved - no longer an issue with newer versions.

@the42 thanks for the feedback. I'll close the issue for now, but if it still exists I'll reopen.

@webron I'm not sure, I haven't been working on swagger stuff recently. I think closing this is fine for now.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

grosch picture grosch  路  75Comments

chanurahemal picture chanurahemal  路  87Comments

lmprice picture lmprice  路  104Comments

replaysMike picture replaysMike  路  120Comments

marlandy picture marlandy  路  53Comments