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

API call in no-server UI

Open peter004 opened this issue 13 years ago • 10 comments

I'm using no-server UI and its working for most part, but when I changed the API url in (lets say) "/api-docs/pet" from: http://petstore.swagger.wordnik.com/api to my APIs url, it doesn't work in "Try It Out!".

It shows the correct Request URL but no Response Body with Response Code '0'. I know the URL is correct, as in the browser URL returns the correct json!

Any thoughts why its not working?

Thank you for your time

peter004 avatar Feb 28 '13 22:02 peter004

If you have the latest version of the ui, you should get a more friendly message. Can you please confirm that you have this version?

https://github.com/wordnik/swagger-ui/tree/master/dist

fehguy avatar Mar 01 '13 04:03 fehguy

nop, I believe I had the older version got it from here: https://github.com/wordnik/swagger-core/tree/master/samples/no-server

I downloaded the latest UI (from the link above) and in index.html I changed the discoveryUrl to "http://localhost:8000/api-docs.json" when put this URl to a browser it shows the json also keeping apiKey blank: apiKey:"",

but now it say: "Can't read from server. It may not have the appropriate access-control-origin settings." ??

peter004 avatar Mar 05 '13 00:03 peter004

Use chrome developer tools and look for errors in the console. If you are reading the UI from the file system and pointing to a server which doesn't support the correct headers (see here https://github.com/wordnik/swagger-core/wiki/java-jax-rs under "Troubleshooting"), you'll get that error.

fehguy avatar Mar 05 '13 01:03 fehguy

Ahh its throwing this error: (why Origin is "http://localhost", shouldn't it suppost to be "http://localhost:8000" ?)

XMLHttpRequest cannot load http://localhost:8000/api-docs.json. Origin http://localhost is not allowed by Access-Control-Allow-Origin. localhost:1 Unable to Load SwaggerUI localhost:63 Can't read from server. It may not have the appropriate access-control-origin settings. localhost:64 Uncaught Can't read from server. It may not have the appropriate access-control-origin settings. swagger.js:133

peter004 avatar Mar 08 '13 01:03 peter004

Also: No "Access-Control-Allow-Origin: *"

$ curl -i http://localhost:8000/api-docs.json HTTP/1.0 200 OK Date: Fri, 08 Mar 2013 02:04:34 GMT Server: Apache/2.2.22 (Ubuntu) Vary: Accept-Encoding Transfer-Encoding: chunked Content-Type: text/html; charset=utf-8

{ "apiVersion":"1.0", "swaggerVersion":"1.1", "basePath":"https://localhost:8000", "apis":[ { "path":"/api-docs/v1", "description":"Operations about V1" },{ "path":"/api-docs/v2", "description":"Operations about V2" } ] }

peter004 avatar Mar 08 '13 02:03 peter004

that'll do it. Have you been able to add those headers on your server?

fehguy avatar Mar 08 '13 04:03 fehguy

yup files are there I can access them from browser like: https://localhost:8000/api-docs/v1 but its just not working with UI! and throwing this error: "Can't read from server. It may not have the appropriate access-control-origin settings."

do you have any step-by-step guide to change the api url in here? maybe I missed something, I dont know!

peter004 avatar Mar 08 '13 19:03 peter004

same problem here...

oak-tree avatar Jun 07 '13 16:06 oak-tree

@oak-tree best thing to do is use chrome, open the developer console and look for error codes. Most likely, your server doesn't have the correct CORS settings.

fehguy avatar Jun 07 '13 16:06 fehguy

@fehguy Thanks for the quick reply! I did the following https://github.com/martypitt/swagger-springmvc/issues/77 put the swagger-ui in my java-web-app. so i dont have to deal with CORS Settings

oak-tree avatar Jun 07 '13 16:06 oak-tree