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
Uncaught TypeError: Cannot read property 'definitions' of null #58
Comments
It looks like your API requires authentication. What happens if you just go to /content/api/v1/activities in a browser? |
@dblock No, I commented all authentication and autorization part and started to test. In browser the path /content/api/v1/activities gives all activities json.I am testing it in postman. And it also gives json response back when simply accessing '/content/api/v1/activities'. |
Well, the API responds with a 401, examine the network tab and see why. Could be CORS or something like that. |
:) I think you are misunderstood because of I mentioned as '1st Error: 401 Unauthorised'. I modified the description now. Actually I meant I was testing this '401 Unauthorised' functionality in the 2nd case (here I am not commented the authentication). It works well. 401 is my expected answer. But in this case also Swagger shows Unable to load Swagger ui. Atleast I am expecting some ui from swagger in 401 page also. And the real bug comes in the my 3rd test, where I commented the authentication and tested the response. Server sending the json response back and swagger shows some javascript error ( Uncaught TypeError: Cannot read property 'definitions' of null) in console. Why that? '/content/api/v1/activities' url cannot found by swagger? |
That bar at the top is NOT to test your API endpoints. It is to put the JSON endpoint of your valid OpenAPI v2. When you put a URL in that bar, Swagger UI tries to build the API calls and if the endpoint doesn't return JSON, it errors out. As you add your API calls to grape (which I assume you're using) and document them using grape-swagger, they will automatically begin populating on your documentation page as long as you're pointing to you JSON endpoint. Eventually your API will look like this and you'll be able to interact with it on the page. |
@aschuster3 Great. I totally misunderstood this may be. Now I got the idea. Thank you. Yes I am using Grape. Here I used grape-swagger-rails. My doubt is how to generate this 'Valid OpenAPI v2 JSON endpoint' to give in that top bar? Is that already generated by grape-swagger when I add 'add_swagger_documentation' as in screenshot no. 2 line no. 5? |
Ah thanks @aschuster3 I see what's happening here ;) @abhilashak the documentation endpoint should be /api/v1/swagger_doc I believe. That initial page should have all you need. Not sure what's in |
@dblock No, I given the path 'api/v1/swagger_doc' but it not works. It shows the same error: 'Unable to Load SwaggerUI'. I think 'content/swagger_doc.json' is the correct JSON Endpoint as @aschuster3 specified, as it loads well without any issue (see screenshot no.1). But it not showing my Grape API calls. Just showing
I don't know how to populate these Grape API calls that I written in swagger ui. I think it should be done by grape-swagger as we are calling 'add_swagger_documentation' method inside base api file (Where we mount all the Grape apis) |
Yep, grape-swagger auto-generates the Valid OpenAPI v2 JSON endpoint. You should be able to check that the behavior is correct by visiting You can take a look over at grape-swagger's instructions for configuring to know what the default behavior is. By looking at your first picture in your original question, it appears that you are navigating to the correct path for the JSON. After verifying all of that, the problem might be arising from how you're mounting your APIs. require 'grape-swagger'
module ContentManager
class API < Grape::API
# All of your mount statements and logic
add_swagger_documentation(hide_documentation_path: true)
end
end I think that should solve your problem! |
@aschuster3 Wahhh Super great ...Thank you so much 💯 That was the issue!! When I was adding the method 'add_swagger_documentation' I thought It will fetch all the API calls mentioned in that API class. But we are mounting the calls later. So the method cannot find the APIs! When it was not working, I thought we should give each api urls in that top box to make it work!! Haha. even though it doesn't make sense. Just a Developer thought! I added the method above the mount calls, just for nice code! Guys finally it looks like this: Thank you, @dblock @aschuster3 👍 |
Great! I'm gonna go ahead and close this issue. Glad I could help! |
Excellent detective work @aschuster3! |
Hi authors,
I followed the 'grape-swagger-rails' documentation and the /swagger_doc.json initial page loads fine from swagger ui as follows:
But apart from this page all other requests, I am getting one of the 2 errors
1st Error: Unable to Load SwaggerUI
(I am testing '401 Unauthorised' page works or not with swagger documentation)
For this response Swagger ui is not loading and showing the following error:
Unable to Load SwaggerUI
apidoc:50 401 : http://g_m.lvh.me:3000/content/api/v1/activities/23
2nd Error: Uncaught TypeError: Cannot read property 'definitions' of null
(I am testing '200 Created' page works or not with swagger documentation)
For all other successful requests (200) where I am sending json response back, occurs the following error:
Uncaught TypeError: Cannot read property 'definitions' of null
NOTE: I implemented this on a Rails Engine that is mounted on '/content'
I tried a lot, feeling that any configuration I missed to include all these urls in swagger ui. But nothing I can found. Reply me if you have a solution for this else please fix this issue as soon as possible.
The text was updated successfully, but these errors were encountered: