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

swagger.ready is not set when running from browser #238

Closed
alycda opened this issue Feb 12, 2015 · 0 comments
Closed

swagger.ready is not set when running from browser #238

alycda opened this issue Feb 12, 2015 · 0 comments

Comments

@alycda
Copy link

alycda commented Feb 12, 2015

Hi,

I have cloned the latest version of this project, v2.1.4-M1(75ca50f), and added an index file using the example from your readme:

<!DOCTYPE html>
<html>
<head>
<script src='lib/shred.bundle.js' type='text/javascript'></script>
<script src='lib/swagger-client.js' type='text/javascript'></script>
<script type="text/javascript">
  // initialize swagger, point to a resource listing
  window.swagger = new SwaggerClient({
    url: "http://petstore.swagger.wordnik.com/api/api-docs",
    success: function() {
      if(swagger.ready === true) {
        // upon connect, fetch a pet and set contents to element "mydata"
        swagger.apis.pet.getPetById({petId:1}, function(data) {
          document.getElementById("mydata").innerHTML = data.content.data;
        });
      }
    }
  });

</script>
</head>
<body>
  <div id="mydata"> </div>
</body>
</html>

First, I get the following warnings/errors in the console:

shred.bundle.js:1726 no zlib library
shred.bundle.js:1734 no iconv library
index.html:1 XMLHttpRequest cannot load http://petstore.swagger.wordnik.com/api/api-docs. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.
swagger-client.js:548 Uncaught Can't read from server.  It may not have the appropriate access-control-origin settings.

So I change the url to http://petstore.swagger.io/v2/swagger.json, and I only get the warnings from shred (which can safely be ignored). But swagger.ready is never set and no data is output to the div.

Personally, I want to use jQuery anyway, so I added the flag useJQuery: true (as well as replacing the reference to shred with jQuery), but I still get no results.

<!DOCTYPE html>
<html>
<head>
<script src='lib/jquery-1.8.0.min.js' type='text/javascript'></script>
<script src='lib/swagger-client.js' type='text/javascript'></script>
<script type="text/javascript">
  // initialize swagger, point to a resource listing
  window.swagger = new SwaggerClient({
    url: "http://petstore.swagger.io/v2/swagger.json",
    useJQuery: true,
    progress: function(message) {
      console.log(message)
    },
    success: function() {
      if(swagger.ready === true) {
        // upon connect, fetch a pet and set contents to element "mydata"
        swagger.apis.pet.getPetById({petId:1}, function(data) {
          document.getElementById("mydata").innerHTML = data.content.data;
        });
      }
    }
  });

</script>
</head>
<body>
  <div id="mydata"> </div>
</body>
</html>

I believe this was last working with version v2.1.1-M1 (f29b091).

@alycda alycda changed the title Can't run from the browser swagger.ready is not set when running from browser Feb 12, 2015
fehguy added a commit that referenced this issue Feb 19, 2015
fehguy added a commit that referenced this issue Feb 19, 2015
Fix for #238, overflow on self-referencing models
@fehguy fehguy closed this as completed Feb 19, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants