Uncaught ReferenceError: client is not defined

1,277 views
Skip to first unread message

Nahúm Santiago Fabián

unread,
Apr 20, 2015, 5:24:17 PM4/20/15
to swagger-sw...@googlegroups.com
Hi,

Anybody have any idea how to solve the following error:

Uncaught ReferenceError: client is not defined

<script src="/lib/swagger-client.js"></script>

<script type="text/javascript">
    $(document).ready(function () {

        // initialize swagger, point to a resource listing
        window.swagger = new client.SwaggerClient({
            success: function () {
                // upon connect, fetch a pet and set contents to element "mydata"
                swagger.apis.pet.getPetById({ petId: 1 }, function (data) {
                    document.getElementById("mydata").innerHTML = JSON.stringify(data.obj);
                });
            }
        });

    });
</script>

The error is in the initialization line window.swageer = new client.SwaggerClient()


thanks in advance. 

tony tam

unread,
Apr 21, 2015, 12:26:26 AM4/21/15
to swagger-sw...@googlegroups.com
Hi, in your example, you're connecting to the wordnik api but making calls against the petstore.  Please try the following:

<script src='browser/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/api/api-docs",
    success
: function() {

     
// upon connect, fetch a pet and set contents to element "mydata"
      swagger
.apis.pet.getPetById({petId:1}, function(data) {
        document
.getElementById("mydata").innerHTML = JSON.stringify(data.obj);
     
});
   
}
 
});


</script>


<body>
 
<div id="mydata"></div>
</body>

Nahúm Santiago Fabián

unread,
Apr 21, 2015, 12:08:09 PM4/21/15
to swagger-sw...@googlegroups.com
Hi, thanks. now its working
I see that the problem was with the client word.

but dont know why there is an example in the master that throws an error.

I think they should replace this window.swagger = new client.SwaggerClient({
with this  window.swagger = new client.SwaggerClient({

Nahúm Santiago Fabián

unread,
Apr 21, 2015, 12:09:35 PM4/21/15
to swagger-sw...@googlegroups.com
CORRECTION:

I think they should replace this window.swagger = new client.SwaggerClient({
with this  window.swagger = new SwaggerClient({

Ron Ratovsky

unread,
Apr 21, 2015, 12:13:23 PM4/21/15
to swagger-sw...@googlegroups.com
I believe that's already fixed in the develop_2.0 branch.

--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
-----------------------------------------
http://swagger.io
https://twitter.com/SwaggerApi
-----------------------------------------
Reply all
Reply to author
Forward
0 new messages