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

uncaught TypeError in dist demo

Open dhalperi opened this issue 12 years ago • 7 comments

To reproduce (using Chrome latest):

  • Using latest swagger-ui master (6b400b22fee55a7a861ac5ba65c2057ca0398168)
  • Open dist/index.html
  • Choose Pet and then GET > /pet/{petId}
  • enter an invalid pet ID to get the server to throw a 404
  • infinite throbbing.gif, no change to webpage.

In the developer tools I see that the request did indeed return a 404. The console also shows the following error:

Uncaught TypeError: Cannot read property 'Content-Type' of undefined swagger-ui.js:1821
OperationView.showStatus swagger-ui.js:1821
OperationView.showErrorStatus swagger-ui.js:1737
SwaggerRequest.obj.on.error swagger.js:1086
res.error swagger.js:1193
EventEmitter.emit shred.bundle.js:1408
emit shred.bundle.js:1189
(anonymous function) shred.bundle.js:1208
setBodyAndFinish shred.bundle.js:1815
(anonymous function) shred.bundle.js:1832
EventEmitter.emit shred.bundle.js:1388
Response.handle shred.bundle.js:2715
xhr.onreadystatechange shred.bundle.js:2584

dhalperi avatar Jan 27 '14 06:01 dhalperi

I dug in a little bit into the problem, and found that changing headers = response.headers; to headers = response._headers; on the line above this eliminated that particular error. Perhaps this is old code not updated to a new format for the response object?

I changed one other occurrence of response.headers to response._headers and then I got this output: but it is clearly still wrong.

screen shot 2014-01-26 at 10 35 25 pm

dhalperi avatar Jan 27 '14 06:01 dhalperi

(FYI:) And I followed the "install npm, handlebars, recompile" process and though it did change the various javascript files, it did not fix this problem.

dhalperi avatar Jan 27 '14 06:01 dhalperi

have the exact same problem

andyxukq avatar Jan 27 '14 13:01 andyxukq

Thanks--this was an issue in swagger-js introduced when abstracting the HTTP client to support IE8. It is fixed in this patch:

https://github.com/wordnik/swagger-js/commit/a0a39c14d8667742916093759f14b041538145c9

And also pushed to swagger-ui master.

fehguy avatar Jan 27 '14 15:01 fehguy

Confirmed! Fix works. thanks

dhalperi avatar Jan 27 '14 18:01 dhalperi

I am getting this same error while pointing to my api, the ../api-docs endpoint responds as expected but swagger ui never displays the page but a message: "fetching resource list: http://localhost:8080/myapp/api-docs"

I see that you had a fix on Jan 27 but it seems it hasn't be applied to the code in dist folder.

I downloaded the swagger.js with the fix, but the problem continues with a different message. I am using swagger-jersey2-jaxrs_2.10 version: 1.3.5 which seems to be the most recent.

By debugging I found that the line failing is:

for (_i = 0, _len = _ref.length; _i < _len; _i++) {

with the message: Uncaught TypeError: Cannot read property 'length' of undefined

_ref = response.apis;

So I assume that it expects to find an apis property in the JSON in the response, but the response from my api-docs endpoint is just:

{"apiVersion":"1.0.0","swaggerVersion":"1.2"}

In my configuration I am setting apiVersion programatically but I cannot find any property for setting apis.

swaggerConfig.setBasePath("http://localhost:8080/synthetic"); swaggerConfig.setApiVersion("1.0.0");

....UPDATE:

Never mind, while updating my methods I deleted the @ApiOperation and @ApiResponses annotations, I just added that again and it works like a charm.

raspacorp avatar Jun 13 '14 00:06 raspacorp

great

fehguy avatar Jun 13 '14 06:06 fehguy