Swagger UI -- Uncaught TypeError: Cannot read property 'length' of undefined

3,977 views
Skip to first unread message

Arun

unread,
Jul 2, 2014, 6:26:51 AM7/2/14
to swagger-sw...@googlegroups.com
Hi,

I am quite new to Swagger and can't get my head around it yet. 

What I am trying to do is to document our Ladbrokes API's using swagger. I am not trying to create stubs either client or server.

Using the editor available here, http://editor.swagger.wordnik.com/#/
I created a spec.json for one of the Ladbrokes API call.

Then I downloaded the latest version of Swagger UI from here, https://github.com/wordnik/swagger-ui

I have a local tomcat running where I have added the whole of Swagger UI and the spec.json into webapps/ROOT.

When I access http://localhost:8080/swagger-ui/dist/index.html I am able to see the PET sample project getting loaded.

I tried pointing to "http://localhost:8080/spec.json" and clicked explore.
In Chrome console I can see this error,
Uncaught TypeError: Cannot read property 'length' of undefined

The error is thrown because "response.apis" is null. As the apis are defined under apiDeclarations.
To be precise the apis are defined under response.apiDeclarations[0].apis

But this should be an issue with everyone, so I think I am doing something wrong, can you please help.

I am attaching you my spec.json

Thanks,
Arun
spec.json

Ron

unread,
Jul 2, 2014, 6:34:20 AM7/2/14
to swagger-sw...@googlegroups.com
Hi Arun,

The editor you mentioned is still under development and not a final product, so it may not work as expected. The resulted spec.json is not valid for usage with swagger-ui.

Documenting according to Swagger can be done either by creating static files (which the editor is meant to help with) or by using a library and integrating it with your code, that way creating the documentation dynamically.
Even though you've used the editor, is this what you're trying to accomplish? Normally, people would use the editor for a top-down way of work (creating the docs and generating code from it) but it sounds like you have an existing API.

To give you an idea of what it should look like (at the very basic level), I'd suggest going over https://github.com/wordnik/swagger-spec/wiki/Hello-World-Sample which would also explain how to deploy and run static files.

Let me know if you have any other questions.


--
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.

Arun

unread,
Jul 2, 2014, 6:47:41 AM7/2/14
to swagger-sw...@googlegroups.com
Hi Ron,

Thank you for the quick reply.

Yes, we have an existing API and implemented through Layer 7.

My thinking was to get it integrated from a documentation point of view first and then see options around doing a top-down approach.

I see that there's an editor available here, https://github.com/wordnik/swagger-editor
 Will that produce compatible specs?

Thanks,
Arun

Ron

unread,
Jul 2, 2014, 7:00:50 AM7/2/14
to swagger-sw...@googlegroups.com
I think that's the source code for the website editor you've seen. There's no editor available right now for the current spec, the one you're seeing is part of the process of the next spec.

Writing an actual specification isn't that difficult though. You can look at http://petstore.swagger.wordnik.com/api/api-docs/ and its subsequent files for a simple example (this is what you see here http://petstore.swagger.wordnik.com/).

Of course, if you have any questions feel free to ask, either here or by joining the IRC channel and asking directly there.


Reply all
Reply to author
Forward
0 new messages