API call in no-server UI
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
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
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." ??
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.
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
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" } ] }
that'll do it. Have you been able to add those headers on your server?
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!
same problem here...
@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 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